PDA

View Full Version : Rotating about global axis at all times



SpeakerX
05-05-2001, 12:26 AM
Hi!
I want to be able to rotate a sphere about the "world axis" at all times. But when I rotate about the x-axis the local axis for the sphere will change and then when I want to rotate about the z-axis I want to be able to do that rotation as if I never did the first one... Sorry about my bad english.

glLoadIdentity();

glTranslatef(0.0f,0.0f,-5.0f);

glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(zrot,0.0f,0.0f,1.0f);

gluSphere(quadratic,1.0f,19,19)

Please help me out! http://www.opengl.org/discussion_boards/ubb/smile.gif

05-05-2001, 12:44 AM
I think it will be something like this:
glLoadIdentity();
glRotatef(around world axis);
glTransletf(...);
glRotatef(around myself);

SpeakerX
05-05-2001, 01:16 AM
Well... It's the rotation about "my self" that I want to avoid. I want both rotations to be about the world/global axis...

SpeakerX
05-05-2001, 02:13 AM
I think I might have been a bit unclear in my first post... I want the sphere to stay i the same place and rotate it about axis parallel to the world's axis. Pherhaps this makes it clearer.
I would still be happy for any information on this! http://www.opengl.org/discussion_boards/ubb/smile.gif

T2k
05-05-2001, 08:42 AM
glRotate ... rotates your matrix around a build matrix, this produces local rotation! to get global rotation you have to multiply the constructed matrix with your object matrix ( opengl: matrix* rotationm.= result, youneed: rotationm.* matrix=result)

the problem is that reading states/matrices is slow, so you have to calc all matrixopps by yourself and load the result into opengl via glLoadMatrix ...

SpeakerX
05-05-2001, 08:49 AM
Thank you!
I'll try that!

05-06-2001, 01:55 PM
You can also try

glLoadIdentity();
glTranslatef(...);
glRotatef(1.0f, xrot, 0.0f, zrot);

Bob
05-07-2001, 06:29 AM
glRotatef(1.0f, xrot, 0.0f, zrot);

is not the same as



glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(zrot,0.0f,0.0f,1.0f);

The first piece will rotate the object one degree about the vector (xrot, 0, zrot), while the second piece will rotate the object first zrot degrees about the Z-axis, and then xrot degrees about the X-axis. Two completely different operations.

05-07-2001, 11:59 PM
Yes, you are right. he he http://www.opengl.org/discussion_boards/ubb/redface.gif
I always use (rot,...,1.0f, ..) and interpreted that a multiplication around the given axis.

Well, live and learn... http://www.opengl.org/discussion_boards/ubb/smile.gif