Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

Thanks.

share|improve this question

1 Answer 1

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. –  Saurabh S 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

 
discard

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.