Game Development Reference
In-Depth Information
camera's up vector in the yaw method, and we disable rolling for land
objects completely. Keep in mind that you can alter the Camera class to
suit your application; we offer only an example.
The code for the pitch, yaw, and roll methods is implemented as
follows:
void Camera::pitch(float angle)
{
D3DXMATRIX T;
D3DXMatrixRotationAxis(&T, &_right, angle);
// rotate _up and _look around _right vector
D3DXVec3TransformCoord(&_up,&_up, &T);
D3DXVec3TransformCoord(&_look,&_look, &T);
}
void Camera::yaw(float angle)
{
D3DXMATRIX T;
// rotate around world y (0, 1, 0) always for land object
if( _cameraType == LANDOBJECT )
D3DXMatrixRotationY(&T, angle);
// rotate around own up vector for aircraft
if( _cameraType == AIRCRAFT )
D3DXMatrixRotationAxis(&T, &_up, angle);
// rotate _right and _look around _up or y-axis
D3DXVec3TransformCoord(&_right,&_right, &T);
D3DXVec3TransformCoord(&_look,&_look, &T);
}
void Camera::roll(float angle)
{
// only roll for aircraft type
if( _cameraType == AIRCRAFT )
{
D3DXMATRIX T;
D3DXMatrixRotationAxis(&T, &_look, angle);
// rotate _up and _right around _look vector
D3DXVec3TransformCoord(&_right,&_right, &T);
D3DXVec3TransformCoord(&_up,&_up, &T);
}
}
12.2.4 Walking, Strafing, and Flying
When we refer to walking, we mean moving in the direction that we are
looking (that is, along the look vector). Strafing is moving side to side
from the direction we are looking, which is of course moving along the
right vector. Finally, we say that flying is moving along the up vector. To
move along any of these axes, we simply add a vector that points in the
Search WWH ::




Custom Search