Rotating around any referential

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

Recommended Posts

Im slowly getting into this 3D programming thing and there is one thing I've found myself incapable of doing: rotating an object around a referential other than its own. Right now im using quaternions hold my rotation information. I then compute my world matrix by applying the scale, then the rotation, then the translation. This results in a local rotation (object rotates using its own axis as referential) What I'd like to do is rotate around "world" referential. That is, no matter what orientation my object currently has, I want it to spin in the same absolute direction. How do I go doing that?

Share on other sites
if scale * rotate * translate give you a local rotation

scale * local_rotate * translate * world_rotate should give you what you want

Share on other sites
Im not sure I fully understand what you mean. What do you mean by that 2nd and 4th matrix, local_rotate and world_rotate ?

I create the scale matrix from a scaling factor, this one is easy to understand.
I create the translate matrix from a Vector3, again not much going on.

I create the rotation matrix based on a an axis and an angle. For example (0,1,0) and 90 degree would rotate my object 90 degree around its Up axis.

Now you're bringing in a local_rotate and world_rotate. Which one of these is the matrice I create from my axis and angle? And how do I get the other ?

Share on other sites
whoops. guess i coulda been more clear. sorry, sometimes I post before I remember being a teacher means NOT assuming the student can read my mind.

lets try:
Quote:
 I create the rotation matrix based on a an axis and an angle. For example (0,1,0) and 90 degree would rotate my object 90 degree around its Up axis.

do that for any rotation matrix.

LocalMatrix = scale * local_rotate
WorldRotation = world_rotation_translate * world_rotation * inv_world_rotation_translate
WorldMatrix = LocalMatrix * world_translate * WorldRotation

local_rotate - matrix from axis + angle that will be preformed in local space to the object. In this case, you said this is 90deg around (0,1,0)

lets put you at (5,5,5):
world_translate - where you want the object is world space

lets rotate about the world axis (0,0,1), and the world point (1,1,1):

inv_world_rotation_translate - think of all rotations happening at the origin, and thus you have to move things around to get everything in the right place. So you need to translate your object so the rotation point IS the origin.
In this case, you inv_translate by (-1,-1,-1).
then rotate

world_rotation - just another axis+angle matrix. In this example, around (0,0,1).

--edit. re-read. I screwed up in my first posting of this.

Share on other sites
Oh yeah I should've thought about the whole inverse matrix thing *boink* Thanks alot!

I had found a way around it due to XNA providing a ton of functions for everything. If I wanted a local rotation, I'd do it with quaternion. If I wanted world, I'd do it with a matrix. I used matrix->quaternion and quaternion->matrix conversion to keep both coherent with one another.

But invert matrices are cleaner and more efficient.

Share on other sites
Quote:
 I had found a way around it due to XNA providing a ton of functions for everything. If I wanted a local rotation, I'd do it with quaternion. If I wanted world, I'd do it with a matrix. I used matrix->quaternion and quaternion->matrix conversion to keep both coherent with one another. But invert matrices are cleaner and more efficient.
Even if you've managed to get things working the way you want, what you're doing doesn't sound quite right. A couple of things to consider:

1. There's no particular correlation between quaternions and local rotations and matrices and world matrices. If you're finding you're having to use one representation or the other or convert back and forth between the two representations to get the results you want, then you're doing something wrong.

2. If all you're wanting to do is to apply a world-axis rotation rather than local-axis rotation, you shouldn't need to perform any matrix (or quaternion) inversions.

Now, to answer your original question (as I understand it at least), one way to change a local-axis rotation to a world-axis rotation or vice versa is to reverse the order of multiplication, e.g.:
// If this results in a local-axis rotation:m = m * matrix_from_axis_angle(yaw, 0, 1, 0);// Then this will result in a world-axis rotation:m = matrix_from_axis_angle(yaw, 0, 1, 0) * m;// And vice versa (which order results in a local-axis rotation and// which order results in a world-axis rotation depends on the vector// notation convention being used).
So I would try just reversing the order of multiplication of the rotation matrices in your original code, and see if you get the results you're after.

• 18
• 11
• 16
• 9
• 49
• Forum Statistics

• Total Topics
631397
• Total Posts
2999783
×

Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!