Game Development Reference
In-Depth Information
auto-rotates so that it is always looking towards the cube, no matter where you move
it. The next block of code recreates the view matrix, and then sends that data into the
m_CbChangesPerFrame constant buffer. We need to update the view matrix every
time the camera moves. The following is that code:
// Update the view matrix.
m_ViewMatrix =
Matrix.LookAtLH(m_CameraPosition,new Vector3(0,
0, 0),new Vector3(0, 1, 0));
// Send the updated view matrix into its
constant buffer.
m_DataStream.Position = 0;
m_DataStream.Write(Matrix.Transpose(m_ViewMatrix));
m_DataStream.Position = 0;
m_Device.ImmediateContext.UpdateSubresource(new
DataBox(0, 0,
m_DataStream),m_CbChangesPerFrame,0);
Lastly, we update the cube's rotation matrix with the new value in the
m_CubeRotation variable that we updated at the top of this method:
// Update the cube's rotation matrix.
Vector3 rotationAxis = new Vector3(0.0f, 1.0f,
0.0f);
m_CubeRotationMatrix
=Matrix.RotationAxis(rotationAxis,
m_CubeRotation);
// Update the cube's world matrix with the new
translation and rotation matrices.
m_CubeWorldMatrix = m_CubeRotationMatrix;
The first parameter of the Matrix.RotationAxis() method is Vector3 specify-
ing the axis we want the cube to rotate around. The second parameter is our rotation
Search WWH ::




Custom Search