Time for action – the View matrix
1. Add the following variable to the
Fields
region of theCamera
class:private Matrix cachedViewMatrix;
2. Add the following property to the
Properties
region of theCamera
class:public Matrix View { get { if (needViewResync) cachedViewMatrix = Matrix.CreateLookAt( Position, lookAt, Vector3.Up); return cachedViewMatrix; } }
What just happened?
We could simply recalculate the View
matrix every time the Camera
class was asked for it, but doing so would incur a small performance penalty. Because we do not have a lot of action happening in Cube Chaser, this penalty would not impact our game, but we can avoid it altogether. We are building a caching mechanism into the camera code in the event our game develops to the point that this optimization is helpful. Any time the View
matrix is calculated, we will store it in cachedViewMatrix
and simply return that matrix if the View...