Frame rate and animation speed
Hi,
The frame drawing method for most of the tutorial code ive seen is called by a loop in the main method. Does this mean that the framerate is solely dependant on the speed of execution of that loop? If this is the case then the animation speed of your graphics will be dependant only on how fast your computer is.
If that is right, is it common for people to put framerate limiters into their program? Otherwise animations might look stupidly fast e.g. If you make an animation of someone walking, you want them to walk at a constant speed regardless of the computer your program runs on(as long as their computer meets the minimum specs).
Id appreciate if someone could explain how the framerate works in the examples as im having troubles trying to figure out what appropriate rotation speeds etc to use.
Thanks,
Vipa.
there are 2 ways for animations:
fixed fps:
(though better only on a console) you know exactly how often the game updates, so you know how much to increment your variables. This is achieved by making that loop check how long it has been since the last update and if it was longer than x ms ago, make it update.
variable fps:
your variables are increased each frame, but the amount is multiplied by the result of a formula that calculated how much time passed since the last frame.
So with a variable fps and your example of walking, you simply increase the position less than with a fixed fps.
fixed fps:
(though better only on a console) you know exactly how often the game updates, so you know how much to increment your variables. This is achieved by making that loop check how long it has been since the last update and if it was longer than x ms ago, make it update.
variable fps:
your variables are increased each frame, but the amount is multiplied by the result of a formula that calculated how much time passed since the last frame.
So with a variable fps and your example of walking, you simply increase the position less than with a fixed fps.
There''s a good tutorial on gametutorials.com on time-based movement.
http://www.gametutorials.com/Tutorials/OpenGL/OpenGL_Pg1.htm
http://www.gametutorials.com/Tutorials/OpenGL/OpenGL_Pg1.htm
The code in these here tutorials (If I remember correctly), retrieve the number of milliseconds that have past, since the last frame was rendered.
Say your app is running at 100 fps on one machine, 10 (Oh dear), on another.
There's 1000 milliseconds in a second so...
Milliseconds past on the 100fps machine would be 10 (1000/100)
........................ 10fps ................ 100 (1000/10)
So we got 10ms since the last frame was rendered on the fast machine, 100ms on the slow one.
This could be a way of moving an alien as the same speed on whatever speed machine, no matter how fast or slow it is...
AlienXpos += 0.001f * ms; // Move an alien 1 pixel per second on either machine.
On the fast machine the above would be...
AlienXpos += 0.001f * 10; // this equals 0.01f
On the slow machine...
AlienXpos += 0.001f * 100; // this equals 0.1f;
Looking at the above two simple equations, on the fast machine which is rendering along at 100fps, it's moving the alien along X in very small increments, but it moves it more often (More frames per seconds). The slow machine is updating the position of alien less often, but at a greater amount.
So no matter what the framerate of the machine, the alien will move at the same speed.
On the fast 100fps machine it increase X by...
0.01f, 100fps therefore 0.01f * 100fps = 1
AND...
On the slow 10fps machine it increases X by...
0.1f, 10fps and 0.1f * 10fps = 1
Both 1!
Hope this helps, I've had a couple of beers, so if it don't, I appologise
My personal thoughts on frame limiting?
Stated above by Ruudje, it's cool to use it if every machine will run at the same speed, but that's not even remotely possible with all those PC configurations out there
I don't like it, i prefer using the above time based movement.
EDIT: My math ain't too good with beer in my brain
Fixed: Milliseconds past on the 100fps machine would be 10 (1000/10)
[edited by - TerraX on July 21, 2003 4:30:10 AM]
EDIT: Whoops! My spelling ain't too great either, lol!
[edited by - TerraX on July 21, 2003 4:32:14 AM]
Download some source: www.DavesProgramming.com
[edited by - TerraX on July 21, 2003 4:38:31 AM]
[edited by - TerraX on July 21, 2003 6:26:57 AM]
Say your app is running at 100 fps on one machine, 10 (Oh dear), on another.
There's 1000 milliseconds in a second so...
Milliseconds past on the 100fps machine would be 10 (1000/100)
........................ 10fps ................ 100 (1000/10)
So we got 10ms since the last frame was rendered on the fast machine, 100ms on the slow one.
This could be a way of moving an alien as the same speed on whatever speed machine, no matter how fast or slow it is...
AlienXpos += 0.001f * ms; // Move an alien 1 pixel per second on either machine.
On the fast machine the above would be...
AlienXpos += 0.001f * 10; // this equals 0.01f
On the slow machine...
AlienXpos += 0.001f * 100; // this equals 0.1f;
Looking at the above two simple equations, on the fast machine which is rendering along at 100fps, it's moving the alien along X in very small increments, but it moves it more often (More frames per seconds). The slow machine is updating the position of alien less often, but at a greater amount.
So no matter what the framerate of the machine, the alien will move at the same speed.
On the fast 100fps machine it increase X by...
0.01f, 100fps therefore 0.01f * 100fps = 1
AND...
On the slow 10fps machine it increases X by...
0.1f, 10fps and 0.1f * 10fps = 1
Both 1!
Hope this helps, I've had a couple of beers, so if it don't, I appologise

My personal thoughts on frame limiting?
Stated above by Ruudje, it's cool to use it if every machine will run at the same speed, but that's not even remotely possible with all those PC configurations out there

I don't like it, i prefer using the above time based movement.
EDIT: My math ain't too good with beer in my brain

Fixed: Milliseconds past on the 100fps machine would be 10 (1000/10)
[edited by - TerraX on July 21, 2003 4:30:10 AM]
EDIT: Whoops! My spelling ain't too great either, lol!
[edited by - TerraX on July 21, 2003 4:32:14 AM]
Download some source: www.DavesProgramming.com
[edited by - TerraX on July 21, 2003 4:38:31 AM]
[edited by - TerraX on July 21, 2003 6:26:57 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement