Determining Time DifferencesAfter rendering the scene, compare the current time with the one you last took. We will store this in the secsperframe variable. //first determine how many seconds elapsed timerdiff = TimerGetTime()-timer; //the function reads in milliseconds so convert to seconds by dividing by 1000 secsperframe=(float)(timerdiff/1000.0f); Let's say the number comes out to be .0125. To get the frame rate, simply divide 1 second by that .0125. This gives you an answer of 80, since 80 times that .0125 is equal to 1 second. To determine how much to move, you simply take the desired distance and divide by the frames per second. Movement = (desired distance)/(frames a second) In this example, that would be 1 divided by 80 which would give you .0125 as stated above. The equation can be changed, though, if we substitute in the equation for frames per second. Now it reads: Movement = (distance desired)/(1/seconds per frame) This can be further simplified to: Movement = (distance desired)*(seconds per frame) I find this equation to be the easiest to use. In NeHe Lesson 23, this looks like: //now compute the movement value movementval = (float)(desireddistance*secsperframe); //get the new time timer = TimerGetTime(); |