Continuous Rotation

Hello all,
I have a program that correctly draws an object on the screen. Now, I want to rotate the scene continuously when the user presses the enter.


else if(key==13){
		while(1){
			GLfloat yAxis=cam.getPos()[1];
			cam.setAlpha(fmod(cam.getAlpha()+10.0,360));
                        cam.setPos(xComp*cos(cam.getAlpha()*DEGREE_
        TO_RADIAN),yAxis,xComp*sin(cam.getAlpha()*DEGREE_TO_RADIAN));
			glutPostRedisplay();
		}
	}

where cam is an instance of Camera class and the calculations inside are made to move the position of the camera on a circle in x-z plane.

When I replace while(1) line to for(i=0;i<5;i++), this code calculates the camera positions for 5 times and displays only the last position of the screen.
I added a Sleep function but it did not solve the problem.

How can I make it draw not only the last but also other positions of the screen.

Thanks in advance.

Add a variable holding state of enter key (eg. 1 - pressed, 0 - not pressed), and update position of Your camera per frame (when key is pressed). Your program must catch key press, and key release events, and update variable.

in your draw function:


if(key_is_pressed)
        update_camera_pos();