Archived

This topic is now archived and is closed to further replies.

Rotation about world, instead of object axes?

This topic is 5226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a 3x3 rotation matrix that represents an object''s orientation. I''ve applied several rotations to the object that compound so that rotation always occurs around the object''s rotated x, y, and z axes, not the original world x, y, and z axes. However, as an additional feature I want to be able to rotate objects around the world axes as well. That''s where the problem begins because I can''t stop the objects rotating around the new rotated axes. I thought it would make sense to reverse the matrix order so that instead of applying a yaw rotation matrix: [cos a, 0, -sin a] [0, 1, 0] [sin a, 0, cos a] to the object''s existing matrix, I would reverse the order to that the orientation became a fresh rotation around the world axes, with the existing matrix applied afterwards, however it still won''t work. I WAS really pleased with this compounding rotation effect, because I used to suffer from gimbal lock, but now I need to be able to rotate both ways and I can''t figure it out. Paulcoz.

Share this post


Link to post
Share on other sites
To rotate around the world z-axis, you need to rotate the vector (0,0,1) by the inverse of your current rotation matrix. This is the world z-axis, so you can just do a standard axis-angle rotation around it. Let me know how it works.


Mike

Edited by - Vetinari on June 24, 2001 1:01:38 AM

Share this post


Link to post
Share on other sites
Vetinari, do you mean this (* asterix for formatting only):

[0,0,1]*X**[1,0,0] x vector
*********[0,1,0] y vector
*********[0,0,1] z vector

It seems that multiplying the 0,0,1 vector by the inverse of the rotation matrix will just give you [0, 0, (z vector z value) ]

What do you do with the resulting vector once you have it? How do you apply this to the existing rotation matrix?

Regards,
Paulcoz.

Edited by - paulcoz on June 24, 2001 2:11:04 AM

Share this post


Link to post
Share on other sites
Ok, here''s the steps, let me know which ones you don''t understand.

1) Invert your current rotation matrix.

2) Apply that to whatever world axis you want to rotate around.

3) Rotate around the resulting vector.


Mike

Share this post


Link to post
Share on other sites
I haven't used an axis-angle representation before, that's why I'm having trouble - it looks like your method comes up with a single vector to rotate around, whereas I'm used to applying a whole matrix when I do local rotations.

The step I don't understand is No. 3. Can you explain how to do the same thing using a UVN vector system? (eg. 3 unit vectors)

Thanks,
Paulcoz.

Edited by - paulcoz on June 24, 2001 9:55:24 PM

Share this post


Link to post
Share on other sites
I''m not that familular with the UVN system. Isn''t it just three vectors (view directon, up direction and right direction) that form a matrix?

To rotate around an arbitray vector, you should multiply your 3x3 rotation matrix (the one you mention in your first sentence of your first post) by the axis-angle matrix. The axis-angle matrix is a bit complex to type here, but it is described in detail on this site in Diana Gruber''s article "Do we Really Need Quaternions?".

It is located here:
http://www.gamedev.net/reference/programming/features/whyquats/

The matrix you want is the second matrix on the first page, matrix ''R''; if you are using a 3x3 matrix, you only need the top left 3x3 matrix of the 4x4 matrix she provides.

So why did you give up on quaternions? They are much easier for this kind of thing.


Mike

Share this post


Link to post
Share on other sites
Vetinari,

Now that I've seen your description I think you need to do the following when using the UVN vector system:

(1) Calculate an inverse matrix for the current 3x3.
(2) Calculate a matrix for rotation around the world axis you want.
(3) Multiply these in 1 then 2 order.
(4) Multiply this new matrix by the original 3x3 again.
(5) The matrix calculated in step 4 is the one you apply to your current 3x3 to get the new rotated position.

You rotate your current matrix back to its identity position (perfectly aligned with world axes), perform the new rotation, then apply your starting orientation again to get the final position, I THINK...

I could use your axis-angle matrix in step 2, but I don't have a problem creating rotation matrices for the world axes - it's applying this rotation to my existing matrix that confused me & I think I've found the answer now.

I'll test it out, and let you know how I go (I may need to cry like a baby for help if this doesn't work).

Paulcoz.

Edited by - paulcoz on June 25, 2001 4:05:38 AM

Share this post


Link to post
Share on other sites
For any 3x3 orthonormal matrix, you don''t really need to calculate it''s inverse. Just transpose it, and that will do.
(Consider mathematical proof of this statement your home assignment

Share this post


Link to post
Share on other sites
In theory, I should be able to skip steps 1, 3 and 5 as long as I apply the world rotation matrix and the existing one in reverse order (world * existing). I've already tried it that way (it didn't work) so I'll need to try the axis-angle matrix. I'll do it tonight and give you an answer one way or the other.

Paulcoz.

Edited by - paulcoz on June 25, 2001 11:47:35 PM

Share this post


Link to post
Share on other sites
O.k, the five step idea I mentioned didn't work (that was my invention so was understandable!), and neither did the axis-angle one.

If you recall I want to rotate around the world axes, not the object's axes so I plug in the unit vectors 0,0,1 ,0,1,0 and 0,0,1 without an angle to see what the axis-angle matrices look like compared to my existing rotation matrices (seen in first post of this thread). It's exactly the same thing for these particular unit vectors so I guess I've got the matrix right - I'm doing something else wrong.

Perhaps it's something to do with the matrix multiplication order, or maybe I need to transpose or inverse one or more of the matrices first, or after multiplication. I'm all out of ideas, so if anyone else has any, I'm all ears!

Paulcoz.

Edited by - paulcoz on June 28, 2001 8:08:51 PM

Share this post


Link to post
Share on other sites
Paulcoz -
Here''s what you need to do. You need to find transform the world axis into your local frame, then rotate around that axis. In general this requires an inverse of the current matrix. Show me the code of my three step process and I''ll tell you what you are doing wrong.


Mike

Share this post


Link to post
Share on other sites
Sorry Mike, I think I see what you mean now - you have to transform the world axis you want to rotate around into the coordinate system of the existing 3x3 matrix before you rotate around it.

Paulcoz.

Edited by - paulcoz on June 28, 2001 11:55:28 PM

Share this post


Link to post
Share on other sites
Hi Mike, it''s working now thanks.

Do you have any screenshots or demos of your own project I can have a look at? It seems I''ve been making some progress on my own project (a level editor), but there''s always someone out there who''s already been through all the stuff I have whenever I have a question - I''m surprised there aren''t more people eager to show off their work!

Paulcoz.

Share this post


Link to post
Share on other sites
quote:
Original post by paulcoz
Do you have any screenshots or demos of your own project I can have a look at?


My last project was a Q3A level loader; I don''t have any screenshots readily available mainly because I don''t have the inclination to make a website. If you can imagine, it looked similar to quake 3


Mike

Share this post


Link to post
Share on other sites
two quite easy ways: if you do matrix multiplication, then having the matrix one side will result in a local transformation and having it on the other side will result in a global transformation. so all you have to do is let the two matrices switch places.

reason. left or right side decides if your transformation is applied before or after. obviously doing it before means doing it when local and global is still the same.

the other option is to use the transposed of the axis you want to rotate around, as an orthonormal matrix can be inversed by simply transposing it.

if you have this:
x0 y0 z0
x1 y1 z1
x2 y2 z2

you rotate around x1 y1 z1 instead of y0 y1 y2 etc.

in my camera im using the first version for directx and the second for opengl and they both work fine.

[edited by - Trienco on August 23, 2003 3:30:16 AM]

Share this post


Link to post
Share on other sites