Graphics Reference
In-Depth Information
The completed sample maps the P key to pause/unpause the
simulation, and maps the R key to reset the simulation with a
call to the initializePhysics() method.
10. The MeshMotionState objects that we created for each mesh are already
updating the mesh's world matrix, so now we just have to render the objects:
meshes.ForEach((m) =>
{
perObject.World = m.World * worldMatrix;
perObject.WorldInverseTranspose = Matrix
.Transpose(Matrix.Invert(perObject.World));
perObject.WorldViewProjection = perObject.World *
viewProjection;
perObject.ViewProjection = viewProjection;
perObject.Transpose();
context.UpdateSubresource(ref perObject,
perObjectBuffer);
// Provide the material constant buffer
m.PerMaterialBuffer = perMaterialBuffer;
m.PerArmatureBuffer = perArmatureBuffer;
m.Render();
}
11. Lastly, we can render the debug layer (over the existing geometry) by using the
following code snippet:
if (debugDraw)
{
perObject.World = Matrix.Identity;
... as above
perObject.Transpose();
context.UpdateSubresource(ref perObject,
perObjectBuffer);
(world.DebugDrawer as PhysicsDebugDraw)
.DrawDebugWorld(world);
// Restore vertex/pixel shader and vertex layout
context.VertexShader.Set(vertexShader);
context.PixelShader.Set(pixelShader);
context.InputAssembler.InputLayout = vertexLayout;
}
 
Search WWH ::




Custom Search