D3DXVec3TransformCoord

Started by
0 comments, last by xissburg 16 years, 3 months ago
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]
Advertisement
Its useless to call D3DXVec3TransformCoord() there. You can get the up, right and lookAt vectors from the matTotal:

D3DXMatrixRotationAxis(&matRotAboutRight,&m_Right,m_fRotAboutRight);D3DXMatrixRotationAxis(&matRotAboutUp,&m_Up,m_fRotAboutUp);D3DXMatrixRotationAxis(&matRotAboutFacing,&m_LookAt,m_fRotAboutFacing);D3DXMatrixMultiply(&m_ViewTransform,&matRotAboutUp,&matRotAboutRight);D3DXMatrixMultiply(&m_ViewTransform,&matRotAboutFacing,&m_ViewTransform);m_Right = D3DXVECTOR3(m_ViewTransform._11, m_ViewTransform._21, m_ViewTransform._31);//X axism_Up = D3DXVECTOR3(m_ViewTransform._12, m_ViewTransform._22, m_ViewTransform._32);//Y axism_LookAt = D3DXVECTOR3(m_ViewTransform._13, m_ViewTransform._23, m_ViewTransform._33);//Z axis//continuingm_ViewTransform._41 = -D3DXVec3Dot(&m_Right,&m_Position);m_ViewTransform._42 = -D3DXVec3Dot(&m_Up,&m_Position);m_ViewTransform._43 = -D3DXVec3Dot(&m_LookAt,&m_Position);//done


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.
.

This topic is closed to new replies.

Advertisement