object constantly moving side to side
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?
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
Popular Topics
Advertisement