Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on my own quadtree for use in games for physics (collision detection to be exact) but am unable to move an object from one node to another node.

What I'm doing is if some object is to be moved, I'm deleting it from its old position and adding a new object (with same property, such as width and height) to the new position. Is my approach correct or is there any other optimized process to do same?

The problem I'm facing is that if I move an object from node 0 to node 3 (both node being children of, for ex., root node) the root node container(I'm using std::vector) gets the object but it is not updated in the node 3's container.

Any solution to my problem? Though would be happy to try some other method too.


share|improve this question
up vote 2 down vote accepted

You should be working with references (or pointers depending on your language) ... moving something should almost never require one object to be destroyed and another created.

share|improve this answer
As an example Double Linked Lists use pointers to the next an previous objects in the list so you can interchange them easily, this comes with it's own disadvantages though, like not being able to directly access an element. – Jonathan Connell Jun 15 '11 at 14:43
Well I'm programming in C++ and using pointers for nodes, the prob I'm having is updating the child nodes with the (moved) object though. Anyways giving it a try again, without deleting the obj, like you said. – saurabhs Jun 15 '11 at 15:35
Just to be clear, you will still have to remove the object from the prior node ... but since you're using pointers you can just zero/null out that pointer rather than killing the underlying object :-) – Joel Martinez Jun 15 '11 at 17:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.