Advertisement

need to animate circles

Started by September 29, 2002 06:26 PM
0 comments, last by LisaSnyder 22 years, 5 months ago
i have this working code, now i want to make them just move from one point to another point, all at once, or individually. can anyone help me figure out how to do this? /* PROJECT 2 TRIAL different circles on the screen */ #include <cgr331_02.h> /* this function is used to draw and place circles with variables that will be changed through a looping mechanism*/ void display (void) { //LEFT SIDE glClear (GL_COLOR_BUFFER_BIT); //added in glPushMatrix(); glColor3f(0.0, 0.0, 1.0); drawSolidCircle(100.0, 400.0, 40.0); // big circle 1 glColor3f(0.0, 0.2, 1.0); drawSolidCircle(150.0, 400.0, 30.0); //circle 2 glColor3f(0.0, 0.4, 1.0); drawSolidCircle(175.0, 400.0, 20.0); //circle 3 glColor3f(0.0, 0.6, 1.0); drawSolidCircle(180.0, 400.0, 10.0); // small circle 4 //RIGHT SIDE glColor3f(0.0, 0.0, 1.0); drawSolidCircle(380.0, 400.0, 40.0); //big circle 1 glColor3f(0.0, 0.2, 1.0); drawSolidCircle(330.0, 400.0, 30.0); //circle 2 glColor3f(0.0, 0.4, 1.0); drawSolidCircle(305.0, 400.0, 20.0); // circle 3 glColor3f(0.0, 0.6, 1.0); drawSolidCircle(300.0, 400.0, 10.0); // small circle 4 //BOTTOM of design glColor3f(0.0, 0.0, 1.0); drawSolidCircle(240.0, 300.0, 40.0); //big circle 1 glColor3f(0.0, 0.2, 1.0); drawSolidCircle(240.0, 350.0, 30.0); //circle 2 glColor3f(0.0, 0.4, 1.0); drawSolidCircle(240.0, 375.0, 20.0); // circle 3 glColor3f(0.0, 0.6, 1.0); drawSolidCircle(240.0, 380.0, 10.0); // small circle 4 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 ("PROJECT 2 TRIAL"); glutReshapeFunc(myReshape); glutDisplayFunc(display); glutMainLoop(); }
Well, at first ... you should change set your display function to be in an Idle function as well, or just create a new one.
glutIdlefFunc(...);
This is the function that glut will call if there''s no process to handle.

in your idle function, use combination of global values and glTranslatef to move things... For Ex.

GLfloat X_Position = 0.0f;

void Idle() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity(); //Quite important here.
glTranlatef(X_Position,0.0f,0.0f);
//draw.....
//Advance value
X_Position++;
}

Note that the whole thing might move really fast...

This topic is closed to new replies.

Advertisement