View Full Version : Make sphere move in a circle

04-20-2010, 04:58 AM
I'm trying to get a sphere to move around in a circle. I know how to make it spin by using glRotatef but how do i do if i want to move it around in a circle?

This is the part of my code that does the spinning animation right now:

if (animation == TRUE) {
glRotatef(angle, 1.0f, 1.0f, 1.0f);
glColor3f(1.0, 1.0, 1.0);
glScaled(2, 1, 1);

This code makes it rotate around itself. But thats not what i want...

Thank you!

04-20-2010, 08:14 AM
Everything spins around the origin, so if you want it to not to rotate around itself, you have to move it off the origin with a translation then rotate it.

04-20-2010, 11:07 PM
Thank you for your reply. I got it to work by using glRotateF and then glTranslatef!

I now have another question. I've just put "legs", aka spheres, on my other sphere. I want these legs to move like legs. I've been able to make them spin around 360 degrees by using glRotatef but i want them to go 180 degrees and then go back and so forth. How do i do this? This is the part of my code that generates the spinning:

idle (void)
angle += 0.05;

elbow = (elbow - 1) % 360;


glTranslatef(0.0, 0.3, 0.0);
glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0);
glTranslatef(0.0, -0.3, 0.0);

Thanks in advance!