• Advertisement
Sign in to follow this  

D3DXMatrixMultiply, order & X/Y switch?

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

Hi,

I've noticed something 'strange' when I multiply a parent world matrix with a childs transform matrix.

Depending on the order:

 

1 - the result is as expected

2 - the X and Y transformation are switched and - = + and the vice versa

 

No problem for the result, because option 1 works fine.

But I'm curious why option 2 gives the result as described.

Any logical explanations?
 

Here are the 2 variants:

// OPTION 1 = OK

void CD3drenderable::CreateWorldMatrix(const D3DXMATRIX &pMatWorldParent)
{
	ComposeD3DXWorldMatrix(&mMatTransform, D3DXVECTOR3(mScale, mScale, mScale), DEGTORAD(mRot.x), DEGTORAD(mRot.y), DEGTORAD(mRot.z), mPos);
	D3DXMatrixMultiply(&mMatWorld, &pMatWorldParent, &mMatTransform);
}

// OPTION 2 = NOT OK (X/Y and pos/neg switched)

void CD3drenderable::CreateWorldMatrix(const D3DXMATRIX &pMatWorldParent)
{
	ComposeD3DXWorldMatrix(&mMatTransform, D3DXVECTOR3(mScale, mScale, mScale), DEGTORAD(mRot.x), DEGTORAD(mRot.y), DEGTORAD(mRot.z), mPos);
	D3DXMatrixMultiply(&mMatWorld, &mMatTransform, &pMatWorldParent);
}

Share this post


Link to post
Share on other sites
Advertisement

Matrix multiplication is not commutative.  A × B ? B × A.

 

Your matrices are row-major, so option #1 is the correct choice, which is the logical result of combining the parent transform followed by the child transform.

If your matrices are column-major (transposed from row-major) then the order of multiplication is reversed and #2 is correct.

 

 

L. Spiro

Share this post


Link to post
Share on other sites

Thanks LSpiro, also for the quick response.

 

Just 'for fun' I've transposed the matrices and tried it like option 2, and it worked as expected.

	D3DXMATRIX transform;
	D3DXMatrixTranspose(&transform, &mMatTransform);
	D3DXMATRIX world;
	D3DXMatrixTranspose(&world, &pMatWorldParent);

	D3DXMatrixMultiply(&mMatWorld, &transform, &world);
	D3DXMatrixTranspose(&mMatWorld, &mMatWorld);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement