D3DXMatrixRotationYawPitchRoll(...) not working?

Started by
5 comments, last by JohnBolton 18 years, 7 months ago

	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
--X
Advertisement
you need to multiply your matrices
-----------------www.stevemata.com
Yea I found that using 3 different matricies works after multiplying them together. But isnt that a waste of space?
--X
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);
_______________________________________________________________________Hoo-rah.
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.
--X
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.
_______________________________________________________________________Hoo-rah.
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);
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

This topic is closed to new replies.

Advertisement