Sign in to follow this  

Camera Translation/Rotation

Recommended Posts

Moving on the axis's is fine and dandy, and so is rotating the view of the camera. Combining the two so that I always move in the direction I am viewing however, I'm rather confused with. This is my (pseudo)code:

Camera.Move x, 0, z

Camera.Rotate x * RAD, 0, 0


Any simplistic suggestions?

Share this post

Link to post
Share on other sites
Original post by streamerYou need to multiply matrices in specific order.

Rotation prior to translation still results in my having the issue of only moving along the x or z axis. It just gives me the lovely view of the direction I'd like to be moving in as I do so.

Share this post

Link to post
Share on other sites
Your camera's position is in world coordinats, so forward isn't always going to be along the x axis. You have to figure out which way forward is and move in that direction instead.

Camera.Move(vForward * distance)

Share this post

Link to post
Share on other sites
this is part of my camera class.

void CCamera::MoveCamera(float Speed)
// Get vVector: Direction camera is facing
D3DXVECTOR3 vVector = m_vView - m_vPosition;


// Move camera along the vVector
m_vPosition.x += vVector.x * Speed;
m_vPosition.z += vVector.z * Speed;
m_vView.x += vVector.x * Speed;
m_vView.z += vVector.z * Speed;


then just update our view matrix
with something like

D3DXMATRIX CCamera::Look()
D3DXVECTOR3 position(m_vPosition.x, m_vPosition.y, m_vPosition.z);
D3DXVECTOR3 target(m_vView.x, m_vView.y, m_vView.z);
D3DXVECTOR3 up(m_vUpVector.x, m_vUpVector.y, m_vUpVector.z);

// cameras view matrix
D3DXMatrixLookAtLH(&V, &position, &target, &up);

return V;

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this