Two things should be said to preface this topic:
1. This question really pertains to any spatial partitioning data structure I can think of using, but currently it is the octree that's giving me trouble so I'll just go with that.
2. This is NOT a question about how octrees are implemented in order to achieve collision detection. It is about types stored in the octree and resolving collisions after the fact. I saw similar questions while googling and the answers deteriorate to that. All functionality regarding that is all right in my implementation (minus some needed optimization).
My current setup and issues:
Octree stores "SphereHull*", pointers to a culling data structure I use most often. This sphere hull is a member of any actor that wants to use the octree. Sphere hulls only are inserted into the octree, with their own transforms (that update when parents move) and they signal the parent if collision moved them, making the parent GameObject move accordingly. This is a lot of back and forth copying and is error prone if you forget to do it. Seems inelegant to me.
This is the first issue - I was squeamish about virtual functions in an octree itself so I went and made it SphereHull only which is ok for now but I'm not sure it will hold up, for reasons explained below. Actor itself CAN store any hull (using base pointer to Hull* class) but I can't use anything else with my octree yet. :(
Motivation to change it:
Octree then goes through all that jazz every frame, finds matching pairs and executes a fixed, static function on both (moves them apart). It is very rudimentary because it was tacked on as an afterthought when the primary challenge was to get the octree working. Basically - it's good that it's type agnostic but also it's really “stupid” and can't do anything yet but move items apart if they collide.
Now I wanted to start using it for light-to-object assignment, by intersecting light volumes with drawable items. Obviously, I do NOT want to collide lights in the same way… I must have a way to resolve different types of collisions (not just this, also projectiles, non-blocking trigger zones etc…) with different callbacks. It seems that virtual functions (or similar mechanisms) are the best way.
Proposed resolution:
I saw another implementation where every type that we want to insert into the octree has a function to resolve it's insertion into a node that it can override (base class OctreeMember ). This would let me basically use any of the hulls I want instead of sphere hulls only, big plus. It would also let me implement resolution callbacks on each type (also override OnCollide(HitResult)). It also doesn't require the often cumbersome updates of hull and parent transforms separately, it's all in one place.
The “please hep” section:
Is this how one would approach it? Use an OctreeMember interface (or whatever you would name it). I can then override this for every hull type quite easily as I have all the intersection tests programmed already, and use virtual calls to insert anything.
Also, should the stored type, whatever it is, contain the pointer to it's parent spatial node for easy removal? Right now I'm doing a search from _root for it first which is really wasteful and I think the node pointer is the right way.