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 cozzie   Members   -  Reputation: 1764

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



Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 14262

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


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 cozzie   Members   -  Reputation: 1764

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






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.



PARTNERS