PDA

View Full Version : Combining 2 rotation matrix



nuser
06-30-2010, 05:21 AM
Hello!

I am working with openGL ES 2.0. I have checked on The Matrix and Quaternions FAQ what I want to do, but I couldn't find it. I have 2 rotation matrix. First, I have a 4x4 matrix that orientates the model in the space. I got the matrix from a library, so I do not have the single angles. Then, I have a rotation matrix to make my own rotations. However, I have realised I cannot simply multiply them, as I want to apply both rotations with the original coordinate system. In other words, if I apply one of the two matrices work as expected as it rotates from the original coordinates system. However, If I apply both, the second rotation use the coordinate system modified by the first matrix.

Is it a way to add both matrices?

Thanks!!

strattonbrazil
06-30-2010, 12:56 PM
I don't believe this is technically possible. You're either rotating by one then rotating by the other or vice versa. It doesn't make any sense to apply both of them to the original system. You can only change the ordering. In this case, it sounds like you need to multiply the vertices by the one from the library and then multiply on your own.

aqnuep
06-30-2010, 02:06 PM
Are you sure that you don't have any translation information also in your matrices? If both are pure rotation matrices then they are actually "summed" if you multiply them. What means first it rotates based on the first matrix and then based on the second. Would this be the expected behavior btw?

strattonbrazil
06-30-2010, 03:40 PM
They're only "summed" if both are rotating along the same axis, which probably isn't the case. Otherwise, the multiplication of the two matrices isn't commutative.

nuser
07-01-2010, 03:01 AM
Thanks for all the replies!

Is there a way to decompose the matrix I get from the library? Then, I could use the angles to make only one rotation matrix. Would it be a big error on the calculations supposing that it is possible to do it?

strattonbrazil
07-01-2010, 08:35 AM
I don't think you're understanding what I'm saying. Even if you knew the rotation of the first matrix, you would only be able to combine the two matrices if they had the same axis of rotation. I assume that is not the case, however, or you wouldn't be on this forum since it would be working fine.

Having said that, you have one matrix A and another matrix B that rotate along different axi. These rotation matrices are not commutative so AB != BA. This is a mathematical property and not a restriction of the OpenGL language.

Maybe you could step back and explain what you're trying to do. If the model is coming with a rotation matrix, I would assume you just apply it and treat that as if it were the real object space for the model. Then use your own rotation matrix. If you don't like what this model matrix is doing, why are you using it?