Collision Detection Only
Posted: Tue Feb 28, 2012 6:45 pm
I am working on a space combat game that requires very specific flight mechanics, something I don't want to use physical simulations for. However, I am very interested in using the collision detection features of BEPU Physics, and after floundering with it for a week or so (very new to physics engines) I'm beginning to think I'm not using the engine the proper way.
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:
During the update loop, I set the _physicsMesh.WorldTransform equal to my manually-transformed graphics mesh's world matrix, and update the Space, expecting that when two of these meshes collide, it should call their respective HandleCollision methods:
Except, of course, that this doesn't work. I suspect it's either because I'm creating the wrong kind of entity, or that I'm simply using BEPU fundamentally the wrong way. Any suggestions to get me pointed in the right direction would be greatly appreciated! Thanks in advance!
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();