univers coordinates for rotations

I have a fixed camera position and I want to perform rotations around an axe which must stay in its position during the rotation in order to be able to move the object in the correct way (and not int the way it should take if it was a local coordinates system, which one would have turn during the rotation and become uncorrect). I have to use a mouse move event to do this…
Think you for your reply and Xcuse me for my bad english.

I’m not sure but…
I think Jambolo 's just answered quite correctly to the question today…

look at : http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/008415.html

I’m sorry but Jambolo explain exactly what i don’t want : how to turn around the object’s axes. In fact, i would like to keep a global coordinates system even if i perform 2, 3 or more rotations on theX and Y axes. In that way, the one who uses my program can see the objects turning always in the same way (such as in a 3D viewer or modeler program). Maybe i have to combine the 2 rotations:
glRotatef (Xangle , 1.0 , 0.0 , 0.0);
glRotatef (Yangle , 0.0 , 1.0 , 0.0);
in something like that:
glRotatef (angle , Xaxe , Yaxe , 0.0);
but i don’t know how to get 3 values (angle , Xaxe , Yaxe) just with the mouse moving…

I still don’t understand what you want.
Do you want :

1- your object rotating on every axes of its local axes following the movement of the mouse (like in 3DS Max when choosen the overview option)

2- an other movement ?

if it’s 1- (i hope ), the only difference with what Jambolo explained is hte order of your :
glTranslatef() and glRotatef()

  • if you use glRotate first the object will be rotating on its locale axes
  • if you use glTranslate first the object will be rotating around the global axes (as far as you decide that (0,0,0) is the center of your globval coordinates)

ex :

glRotate( yaw, 0,1,0 );
glRotate( pitch, 1,0,0 );
glRotate( roll, 0, 0, -1 );

will make the object rotating on its local axes.
whereas :

glRotate( yaw, 0,1,0 );
glRotate( pitch, 1,0,0 );
glRotate( roll, 0, 0, -1 );

will make the object rotating on the global coordinates.

About the mouse movement, GLUT mouse function catch cursor coordinates quit well.
take a look to : http://www.gamedev.net/reference/articles/article539.asp

[This message has been edited by MPech (edited 05-03-2002).]

[This message has been edited by MPech (edited 05-03-2002).]

The Red Book actually has a decent explanation of order of transformations. There are two ways to think about transformations, but they really just differ in how you think of things.

For me it’s easier to think in terms of global coordinates. If you think in this manner, you have to realize that the LAST transform you did is actually what will get performed FIRST.

So… if you do this…

glTranslatef(10.0, 0.0, 0.0);
glRotatef(90, 0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, 0.0);

Your point ends up sitting at 10, 0, 0 with it rotated at a 90 degree angle. (You wouldn’t really be able to tell it was rotated, but bear with me…) That’s because it was rotated and then moved. The axis system remained in tact. Now… if you are the type who thinks locally you would say, the vertex is first translated to 10,0,0. The local coordinate system is now sittting there as well, so that point has now become 0,0,0. Now we rotate… the whole coordinate system will rotate as well… You still end up with a point rotated 90 degrees sitting at 10,0,0.

Now let’s reverse the order.
glRotatef(90, 0.0, 0.0, 1.0);
glTranslatef(10.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);

You now end up with your point sitting at 0, 10, 0. (or would it be 0, -10, 0 I never remember if positive rotations are clockwise or counter clockwise… ugh…)

How did that happen?

Global point of view:
Point is first moved to 10,0,0. Origin is still at 0,0,0 because the coordinate system hasn’t shifed. Now when we rotate 90 degrees, we are actually rotating around 0,0,0 so the point rotates at an arc putting it at 0,10,0 (or 0,-10, 0)

Local point of view:
First of all we rotate our point… this causes the coordinate system to rotate as well, so that basically, the y axis is horizontal, and the x axis is vertical. Now when we translate, we are moving along this new coordinate system, so we end up moving up (or down) to 0,10,0 (0,-10,0)

Whew… Hope that helps somewhat. I’ve tried to explain this concept many times before to people here and other places and always seem to come up with different ways of giving examples. The main thing you have to realize is that transforms are all relative to how you want to think about them.

[This message has been edited by Deiussum (edited 05-03-2002).]

I assume what you are looking for is a way to rotate around 3 axes in a global space such that each of the rotations are independent. In short, it is not possible – rotating around one axis will affect a subsequent rotation around the others. Order of rotation makes a difference even when rotating in a global system.

However, it is possible to use the difference between the starting orientation and the ending orientation to compute an axis and angle for a single rotation.

Jambolo, that’s exactly what I want but i don’t know how i can compute this rotation… if someone know that it would be very nice ! (i think it implies some skill in math ?) Even if nobody know that, thinks you MPech, Jambolo and Deiussum for your explications.

I don’t know the best way to do it but here is a way off the top of my head:

You want to rotate from orientation A to orientation B. You have the matrix (or quaternion) A, which rotates from 0 (unrotated) to A, its inverse a, and the matrix (or quaternion) B, which rotates from 0 to B.

v’ = Av is a point in orientation A, v’’ = Bv is the point in the orientation B.

v’’ = Bv = BaAv = [i]Ba/i = Bav’

So Ba will rotate from A to B.

[This message has been edited by Jambolo (edited 05-07-2002).]

The way I would do this is by using gluLookAt(…);

I have posted a simple terrain program on my site where I implement rotation in the X and Y axis. It would not be so hard to add a rotation on the Z axis…

Take a look at the camera files to see how you rotate it around… I hope it helps…

If you have difficulties, let me know. email me if you want.

Well, I just went on and added the code for rotating about the Z axis… So get the terrain code and look at the camera code.