Game Development Reference
In-Depth Information
The Camera class's constructor is shown in Listing 4-21. The constructor initializes the camera with
the input parameters and performs the following functions:
m_Orientation .
Sets the camera projection frustrum using the user specified input parameters
Creates a new Orientation class object called
Projleft , Projright , Projbottom , Projtop , Projnear , and Projfar .
Sets the camera's local coordinate axis and position. Sets the forward local axis
(z axis), up local axis (y axis), and the right local axis (x axis). The right local axis
is calculated from the cross product of the Center and Up vectors.
Listing 4-21. The Camera Class's Constructor
Camera(Context context,
Vector3 Eye, Vector3 Center, Vector3 Up,
float Projleft, float Projright,
float Projbottom, float Projtop,
float Projnear, float Projfar)
{
m_Orientation = new Orientation(context);
// Set Camera Projection
SetCameraProjection(Projleft, Projright, Projbottom, Projtop, Projnear, Projfar);
// Set Orientation
m_Orientation.GetForward().Set(Center.x, Center.y, Center.z);
m_Orientation.GetUp().Set(Up.x, Up.y, Up.z);
m_Orientation.GetPosition().Set(Eye.x, Eye.y, Eye.z);
// Calculate Right Local Vector
Vector3 CameraRight = Vector3.CrossProduct(Center, Up);
CameraRight.Normalize();
m_Orientation.SetRight(CameraRight);
}
The SetCameraProjection() function actually sets the projection matrix, using the Matrix.
frustumM() function to generate the matrix, and puts it in m_ProjectionMatrix (see Listing 4-22).
Listing 4-22. Setting the Camera Frustrum
void SetCameraProjection(float Projleft,
float Projright,
float Projbottom,
float Projtop,
float Projnear,
float Projfar)
{
m_Projleft = Projleft;
m_Projright = Projright;
m_Projbottom = Projbottom;
m_Projtop = Projtop;
m_Projnear = Projnear;
 
Search WWH ::




Custom Search