I dont think this is a problem thats going to be solved with a quick one line fix. The way you're doing things is somewhat fubar'd and is going to need to be addressed on a bigger scale.
I'd first start off with Palidine's suggestion on the OctTreeNode object. You can use a linked list for the list of childnodes, but thats just going to make things unnecessarily complicated.
I'd personally use:
class OctTreeNode{public: int numChildren; OctTreeNode *children[8];}
the constructor would look something like this
OctTreeNode::OctTreeNode(){ for (x=0; x<8; x++) { children[x]=NULL; }}
and the destructor:
OctTreeNode::~OctTreeNode(){ for (x=0; x<8; x++) { if (children[x]) { delete children[x]; children[x]=NULL; } }}
The OctTree class at its simplest level would look like this:
class OctTree{public: OctTreeNode *root;};
Don't forget to set root to NULL in the constructor!
then to create the tree and initilize the root node (which is basically the node that encapsulates your entire world) you'd do:
OctTree *tree = new OctTree;tree->root = new OctTreeNode(whateverparamsyouwanttopass);
where "whateverparamsyouwanttopass" would prolly be the min and max coordinates of the bounding box.
Then to build the tree:
OctTree::BuildOctTree(OctTreeNode *node){ //Here you'd split the world up and figure out what polygons go where. for (x=0; x<8; x++) { children[x]= new OctTreeNode (whateverparamsyouwanttopass); BuildOctTree(children[x]); }}
You may want to pass in a list of polygons to the BuildOctTree method, it really depends off how you're managing the dataset.
Finally after creating the root node above you'd basically call:
//recursive methodBuildOctTree(root); //maybe pass in the polylist here...
or
//recursive methodtree->BuildOctTree(tree->root); //maybe pass in the polylist here...
depending on where you actually call the BuildOctTree method.
Rendering the tree would be something like the following"
tree->RenderOctTree(tree->root); //recursive method
and the method to go along with it"
OctTree::RenderOctTree(OctTreeNode *node){ //Here you'd set various renderstates and stuff or whatever for (x=0; x<8; x++) { RenderOctTree(children[x]); }}
If you wanted to destroy the tree:
if (tree->root) { delete tree->root; tree->root = NULL;}delete tree;tree = NULL;
This, due to the OctTreeNode destructor would set up a chain reaction that would destroy and free up the memory for every node in the octree.
Once you have a base foundation like this up and running, you can slowly start adding the DirectX, vertexbuffer and bounding box stuff back in.
This is by no means the best or most efficient way to do this, but hopefully it's enough to help you solve your problems and get you going.
-=[ Megahertz ]=-
Edit, seems using i as an array subscript was causing problems with italics.
[edited by - Megahertz on March 27, 2004 5:08:22 AM]