Sign in to follow this  

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

This topic is 3591 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
{
public:


    cQuadTreeNode(void):m_pParentNode(NULL),NodeType(NODE_TYPE)
	{
		memset(m_pChildNode,NULL,sizeof(m_pChildNode));

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

		NodeCount++;//counts the nodes
	}
	~cQuadTreeNode(void){}


	//----------------------------------------------------------------
	//tells us what type of node we are 
	//-------------------------------------------------------------------
	enum ENODETYPE{ LEAF_TYPE = 0,NODE_TYPE};

	//------------------------------------------------------
	//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_tree(t.left);
delete_tree(t.right);

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



DeleteNode(StartNode);









void cQuadTreeNode::DeleteNode( Node *node)
{
if(node == NULL)
return;
DeleteNode(node->m_pChildNode[0]);
DeleteNode(node->m_pChildNode[1]);
DeleteNode(node->m_pChildNode[2]);
DeleteNode(node->m_pChildNode[3]);

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

This topic is 3591 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this