Rotation matrix: absolute rotation instead of relative?

Hi,

When multiplying rotation matrices for rotating around x, y and z-axes R = Rx * Ry * Rz (http://en.wikipedia.org/wiki/Rotation_matrix), I get a relative rotation matrix, meaning that rotation around Y is not the original Y-axis, but the new axis that has "occured" after rotating around X.

What I want to do, is to have absolute rotation, so that the Y-rotation is performed around the original Y-axis, and not the new one (absolute rotations instead of relative).

If you know the math for this, I would appreciate if you let me in on it :-)

Thanks!!



Answer this question

Rotation matrix: absolute rotation instead of relative?

  • Superboy

    Thanks - I will try to get it right with all of these comments in mind :-)
  • Michal Levy

    I don't know about what your engine does internally, but if you also pass in a translation you could have mixed the order producing a strange result. You should do the rotation first. So your matrix should be M = Rx * Ry * Rz * T. Or do you have two seperate matrices
  • TomPepe

    That's certainly the right way to do it if your rotation is around the model's centre and not around your world's centre. The important thing here is that the transformations happen in the order that you write them so if you were to do T*R then you would translate away from the origin and then rotate around that origin, but if you do it R*T as suggested then you rotate your model first and then translate it to where you want it positioned. It really depends on what you are trying to do.

    Same goes for rotations if you do Rx*Ry*Rz then you will rotate around x first then y then z but there's nothing to stop you doing it in another order. Just be aware of the consequences.

    Certainly scaling first will give you the usual desired transformation.


  • nathan koterba

    Order of rotation is important. If you multiply your matrices in the wrong order it will seem as though you are getting relative rotation. In computer graphics the vector comes first and then the matrices in order from first to last: v*R1*R2*R3 (which is the reverse of how a mathematician would usually write it R3*R2*R1*v).

    Just be sure to multiply the matrices from left to right in the order you want them to take effect and then make sure that you are putting the vector first not the concatenated matrix (if you are multiplying by hand).


  • arvindbksc

    Thanks for the feedback!

    I thought the D3D docs said that multiplication should be Matrix = ScaleMat * Rx * Ry * Rz * Transl

    Isn't that right -Here the translation matrix comes last..


  • question mark

    I think I do exactly what you say, but I still get this result. I will have to look closer at my code, I guess.

    Thanks for your feedback :-)


  • George.Saliba

    Thanks Nico,

    You are probably right then.

    I send the resulting matrix R into a game engine (together with translation), and there the rotation becomes relative. I guess the internals of the game engine is the problem then, and not my math...

    Is it possible that the game engine multiplies my resulting matrix with the internal game-engine matrix so that the rotation becomes relative, or is that "mathematically impossible"

    (The matrix is used for setting the position+orientaition for a mesh, meaning the world matrix for the mesh doing Mesh.SetMatrix(myMatrix) on the mesh. The SetMatrix() is a game engine-specific method)

    -Torbjorn


  • Eva DELORD

    > I get a relative rotation matrix, meaning that rotation around Y is not the original

    > Y-axis, but the new axis that has "occured" after rotating around X.

    Hm, I don't think that should happen. Because you don't rotate the coordinate system, you only rotate your vectors. I think what your matrix R should do, is to rotate your vector first around the x-axis, then around the (original) y-axis, and then around z. So it should do exactly what you want. But it seems it's not what you get. Are you sure that the rotation is wrong Check it with a very simple vector matrix combination.

    Hope this helps a little... I'm also curious to know why you get a strange result ;-)

    Nico


  • Rotation matrix: absolute rotation instead of relative?