Sign in to follow this  
FlaiseSaffron

Framerate independent nonlinear interpolation

Recommended Posts

FlaiseSaffron    216
I can't find anything about this from Google, possibly because I don't know the mathematical name of what I'm trying to calculate. What I'm trying to do is convert a framerate dependent nonlinear interpolation algorithm into an equivalent framerate independent algorithm. What I have now is: newOffset = oldOffset / 2.0; If this executes at a different framerate, the object will move at a different speed, which is precisely what I don't want. How do I rewrite this equation to take into account either the time since the last frame or the current framerate (both of which are available to this function)?

Share this post


Link to post
Share on other sites
alvaro    21266
I don't think I understood everything you said there, but I do know how to transform that formula for a non-integer number of steps:

newOffset = oldOffset * pow(0.5, num_steps);


Share this post


Link to post
Share on other sites
bzroom    647
Your lerp rate in this case is 0.5 per step. And you expect the steps to happen at a certain frequency. You should look for an equation that will modify the lerp rate based on the step frequency so that the result is as close to the original as possible. I'm pretty sure it's impossible, but there is a common formula which is close within a reasonable frame rate range.

Share this post


Link to post
Share on other sites
FlaiseSaffron    216
Let me put this another way. If x is the position of an object at 0 milliseconds, and that object is at x / 2 at 30ms, x / 4 at 60ms, x / 8 at 90ms, etc... then what is the position of that object at any arbitrary time?

Share this post


Link to post
Share on other sites
alvaro    21266
Quote:
Original post by Dathgale
Let me put this another way. If x is the position of an object at 0 milliseconds, and that object is at x / 2 at 30ms, x / 4 at 60ms, x / 8 at 90ms, etc... then what is the position of that object at any arbitrary time?


I just told you...

Share this post


Link to post
Share on other sites
stonemetal    288
In the case of x / 2 at 30ms, x / 4 at 60ms given a time of 40ms you would be (40-30)/(60 - 30)= 1/3 of the way there would be a linear interpolation. If you want a nonlinear interpolation you are going to have to be more specific there is more than one.


Linear interpolation will give you a constant velocity over the motion. if you want a more natural motion where things start moving slowly speed up and then slow down before stopping then you want spline interpolation in animation software(or blender at least) it is called an IPO curve.

Share this post


Link to post
Share on other sites
alvaro    21266
Yes, generally there are many ways of interpolating data, but he has a very particular case that lends itself very naturally to a continuous extension:

a(0) = x
a(n) = a(n-1)/2, if n>0

You can easily get the formula
a(n) = x * pow(0.5, n)

...and then you can evaluate it at any point in time.

Share this post


Link to post
Share on other sites
FlaiseSaffron    216
Quote:
Original post by alvaro
Quote:
Original post by Dathgale
Let me put this another way. If x is the position of an object at 0 milliseconds, and that object is at x / 2 at 30ms, x / 4 at 60ms, x / 8 at 90ms, etc... then what is the position of that object at any arbitrary time?


I just told you...

You said you didn't understand all of my question before; just making sure a better understanding didn't change anything. Thanks for the help.


Stonemetal: x / 2 at 30ms, x / 4 at 60ms, x / 8 at 90ms

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this