-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroups.cpp
More file actions
41 lines (33 loc) · 1.1 KB
/
Copy pathgroups.cpp
File metadata and controls
41 lines (33 loc) · 1.1 KB
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
39
40
41
#include "groups.h"
#include "intersection.h"
Group::Group(const Material &material) : Shape(material) {}
std::vector<Intersection> Group::local_intersects(const Ray &local_ray) const {
if (!bounds_of().intersects(local_ray)) {
return std::vector<Intersection>();
}
std::vector<Intersection> intersections;
for (auto s : child) {
std::vector<Intersection> s_intersect = s->intersects(local_ray);
intersections.insert(intersections.end(), s_intersect.begin(),
s_intersect.end());
}
std::sort(
intersections.begin(), intersections.end(),
[](const Intersection &a, const Intersection &b) { return a.t < b.t; });
return intersections;
}
RayVector Group::local_normal_at(const RayPoint &, const Intersection *) const {
throw std::logic_error(
"Method local_normal_at should never be called on a Group directly.");
}
void Group::add_child(Shape *shape) {
child.push_back(shape);
shape->parent = this;
}
BoundingBox Group::bounds_of() const {
BoundingBox box;
for (auto s : child) {
box.add(s->parent_space_bounds_of());
}
return box;
}