I’m working on a university assignment to improve a game engine. The code we’ve been given stores 3D mesh objects inside a Frame class, which describes the bounding volume for the mesh. The problem is the engine has to handle collisions between different types of bounding volumes, such as spheres, AABBs, and OABBs.
The way the given Frame class works is by having data members for all the different bounding volume types and a type ID to indicate which one it’s using. Given any two Frame objects the calling code requests their type IDs and works out which collision method to use from there.
The first thing I did was create subclasses for the various BV types, so only the memory the object needs is allocated. Now I’m trying to figure out a better way for the calling code to check for a collision between two of these subclasses. Having them return a type ID just seems like bad practice. Is there a standard way of doing this?
What you’re asking about is called double-dispatch.