# any good smooth interpolation method?

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

## 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 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);		return;	}	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;	m_ornt.face(-z);}

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 on other sites
thanks ajas95, I'll try your method and see what I can achieve with it.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633303
• Total Posts
3011278
• ### Who's Online (See full list)

There are no registered users currently online

×