Game Development Reference
In-Depth Information
Chapter 12
Building a Flexible
Camera Class
Thus far, we have used the
D3DXMatrixLookAtLH
function to com-
pute a view space transformation matrix. This function is particularly
useful for positioning and aiming a camera in a fixed position, but its
user interface is not so useful for a moving camera that reacts to user
input. This motivates us to develop our own solution. In this chapter
we show how to implement a
Camera
class that gives us better control
of the camera than the
D3DXMatrixLookAtLH
function and is particu-
larly suitable for flight simulators and games played from the first-
person perspective.
Objective
To learn how to implement a flexible
Camera
class that can be
used for flight simulators and games played from the first-person
perspective
12.1
Camera Design
We define the position and orientation of the camera relative to the
world coordinate system using four
camera vectors
:a
right vector
,
up vec-
tor
,
look vector
, and
position vector
, as Figure 12.1 illustrates. These
vectors essentially define a local coordinate system for the camera
described relative to the world coordinate system. Since the right, up,
and look vectors define the camera's orientation in the world, we some-
times refer to all three as the
orientation vectors
. The orientation
vectors must be
orthonormal
. A set of vectors is orthonormal if they are
mutually perpendicular to each other and of unit length. The reason we
make this restriction is because later we insert the orientation vectors
into the rows of a matrix, and a matrix where the row vectors are
orthonormal means the matrix is orthogonal. Recall that an orthogonal
199
Search WWH ::
Custom Search