Collision Detection with .fbx models

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
GrapicsGear
Posts: 4
Joined: Tue Jul 13, 2010 7:23 pm

Collision Detection with .fbx models

Post by GrapicsGear »

Hi

in the BEPU getting started documentation it shows the following handlecollision method

deleterBox.eventManager.addEventHook(new BEPUphysics.Events.EventHandlerInitialCollisionDetected(handleCollision));

public void handleCollision(Entity sender, Entity other, CollisionPair pair)
{
space.remove(other);
Components.Remove((EntityModel)other.tag); //Remove the graphics too.
}

My question is how would I do this for a .fbx model in stead of an Entity

This is how I load the model:

Model terrain = game.Content.Load<Model>("GYTerrain");
StaticTriangleGroup.getVerticesAndIndicesFromModel(terrain, out staticTriangleVertices, out staticTriangleIndices);
TriangleMesh terrainMesh = new TriangleMesh(staticTriangleVertices, staticTriangleIndices, 0);
StaticTriangleGroup terrainGroup = new StaticTriangleGroup(terrainMesh);
terrainGroup.worldMatrix = Matrix.CreateFromYawPitchRoll((float)Math.PI, 0, 0) * Matrix.CreateTranslation(0, -40, 0);
space.add(terrainGroup);

thanks in advance
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision Detection with .fbx models

Post by Norbo »

You could attach the entity to the incoming entity and watch for collisions with triangle entities that have a tag field containing the StaticTriangleGroup, but the StaticTriangleGroup itself cannot dispatch any events.

People might be getting tired of me saying this so often, but this is another thing that I'd like to address in the upcoming collision detection rewrite :)

Basically, StaticTriangleGroups and Terrains are going to become first-class broadphase citizens, capable of producing collision pairs and contact points just like entities. With that ability comes collision events.
GrapicsGear
Posts: 4
Joined: Tue Jul 13, 2010 7:23 pm

Re: Collision Detection with .fbx models

Post by GrapicsGear »

Thanks it worked
GrapicsGear
Posts: 4
Joined: Tue Jul 13, 2010 7:23 pm

Re: Collision Detection with .fbx models

Post by GrapicsGear »

I now want to teleport the .fbx model to a specified posistion when the collision takes place.

this is my code:

foreach (Entity e in space.entities)
{
if (e.tag != null && e.tag.Equals(s))
{
e.teleport(character.arrow.centerPosition);
}
}

However this is not working, nothing happens when the collision occurs.

I am guessing this is because e is of Type BEPUphysics.Entities.Triangle and not StaticTriangleGroup?

So some kind of cast to StaticTriangleGroup will probably be needed?

Any help on this would be greatly appreciated.

Thanks.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision Detection with .fbx models

Post by Norbo »

I am guessing this is because e is of Type BEPUphysics.Entities.Triangle and not StaticTriangleGroup?

So some kind of cast to StaticTriangleGroup will probably be needed?
It is indeed not an Entity, and so cannot be teleported. It also does not exist in the space.entities list. Entities are just the physical primitives; the StaticTriangleGroup is a higher level system that manages entities. You can still move it by setting the staticTriangleGroup.worldMatrix property.

You can set the StaticTriangleGroup's tag to the StaticTriangleGroup itself if you want. The StaticTriangleGroup gives its tag to any triangle it manages in the space. When other entities detect collision events, you can examine the colliding entities tags to see if they are the StaticTriangleGroup before doing any collision logic.
GrapicsGear
Posts: 4
Joined: Tue Jul 13, 2010 7:23 pm

Re: Collision Detection with .fbx models

Post by GrapicsGear »

Ok thanks this solved my problem.
Post Reply