First, create a shape directly:
Code: Select all
Vector3[] vertices = new Vector3[]
{
new Vector3(-1,0,-1),
new Vector3(-1,0,1),
new Vector3(1,0,-1),
new Vector3(1,0,1),
new Vector3(0,2,0)
};
var convexHullShape = new ConvexHullShape(vertices);
Now, create entities using that shape. In the latest stable release, there's two main ways of doing this: creating a 'typed' entity, and creating a morphable entity. The generic typed entity is the superclass of all the prefabs, and it lets you access the CollisionInformation property of the entity using the most derived available type. The morphable entity is a little simpler to make, but after you make the entity, the CollisionInformation property is just an EntityCollidable (but it is settable!)
In both of these examples, the shape is shared and passed into new collidable objects, which are in turn given to an entity constructor (alongside a mass).
Code: Select all
var entity1 = new Entity<ConvexCollidable<ConvexHullShape>>(new ConvexCollidable<ConvexHullShape>(convexHullShape), 2);
var entity2 = new Entity<ConvexCollidable<ConvexHullShape>>(new ConvexCollidable<ConvexHullShape>(convexHullShape), 2);
var entity3 = new Entity<ConvexCollidable<ConvexHullShape>>(new ConvexCollidable<ConvexHullShape>(convexHullShape), 2);
var entity4 = new Entity<ConvexCollidable<ConvexHullShape>>(new ConvexCollidable<ConvexHullShape>(convexHullShape), 2);
Code: Select all
var mEntity1 = new MorphableEntity(new ConvexCollidable<ConvexHullShape>(convexHullShape), 2);
var mEntity2 = new MorphableEntity(new ConvexCollidable<ConvexHullShape>(convexHullShape), 2);
var mEntity3 = new MorphableEntity(new ConvexCollidable<ConvexHullShape>(convexHullShape), 2);
var mEntity4 = new MorphableEntity(new ConvexCollidable<ConvexHullShape>(convexHullShape), 2);
In the latest development version (
http://bepuphysics.codeplex.com/SourceC ... evelopment), MorphableEntities can also be constructed by simply passing a shape in as well (shortening the constructor a bit):
Code: Select all
var msEntity1 = new MorphableEntity(convexHullShape, 2);
var msEntity2 = new MorphableEntity(convexHullShape, 2);
var msEntity3 = new MorphableEntity(convexHullShape, 2);
var msEntity4 = new MorphableEntity(convexHullShape, 2);
For maximum initialization sharing, you could re-use other data like the inertia tensor. This can be done with both types of entities, but this example shows the last morphable entity setup:
Code: Select all
var msiEntity1 = new MorphableEntity(convexHullShape, 2);
var msiEntity2 = new MorphableEntity(convexHullShape, 2, msiEntity1.LocalInertiaTensor, msiEntity1.Volume);
var msiEntity3 = new MorphableEntity(convexHullShape, 2, msiEntity1.LocalInertiaTensor, msiEntity1.Volume);
var msiEntity4 = new MorphableEntity(convexHullShape, 2, msiEntity1.LocalInertiaTensor, msiEntity1.Volume);
Also, all of these entity constructors will center the entity body on the origin. You can assign their Position property to anything after being created. If you need to know the offset from the 'configuration space' origin of the original vertices and the shape's center, you can use the other ConvexHullShape constructor which outputs a center.
Code: Select all
Vector3 hullCenter;
var convexHullShape = new ConvexHullShape(vertices, out hullCenter);