I’m extending the code in an octree I wrote for my graphics engine to have the ability to return all pairs of intersecting objects (by axis-aligned box) for use in a physics engine I’m working on. The octree can contain data elements at non-leaf nodes (i.e. so that data overlapping two leaves is stored in those leaves parent, etc.). This means that only one node ever contains a data element at a time.
The obvious way of figuring out all of the pairs seemed to be:
1. Start at the root node
2. Go through every element in the node and intersect with elements in node (doing smart so we don't duplicate intersection tests).
3. Test every element in the node with all of the elements in the node chain back up to the root
4. Go to #2 with every child node of the current node
Hopefully I explained it well enough. The algorithm as described works, and is faster than brute force, and faster than doing an octree query for each object in the scene to see which things it intersects with.
My question is whether or not there better approaches to this when using an octree? (I’m not interesting any of the sweep and prune strategies that exist for collision detection).