Original Post
I've got a quadtree add / removing working but now I don't get how to effectively move objects / check for collisions with other objects. To Add: Does it fit into the current node (start at the root): - Yes: return check on all of my children. - No: Add it here. To Remove: Every object has a pointer to it's node, then I just remove it from the list and re-add it from the tree. This is how I update the object's position in the tree. Add / Remove seems to work just fine. Now I need to iterate through all the objects for their collision checks but I don't get why it's any faster. Let's say Object A is in the root node's list (it's right in the centre of the map). Now let's say Object B is in the root node's northwest node's list.
|
- |
|B| |
- -----
| |
---| A |-----
| |
---
|
|
|
(hope this turned out)
Object A could very well be touching Object B, but if I'm only looking at Object A's node's object list, I'm never going to see Object B cuz its in one of its children. So for every object, you gotta find every node that that object could be touching (if you're in the root, that's every other single node). There's no way that's more efficient then just looping through every object after you do all the calculations and stuff to figure out what nodes this node could be touching. I gotta be missing something fundamental here cuz this just doesn't make sense. Please help :(