Game Development Reference
In-Depth Information
Center of view : What part of the scene should be displayed at the exact center of the screen?
The obvious answer that comes to mind is that the player's bike should be there. Although this
sounds logical, it may often not be the best choice. The player's bike is often found on corners
and edges of the grid. Centering the view on the player in these cases obscures most of the grid
surface from view and prevents the player from seeing the big picture of the game. Furthermore,
it often leaves large portions of the screen empty, wasting valuable screen space. The next
simplest option is to center the view at the center of the mesh. With this option, the player is likely
to have good visibility of most of what's going on and the screen is guaranteed to be full at
all times.
The center of the mesh is easily calculated as the average of all coordinates' positions, or more
simply as the center of the axis-aligned bounding box of the grid.
With these details decided upon, creating the transformation matrix for the camera positioning is
a simple matter of taking the right vectors and coordinates and plugging them into the matrix
formula of the gluLookAt() function. gluLookAt() is a function from the GLU API found in desktop
OpenGL implementations. It provides a useful abstraction to setting up a camera viewpoint and
can be reimplemented in JavaScript quite easily. gluLootAt() takes nine float arguments that
make two sets of 3D coordinates and one 3D vector (see Figure 8-14 for an overview).
gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
Figure 8-14. The glLookAt() parameters in a 3D scene and the 3D rendered result.
Center coordinates : The point in the scene at which the camera is looking. As described earlier,
this point is set to be the center of the grid model.
Eye coordinates : The point in the scene where the camera is positioned. This point is set to be
directly above the bike. The normal of the surface at the point where the bike is displayed is used
for computing this point.
Up vector : This vector defines the orientation of the camera around the axis established by the
center and eye coordinates. The game maintains a vector that always points to the top of the
screen and uses it as the camera up vector. When the bike moves to the right of the screen, the
 
Search WWH ::




Custom Search