Jump to content

  • Log In with Google      Sign In   
  • Create Account

D3DXMatrixMultiply, order & X/Y switch?


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1   Members   

4623
Like
0Likes
Like

Posted 01 April 2014 - 03:07 PM

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


Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me


#2   Members   

24826
Like
2Likes
Like

Posted 01 April 2014 - 03:21 PM

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



#3   Members   

4623
Like
0Likes
Like

Posted 01 April 2014 - 03:45 PM

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


Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.