src/octree.cc
branchpyrit
changeset 103 3b3257a410fe
parent 95 ca7d4c665531
equal deleted inserted replaced
102:de3e9ea18f56 103:3b3257a410fe
    24  * THE SOFTWARE.
    24  * THE SOFTWARE.
    25  */
    25  */
    26 
    26 
    27 #include "octree.h"
    27 #include "octree.h"
    28 
    28 
       
    29 const int Octree::MAX_DEPTH = 10;
       
    30 
    29 OctreeNode::~OctreeNode()
    31 OctreeNode::~OctreeNode()
    30 {
    32 {
    31 	if (isLeaf())
    33 	if (isLeaf())
    32 	{
    34 	{
    33 		leaf = leaf^1; // zero leaf bit
    35 		leaf = leaf^1; // zero leaf bit
    99 	dbgmsg(1, "* building octree\n");
   101 	dbgmsg(1, "* building octree\n");
   100 	root = new OctreeNode();
   102 	root = new OctreeNode();
   101 	ShapeList::iterator shape;
   103 	ShapeList::iterator shape;
   102 	for (shape = shapes.begin(); shape != shapes.end(); shape++)
   104 	for (shape = shapes.begin(); shape != shapes.end(); shape++)
   103 		root->addShape(*shape);
   105 		root->addShape(*shape);
   104 	root->subdivide(bbox, max_depth);
   106 	root->subdivide(bbox, MAX_DEPTH);
   105 	built = true;
   107 	built = true;
   106 }
   108 }
   107 
   109 
   108 
   110 
   109 /*******************************************************
   111 /*******************************************************
   153 {
   155 {
   154 	/* if we have no tree, fall back to naive test */
   156 	/* if we have no tree, fall back to naive test */
   155 	if (!built)
   157 	if (!built)
   156 		return Container::nearest_intersection(origin_shape, ray, nearest_distance);
   158 		return Container::nearest_intersection(origin_shape, ray, nearest_distance);
   157 
   159 
   158 #ifdef MSVC
   160 	OctreeTravState st[MAX_DEPTH+1];
   159 	// MSVC wants constant expression here... hope it won't overflow :)
       
   160 	OctreeTravState st[20];
       
   161 #else
       
   162 	OctreeTravState st[max_depth+1];
       
   163 #endif
       
   164 	OctreeTravState *st_cur = st;
   161 	OctreeTravState *st_cur = st;
   165 
   162 
   166 #	define node	st_cur->node
   163 #	define node	st_cur->node
   167 #	define tx0	st_cur->tx0
   164 #	define tx0	st_cur->tx0
   168 #	define ty0	st_cur->ty0
   165 #	define ty0	st_cur->ty0