My object won't rotate and scale in the same time
I'm working to ge开发者_StackOverflow社区t my objects to rotate on my terrain. Now here is my problem, I can rotate my object but not scale them or scale but not rotate. It depends on which of my line of code goes last. For example, If rotation code goes last it will rotate but not scale.
Here is my code
D3DXMatrixMultiply(¤tFrame->exCombinedTransformationMatrix, ¤tFrame->TransformationMatrix, parentMatrix);
D3DXMatrixScaling(¤tFrame->exCombinedTransformationMatrix, trans.Sx, trans.Sy, trans.Sz);
D3DXMatrixRotationX(¤tFrame->exCombinedTransformationMatrix, D3DXToRadian(trans.Rx));
One of my buddies, Said that I'm overwriting the matrix.
So I tried this
D3DXMatrixMultiply(¤tFrame->exCombinedTransformationMatrix, ¤tFrame->TransformationMatrix, parentMatrix);
D3DXMATRIX w;
D3DXMATRIX s;
D3DXMatrixScaling(&s, trans.Sx, trans.Sy, trans.Sz);
D3DXMatrixRotationX(&w, D3DXToRadian(trans.Rx));
D3DXMatrixMultiply(¤tFrame->exCombinedTransformationMatrix, &s, &w);
The result of the code above is now it will only scale no matter what.
Alternatively, you could try using D3DXMatrixTransformation or D3DXMatrixTransformation2D. These functions seem to take care of all the complexities (well at least the 2D one).
http://msdn.microsoft.com/en-us/library/windows/desktop/bb205365(v=vs.85).aspx and http://msdn.microsoft.com/en-us/library/windows/desktop/bb205366(v=vs.85).aspx
精彩评论