Graphics Reference
In-Depth Information
body.Restitution = 1f;
body.Friction = 0.4f;
}
// Add to the simulation
world.AddRigidBody(body);
8.
In order to enable the debug drawing of bodies, you can include the following code
(if you want) after having loaded all the bodies.
#if DEBUG
world.DebugDrawer = ToDispose(
new PhysicsDebugDraw(this.DeviceManager));
world.DebugDrawer.DebugMode = DebugDrawModes.DrawAabb |
DebugDrawModes.DrawWireframe;
#endif
With the physics world and bodies in place, we are ready to step through the
simulation and apply the transformations to our mesh objects.
9.
At the beginning of the D3DApp rendering loop, we will step forward the simulation
in time. We will provide the last frame time, and also provide the maximum number
of steps that the simulation will try to catch-up on, if it has fallen behind. We will use
the default fixed time step of one sixtieth of a second.
var simTime = new System.Diagnostics.Stopwatch();
simTime.Start();
float time = 0.0f;
float timeStep = 0.0f;
#region Render loop
RenderLoop.Run(Window, () =>
{
// Update simulation
if (!paused)
{
if ((float)simTime.Elapsed.TotalSeconds < time)
{ // Reset if the simTime is reset
time = 0;
timeStep = 0;
}
timeStep = ((float)simTime.Elapsed
.TotalSeconds - time);
time = (float)simTime.Elapsed.TotalSeconds;
world.StepSimulation(timeStep, 7);
}
... SNIP
});
 
Search WWH ::




Custom Search