glutTimerFunc problème

- Je utiliser Glut pour faire une animation simple. Dans la fonction principale, glutTimerFunc(TIMERMSECS, animate, 0) est appelé. Les deux morceaux de codes de générer le même graphique.

const int TIMERMSECS = 20;
float animation_time = 0;
const float  animation_step = .5;

Méthode 1:

   void animate(int t){
        float time_elapsed = TIMERMSECS/1000.0;
        float current_step = animation_step* time_elapsed;
        glutTimerFunc(TIMERMSECS, animate, 0);
        if(current_step < animation_step*2) 
                animation_time += current_step;
        glutPostRedisplay();
}

Méthode 2:

   void animate(int t){
        float time_elapsed = TIMERMSECS/1000.0;
        float current_step = animation_step* time_elapsed;      
        if(current_step < animation_step*2) 
                animation_time += current_step;
        glutPostRedisplay();
       glutTimerFunc(TIMERMSECS, animate, 0);
}

La seule différence entre eux est la position de glutTimerFunc. Pour Method 1, il ressemble à un récursif qui n'atteindra jamais la fin de animate()fonction. Mais pourquoi cela fonctionne encore?

OriginalL'auteur Sean | 2011-08-26