Followers 0

# D3DXMatrixMultiply, order & X/Y switch?

## 2 posts in this topic

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


0

##### 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

2

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


0

## Create an account

Register a new account