PDA

View Full Version : Make sphere move in a circle



uberweiss
04-20-2010, 05:58 AM
Hi!
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:


glPushMatrix();
if (animation == TRUE) {
glRotatef(angle, 1.0f, 1.0f, 1.0f);
}
glColor3f(1.0, 1.0, 1.0);
glScaled(2, 1, 1);
glutWireSphere(1.0,40,40);
glPopMatrix();


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

Thank you!

strattonbrazil
04-20-2010, 09: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.

uberweiss
04-21-2010, 12:07 AM
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:


void
idle (void)
{
angle += 0.05;

elbow = (elbow - 1) % 360;
glutPostRedisplay();
}

.............

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!