Hello! I have been staring at this for hours and have played around with all of the logic and numbers and nothing seems to do what I want. I am trying to create an animation that shows how a shape or object is actually rotated in openGL... so I create an object at a particular point in space, I need to animate it moving to the origin, rotating, and then translating back. So I have been able to get the shape to move around, but once it hit the x = 0 point, instead of changing directions, it stays in a jittering mode, like the direction is continuously getting changed...but I can't seem to understand where my code is doing this. I have pretty much commented everything out so I know where the culprit is but I have no idea where I am going wrong :-( Can anyone please help? I am doing this in baby steps, so as soon as I get the x-direction working I'll start adding in the y and z directions as well as the rotation at the origin...

Thanks!! I have taken out all of the commented code that is not in use yet for legibility...I don't think any of it is relevant to my problem...

Code :
 
 
{void display(void)
{
	//color buffer gets cleared everytime a new frame is drawn
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
 
	glLoadIdentity();
	setWindow(-9.0, 9.0, -1.0, 1.0);			// set the window
 
	glColor3f(1,0,0);
 
	glTranslated(xPos, yPos, 0.0);	
	glutWireCube(.25);  //***THIS WORKS***
 
 
	glutSwapBuffers();	
 
	if (xDirection==0){ //if moving left
		xPos-=0.0005;	//move in a negative direction along the xaxis	
	}
	else if (xDirection==1){
		xPos+=0.0005;	//otherwise move in the positive direction
	}
 
	if (xPos > 0.0) {	
		xDirection=0;
	}
	else {
		xDirection=1;
	}
 
	glutPostRedisplay();
 
 
}
 
int main(int argc, char** argv){
	glutInit(&argc, argv);
	//glutInitDisplayMode (GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);  //double pixel buffer that holds RGB 
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(800, 800);
	glutInitWindowPosition(0,0);
 
 
	glutCreateWindow(argv[0]);
	init();
 
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	//glutIdleFunc(animate);
	glutIdleFunc(display);
	glutMainLoop();
	return 0;
}