rotating multiple circles

this is my code…

/* CGR331 Intermediate Computer Graphics I Fall 2002 Lesson 1
Instructor: Douglas Easterly deaster@syr.edu 229 Shaffer
Example program 2b1: starting simple: making a circle*/

#include <cgr331_02.h>

/* this will draw a cirlce in any program - but you would probably remove the glClear and glFlush as they would be put specifically at the beginning and end of your drawing code respectively*/

void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 0.0);
drawSolidCircle(250.0, 250.0, 50.0);

glColor3f(1.0, 0.8, 0.0);
drawSolidCircle(50.0, 30.0, 20.0);

glColor3f(1.0, 0.7, 0.0);
drawSolidCircle(100.0, 30.0, 20.0);

glColor3f(1.0, 0.6, 0.0);
drawSolidCircle(150.0, 30.0, 20.0);

glColor3f(1.0, 0.5, 0.0);
drawSolidCircle(200.0, 30.0, 20.0);
glColor3f(1.0, 0.4, 0.0);
drawSolidCircle(250.0, 30.0, 20.0);
glColor3f(1.0, 0.3, 0.0);
drawSolidCircle(300.0, 30.0, 20.0);
glColor3f(1.0, 0.2, 0.0);
drawSolidCircle(350.0, 30.0, 20.0);
glColor3f(1.0, 0.1, 0.0);
drawSolidCircle(400.0, 30.0, 20.0);
glColor3f(1.0, 0.0, 0.0);
drawSolidCircle(450.0, 30.0, 20.0);
glFlush();
}

/… myReshape …/
void myReshape(int w, int h){
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 500.0, 0.0, 500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/… main …/
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500.0, 500.0);
glutCreateWindow (“CGR topic 2B_1”);
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMainLoop();
}

i want the circles to rotate around the larger circle in the middle and end up one behind the other in the center of the larger cirlce, which is set on the center axis

you could try using the glRotate command with each circle and a difference rotation angle increment. Remembering that angles of rotation need to be global variables incremented as needed. Watch out for strange values when it reaches a certain point and things start looking weird… But then you may be lucky and get it all working…

Not sure how that would work though as several attempts I made using just those commands didn’t work well for me.

I ended up using matrix and vertex rotation calculations similar to those used at gametutorials.com camera tutorials.

I hope that helps you somewhat…

Tina

Here is what you need to add:

First you will need a routine to update you screen objects, which will make the rotation.

// Global variable

GLfloat rotate_circle;

glutIdleFunc( My_IdleFunc ); // add to your main before glutMainLoop();

// The Idle routine to make our circles rotate
void My_IdleFunc()
{
rotate_circle++;
if (rotate_circle > 360) rotate_circle = 0; Max rotation is 360 degrees, reset when over.
}

Next changes to draw() routine.

Between each circle add this:

glPushMatrix();

glColor3f(…); set color of circle
drawSolidCircle(250.0, 250.0, 50.0);
// Is this your routine… what is the function of each variable (x, y, r)?
// If it is x, y, r
then the following change:
x1 = r * cos( angle ); // X, r = a radius greater then the largest circle, a little over 1/2 of the smaller circles, angle has to be converted from degress to rad’s
y1 = r * sin( angle ); // Y
drawSolidCircle(x1, y1, 50.0);
glPopMatrix();

and with each the other circle repeat above structure but add “X” degree offsets. Say you can eight circles going around that it would be about +12 degress for each circle after the first one.

I hope this makes since…

Do you have the code for drawSolidCircle, if it already uses glPush/glPop. then they will not be needed, just put the sin/cos function before each new circle…

Originally posted by nystama:
[b]this is my code…

/* CGR331 Intermediate Computer Graphics I Fall 2002 Lesson 1
Instructor: Douglas Easterly deaster@syr.edu 229 Shaffer
Example program 2b1: starting simple: making a circle*/

#include <cgr331_02.h>

/* this will draw a cirlce in any program - but you would probably remove the glClear and glFlush as they would be put specifically at the beginning and end of your drawing code respectively*/

void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 0.0);
drawSolidCircle(250.0, 250.0, 50.0);

glColor3f(1.0, 0.8, 0.0);
drawSolidCircle(50.0, 30.0, 20.0);

glColor3f(1.0, 0.7, 0.0);
drawSolidCircle(100.0, 30.0, 20.0);

glColor3f(1.0, 0.6, 0.0);
drawSolidCircle(150.0, 30.0, 20.0);

glColor3f(1.0, 0.5, 0.0);
drawSolidCircle(200.0, 30.0, 20.0);
glColor3f(1.0, 0.4, 0.0);
drawSolidCircle(250.0, 30.0, 20.0);
glColor3f(1.0, 0.3, 0.0);
drawSolidCircle(300.0, 30.0, 20.0);
glColor3f(1.0, 0.2, 0.0);
drawSolidCircle(350.0, 30.0, 20.0);
glColor3f(1.0, 0.1, 0.0);
drawSolidCircle(400.0, 30.0, 20.0);
glColor3f(1.0, 0.0, 0.0);
drawSolidCircle(450.0, 30.0, 20.0);
glFlush();
}

/… myReshape …/
void myReshape(int w, int h){
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 500.0, 0.0, 500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/… main …/
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500.0, 500.0);
glutCreateWindow (“CGR topic 2B_1”);
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMainLoop();
}

i want the circles to rotate around the larger circle in the middle and end up one behind the other in the center of the larger cirlce, which is set on the center axis[/b]