View Full Version : how to move based on time ??
doodlemunch
01-19-2006, 05: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 :(
songho
01-19-2006, 06:54 AM
doodlemunch,
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.
cpsmusic
01-20-2006, 01:42 AM
Hi,
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.
Cheers,
Chris
doodlemunch
01-21-2006, 03:45 AM
i could not find much info about the perf counter only msdn but i did not quite get it :(
Not a GL question but...
#define _NO_OLDNAMES 1
#include <sys/timeb.h>
double system_clock;
struct _timeb tm;
_ftime (&tm);
system_clock= static_cast<double> (tm.time);
system_clock += static_cast<double> (tm.millitm*.001);
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.