Interpolation

Basically, I am getting data(x,y,z-> coords of the object) every 100 ms. ( 10 samples a second ).

So rendering this object happens at 10 FPS.

I want to interpolate between the ‘current position’ and ‘next position’ so that object takes 100 ms to go from point-0 to point-1, while maintaining the Frame Rate at 30.

Thanks.

Are you willing to delay everything by 100 milliseconds or do you want to predict it - hopefully without great errors?
Delaying means you won’t get errors, because it allows you to do a true interpolate.

If you delay everything by 100ms (0.1 sec), all you need to do is this:
On receiving a new position:

  1. store current position as “last” position
  2. store new position as “next” position
  3. reset “elapsedtime”

On rendering a frame:

  1. renderposition = elapsedtime * (next-last)/0.1
  2. elapsedtime += framerendertime

That will do a simple linear interpolation.
I doubt it will have to be more precise than that.

The alternative is to extrapolate. For that, you need to do something like this:
(The linear movement formula, you may remember, is:
s = v*t + s0
On getting a new position:

  1. store current position as last position
  2. store new position as current position
  3. reset elapsedtime
  4. velocity = (new position - last position)/0.1

On render:

  1. renderposition = current position + velocity*elapsedtime
  2. elapsedtime += framerendertime

And thats a linear extrapolate. You could build in acceleration, by taking the difference between the last velocity and the current velocity, and dividing that by 0.1, then using that in the linear accelerated movement formula (s=0.5att+vt+s0).

As with many other 3D algorithms, this is all much easier to write if you have a vector class.

Originally posted by T101:
[b]Are you willing to delay everything by 100 milliseconds or do you want to predict it - hopefully without great errors?
Delaying means you won’t get errors, because it allows you to do a true interpolate.

If you delay everything by 100ms (0.1 sec), all you need to do is this:
On receiving a new position:

  1. store current position as “last” position
  2. store new position as “next” position
  3. reset “elapsedtime”

On rendering a frame:

  1. renderposition = elapsedtime * (next-last)/0.1
  2. elapsedtime += framerendertime

That will do a simple linear interpolation.
I doubt it will have to be more precise than that.

The alternative is to extrapolate. For that, you need to do something like this:
(The linear movement formula, you may remember, is:
s = v*t + s0
On getting a new position:

  1. store current position as last position
  2. store new position as current position
  3. reset elapsedtime
  4. velocity = (new position - last position)/0.1

On render:

  1. renderposition = current position + velocity*elapsedtime
  2. elapsedtime += framerendertime

And thats a linear extrapolate. You could build in acceleration, by taking the difference between the last velocity and the current velocity, and dividing that by 0.1, then using that in the linear accelerated movement formula (s=0.5att+vt+s0).

As with many other 3D algorithms, this is all much easier to write if you have a vector class.[/b]

Please help me with an example / algo if you dont mind.