-
Notifications
You must be signed in to change notification settings - Fork 0
/
hittable_list.h
38 lines (29 loc) · 944 Bytes
/
hittable_list.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 HITTABLE_LIST_H
# define HITTABLE_LIST_H
#include "hittable.h"
#include <memory>
#include <vector>
class hittableList : hittable {
public:
hittableList() {}
explicit hittableList(std::shared_ptr<hittable> object) { add(object); }
void clear() { objects.clear(); }
void add(std::shared_ptr<hittable> object) { objects.push_back(object); }
virtual bool hit(const ray& r, double tMin, double tMax, hitRecord& rec) const override;
private:
std::vector< std::shared_ptr<hittable> > objects;
};
bool hittableList::hit(const ray& r, double tMin, double tMax, hitRecord& rec) const {
hitRecord tmpRec;
bool hitAnything = false;
auto closestSoFar = tMax;
for (const auto& object : objects) {
if (object->hit(r, tMin, closestSoFar, tmpRec)) {
hitAnything = true;
closestSoFar = tmpRec.t;
rec = tmpRec;
}
}
return hitAnything;
}
#endif