Advertisement

Time/Frame Based Movement - Need Tutorials!!

Started by June 16, 2004 02:14 PM
4 comments, last by sir_wojciech 20 years, 5 months ago
I need some good sites were I can learn Time Based Movement or Frame Based Movement? Thenks!
Here's one called: Timing and FPS
Minister of Propaganda : leighstringer.com : Nobody likes the man who brings bad news - Sophocles (496 BC - 406 BC), Antigone
Advertisement
gametutorials its in the OpenGL section (time based movement).
And another called: Main Loop with Fixed Time Steps
Minister of Propaganda : leighstringer.com : Nobody likes the man who brings bad news - Sophocles (496 BC - 406 BC), Antigone
You won't need a tutorial for that. All you have to do is measure the frame time (usually in milliseconds, or 1/1000 of a second) and multiply every time-dependent variable with it. Here's an example in not-so-but-still pseudocode:

void IterateFrame(float t){  Object.pos.x += Object.speed.x * t;  Object.pos.y += Object.speed.y * t;  Object.pos.z += Object.speed.z * t;  //do other stuff}int main(){long old_t = GetTimeMarkerInMilliseconds();while(true) { long new_t = GetTimeMarkerInMilliseconds(); float t = (new_t - old_t) / 1000.f; IterateFrame(t); old_t = new_t; }}


In IterateFrame() Object.speed is a simple time-dependent variable, which applies to a constant time period (it's easiest to make this period a second) and t identifies the fraction of a second it took to process the previous frame. t can be anything greater than zero. 1/t gives you the projected framerate for this second.

To find out how to do something like GetTimeMarkerInMilliseconds(), check ou NeHe's tutorials (nehe.gamedev.net) - I beleieve some of those took the QueryPerformanceTimer() approach.

Easy as pie.

Oh, and if this is still too confusing, just ask what you don't understand.
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Thanks!

This topic is closed to new replies.

Advertisement