Requesting Help: Smooth keyframe interpolation algorithm
Animations in my game are stored as a series of keyframes and I use linear interpolation to tween between them when running them on a character  but linear interpolation either makes the animator use extra of keyframes (harder for them (me in this case)) or looks jerky.
I'd like to smoothly tween between the values, but I can't figure out an algorithm for this.
My terms:
time[] is the array of keyframe times
value[] is the array of keyframe values
t# is the time I want a value for
lowIdx is the index of the closest keyframe lower than t
highIdx is the index of the closest keyframe higher than t
rLowHigh# is the ratio of the distance of t from time[lowIdx] relative to the distance between time[highIdx]  time[lowIdx]
vLowHigh# is the value from linear interpolation between value[lowIdx] and value[highIdx]
My linear interpolation algorithm:
I've been trying to think of ways to smooth this, taking into account the keyframes before and after low and high, time[lowIdx  1] and time[highIdx + 1] but I haven't come up with anything that works.
What algorithms do you use that are smoother looking than linear interpolation? I'd really love to fix this
I'd like to smoothly tween between the values, but I can't figure out an algorithm for this.
My terms:
time[] is the array of keyframe times
value[] is the array of keyframe values
t# is the time I want a value for
lowIdx is the index of the closest keyframe lower than t
highIdx is the index of the closest keyframe higher than t
rLowHigh# is the ratio of the distance of t from time[lowIdx] relative to the distance between time[highIdx]  time[lowIdx]
vLowHigh# is the value from linear interpolation between value[lowIdx] and value[highIdx]
My linear interpolation algorithm:
Code:
rLowHigh# = (t  time[lowIdx]) / (time[highIdx]  time[lowIdx])
vLowHigh# = value[lowIdx] + (value[highIdx]  value[lowIdx]) * rLowHigh
I've been trying to think of ways to smooth this, taking into account the keyframes before and after low and high, time[lowIdx  1] and time[highIdx + 1] but I haven't come up with anything that works.
What algorithms do you use that are smoother looking than linear interpolation? I'd really love to fix this
whogben Wrote:What algorithms do you use that are smoother looking than linear interpolation? I'd really love to fix this
Bones.ï»¿ï»¿ï»¿ï»¿
Catmullrom splines.
Here's a good interpolation overview: http://local.wasp.uwa.edu.au/~pbourke/mi...rpolation/ (CatmullRom isn't on that page but it looks the same as Hermite with 0 tension. Google will turn up some more efficient code if you just want CatmullRom).
With that in mind, I've never had any problems using linear interpolation for keyframes  if it looks bad, your keyframes are most likely the problem. Bones won't necessarily fix this either  at some point you have to interpolate bones too...
With that in mind, I've never had any problems using linear interpolation for keyframes  if it looks bad, your keyframes are most likely the problem. Bones won't necessarily fix this either  at some point you have to interpolate bones too...
ThemsAllTook Wrote:Bones.
I'm using bones for my animation, these keyframe values are bone movements, not vertex movements. I'm looking for a smoother way to interpolate the values that factors in an extra keyframe forwards and backwards.
arekkusu Wrote:Catmullrom splines.
Perfect, exactly what I was looking for. I'm adding cardinal splines with a tension of .5 for the interpolation. Thanks Arekkusu!
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Smooth acceleration in every direction.  Honey Sharma  1  5,968 
Aug 16, 2011 01:37 AM Last Post: PoseMotion 

Smooth movement with the accelerometer?  Like a labyrinth game.  DotSlashSlash  12  18,489 
Jul 14, 2010 07:15 AM Last Post: ThemsAllTook 

Depth Sorting algorithm  Leroy  1  5,577 
Jul 2, 2007 01:47 AM Last Post: aegidian 

Algorithm for moving between two points on a plane...  WhatMeWorry  4  6,755 
Aug 23, 2005 11:36 AM Last Post: unknown 

Minesweeper algorithm  Coin  3  6,688 
Jul 29, 2005 09:48 AM Last Post: Coin 