Sign in to follow this  
aston

object constantly moving side to side

Recommended Posts

aston    122
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
RobTheBloke    2553

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this