Camera Translation/Rotation

Started by
3 comments, last by SgtArchAngel 17 years ago
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:

'Identity
Camera.Reset 

'Translation
Camera.Move x, 0, z

'Rotation
Camera.Rotate x * RAD, 0, 0

'Transform
Camera.TransView

Any simplistic suggestions?
Advertisement
Same principle as in this example:
here

You need to multiply matrices in specific order.
Quote: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.
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.

`TranslationCamera.Move(vForward * distance)
this is part of my camera class.
void CCamera::MoveCamera(float Speed){        // Get vVector: Direction camera is facing	D3DXVECTOR3 vVector = m_vView - m_vPosition;	D3DXVec3Normalize(&vVector,&vVector);        // 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	D3DXMATRIX V; 	D3DXMatrixLookAtLH(&V, &position, &target, &up);		return V;}

This topic is closed to new replies.

Advertisement