• Advertisement
Sign in to follow this  

object constantly moving side to side

This topic is 3742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement