Graphics Reference
In-Depth Information
3.
In order to make the physics engine update our mesh's world matrix, we will
implement a class that is inherited from the BulletSharp.MotionState class.
using BulletSharp;
using SharpDX;
public class MeshMotionState : BulletSharp.MotionState
{
public MeshRenderer Mesh { get; private set; }
public MeshMotionState(MeshRenderer mesh)
{
Mesh = mesh;
}
// Retrieve or Sets the Mesh's world transform
public override SharpDX.Matrix WorldTransform
{
get
{
return Mesh.World * Matrix
.Translation(Mesh.Mesh.Extent.Center);
}
set
{
Mesh.World = Matrix
.Translation(-Mesh.Mesh.Extent.Center) *
value;
}
}
}
4.
After initializing the renderers and before the render loop, let's now initialize the
physics engine within the D3DApp.Run method directly.
using BulletSharp;
...
DynamicsWorld world = null;
CollisionConfiguration defaultConfig =
new DefaultCollisionConfiguration();
ConstraintSolver solver =
new SequentialImpulseConstraintSolver();
BulletSharp.Dispatcher dispatcher =
new CollisionDispatcher(defaultConfig);
BroadphaseInterface broadphase = new DbvtBroadphase();
// Function to initialize the world and rigid bodies for
// the loaded meshes. Done as an action so we can easily
 
Search WWH ::




Custom Search