Timing?
I''m having some problems getting my ogl scenes to run at a constant rate...
Like, right now I''m using a laptop with a shitty 8mb card, and on this computer the scenes run as fast as I want ''em to, but if I run the same scene on a killer machine, it''ll run extremly fast...too fast even.
In short, I wanna know how to manipulate the speed of the scene.
- Surreal
(Surreal was already taken, so I went with SurrealSlacker...)
- Surreal(Surreal was already taken, so I went with SurrealSlacker...)
i am just a newbie myself but try the following. i guess right now you are moving your objects a constant distance EVERY FRAME, meaning that the higher the framerate, the higher the speed your object travels at. i.s.o. doing this, declare the speed of your object in function of time, f.i. 5 world units per second. then you implement a function to get the current system time (i believe there is a tut on Nehe''s site) with which you can calculate the elapsed time after every frame. i use Queryperformancetimer for this (or something like that). with this you can calculate the distance your object has moved (distance = speed x elapsed time).
i hope this helps you a bit. for the code how to this, i suggest you to look in the tuts on Nehe''s site or in a book or something. since i am a newbie too, i won''t write code in here, it wouldn''t work anyway.
good luck
i hope this helps you a bit. for the code how to this, i suggest you to look in the tuts on Nehe''s site or in a book or something. since i am a newbie too, i won''t write code in here, it wouldn''t work anyway.

good luck
first you need a timer that gives you time of last frame.
ftime = timer.GetLastFrameTime();
then every object has it speed and position and function to update that object
class myObject {
Vector pos, speed;
void Update( float time ) {
pos += speed*time;
}
...
}
you call car.Update( timer.GetLastFrameTime() );
this way if your framerate is high time of frame is low and object moves just a bit everyframe and if your framerate is low, frame time is high and object moves more in one frame. the result is that it actualy moves the same distance in same time independand of framerate
hope it helps....
There are more worlds than the one that you hold in your hand...
ftime = timer.GetLastFrameTime();
then every object has it speed and position and function to update that object
class myObject {
Vector pos, speed;
void Update( float time ) {
pos += speed*time;
}
...
}
you call car.Update( timer.GetLastFrameTime() );
this way if your framerate is high time of frame is low and object moves just a bit everyframe and if your framerate is low, frame time is high and object moves more in one frame. the result is that it actualy moves the same distance in same time independand of framerate
hope it helps....
There are more worlds than the one that you hold in your hand...
You should never let your fears become the boundaries of your dreams.
March 16, 2002 04:09 AM
1) _never_ use GetTickCount() ! It''s too inaccurate - animations will be non-smooth. Use timeGetTime (multimedia timer) or QueryPerformanceCounter
2) correct timing is good, but if you''ll run app on extremly slow hardware, you''ll see nothing interesting(what for correct move timing if you dont see any moves?). So, I think it will be better to limit delta time(timer.GetLastFrameTime()) to some value(e.g. 50 milliseconds for 20 fps limit). In this case on slow computers scene will be slow, but more informative and on fast computer it will be OK.
2) correct timing is good, but if you''ll run app on extremly slow hardware, you''ll see nothing interesting(what for correct move timing if you dont see any moves?). So, I think it will be better to limit delta time(timer.GetLastFrameTime()) to some value(e.g. 50 milliseconds for 20 fps limit). In this case on slow computers scene will be slow, but more informative and on fast computer it will be OK.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement