Game Development Reference
In-Depth Information
We could actually specify a very simple camera with four attributes:
ï?®
Its position in world space.
ï?®
Its rotation around its x axis (pitch). This is equivalent to tilting your head up
and down.
ï?®
Its rotation around its y axis (yaw). This is equivalent to turning your head left
and right.
ï?®
Its rotation around its z axis (roll). This is equivalent to tilting your head to the
left and right.
Given these attributes, we can use OpenGL ES methods to create a camera matrix. This is
called a Euler rotation camera. Many first-person shooter games use this kind of camera to
simulate the tilting of a head. Usually you'd leave out the roll and only apply the yaw and pitch.
The order in which the rotations are applied is important. For a first-person shooter, you'd first
apply the pitch rotation and then the yaw rotation:
gl.glTranslatef(−cam.x,- cam.y,-cam.z);
gl.glRotatef(cam.yaw, 0, 1, 0);
gl.glRotatef(cam.pitch, 1, 0, 0);
Many games still use this very simplistic camera model. If the roll rotation had been included,
you might observe an effect called gimbal lock . This effect will cancel out one of the rotations
given a certain configuration.
Note Explaining gimbal lock with text or even images is very difficult. Since we'll only use yaw
and pitch, we won't have this problem. To get an idea of what gimbal lock actually is, look it up on
your favorite video site on the Web. This problem can't be solved with Euler rotations. The actual
solution is mathematically complex, and we won't go into that in this topic.
A second approach to a very simple camera system is the use of the GLU.glLookAt() method:
GLU.gluLookAt(GL10 gl,
float eyeX, float eyeY, float eyeZ,
float centerX, float centerY, float centerZ,
float upX, float upY, float upZ);
Like the GLU.gluPerspective() method, GLU.glLookAt() will multiply the currently active matrix
with a transformation matrix. In this case, it's a camera matrix that will transform the world:
ï?® gl is just the GL10 instance used throughout the rendering.
ï?® eyeX , eyeY , and eyeZ specify the camera's position in the world.
 
 
Search WWH ::




Custom Search