-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththings.h
38 lines (28 loc) · 804 Bytes
/
things.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef THINGS_H
#define THINGS_H
#include <vector>
#include "thing.h"
class Things : public Thing {
public:
Things() {}
Things( std::shared_ptr<Thing> thing ) { add( thing ) ; }
void clear() { things_.clear() ; }
void add( std::shared_ptr<Thing> thing ) { things_.push_back( thing ) ; }
virtual bool hit( const Ray& ray, double tmin, double tmax, Binding& binding ) const override ;
private:
std::vector<std::shared_ptr<Thing>> things_ ;
} ;
bool Things::hit( const Ray& ray, double tmin, double tmax, Binding& binding ) const {
Binding buffer ;
bool shot = false ;
auto tact = tmax ;
for ( const auto& thing : things_ ) {
if ( thing->hit( ray, tmin, tact, buffer ) ) {
shot = true ;
tact = buffer.t ;
binding = buffer ;
}
}
return shot ;
}
#endif // THINGS_H