Problem understanding and using Rotation

OK I am having a real hard time getting rotation to work for me, so I would appreciate any help. Here is the situation:

I am drawing a sphere (glutSolidSphere) centered at “origin”, ox, oy, oz.

I am drawing a smaller sphere (electron, heh) at location ex, ey, ez.

I need to make the electron rotate around the central sphere. What translations/rotations do I need to perform to make this happen?

I tried all sorts of combinations and feeding glRotatef different vectors, but none of it seems to give me the results I expect.

Please help me understand this.

Here’s an example to cause it to rotate around the sphere at the origin in the xz plane.

glRotate(angle, 0, 1, 0);
glTranslate(distanceFromCenter, 0, 0);

Notice the order of the calls. If you think about things in terms of world coordinates, the last transformation called is effectively is the first transformation applied.

Now… assuming you want to rotate around an arbitrary plane you would find the perpendicular vector to that plane to use in the glRotate above, and find a point in the plane that is the appropriate distance from the center for the translate.

Here:

// Create atom
// Store matrix
glPushMatrix()
glTranslate // Location in world of Atom.
glRotate // Rotation of Atom

Draw_nucleus_of_atom();

// Draw first Electron
//
glRotate // Location in orbit
glTranslate // Distance from nucleus
// Notice we switch location of glRotate and glTranslate

Draw_electron();
glPopMatrix();

// Start next electron
// Repeat above steps.

glPopMatrix(); //End of Draw Atom.

Notice with the electron we only need tell the distance from the nucleous to the electron and the glRotate takes care of movement around the nucleous.

This work’s also for planet’s…

See my clock demo on my website, is a good example of rotation’s and matrix usage:
www.angelfire.com/linux/nexusone/

Originally posted by xenadu:
[b]OK I am having a real hard time getting rotation to work for me, so I would appreciate any help. Here is the situation:

I am drawing a sphere (glutSolidSphere) centered at “origin”, ox, oy, oz.

I am drawing a smaller sphere (electron, heh) at location ex, ey, ez.

I need to make the electron rotate around the central sphere. What translations/rotations do I need to perform to make this happen?

I tried all sorts of combinations and feeding glRotatef different vectors, but none of it seems to give me the results I expect.

Please help me understand this.[/b]

[This message has been edited by nexusone (edited 04-28-2003).]

Thanks!