Jump to content
  • Advertisement
Sign in to follow this  
Mythics

Camera Translation/Rotation

This topic is 4275 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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:
'Identity
Camera.Reset 

'Translation
Camera.Move x, 0, z

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

'Transform
Camera.TransView

Any simplistic suggestions?

Share this post


Link to post
Share on other sites
Advertisement
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.

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.


`Translation
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;

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;
}



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!