Game Development Reference
In-Depth Information
Local up Axis = (0,1,0)
World Coordinates Local Up Axis =
Local Up Axis *Rotation Matrix
Figure 4-16. Camera local y axis after rotation
Figure 4-15 shows the camera before rotation, where the local up axis and the world coordinates of
the local up axis are the same, which is pointing 1 unit along the positive y axis.
Figure 4-16 shows the camera after rotation. The local axis still points 1 unit along the y axis;
however, the world coordinates of the local axis has now changed. You can clearly see from the
figure that the Up camera vector is no longer pointing straight up along the positive y axis. The new
world coordinates for the local axis is found by multiplying the local up axis vector (0,1,0) by the
rotation matrix for the object which in this case is the camera.
Next, the CalculatePosition() function sets the current camera position held in the m_Orientation
variables into the m_Eye variable (see Listing 4-26).
Listing 4-26. Calculate Position() function
void CalculatePosition()
{
m_Eye.Set(m_Orientation.GetPosition().x,
m_Orientation.GetPosition().y,
m_Orientation.GetPosition().z);
}
The UpdateCamera() function is called continuously to update the player's viewpoint. It calculates the
Center ( LookAt ) vector, the Up vector, and the Eye (Position) vector and then sets the camera view by
setting the m_ViewMatrix (see Listing 4-27).
Listing 4-27. UpdateCamera() Function
void UpdateCamera()
{
CalculateLookAtVector();
CalculateUpVector();
CalculatePosition();
SetCameraView(m_Eye, m_Center, m_Up);
}
 
Search WWH ::




Custom Search