76 dbgmsg(1, "* building octree\n"); |
77 dbgmsg(1, "* building octree\n"); |
77 root = new OctreeNode(); |
78 root = new OctreeNode(); |
78 ShapeList::iterator shape; |
79 ShapeList::iterator shape; |
79 for (shape = shapes.begin(); shape != shapes.end(); shape++) |
80 for (shape = shapes.begin(); shape != shapes.end(); shape++) |
80 root->addShape(*shape); |
81 root->addShape(*shape); |
81 |
|
82 root->subdivide(bbox, max_depth); |
82 root->subdivide(bbox, max_depth); |
83 built = true; |
83 built = true; |
84 } |
84 } |
85 |
85 |
86 |
86 |
194 if (!(tx1 < 0.0 || ty1 < 0.0 || tz1 < 0.0)) |
194 if (!(tx1 < 0.0 || ty1 < 0.0 || tz1 < 0.0)) |
195 { |
195 { |
196 if (node->isLeaf()) |
196 if (node->isLeaf()) |
197 { |
197 { |
198 ShapeList::iterator shape; |
198 ShapeList::iterator shape; |
199 register Float mindist = max3(tx0,ty0,tz0); |
199 //register Float mindist = max3(tx0,ty0,tz0); |
200 /* correct & slow */ |
200 register Float dist = min(nearest_distance, min3(tx1,ty1,tz1)); |
201 //Float dist = min(min3(tx1,ty1,tz1),nearest_distance); |
|
202 /* faster */ |
|
203 register Float dist = nearest_distance; |
|
204 for (shape = node->shapes->begin(); shape != node->shapes->end(); shape++) |
201 for (shape = node->shapes->begin(); shape != node->shapes->end(); shape++) |
205 if (*shape != origin_shape && (*shape)->intersect(ray, dist) && dist >= mindist) |
202 if (*shape != origin_shape && (*shape)->intersect(ray, dist)) |
206 { |
203 { |
207 nearest_shape = *shape; |
204 nearest_shape = *shape; |
208 nearest_distance = dist; |
205 nearest_distance = dist; |
209 } |
206 } |
|
207 if (nearest_shape != NULL) |
|
208 return nearest_shape; |
210 } |
209 } |
211 else |
210 else |
212 { |
211 { |
213 txm = 0.5 * (tx0+tx1); |
212 txm = 0.5 * (tx0+tx1); |
214 tym = 0.5 * (ty0+ty1); |
213 tym = 0.5 * (ty0+ty1); |