Game Development Reference
In-Depth Information
the look vector to ensure that they are all mutually orthogonal to each
other. A new orthogonal up vector is found by up = look right. Then a
new orthogonal right vector is found with right = up look.
12.2.2 Rotation about an Arbitrary Axis
To implement our camera rotation methods, we need to be able to
rotate around an arbitrary axis. The D3DX library provides the follow-
ing function for just that purpose:
D3DXMATRIX *D3DXMatrixRotationAxis(
D3DXMATRIX *pOut, // returns rotation matrix
CONST D3DXVECTOR3 *pV, // axis to rotate around
FLOAT Angle
// angle, in radians, to rotate
);
Figure 12.3: Rotations about an arbitrary axis
defined by the vector A
For example, suppose we want to rotate /2 radians around the axis
defined by the vector (0.707, 0.707, 0). We would write:
D3DXMATRIX R;
D3DXVECTOR3 axis(0.707f, 0.707f, 0.0f);
D3DXMatrixRotationAxis(&R, &axis, D3DX_PI / 2.0f);
A derivation of the matrix D3DXMatrixRotationAxis builds can be
found in Eric Lengyel's Mathematics for 3D Game Programming &
Computer Graphics .
12.2.3 Pitch, Yaw, and Roll
Because the orientation vectors describe the orientation of the camera
relative to the world coordinate system, we must figure out how we
update them when we pitch, yaw, and roll. This is actually very easy.
Consider Figures 12.4, 12.5, and 12.6, which show the camera pitching,
yawing, and rolling, respectively.
 
Search WWH ::




Custom Search