Game Development Reference
In-Depth Information
m_Projfar = Projfar;
Matrix.frustumM(m_ProjectionMatrix, 0,
m_Projleft, m_Projright,
m_Projbottom, m_Projtop,
m_Projnear, m_Projfar);
}
The function to actually create and set the camera's view matrix is the SetCameraView() function
(see Listing 4-23). The function calls the setLookAtM() function, which is part of the standard
Android Matrix class, to create the actual matrix that is put into m_ViewMatrix . The function takes
as parameters the location of the camera or eye, the center or focus point of the camera, and the
vector that points in the up direction with respect to the camera.
Listing 4-23. Setting the Camera View Matrix
void SetCameraView(Vector3 Eye,
Vector3 Center,
Vector3 Up)
{
// Create Matrix
Matrix.setLookAtM(m_ViewMatrix,0,
Eye.x, Eye.y, Eye.z,
Center.x, Center.y, Center.z,
Up.x, Up.y, Up.z);
}
In order to produce accurate camera views, you must have accurate camera Center, or LookAt,
and Up, and Eye vectors in world coordinates, not just local coordinates. In the function
CalculateLookAtVector() (see Listing 4-24), you find the Center, or LookAt , vector by
1.
Finding the Forward camera vector that represents the direction the camera
lens is pointing in world coordinates, which is how the Forward vector is
pointing with respect to the world coordinate system. The Forward vector will
be returned normalized with length 1.
Note In order to convert an object's local axis orientation from local object coordinates to world coordinates,
you must multiply the local axis by the rotation matrix, using the Matrix.multiplyMV() function. This is
done in the GetForwardWorldCoords() function in the Orientation class.
2.
Lengthening the Forward vector by how far you wish to look into the scene.
In this case, we chose 5.
3.
Adding your camera's current position to the lengthened Forward vector
you calculated in the previous step to determine the final Center, or LookAt,
vector. This result is stored in m_Center .
 
 
Search WWH ::




Custom Search