Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Rotation Multipcation order

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

whats the order to mutliply? Yaw,pitch,roll,translate or roll,yaw,pitch,translate? if anyone have any good sites for making my OWN local axis to move my object, i dont want to rotate it on the world axis.

Share this post

Link to post
Share on other sites
Heh... i already posted the answer.


pPlayer->vPos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
pPlayer->vLook = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
pPlayer->vUp = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
pPlayer->vRight = D3DXVECTOR3(1.0f, 0.0f, 0.0f);


// Normalizing Axis


D3DXMATRIX matPitch,matYaw,matRoll;
D3DXMATRIX matWorld, matRot;

//Rotate the Right & Up vectors on the Look vector


//Rotate the LOOK & Right vectors on the UP vector

D3DXVec3TransformCoord(&pPlayer->vLook, &pPlayer->vLook, &matYaw);

//Rotate the LOOK & Up vectors on the Right vector


pPlayer->vPos += -pPlayer->vLook * (pPlayer->fSpeed + pPlayer->fThrust) * m_fElapsedTime;

D3DXMatrixTranslation(&pPlayer->matLocal, pPlayer->vPos.x, pPlayer->vPos.y, pPlayer->vPos.z);
D3DXMatrixLookAtLH(&matRot, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &pPlayer->vLook, &pPlayer->vUp);
D3DXMatrixInverse(&matRot, NULL, &matRot);
pPlayer->matLocal = matRot * pPlayer->matLocal;

Share this post

Link to post
Share on other sites
Order is arbitrary if you are doing it the simple way (which is to simply multiply by 3 rotation matrices around "global" x,y,z axis)

But, i think what you want to to rotate around a local axis every time -- so rotating around x will have no influence on the rotation around y.

Simply store the local axis. So, you''d store, say the x,y, and z axis with your object. Now whenever you rotate, you rotate around the stored x,y,z axis not the global axii -- and whenever you rotate your object you also need to rotate the three axii (what the hell is plural if axis?)

Of course, you technically only need to store two axii (say x and y, as the 3rd axis can be derived using cross product.)

Hope this makes sense -- i''m in a rush otherwise i''d explain better.

post again if you don''t get it.


Share this post

Link to post
Share on other sites
You should use quaternions to get smooth rotations and avoid Gimbal lock.

Here is some code :

D3DXQUATERNION qYaw, qPitch, qRoll ;
D3DXQuaternionRotationAxis ( & qYaw , & m_vUp , fYaw ) ;
D3DXQuaternionRotationAxis ( & qPitch , & m_vRight, fPitch ) ;
D3DXQuaternionRotationAxis ( & qRoll , & m_vDir , fRoll ) ;
m_qOrientation *= qYaw ;
m_qOrientation *= qPitch ;
m_qOrientation *= qRoll ;

D3DXMATRIX matOrientation ;
D3DXMatrixRotationQuaternion ( & matOrientation , & m_qOrientation ) ;

// Z vector
m_vDir.x = matOrientation._31;
m_vDir.y = matOrientation._32;
m_vDir.z = matOrientation._33;

// Right vector
m_vRight.x = matOrientation._11;
m_vRight.y = matOrientation._12;
m_vRight.z = matOrientation._13;

// Up vector
m_vUp.x = matOrientation._21;
m_vUp.y = matOrientation._22;
m_vUp.z = matOrientation._23;

Laurent - http://www.lafaqmfc.com/
My little game: http://www.lafaqmfc.com/home/play_starshooter.htm

Share this post

Link to post
Share on other sites
Try removing this line: D3DXMatrixInverse(&matRot, NULL, &matRot);

Well, i can assure that this code works for me BTW, you don''t need to multiply pitch/yaw/roll matrices, because they are used only in rotating local axis. Objects rotation is set by D3DXMatrixLookAtLH(). Try pasting the code again, and don''t mix the lines, cause some of them should be in particular order.

Share this post

Link to post
Share on other sites
I''ve been on this problem for a while. None of the above methods give a true local YPR rotation. It is possible with each of the methods given here (and many others) to even get 2 of the axes of rotation to coincide (input rotations on 2 axes give same rotation of object).

...the search continues

Share this post

Link to post
Share on other sites

Can anybody explain why in Trinka''s code, the matrix generated from D3DXMatrixLookAtLH needs to have its inverse taken?



Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!