PDA

View Full Version : AHHH its the timer crisis



iNsaNEiVaN
05-31-2001, 04:00 PM
Ok, iv'e read NeHe's tutorial on creating a timer and all of that but I'm not sure if that code fits my case. I want the screen to render fast but I want only certain things in my scene to be slowed down (because now they are way too fast). This is much like how it is in modern games; a screen could render 20fps or 100fps but all the moving objects move at the same speed in both cases. How can I do this??

Thanks!

AndersO
05-31-2001, 11:37 PM
Position+=Velocity*dtime;

Where dtime is the time it took to draw previous frame. Use timeGetTime() or QueryPerformanceCounter() to calculate dtime, assuming your in windows.

dans
06-01-2001, 02:09 PM
dont forget set your movement to units per second.. then work from a scalar value which represtents how long in seconds the last frame took to render.

float starttime, endtime, timetaken, scalar;

float movespeed = 10; // move at 10 units per sec
starttime = currenttime;
render();
endtime = currenttime;
timetaken = endtime-starttime;
// assuming your timer reports in 1000's of a second
scalar = timetaken/1000.0f;
position+=movespeed*scalar;

iNsaNEiVaN
06-02-2001, 09:26 AM
How do you round a floating-point number into an integer?

zed
06-02-2001, 01:07 PM
on a similar thread u all might wanna have a looksy at this http://www.flipcode.com/cgi-bin/msg.cgi?showThread=Tip-MainLoopTimeSteps&forum=totd&id=-1