Essentially what I'd like to do is simply create a couple of collidable triangle meshes and hook into the collision event with my own handler. It seems as though this should be very easy with BEPU, but I feel like I'm doing something wrong. Currently what I'm doing is after loading my graphics model, I load a separate mesh representing the collision model, extract its vertices and indices, create a MobileMeshShape out of them, create a MobileMeshCollidable out of that, and then an Entity out of that. Then I add a collision handler to it and add it to the Space:
Code: Select all
private Entity _physicsMesh;
void LoadContent()
{
Vector3 [] verts;
int [] inds;
Model physModel = EngineManager.ContentManager.Load<Model>(_phyicsModelFilename);
TriangleMesh.GetVerticesAndIndicesFromModel(physModel, out verts, out inds);
MobileMeshCollidable mmc = new MobileMeshCollidable(new MobileMeshShape(verts, inds, AffineTransform.Identity, MobileMeshSolidity.Counterclockwise));
_physicsMesh = new Entity(mmc);
_physicsMesh.CollisionInformation.Events.InitialCollisionDetected += HandleCollision;
MyEngine.PhysicsSpace.Add(_physicsMesh);
}
public void HandleCollision(EntityCollidable sender, Collidable other, CollidablePairHandler pair)
{
// Do stuff...
}
Code: Select all
_physicsMesh.WorldTransform = _graphicsMesh.WorldMatrix;
// ...
MyEngine.PhysicsSpace.Update();