Advertisement

Move view(camera) matrix

Started by September 23, 2018 02:24 PM
3 comments, last by MJP 6 years, 4 months ago

D3DXVECTOR3 m_pos;
D3DXVECTOR3 pos;
D3DXVECTOR3 lookAt;
D3DXVECTOR3 up;
D3DXMATRIX m_cameraMatrix;
D3DXMATRIX translate, result;

D3DXMatrixLookAtRH(&m_cameraMatrix, &pos, &lookAt, &up);
D3DXMatrixIdentity(&translate);
D3DXMatrixTranslation(&translate, m_pos.x, m_pos.y, m_pos.z);
result = m_cameraMatrix * translate;
return result;

I want to move camera to m_pos position, as i do it with world matrix, but it seems it doesn't work, any ideas?

You have to translate by the vector between pos and m_pos, so use m_pos - pos instead of just m_pos.

(But in this case I'd simply call D3DXMatrixLookAtRH again with m_pos instead of pos.)

Advertisement
31 minutes ago, Koen said:

You have to translate by the vector between pos and m_pos, so use m_pos - pos instead of just m_pos.

(But in this case I'd simply call D3DXMatrixLookAtRH again with m_pos instead of pos.)

I see world much difficult than it is... 

Your view matrix is just the inverse of a matrix representing the world-space transform for your camera. "LookAt" functions will automatically invert the transform for you, but you can also build a "normal" transformation matrix for your camera and then compute the inverse to get a view matrix.

This topic is closed to new replies.

Advertisement