Hello,
not so much a math/physic than rather a code design oriented problem. Give a simple system for checking collisions, nothing fancy, only "does body A touch body B right now", whats a good solution for implementing a system where you can test any two shapes, without knowing what they are (so I can compare two ICollisionShape-Pointer e.g.)? Given that there is a known implementation for those two bodies, otherwise simply no collision is reported. I'm not very satisfied with my current solution, so I'm looking for ways to improve/totally new ways:
class IVolume
{
public:
virtual ~IVolume(void) {}
virtual bool IsInside(const IVolume& volume) const = 0;
virtual bool WithBox(const AABB& box) const { return false; }
virtual bool WithOBB(const OBB& box) const { return false; }
virtual bool WithSphere(const Sphere& sphere) const { return false; }
virtual bool WithHeightfield(const Heightfield& field) const { return false; }
virtual bool WithTriangle(const Triangle& triangle) const { return false; }
};
So that is the actual interface I'm using, which has a lot of methods for certain shapes already defined. I'll show you why (let me add this is one of the points that annoy me the most):
bool AABB::IsInside(const IVolume& volume) const
{
return volume.WithBox(*this);
}
Thats the poorly titled "IsInside" method, which checks collision between two shapes. Now thats the only way I found to being able to achieve such an each vs. any - collision: Overloading a generic method, which can be used on any shape and takes any shape, can call the correct method on the unkown shape, to pick the correct collision. Clever, huh? Well...
While this at least doesn't need RTTI, it still bums me. First of all, I have to implemented a new method in the interface for every implementation of it. Eww. Also, I potentially have to dublicate the collision implementation (AABB-OBB is different than OBB-AABB in that case, though I can get rid of that by a seperate file). So, any ideas or concrete examples how to implement this more extendable/faster (didn't I hear something about virtual being bad at this low level of "phyiscs" for caching behaviour? *ducks before getting hit for premature optimization-ism*)? Anything would be welcome!