Game Development Reference
In-Depth Information
same direction as the axis that we want to move along to our position
vector (see Figure 12.7).
Figure 12.7: Moving along
the camera's orientation
vectors
As with the rotations, we need to set some restrictions on moving for
land objects. For example, LANDOBJECT s shouldn't be able to get air-
borne by either flying on their up vector or moving forward if they're
looking up or by strafing at a tilt. Therefore, we restrict movement to
the xz plane. However, because LANDOBJECT s can change their eleva-
tion by climbing stairs or a hill, for example, we expose the
Camera::setPosition method, which allows you to manually posi-
tion your camera to a desired height and position.
The code that implements the walk, strafe, and fly methods
follows:
void Camera::walk(float units)
{
// move only on xz plane for land object
if( _cameraType == LANDOBJECT )
_pos += D3DXVECTOR3(_look.x, 0.0f, _look.z) * units;
if( _cameraType == AIRCRAFT )
_pos += _look * units;
}
void Camera::strafe(float units)
{
// move only on xz plane for land object
if( _cameraType == LANDOBJECT )
_pos += D3DXVECTOR3(_right.x, 0.0f, _right.z) * units;
if( _cameraType == AIRCRAFT )
_pos += _right * units;
}
 
Search WWH ::




Custom Search