Time for action – computing normals
To complete the normals, perform the following steps:
1. Near the end of the
BuildVertexBuffer()
method of theTerrain
class, modify the code that defines thevertexBuffer
variable by changingBufferUsage.WriteOnly
toBufferUsage.None
. The new statement should read as follows:vertexBuffer = new VertexBuffer( device, typeof(VertexPositionNormalTexture), vertices.Length, BufferUsage.None);
2. Similarly, near the end of the
BuildIndexBuffer()
method, when theindexBuffer
is defined, changeBufferUsage.WriteOnly
toBufferUsage.None
. The statement should be as follows:indexBuffer = new IndexBuffer( device, IndexElementSize.SixteenBits, indices.Length, BufferUsage.None);
3. In the
Helper Methods
region of theTerrain
class, add theCalculateNormals()
method as follows:private void CalculateNormals() { VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[vertexBuffer.VertexCount]; short[] indices...