Archived

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

EagleWarrior

Rotation Multipcation order

Recommended Posts

EagleWarrior    122
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
Smilediver    142
Heh... i already posted the answer.

Init:

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


Moving:

  
// Normalizing Axis

D3DXVec3Normalize(&pPlayer->vLook,&pPlayer->vLook);
D3DXVec3Cross(&pPlayer->vRight,&pPlayer->vUp,&pPlayer->vLook);
D3DXVec3Normalize(&pPlayer->vRight,&pPlayer->vRight);
D3DXVec3Cross(&pPlayer->vUp,&pPlayer->vLook,&pPlayer->vRight);
D3DXVec3Normalize(&pPlayer->vUp,&pPlayer->vUp);

D3DXMATRIX matPitch,matYaw,matRoll;
D3DXMATRIX matWorld, matRot;
D3DXMatrixIdentity(&matWorld);

D3DXMatrixRotationAxis(&matRoll,&pPlayer->vLook,pPlayer->fRoll);
//Rotate the Right & Up vectors on the Look vector

D3DXVec3TransformCoord(&pPlayer->vRight,&pPlayer->vRight,&matRoll);
D3DXVec3TransformCoord(&pPlayer->vUp,&pPlayer->vUp,&matRoll);

D3DXMatrixRotationAxis(&matYaw,&pPlayer->vUp,pPlayer->fYaw);
//Rotate the LOOK & Right vectors on the UP vector

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

D3DXMatrixRotationAxis(&matPitch,&pPlayer->vRight,pPlayer->fPitch);
//Rotate the LOOK & Up vectors on the Right vector

D3DXVec3TransformCoord(&pPlayer->vLook,&pPlayer->vLook,&matPitch);
D3DXVec3TransformCoord(&pPlayer->vUp,&pPlayer->vUp,&matPitch);

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

Alexander

Share this post


Link to post
Share on other sites
Laurent    100
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
Smilediver    142
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
axon    100
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
Barn Door    140
Hello,

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

Thanks,

BD.

Share this post


Link to post
Share on other sites