1: NewtonCollision requires an unique ID when being constructed. A manager is a good place to put the ID seed.
2: Collisions can be reused in different bodies.
First of all, I already have an convex mesh manager, from which a convex mesh can be fetched from a name string.
An NewtonCollision is created from an convex mesh and a offset matrix. So a collision can be uniquely keyed by a name and a matrix. I can define a key class to organize collisions into a std::map.
So I can use something like this:
- Code: Select all
class CollisionKey {
string name;
Vector3 position;
Quaternion orientation;
}
class Manager {
public:
NewtonCollision* getOrCreateCollision(string& name, Vector3& position, Quaternion& orientation);
protected:
std::map<CollisionKey,int> collisionIDs;
std::map<int,NewtonCollision*> collisions;
}
Then the problem comes: How can I cope with CompoundCollision?