   glutTimerFunc runs too fast
  Hey everyone. I have a small game development project that I am doing for my graphics class and I seem to be having some issues with the glutTimerFunc in GLUT. I've searched the Internet quite thoroughly but I can't seem to come up with a solution to my problem. I am using glutTimerFunc to animate a shape when a user presses a button. In my game, for example, when the user presses the space bar, a stone is supposed to be launched from a catapult. It works pretty well (I say pretty well because I still have some bugs to work out with the physics equations) the first time. Every time after that though, the animation increases absurdly fast in execution time to the point where you don't even see it. I had this problem before with a bowling game that I had to create. Nothing that I've found online seems to fix the problem. I'll post my code for the glutTimerFunc, keyboardFunc, and the animation code itself. I would greatly appreciate any input./******************************************************************//* Function: drawProjectile/******************************************************************/void drawProjectile(void){if(launched){// draw the projectileglColor3f(1.0, 1.0, 1.0);drawCircle(projRadius, projXC, projYC);//cout << "XC: " << projXC << " YC: " << projYC << endl;glutTimerFunc(ANIMATION_SPEED, timerFunc, 0);}}/******************************************************************//* Function: launchProjectile/******************************************************************/void launchProjectile(void){if(launched && !moving){moving = true;// I added this because whenever the angle was 0// I got an undefined for the y velocityif(angle > 44)initVelocity = maxAngle - angle + 1;elseinitVelocity = maxAngle - angle;// calculate the time it will take to move from current point// to point of impact   totalTime = (2*initVelocity*sin(angle*PI/180))/gravity; //(2*initVelocity*sin(angle))/gravity// get range between point of launch and point of impactrange = initVelocity*totalTime*cos(angle*PI/180); // initVelocity * time * cos(angle)// calculate x and y velocitiesvelocityX = range/totalTime;velocityY = totalTime * gravity * 0.5;//cout << "iVelocity: " << initVelocity << " range: " << range//<< " velocityX: " << velocityX << " veloctiyY: " << velocityY << endl;}if(moving){projXC += velocityX/2;projYC += velocityY;velocityY -= gravity;}if(projXC + projRadius > 800 || projYC + projRadius > 400 ||   projXC - projRadius < 0   || projYC - projRadius < 0){// reset all the values (thought it might solve the issue with// hyper-fast animation speedslaunched = false;moving = false;initVelocity = 0;totalTime = 0;range = 0;velocityX = 0;velocityY = 0;projXC = -10;projYC = -10;}}/******************************************************************//* Function: displayFunc/******************************************************************/void displayFunc(void){glClear(GL_COLOR_BUFFER_BIT);// call functions for drawing the gamedrawTerrain();drawCastle();drawCatapult();drawProjectile();writeMessage(25, 10, message); // 'angle' word_itoa_s(angle, buffer, 10);writeMessage(110, 10, buffer); // angle valuewriteMessage(25, 370, health); // 'health' for cata_itoa_s(cataHealth, buffer, 10);writeMessage(120, 370, buffer);writeMessage(500, 370, health); // 'health' for castle_itoa_s(castleHealth, buffer, 10);writeMessage(595, 370, buffer);glutSwapBuffers();} /*****************************************************************//* Function: timerFunc/*****************************************************************/void timerFunc(int value){launchProjectile();glutPostRedisplay();glutTimerFunc(ANIMATION_SPEED, timerFunc, 0);}/*****************************************************************//* Function: keyboardFunc/*****************************************************************/void keyboardFunc (unsigned char c, int x, int y){if(c == 32) // ascii value for spacebar{// try to draw the stone relatively near the// 'arm' of the catapultprojXC = cataXStart-40;projYC = cataYStart+angle+10;launched = true;}glutPostRedisplay();}Sorry for the enormous post. This is really frustrating though, and I would like to figure out what's going on. If anyone wants/needs all the source code, please just send me a message and I can e-mail.Thanks!-Zach   
  I figured it out! Apparently glutTimerFunc doesn't appreciate being called twice. :OI was calling it in the timerFunc function AND in the movement function. Not really sure what that did, but moving the glutTimerFunc out of the movement function and into main() solved the problem.   