59 StackElem(KdNode *anode, const Float &at, const Vector3 &apb): |
59 StackElem(KdNode *anode, const Float &at, const Vector3 &apb): |
60 node(anode), t(at), pb(apb) {}; |
60 node(anode), t(at), pb(apb) {}; |
61 }; |
61 }; |
62 |
62 |
63 // ---------------------------------------- |
63 // ---------------------------------------- |
64 |
|
65 void Container::addShape(Shape* aShape) |
|
66 { |
|
67 shapes.push_back(aShape); |
|
68 if (shapes.size() == 0) { |
|
69 /* initialize bounding box */ |
|
70 bbox = aShape->get_bbox(); |
|
71 } else { |
|
72 /* adjust bounding box */ |
|
73 BBox shapebb = aShape->get_bbox(); |
|
74 if (shapebb.L.x < bbox.L.x) bbox.L.x = shapebb.L.x; |
|
75 if (shapebb.L.y < bbox.L.y) bbox.L.y = shapebb.L.y; |
|
76 if (shapebb.L.z < bbox.L.z) bbox.L.z = shapebb.L.z; |
|
77 if (shapebb.H.x > bbox.H.x) bbox.H.x = shapebb.H.x; |
|
78 if (shapebb.H.y > bbox.H.y) bbox.H.y = shapebb.H.y; |
|
79 if (shapebb.H.z > bbox.H.z) bbox.H.z = shapebb.H.z; |
|
80 } |
|
81 }; |
|
82 |
|
83 Shape *Container::nearest_intersection(const Shape *origin_shape, const Ray &ray, |
|
84 Float &nearest_distance) |
|
85 { |
|
86 Shape *nearest_shape = NULL; |
|
87 ShapeList::iterator shape; |
|
88 for (shape = shapes.begin(); shape != shapes.end(); shape++) |
|
89 if (*shape != origin_shape && (*shape)->intersect(ray, nearest_distance)) |
|
90 nearest_shape = *shape; |
|
91 return nearest_shape; |
|
92 } |
|
93 |
64 |
94 KdNode::~KdNode() |
65 KdNode::~KdNode() |
95 { |
66 { |
96 if (isLeaf()) |
67 if (isLeaf()) |
97 delete shapes; |
68 delete shapes; |