u56237z 100 Report post Posted February 22, 2010 Hi everybody, Im going mad with a problem I have in developing an application that lets the user rotate a simple object around a specific origin.. the rotations are only about the Y and X axis.. the problem is that the origin of rotation can change. now, everything is ok until I change the rotation origin.. it seems like the first rotation changes the axis for the subsequent rotations example: rotate 47deg around Y rotate 23deg around X and everything is fine.. then I change the rotation origin and when I, say, rotate 20deg around X, the X axis the object will rotate is not anymore world-X. Im using matrices, and multiply the new rotation mat everytime the origin changes. I switched to quaternions, and got exactly the same results I had with matrices. Is there something Im missing? Thank you :) 0 Share this post Link to post Share on other sites
haegarr 7374 Report post Posted February 22, 2010 Assume that an object is transformed by a matrix M so far. An additional rotation R applied about a world axis gives thenR * M(using column vectors; change the order if you're using row vectors). If you want to use another center of rotation, then you have to make the desired center temporarily the origin, i.e. you define another "rotation"R' := T * R * T^{-1}where T denotes the translation matrix to the desired center of rotation. Substition gives thenT * R * T^{-1} * M 0 Share this post Link to post Share on other sites
u56237z 100 Report post Posted February 22, 2010 sorry I was in a bit of a hurry while writin my last post..of course, in order to define a new center of rotation, opportune translations take place..the actual code is something like this:translate(x,y,z);multiply_matrix(m);translate(-x,-y,-z);m is a matrix converted from the rotation quaternionthere is a main matrix k, which gets modified by each translation and rotation, and is reset before each loop, unless there is an origin change, in which case it is multiplied by the new translation/rotation/translation matrix and so forth..I can rotate and translate everything for as long as I want, and everything is ok (k -identity at the beginning- is calculated at each loop).but when I chancge the origin, I get a new x,y,z, reset rotation angles, recalulate m. k (which holds t/r/t around the last origin) is saved and reloaded at each loop, so that the new transformations (t/r/t) add up to the last-origin k.I have to multiply matrices when changing origin, otherwise the rotations will be ok, but the object will suddently change screen position while rendering (the new origin will be in the middle of the screen).the problem is that the new rotations will not refer to the world axis anymore.hope Ivenot been too messy :) 0 Share this post Link to post Share on other sites
haegarr 7374 Report post Posted February 22, 2010 Err, well, I'm sure that I haven't understood ;(Mathematically the precedence is clear: When using column vectors, then the sequenceR_{1} * vmeans that v is rotated about the global axis as incorporated in R_{1}.Multiplying another rotation on the left (remember: column vectors) ever means to do another rotaton about a global axis.R_{2} * R_{1} * vi.e. v is rotated about the global axis as incorporated in R_{1}, and the result of that is rotated about the global axis as incorporated in R_{2}. There is no possibility that a translation changes this.If you accidentally do a multiplication on the rightR_{1} * R_{2} * vthen the effect is that you seem to rotate about a local axis.This is because after the first rotationR_{1}you may create a rotationR_{2}' := R_{?} * R_{2} * R_{?}^{-1}so that the desired local axis becomes temporarily the global one (this is equivalent to the temporary center of rotation concept). Now, since R_{1} defines the current orientation, it is clear thatR_{?} == R_{1}must hold. Hence after substitution we getR_{1} * R_{2} * R_{1}^{-1} * R_{1}= R_{1} * R_{2}q.e.d.For row vectors you have to reverse all the matrix products, of course. So, the only explanation I have ATM is: Either you use a wrong order and hence has a mathematical error, or else your implementation is messed up (in which case we need to inspect code). 0 Share this post Link to post Share on other sites
u56237z 100 Report post Posted February 22, 2010 uh.. hmm..no,implementation is ok.. but you gave me a couple of things to think about..thank you! 0 Share this post Link to post Share on other sites