Advertisement Jump to content
Sign in to follow this  

any good smooth interpolation method?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all: We are doing a racing game, we want the car move as smooth as possible. The physics engine we use doesn't gaurantee that, especially when the car is colliding with the environment. So we need to do interpolation on the car's pose(including position and orientation) to obtain a smooth result. The interpolator should be able to filter out the "noises" and introduce little latency(some interpolators we tried introduced too much latency, the car is far behind its real position after interpolation). Can anyone with related experience give me some hint? Thanks.

Share this post

Link to post
Share on other sites
I might be able to help some. Your problem is hard, first of all, so here is the strategy and code I use. First both position and orientation are constrained by the "current" and "target" pos/ornt. Each has a velocity. Then I use a critically-damped spring to restore the current to the target. The parameter to determine how much time it takes for current to equal target is what I feed to this algorithm (actually, it's the time for it to restore 90% the distance, since it never totally is exactly equal!).

First, the simple one is position:

// use a damped spring to move v0 towards target given a current velocity,
// time over which the spring would cover 90% of the distance from rest;
// and dt, the change in time.

template<typename T>
inline void damp_spring(T& v0, const T& target, T& vel, float time_90, float dt)
const float c0 = dt * 3.75f / time_90;

if(c0 >= 1.0f)
v0 = target;
vel = T(0.0f);

const T delta = target - v0;
const T force = delta - 2.0f * vel;

v0 += vel * c0;

vel += force * c0;

Then, the tricky one is orientation. In this code I only handle the case where there is no "roll" component (the 'y' component of the x-axis is zero, because y is up and x is sideways in my scheme).

So here's for orientation (assumes -z is facing direction):

void Frame::spring_facing(float dt, float spring)
vec4 z(m_ornt.z_axis());

damp_spring<vec4>(z, m_target_z, m_zvel, spring, dt);

// now make sure that normalizing z preserves the y coord.
// linearly interpolating the z-axis is an approximation,
// and the y distortion is most noticeable.

const float D = 1.0f - z.y * z.y;
const float L = z.x * z.x + z.z * z.z;
const float mult = sqrtf(D / L);

z.x *= mult;
z.z *= mult;


If your objects might have roll, I suggest to use the same thing I have here, but treat roll component as a scalar and use this same 'damp_spring' algorithm for that too. Then, you've computeted heading and roll separately, it's easy to combine (post-multiply heading by roll matrix).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!