# D3DXMatrixMultiply, order & X/Y switch?

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

## 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)
{
D3DXMatrixMultiply(&mMatWorld, &pMatWorldParent, &mMatTransform);
}

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

void CD3drenderable::CreateWorldMatrix(const D3DXMATRIX &pMatWorldParent)
{
D3DXMatrixMultiply(&mMatWorld, &mMatTransform, &pMatWorldParent);
}



##### Share on other sites

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



• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 14
• 30
• 9
• 16
• 22