object constantly moving side to side

Started by
0 comments, last by RobTheBloke 16 years, 5 months ago
hi, can anyone help to make a simple rectangle move constantly side to side i.e. move horizontally along the x axis, do you have to use the idle function?
Advertisement
float gTime=0;float gPosX=0;void idle(){  float dt = getTimeBetweenThisUpdateAndLastFromSomewhere();  gTime += dt;  gPosX = sin(gTime);  // i assume you are using glut?  glutPostRedisplay();}void display(){  // set up camera etc  glPushMatrix();   glTranslatef(gPosX,0,0);   glutSolidCube(1.0f);  glPopMatrix();}


something like this?

This topic is closed to new replies.

Advertisement