View Full Version : how to move based on time ??

01-19-2006, 06:35 AM
hi i want to move objects and quads by time and not by step every frame you know what i mean how should i start? an easy aproach please! it is important and i dont know tis yet :(

01-19-2006, 07:54 AM
First, define the speed (e.g: units per second) of a moving object then measure the elapsed time for each frame.
The delta distance to move for each frame can be computed like this;

dt = currTime - prevTime;
distance = speed * dt;

You need a timer to measure at least millisecond precision.

01-20-2006, 02:42 AM

You need a clock of some sort. The clock can be used to update whatever you're doing at a particular time interval (e.g. 5 ms).

On Windows, I've used QueryPerformanceCounter(), but there are other clocks available (DirectX, etc.). There are probably similar things available for other platforms.

I've got some code that shows how to use the Performance Counter if you need it.



01-21-2006, 04:45 AM
i could not find much info about the perf counter only msdn but i did not quite get it :(

01-22-2006, 07:35 AM
Not a GL question but...

#define _NO_OLDNAMES 1
#include <sys/timeb.h>

double system_clock;
struct _timeb tm;
_ftime (&amp;tm);
system_clock= static_cast<double> (tm.time);
system_clock += static_cast<double> (tm.millitm*.001);