Speed Control In DirectX

Started by
3 comments, last by mmarvi 23 years, 1 month ago
I have a Pentium 3, 933 MHz computer, and when I write DirectX programs on that computer, I notice that it runs perfectly on my system, but when I try it out on other computers, like my brother''s Pentium 3 450 MHz system, they run much slower and sluggishly, in fact too slow to function properly. I tested the frame rates on these two systems, and I discovered that on my system, the frame rate was AT LEAST 150 FPS, and on all other computers it was around 60-80 FPS. My question is, how can I control the pace of my DirectX programs so that they always run at 60-80 FPS regardless of the speed of the computer it''s being run on, whether it''s 400 MHz or 933 MHz?
Advertisement
Never cap your frame rate! What you should do is test how much time has passed since your last frame, and make movement a factor of that. Look into timeGetTime, GetTickCount, or QueryPerformanceCounter.

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
http://www.gdarchive.net/druidgames/
How would I go about doing what Null and Void said about making movement a factor of how much time has passed since the last frame?
What you should do is to remeber the physics:

LengthOfMovement = Speed * Time

What I do is that I specify speed in units/per second.

Then each loop:

ElapsedTimeInSeconds = 1000 * (LastTime - TimeGetTime())
LastTime = TimeGetTime()

Then in my movement functions:

LengthOfMovement = Speed * ElapsedTimeInSeconds

Since I work in 3D I then multiply my LengthOfMovement
with the normalized vector that describes the orientation
of my desired movement and get a velocity vector.
Then just add posistion and velocity vector and voilá,
the new position and you move with the same pace regardless
of the computers speed.
CrazySwede, can you clarify what the variables in your post represent? By units per second, do you mean velocity (like 2 pixels a frame)? Under DirectDraw, how would I use LengthOfMovement to update the sprites' positions? A sample function would really help. Remember that this is a 2D game that I am writing using DirectX.

Edited by - mmarvi on February 20, 2001 9:29:16 PM

This topic is closed to new replies.

Advertisement