Rotating about global axis at all times

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!

I think it will be something like this:
glLoadIdentity();
glRotatef(around world axis);
glTransletf(…);
glRotatef(around myself);

Well… It’s the rotation about “my self” that I want to avoid. I want both rotations to be about the world/global axis…

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!

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 …

Thank you!
I’ll try that!

You can also try

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

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.

Yes, you are right. he he
I always use (rot,…,1.0f, …) and interpreted that a multiplication around the given axis.

Well, live and learn…