Jump to content
  • Advertisement
Sign in to follow this  

dynamic object in oct/qt?

This topic is 879 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

i have a simple scene graph,  which can hold dynamic or static object.

If i place the object into the oct/qt , how to effective find which oct/qt node an dynamic object is attached when the object move?

I know a slow implementation is to detach the object from where it attach and insert to the tree again..

Edited by poigwym

Share this post

Link to post
Share on other sites

Probably your implementation is slow because you allocate / deallocate the memory for nodes?

Just a guess, but if you use a preallocated pool of fixed size memory the problem may go away (but it's some additional work).


To find nodes to delete, you can decrease a content counter in the leaving object node and its parents.

Detach all nodes from the tree where the counter hits zero.


To find nodes to create, first find the closest existing mode and create new nodes as you go, that can be pretty fast:

QuadTreeNode *node = quattree.rootNode;
for (int level = quattree.rootLevel; level > objectTargetLevel; level--) // assuming the object already knows the tree level it wants to go
int childIndex = ( ((object.x >> level)&1) | (((object.y >> level)&1)<<1); // find child assuming integer coords and consistent ordering of children in space
if (!node->childPointers[childIndex]) quattree.CreateChild (node, childIndex);
node = node->childPointers[childIndex];
AddObject (node, object);
Edited by JoeJ

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!