Collision System – Update I
Before I can actually start coding something for the collision system there were two main considerations that I had to make. First what kind of bounds should I use as my colliders. I have a choice (based on the amount of time I have) between Axis aligned bounding box (AABB) but in 3D and, sphere colliders.
The first hurdle was how to calculate the coordinates for my collider bounds. Turns out this is pretty easy to extrapolate from the mesh coordinates for the game object. For a sphere collider, averaging out all the vertices of the mesh gives the center of the sphere and, distance between this center and the furthest vertex gives the radius. As for an AABB, getting the minX, minY, minZ and maxX, maxY and maxZ from the vertices makes it easy enough to get the bounding coordinates.
Now the question is which one of these to use? A sphere collider will require fewer and less complicated calculations for collision detection and subsequent resolution whereas for an AABB it will be much more complicated. On the other hand a sphere collider is much less accurate than an AABB.
Based on these considerations and on the time I have for this project, I’ve decided to go with sphere colliders for my collisions. Doing AABB would be more interesting but the focus of this project is to create a something useful that can be used by other people in the class and I’d rather focus on that.
The other thing I had to decide was what kind of interface I will use to expose functionality for the collision system. I could have a game object inherit from a collider object and have that object then override the function which fires when a collision occurs for that object. Or I could go the component route and have the game object declare a pointer to a collidable object. To detect collisions then I would have to use function pointers (as JP suggested in class) which sounds promising.
I’m still on the fence about this one. But this does not sound super complicated to do either way and should be easy enough to change I think it necessary.
I will be using the STL smart pointers to keep track of my collidable object references.
P.S I might also look into using the EASTL (open source STL made by EA games) as a fun side challenge.