This topic is now archived and is closed to further replies.


timing the scene

Recommended Posts

dadio    122
we all know that we want our GL app to run at same speeds on all systems... and to do it, we limit the fps to ~30. my question is: should I design my personal timig system, or work with the win32 WM_TIMER? any disadvanteges to the latter? thx

Share this post

Link to post
Share on other sites
Maximus    124
You dont limit the fps at all, you interpolate instead! Use a high-performance timer and get the time delta of each frame, and use it in your next frame to smooth out movement, and making it run at the appropriate speed.

Share this post

Link to post
Share on other sites
TheGilb    372
Ok imagine this, instead of moving a vertex by .x of a unit every frame and limiting the frame rate (Because what happens then if the computer isn''t fast enough to run @~30FPS?), you say how many units you would like the vertex to move over the course of a single second.

// get the current time
currenttime = gettime()
// assume 1000 ticks in a second (note lasttime is the time when this function was last called)
delta = (currenttime - lasttime) / 1000

// now we add a part of the total desired velocity over 1 second, depending on how much of a full second has elapsed since we last updated the position
vertex.x += (vertex.xvel * delta)
vertex.y += (vertex.yvel * delta)
vertex.z += (vertex.zvel * delta)

// and finally update lasttime
lasttime = currenttime

Ok that code fragment probably doesn''t work However, hopefully it gives you the general gyst (It''s too early for me to try and be specific!) of what''s going on. Delta must be a part of 1. If a full second has elapsed since the last frame then the whole of the velocity is added to the vertex position, but even if the function is called several times a second, it will still appear to the user that the object has travelled the same distance over the course of a second.

Hope that helps :-)

Share this post

Link to post
Share on other sites