# smoothing measure of FPS/timeDelta

This topic is 4911 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm currently measuring the time between frames and using it to update the display. For example, in a simple spinning cube demo using my library I adjust all of the rotation variables by a constant multiplied by my timeDelta:
xRot += 30*dt;
yRot += 40*dt;
zRot += 50*dt;

The trouble is that roughly every 0.5 seconds, the cube jumps a little bit. The application is running at 800fps, but it seems like there are small hiccups. I've done a bit of searching, and I've gathered essentially what the problem is. When the FPS is this high, the smallest jump in FPS can make things look choppy. What I'm wondering is what my options are to solve this? I'd like to have a value that I can use in a manner similar to a timeDelta, but is reasonably stable. The only option I've thought of so far is to calculate FPS based on a number of frames so that it is an average, and using the inverse of FPS. Although this would certainly give smoother results, it doesn't seem like the best option. Note that I'm looking for a general solution, not talking about fixed-step physics or anything like that. This question is purely what techniques people use to "smooth" their timeDelta values.

##### Share on other sites
Well I'm not too sure because I have yet to have a computer that ever ran anything at 800fps, but I would say just buffer, and average the last 2 to 5 values, I would think that this would give smoother results. The more you average, the smoother, though less accurate your results will be.

So like have an array.

float dtArr[5];

dtArr[arrCounter] = realdt;

arrCounter++;

if (arrCounter >4)
{
arrCounter=0;
}

dt = (dtArr[0] + dtArr[1] + dtArr[2] + dtArr[3] + dtArr[4])/5

##### Share on other sites
That is one of the options I'd been considering, I know that by averaging I can smooth FPS/timeDelta, but the loss in accuracy is undesirable. I was wondering if there are any techniques that are common that give a better trade-off than averaging the last N frames.

##### Share on other sites
While I'm sure there's some nifty mathematical trick to smooth it, I too just increase the 'frames per second' to 'frames per X seconds divded by X'.

One thing you might consider is some sort of non-linear proportion between the FPS and the cube's rotation. Make the cube accelerate just as much when the FPS jumps from 5 to 6 as it does from say... 200 to 240.

##### Share on other sites
Quote:
 Original post by Anonymous PosterWhile I'm sure there's some nifty mathematical trick to smooth it, I too just increase the 'frames per second' to 'frames per X seconds divded by X'.One thing you might consider is some sort of non-linear proportion between the FPS and the cube's rotation. Make the cube accelerate just as much when the FPS jumps from 5 to 6 as it does from say... 200 to 240.

oops, that was me.

##### Share on other sites
The more I look over it the more it seems that an average would be the best way to eliminate skips, and so far it seems like what others are doing.. I'll probably add smoothing that stores a sum of N frames and averages them.

Thanks for the help Telastyn and other AP, and if anybody has any more suggestions I'd still be up to hearing them.

##### Share on other sites
'frames per X seconds divded by X' = 1 ?

There could be a lot of reasons for the skip. I know I’m trying to get rid of the same thing in my app.

Is xRot an angle? Can it be over 360?
Are you resetting this angle with out taking into account the over shoot.?

Where are you getting dt from? TimerGetTime, TickCount, QueryPerformanceCounter. All have pro’s and cons QueryPerformanceCounter has a known bugs.

##### Share on other sites
You need to fix your timestep for the physics simulation. It needs to be running at a fixed rate regardless of how often your scene is getting rendered.

##### Share on other sites
Quote:
 Original post by bobason456'frames per X seconds divded by X' = 1 ?.

(frames per X seconds) / X

so let's say you're app is running at about 100fps, and X is 10
frames per X seconds ~= 1000
X = 10

(frames per X seconds) / X = 100

Actually I've come up with a decent idea of what I'm going to do, this question was actually for my open source game library (Photon, see my sig). I am going to have a method to set what sort of timeDelta should be used, giving the user an option between the actual amount of elapsedTime, elapsedTime over X seconds, or a fixed step.

##### Share on other sites
Weird, not sure how I got logged out, but in case you couldn't tell, that was me

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 11
• 9
• 9
• 40
• ### Forum Statistics

• Total Topics
634130
• Total Posts
3015704
×