Graphics Reference
In-Depth Information
vertexBuffer = ToDispose(Buffer.Create(device, BindFlags.
VertexBuffer, vertices));
// Create vertex binding
vertexBinding = new VertexBufferBinding(vertexBuffer, Utilities.
SizeOf<Vertex>(), 0);
// Create index buffer
indexBuffer = ToDispose(Buffer.Create(device, BindFlags.
IndexBuffer, indices));
totalVertexCount = indices.Length;
13. The DoRender method is similar to the cube rendering code, except that we pass
totalVertexCount into DrawIndexed .
14. Finally, back in D3DApp , create an instance of the sphere renderer and call its
Render method as per the cube.
Running the project at this point will show just the cube. This is because the quad
and sphere are hidden inside the cube. To rectify this, we will create a matrix in
D3DApp.Run for each of our 3D objects to translate them from the local model
space to world space.
15. Where we initialize the renderers, add the following matrix definitions:
// Scale to 5x and translate the quad on Y axis by -0.5
quad.World = Matrix.Scaling(5f);
quad.World.TranslationVector = new Vector3(0, -0.5f, 0);
// Move the cube along the X axis by -1
cube.World = Matrix.Translation(-1, 0, 0);
// Move the sphere along the Z axis by 1.1f
sphere.World = Matrix.Translation(0, 0, 1.1f)
16. We need to change the worldViewProjection calculation immediately before
the quad.Render() call with the following code:
var worldViewProjection = quad.World * worldMatrix *
viewProjection;
17. Immediately before the cube.Render() call, we add the following code:
worldViewProjection = cube.World *worldMatrix*viewProjection;
worldViewProjection.Transpose();
context.UpdateSubresource(ref worldViewProjection,
worldViewProjectionBuffer);
18. And finally, before the sphere.Render() call, we add the same code as for the
cube with the exception of using sphere.World in this case.
 
Search WWH ::




Custom Search