• Advertisement
Sign in to follow this  

How do I delete my QuadTree (Works now) 1 more Question left

This topic is 3688 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, this is my first quadtree here quadtree.h

class cQuadTreeNode


		Bounds.bottom = Bounds.left = Bounds.right = Bounds.top = 0;

		NodeCount++;//counts the nodes

	//tells us what type of node we are 

	//public members only
	cQuadTreeNode *m_pChildNode[4];
	cQuadTreeNode *m_pParentNode;
	ENODETYPE NodeType;//branch or leaf
	RECT Bounds;//the area this node contains
	static DWORD NodeCount;//howmany nodes we have

};//end class cQuadTreeNode

this is my node type and I allocate the first like this RECT mapsize{0,0 256,256}; CreateNode(StartNode ,rect); rectdivided = 4 quads of this rect CreateNode(StartNode->m_pChildNode[0],rectdivided); so on recursive What way should I delete them I only have StartNode [Edited by - ankhd on February 14, 2008 8:24:41 PM]

Share this post

Link to post
Share on other sites
Look up depth-first trasveral. Using a recursive function, you can delete a tree as easy as this (for a binary tree, same difference for quad tree).

void delete_tree( tree& t ) {

delete t;

Share this post

Link to post
Share on other sites
I have spent the last 3 days looking up quadtrees and not one say any thing about deleting or adding .

Im think I may have to make a list of all node pointer and just delete that be easy. or is this what I should do


void cQuadTreeNode::DeleteNode( Node *node)
if(node == NULL)

delete node;

is that all it needs

[Edited by - ankhd on February 14, 2008 8:41:01 PM]

Share this post

Link to post
Share on other sites
Ok that seam to work.

New question.
If my terrain is 256 X 256 and it has a vertex distance of dx = 20 , dz = 20

do I feed in a Rect(0,0, 256, 256) to the quadtree or do I send in RECT(0,0,256 *dx, 256 * dz) as the maps size.

found some things out testing the quadtree?
I think I will need the DX and DZ added to the map size or when moving object I would need to convert the objects pos into QuadTree Space to see if the object leave this leaf. Does this sound right.

[Edited by - ankhd on February 15, 2008 4:17:46 AM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement