# A problem about world transform

This topic is 4193 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Quote:
 Original post by wswqwpsI think the codeD3DXMatrixMultiply(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 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.

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013707
×