equal
deleted
inserted
replaced
|
1 #include "common.h" |
|
2 #include "container.h" |
|
3 |
|
4 void Container::addShape(Shape* aShape) |
|
5 { |
|
6 shapes.push_back(aShape); |
|
7 if (shapes.size() == 0) { |
|
8 /* initialize bounding box */ |
|
9 bbox = aShape->get_bbox(); |
|
10 } else { |
|
11 /* adjust bounding box */ |
|
12 BBox shapebb = aShape->get_bbox(); |
|
13 if (shapebb.L.x < bbox.L.x) bbox.L.x = shapebb.L.x; |
|
14 if (shapebb.L.y < bbox.L.y) bbox.L.y = shapebb.L.y; |
|
15 if (shapebb.L.z < bbox.L.z) bbox.L.z = shapebb.L.z; |
|
16 if (shapebb.H.x > bbox.H.x) bbox.H.x = shapebb.H.x; |
|
17 if (shapebb.H.y > bbox.H.y) bbox.H.y = shapebb.H.y; |
|
18 if (shapebb.H.z > bbox.H.z) bbox.H.z = shapebb.H.z; |
|
19 } |
|
20 }; |
|
21 |
|
22 Shape *Container::nearest_intersection(const Shape *origin_shape, const Ray &ray, |
|
23 Float &nearest_distance) |
|
24 { |
|
25 Shape *nearest_shape = NULL; |
|
26 ShapeList::iterator shape; |
|
27 for (shape = shapes.begin(); shape != shapes.end(); shape++) |
|
28 if (*shape != origin_shape && (*shape)->intersect(ray, nearest_distance)) |
|
29 nearest_shape = *shape; |
|
30 return nearest_shape; |
|
31 } |