glutTimerFunc problem

Benutze ich Glut um eine einfache animation. In der main-Funktion glutTimerFunc(TIMERMSECS, animate, 0) genannt wird. Die beiden Teile des codes generieren, die gleiche Grafik.

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

Methode 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();
}

Methode 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);
}

Der einzige Unterschied zwischen Ihnen ist die position der glutTimerFunc. Für Method 1 sieht es aus wie eine rekursive, dass wird nie erreichen das Ende animate()Funktion. Aber warum heißt das immer noch funktionieren?

InformationsquelleAutor Sean | 2011-08-26

Schreibe einen Kommentar