Jump to content
  • Advertisement
Sign in to follow this  


This topic is 3991 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

This is code part of a camera class that I am looking at and trying to understand. D3DXMatrixRotationAxis(&matRotAboutRight,&m_Right,m_fRotAboutRight); D3DXMatrixRotationAxis(&matRotAboutUp,&m_Up,m_fRotAboutUp); D3DXMatrixRotationAxis(&matRotAboutFacing,&m_LookAt,m_fRotAboutFacing); D3DXMatrixMultiply(&matTotal,&matRotAboutUp,&matRotAboutRight); D3DXMatrixMultiply(&matTotal,&matRotAboutFacing,&matTotal); D3DXVec3TransformCoord(&m_Right,&m_Right,&matTotal); D3DXVec3TransformCoord(&m_Up,&m_Up,&matTotal); D3DXVec3Cross(&m_LookAt,&m_Right,&m_Up); if(fabs(D3DXVec3Dot(&m_Up,&m_Right)) > 0.01) { D3DXVec3Cross(&m_Up,&m_LookAt,&m_Right); } D3DXVec3Normalize(&m_Right,&m_Right); D3DXVec3Normalize(&m_Up,&m_Up); D3DXVec3Normalize(&m_LookAt,&m_LookAt); float fView41,fView42,fView43; fView41 = -D3DXVec3Dot(&m_Right,&m_Position); fView42 = -D3DXVec3Dot(&m_Up,&m_Position); fView43 = -D3DXVec3Dot(&m_LookAt,&m_Position); m_ViewTransform = D3DXMATRIX(m_Right.x, m_Up.x, m_LookAt.x, 0.0f, m_Right.y, m_Up.y, m_LookAt.y, 0.0f, m_Right.z, m_Up.z, m_LookAt.z, 0.0f, fView41, fView42, fView43, 1.0f); I understand the RotationAxis calls and Multiply calls but how does the D3DXVec3TransformCoord() work? How does it get the right vector and the up vector how does it diffrentiate it from the same matrix? What is fView41,fView42,fView43? EDIT: Ok I found out what the function does, but now that makes me think why do we need to multiply the matrix by the up vector to get the new up vector? [Edited by - TehCoyote on January 11, 2008 8:57:54 PM]

Share this post

Link to post
Share on other sites
Its useless to call D3DXVec3TransformCoord() there. You can get the up, right and lookAt vectors from the matTotal:


m_Right = D3DXVECTOR3(m_ViewTransform._11, m_ViewTransform._21, m_ViewTransform._31);//X axis
m_Up = D3DXVECTOR3(m_ViewTransform._12, m_ViewTransform._22, m_ViewTransform._32);//Y axis
m_LookAt = D3DXVECTOR3(m_ViewTransform._13, m_ViewTransform._23, m_ViewTransform._33);//Z axis

m_ViewTransform._41 = -D3DXVec3Dot(&m_Right,&m_Position);
m_ViewTransform._42 = -D3DXVec3Dot(&m_Up,&m_Position);
m_ViewTransform._43 = -D3DXVec3Dot(&m_LookAt,&m_Position);


What he does, is to create an updated transformation matrix of your camera through the new angles. Then, he updates the up, right, lookat vectors by multiplying them by this matrix, but the columns of this matrix already contains these vectors, then there's no need to do that.

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!