In my game attempt, I render several objects that can collide. The collision detection is not dynamic, but only per-frame, so defects can occur. Anyway, I need to share a collision object among many classes, so they can place collision information into it. How could I go about this. I’ve had the following ideas:
a mostly static base class of the classes supporting collision
making a single instance of the collision class, then sharing it with all the classes at their creation time
making collision data structures static, then instantiating the collision class with a reference to it, the collision class is the base class of all classes that need to handle collision
Which approach should I take? Maybe there are better ways?
I got a lot of help with architecting my collision engine by examining who the bullet library was put together: www.bulletphysics.com
The code is pretty accessible.
They have a collision world object that contains all objects that can interact. They have a nice hierarchy of different collision shapes that all share a common base class and implement the needed interfaces for narrow and broadphase collision.
I still haven’t totally ironed out how to cross talk between my graphics engine and the physics engine yet. For now they communicate just by passing a local to world transform buffer…
I am in the process of implementing my own physics and collision ‘engine’. I don’t need any sophistication and doing my own allows be to avoid possible bottlenecks in bullet or some other physics engine.
I am currently experimenting with the hashing collision approach, where you hash aabbs and then place them into the hash table.