Archived

This topic is now archived and is closed to further replies.

doctorsixstring

Camera Movement

Recommended Posts

I have a camera at a given position (vCameraTranslation) with a yaw/pitch/roll stored in the variable ''vCameraRotation''. I am using quaternions to set the camera''s facing. My problem is that I want to be able to move the camera forward/backward/side-to-side based on its current yaw/pitch. So basically I need to calculate the 3D vector described by the yaw/pitch angles. Any thoughts/solutions? -Mike

Share this post


Link to post
Share on other sites
I figured it out. In case any one else was wondering, here''s how I did it:

void MoveCam(float x, float y, float z)
{
//build a matrix from the camera''s yaw/pitch/roll (''m_vCameraRot'')
D3DXMATRIX matCam;
D3DXMatrixRotationYawPitchRoll( &matCam, m_vCameraRot.x, m_vCameraRot.y, m_vCameraRot.z);

//rotate the movement vector by the rotation matrix
D3DXVECTOR3 vMove(x, y, z);
D3DXVec3TransformCoord(&vMove, &vMove, &matCam);

//move the camera
m_vCameraTrans += vMove;
}

Then apply ''m_vCameraTrans'' and ''m_vCameraRot'' to the view matrix and your all set.

-Mike

Share this post


Link to post
Share on other sites