Jump to content
  • Advertisement
Sign in to follow this  
xsirxx

D3DXMatrixRotationYawPitchRoll(...) not working?

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

	ObjectList.push_back(loInc);
	int iThisObj = ObjectList.size() - 1;

	D3DXMatrixIdentity( &ObjectList[iThisObj].matObjectToWorld );
	D3DXMatrixScaling( &ObjectList[iThisObj].matObjectToWorld, ObjectList[iThisObj].vecScale.x, ObjectList[iThisObj].vecScale.y, ObjectList[iThisObj].vecScale.z );
	D3DXMatrixRotationYawPitchRoll( &ObjectList[iThisObj].matObjectToWorld, ObjectList[iThisObj].vecRotation.x, ObjectList[iThisObj].vecRotation.y, ObjectList[iThisObj].vecRotation.z );
	D3DXMatrixTranslation( &ObjectList[iThisObj].matObjectToWorld, ObjectList[iThisObj].vecTranslation.x, ObjectList[iThisObj].vecTranslation.y, ObjectList[iThisObj].vecTranslation.z );
	D3DXVECTOR3 test1, test2;
	D3DXQUATERNION test3;
	D3DXMatrixDecompose(&test1, &test3, &test2, &ObjectList[iThisObj].matObjectToWorld);
	ObjectList[iThisObj].iMaterialIndex = (MeshList[ObjectList[iThisObj].iMeshIndex].VertexList[0].iMaterialID - START_MATERIAL);

	return;

When I use the D3DXMatrixDecompose(...) everything comes back fine except all the rotations are coming back as 0,0,0? Why is this? In my game everything is scaled and translated properly but not rotated. So thats why I put in the decompose to test what was wrong. Also the rotations are in radians and they are correct when I build the matrix.... Also RotationX, Y , Z doesnt work when I seperate it. Ideas? Thanks, Brad

Share this post


Link to post
Share on other sites
Advertisement
Yea I found that using 3 different matricies works after multiplying them together. But isnt that a waste of space?

Share this post


Link to post
Share on other sites
Whenever you use a function like MatrixTranslation or MatrixRotationYawPitchRoll, the function erases whatever was in the destination matrix. That is, the function doesn't multiply the destination by a new transformation, it sets the destination matrix to the new transformation.

You don't have to "waste space" in your class to do this properly, you can use temp variables. So you'd do something like

D3DXMATRIX matRotate, matTranslate, matScale;
D3DXMatrixRotationYawPitchRoll(&matRotate,...);
D3DXMatrixTranslation(&matTranslate,...);
D3DXMatrixScaling(&matScale,...);
D3DXMatrixMultiply(&ObjectList[iThisObj].matObjectToWorld,&matScale,&matRotate);
D3DXMatrixMultiply(&ObjectList[iThisObj].matObjectToWorld,&ObjectList[iThisObj].matObjectToWorld,&matTranslate);

Share this post


Link to post
Share on other sites
Quote:
Original post by Drakex
You don't have to "waste space" in your class to do this properly, you can use temp variables. So you'd do something like


Right That I know, but it is still taking up space, temp or not. In which multiply them against 4 floats takes alot less. Anywho it works I guess I shouldnt bitch too much about 16 * 3 extra floats.

Share this post


Link to post
Share on other sites
Lol, it's not like computers today (especially gaming computers) are exactly running short on memory :) In just 1MB, you could store 16,384 matrices, a number which I doubt you'll be approaching any time soon; and temp mats go away when the function returns anyway.

Share this post


Link to post
Share on other sites
Take a look at these improvements:

ObjectList.push_back(loInc);
Object & object = ObjectList.back();
D3DXMATRIX temp;

D3DXMatrixIdentity( &object.matObjectToWorld );

D3DXMatrixScaling( &temp, object.vecScale.x, object.vecScale.y, object.vecScale.z );
D3DXMatrixMultiply( &object.matObjectToWorld, &temp, &object.matObjectToWorld );

D3DXMatrixRotationYawPitchRoll( &temp, object.vecRotation.x, object.vecRotation.y, object.vecRotation.z );
D3DXMatrixMultiply( &object.matObjectToWorld, &temp, &object.matObjectToWorld );

D3DXMatrixTranslation( &temp, object.vecTranslation.x, object.vecTranslation.y, object.vecTranslation.z );
D3DXMatrixMultiply( &object.matObjectToWorld, &temp, &object.matObjectToWorld );

D3DXVECTOR3 test1, test2;
D3DXQUATERNION test3;
D3DXMatrixDecompose(&test1, &test3, &test2, &object.matObjectToWorld);
object.iMaterialIndex = (MeshList[object.iMeshIndex].VertexList[0].iMaterialID - START_MATERIAL);



Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!