Jump to content
  • Advertisement
Sign in to follow this  
wswqwps

A problem about world transform

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

In the SDK I saw the code:

void C3DModel::MakeWorldMatrix( D3DXMATRIX* pMatWorld )
{
    D3DXMATRIX MatTemp;  // Temp matrix for rotations.
    D3DXMATRIX MatRot;   // Final rotation matrix, applied to 
                         // pMatWorld.
 
    // Using the left-to-right order of matrix concatenation,
    // apply the translation to the object's world position
    // before applying the rotations.
    D3DXMatrixTranslation(pMatWorld, m_xPos, m_yPos, m_zPos);
    D3DXMatrixIdentity(&MatRot);

    // Now, apply the orientation variables to the world matrix
    if(m_fPitch || m_fYaw || m_fRoll) {
        // Produce and combine the rotation matrices.
        D3DXMatrixRotationX(&MatTemp, m_fPitch);         // Pitch
        D3DXMatrixMultiply(&MatRot, &MatRot, &MatTemp);
        D3DXMatrixRotationY(&MatTemp, m_fYaw);           // Yaw
        D3DXMatrixMultiply(&MatRot, &MatRot, &MatTemp);
        D3DXMatrixRotationZ(&MatTemp, m_fRoll);          // Roll
        D3DXMatrixMultiply(&MatRot, &MatRot, &MatTemp);
 
        // Apply the rotation matrices to complete the world matrix.
        D3DXMatrixMultiply(pMatWorld, &MatRot, pMatWorld);
    }
}

I think the code

D3DXMatrixMultiply(pMatWorld, &MatRot, pMatWorld);

shoule be

D3DXMatrixMultiply(pMatWorld, pMatWorld , &MatRot);

because I think the Matrix pMatWorld = pMatWorld X MatRot and the function should work like this. Am I wrong?Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by wswqwps
I think the code


D3DXMatrixMultiply(pMatWorld, &MatRot, pMatWorld);



shoule be



D3DXMatrixMultiply(pMatWorld, pMatWorld , &MatRot);



because I think the Matrix

pMatWorld = pMatWorld X MatRot and the function should work like this.
Am I wrong?Thanks!


If you did your way, you would be applying translations (b'cos pMatWorld holds that when you call the function) before rotations. You typically apply rotations before translations ( I say "typically" although that depends on the behaviour you want), which is why the call is set up that way. Then,

pMatWorld = matRot x matWorld; //apply rotation and translation to matWorld

HTH

Share this post


Link to post
Share on other sites
Hi, not sure what you want but why can't you just do some thing like this
MatResult = (matscale *(matRotationX, * matRotationY))* matTrans.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!