Game Development Reference
In-Depth Information
if (m_CubeRotation > 6.28f) // 2 times PI
m_CubeRotation = 0.0f;
Here, we increment the
m_CubeRotation
variable to increase the cube's rotation
slightly for this frame. Note that this rotation value is in radians, not degrees. The
if
statement resets this variable to
0
when it gets too large. Over many frames, this
causes the cube to rotate.
Below that, we will add the following
if
statement:
// If the player pressed forward.
if (UserInput.IsKeyPressed(Key.UpArrow)
||UserInput.IsKeyPressed(Key.W))
{
m_CameraPosition.Z = m_CameraPosition.Z +
m_MoveSpeed;
}
This
if
statement checks if the player has pressed the up arrow key or the
W
key.
If so, we increase the camera's position on the z axis. Then, below this we would
add another
if
statement that does the same for moving backwards if you press
the down arrow key or the
D
key. If you have pressed one of these keys, it will de-
crease the camera's position on the z axis. Check out the downloadable code for this
chapter to see this code.
Note
Remember that
UserInput
is a variable defined by our
GameWindow
base
2
,
Responding to Player Inputs
.
You may notice that the camera acts a bit oddly if you move forward until you pass
the cube. This is just because the camera is effectively locked on to the cube. If you
try to add controls for moving left/right or up/down, you will notice the camera will act
a bit oddly for this same reason when you move it in those directions. The camera