Cquest

01-18-2014, 09:49 PM

Greetings! I encounter some problems while learning openGL.

Here is my problem:

I use 241 points to draw a curve as track.

Then draw a cylinder move on the track(241 points) at the same time rotate about axis which parallel to x-axis.

rotate rate:9 degrees per step

I want to use TimerFunction(or any other ways) to make the cylinder move but remain the track fixed, but they will rotate together.

Could anyone tell me how to use TimerFunction, glPushMatrix(); , and glPopmatrix(); ?

Here is my code: use visual C++ 6.0

//draw a cylinder

GLUquadricObj *quadratic;

quadratic=gluNewQuadric();

glPushMatrix();

glTranslatef(-2.0f,-2.0f,0.0f);

glColor3f(1.0f,0.0f,0.0f);

gluDisk(quadratic,0.0f,0.05f,32,32);

glColor3f(0.9f,0.91f,0.98f);

gluCylinder(quadratic,0.05f,0.05f,0.5f,32,32);

glTranslatef(0.0f,0.0f,0.5f);

glColor3f(0.0f,0.0f,1.0f);

gluDisk(quadratic,0.0f,0.05f,32,32);

glPopMatrix();

glutSwapBuffers();

//draw the curve

glBegin(GL_LINE_LOOP);

glVertex2f(-2.0f,-2.0f);

glVertex2f(-1.94109f,-2.05415f);

glEnd();

//I simply post on all 241 points to draw the curve.

glFlush();

}

void TimerFunction(int value)

{

glTranslatef(241 points);

glRotatef(9,1.0,0.0,0.0);

glutPostRedisplay();

glutTimerFunc(33,TimerFunction,1);

}

Thank you very much.

Here is my problem:

I use 241 points to draw a curve as track.

Then draw a cylinder move on the track(241 points) at the same time rotate about axis which parallel to x-axis.

rotate rate:9 degrees per step

I want to use TimerFunction(or any other ways) to make the cylinder move but remain the track fixed, but they will rotate together.

Could anyone tell me how to use TimerFunction, glPushMatrix(); , and glPopmatrix(); ?

Here is my code: use visual C++ 6.0

//draw a cylinder

GLUquadricObj *quadratic;

quadratic=gluNewQuadric();

glPushMatrix();

glTranslatef(-2.0f,-2.0f,0.0f);

glColor3f(1.0f,0.0f,0.0f);

gluDisk(quadratic,0.0f,0.05f,32,32);

glColor3f(0.9f,0.91f,0.98f);

gluCylinder(quadratic,0.05f,0.05f,0.5f,32,32);

glTranslatef(0.0f,0.0f,0.5f);

glColor3f(0.0f,0.0f,1.0f);

gluDisk(quadratic,0.0f,0.05f,32,32);

glPopMatrix();

glutSwapBuffers();

//draw the curve

glBegin(GL_LINE_LOOP);

glVertex2f(-2.0f,-2.0f);

glVertex2f(-1.94109f,-2.05415f);

glEnd();

//I simply post on all 241 points to draw the curve.

glFlush();

}

void TimerFunction(int value)

{

glTranslatef(241 points);

glRotatef(9,1.0,0.0,0.0);

glutPostRedisplay();

glutTimerFunc(33,TimerFunction,1);

}

Thank you very much.