Graphics Reference
In-Depth Information
// reset the simulation state.
Action initializePhysics = () =>
{
RemoveAndDispose(ref world);
// Initialize the Bullet Physics "world"
world = ToDispose(new DiscreteDynamicsWorld(dispatcher,
broadphase, solver, defaultConfig));
world.Gravity = new Vector3(0, -10, 0);
// For each mesh, create a RigidBody and add to "world"
// for simulation
meshes.ForEach(m =>
{
... SNIP see below
});
});
initializePhysics();
5.
Within the meshes.ForEach loop in the previous code snippet, we'll initialize a
rigid body for each mesh. Initially check to ensure that the mesh has a value for
the Name attribute.
// We use the name of the mesh to determine the correct
// type of physics body to create
if (String.IsNullOrEmpty(m.Mesh.Name))
return;
var name = m.Mesh.Name.ToLower();
var extent = m.Mesh.Extent;
BulletSharp.CollisionShape shape;
6.
Next, we will determine whether to use a BulletSharp box or sphere collision
shape, or to create one based on the mesh's vertices.
#region Create collision shape
if (name.Contains("box") || name.Contains("cube"))
{
// Assumes the box/cube has an axis-aligned orientation
shape = new BulletSharp.BoxShape(
Math.Abs(extent.Max.Z - extent.Min.Z) / 2.0f,
Math.Abs(extent.Max.Y - extent.Min.Y) / 2.0f,
Math.Abs(extent.Max.X - extent.Min.X) / 2.0f);
}
else if (name.Contains("sphere"))
{
 
Search WWH ::




Custom Search