   [DX9] Simple rotation problem
  Im trying to rotate an object around its own x, y and/or z axis, but when I rotate it, it rotates around the world's x, y and z axis; therefore it goes around the center point of the world instead of spinning around its own axis.When I export the objects (x-file exporting) I dont export them in their local space, therefore they are exported with their world space coordinate and I render them with an identity matrix.Can anyone direct me in the right direction to get them to spin/rotate around their own axis.   
  I think the simplest way would be to use incremental rotations. This thread has more information (start reading from the post I linked).   ;Quote:Original post by Gage64I think the simplest way would be to use incremental rotations.Im not sure if im doing it right, but is this what you mean?D3DXMATRIX l_d3dmWorldMatrix = this->m_pWorldTransform->GetTransformationMatrix();D3DXMATRIX l_d3dmRotationMatrix;D3DXMATRIX l_d3dmResult;D3DXMatrixRotationX( &l_d3dmRotationMatrix, l_fDx );D3DXMatrixMultiply( &l_d3dmResult, &l_d3dmRotationMatrix, &l_d3dmWorldMatrix );this->m_pWorldTransform->SetTransformationMatrix( l_d3dmResult );where l_fDx is the x mouse movement in one frame. I then render the object with the world transform's transformation matrix. this is still not working though ^\^   ;Quote:Original post by G-Man9566Im trying to rotate an object around its own x, y and/or z axis, but when I rotate it, it rotates around the world's x, y and z axis; therefore it goes around the center point of the world instead of spinning around its own axis.If you multiply a vector with a rotation matrix, e.g. around z like in[ c -s 0 ]<br>[ 0  0 1 ]</pre>(where c denotes the cosine of an angle, and s the sine of the same angle), then there are points in space that are not affected by the rotation (i.e. mapped &#111;nto self). All those points are &#111;n a straight line, usually called the axis of rotation. In the example above that are all points [ 0 0 z ] with an arbitrary z. Would you say that this axis is local or global or whatever? The rotation simply happens in the co-ordinate system in which, due to the structure of the rotation matrix, [ 0 0 z ] (in this example) defines the rotation axis. You cannot really pick either "local" or "global" as the space where the rotation should happen. You can just pick the axis of rotation.<br><br>Now, if you concatenate another rotation, like in (using row vectors, since you use D3D)<br><b>R</b> := <b>R</b><sub>1</sub> * <b>R</b><sub>2</sub><br>to transform a point <b>p</b> like in<br><b>p</b>' := <b>p</b> * <b>R</b><br>mathematics tells us that<br><b>p</b>' = <b>p</b> * ( <b>R</b><sub>1</sub> * <b>R</b><sub>2</sub> ) = ( <b>p</b> * <b>R</b><sub>1</sub> ) * <b>R</b><sub>2</sub><br>so that for each individual rotation the same principle counts.<br><br>Because "global" and "local" are just references, you can express a vector (and hence matrix or transformation) that is defined in the &#111;ne space also in the other space. This is done by applying a space transformation. Such a transformation changes the vector (…) in the space where the transformation is applied, as usual. But it isn't changed when you simultaneously pick the other space as reference. Such a transformation is usually called the "local-to-global" or even better "local-to-"world" transform.<br><br>That said, you can pick an axis of rotation in the "local" space and transform it into the "global" space for ultimately applying the rotation. Let's say you want to apply the above rotation<br><b>R</b><sub>1</sub> * <b>R</b><sub>2</sub><br>where <b>R</b><sub>2</sub> should happen around an axis given as local vector <b>a</b> before <b>R</b><sub>1</sub> was applied.<br><br>What can be done is to use an axis/angle rotation representation with an axis<br><b>a</b>' :=  <b>a</b> * <b>R</b><sub>1</sub><br>and convert that into a matrix.<br><br>Another, more convenient way is to "undo" the former rotation <b>R</b><sub>1</sub> temporarily, so that the wanted axis falls coincident with the same axis but "global" ATM of applying <b>R</b><sub>2</sub>. Because the current transformation is <b>R</b><sub>1</sub>, we need to apply its inverse to undo its effect:<br><b>R</b><sub>1</sub> * <b>R</b><sub>1</sub><sup>-1</sup> * <b>R</b><sub>2</sub><br>Of course the first rotation shouldn't be dropped totally, so we need to redo it after <b>R</b><sub>2</sub> (that is why I said "undo temporarily"):<br><b>R</b><sub>1</sub> * <b>R</b><sub>1</sub><sup>-1</sup> * <b>R</b><sub>2</sub> * <b>R</b><sub>1</sub><br>The above equation can be simplified, so we get<br><b>R</b><sub>2</sub> * <b>R</b><sub>1</sub><br>as result.<br><br>Compare that formula with the original &#111;ne<br><b>R</b><sub>1</sub> * <b>R</b><sub>2</sub><br>and notice that nothing but the order has changed! This is the fact: <i>You can get the result of virtually rotating around local axes by applying the rotations in reverse order, although actually you never rotate around what is considered the local axes</i> (okay: with the exception of the very first rotation applied, because at that moment the axes are coincident in both spaces).<br><br><br>As for the "point to rotate around": A rotation expressed by a rotation matrix always passes through [ 0 0 0 ] because for any matrix <b>R</b> you'll get<br>[ 0 0 0 ] * <b>R</b> == [ 0 0 0 ]<br>what means that the zero vector is ever mapped &#111;nto self, and hence is part of the rotation axis. If you perhaps want the axis virtually pass through another point, you need to make that point temporarily zero:<br><b>T</b><sup>-1</sup> * <b>R</b> * <b>T</b><br>shifts the point that is bound by the vector from which the translation matrix <b>T</b> is computed to zero, just for the time of rotation.<br><br><!–EDIT–><span class=editedby><!–/EDIT–>[Edited by - haegarr on April 8, 2010 5:14:06 AM]<!–EDIT–></span><!–/EDIT–>;  I found an extremely simple solutions that works for me, using DX9 functions...D3DXMATRIX l_d3dmWorldMatrix;D3DXQUATERNION l_d3dqRotation;D3DXQuaternionRotationYawPitchRoll( &l_d3dqRotation, l_fYawRadians, l_fPitchRadians, l_fRollRadians );D3DXMatrixTransformation( &l_d3dmWorldMatrix,    nullptr,   nullptr,   nullptr,  &this->GetPosition(),  &l_d3dqRotation,   nullptr );this->m_pWorldTransform->SetTransformationMatrix( l_d3dmWorldMatrix );;Quote:Original post by G-Man9566I found an extremely simple solutions that works for me, using DX9 functions...*** Source Snippet Removed ***You have hopefully noticed that the D3DX functions you've found do exactly what I've explained in my post above, namely (a) using the "inverted" order due to D3DXQuaternionRotationYawPitchRoll implements an Euler rotation, and (b) surrounding the rotation with a temporary position shift:Quote:from some Microsoft documentationThis function calculates the transformation matrix with the following formula, with matrix concatenation evaluated in left-to-right order:Mout = (Msc)-1 * (Msr)-1* Ms * Msr * Msc * (Mrc)-1* Mr * Mrc * Mtwhere:Mout = output matrix (pOut)Msc = scaling center matrix (pScalingCenter)Msr = scaling rotation matrix (pScalingRotation)Ms = scaling matrix (pScaling)Mrc = center of rotation matrix (pRotationCenter)Mr = rotation matrix (pRotation)Mt = translation matrix (pTranslation);  ^\^ >  No I havent, but thanks for pointing it out.   