Requesting Help: Smooth keyframe interpolation algorithm

Nibbie
Posts: 2
Joined: 2009.01
Post: #1
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:
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 Grin
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
whogben Wrote:What algorithms do you use that are smoother looking than linear interpolation? I'd really love to fix this Grin

Bones.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #3
Catmull-rom splines.
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #4
Here's a good interpolation overview: http://local.wasp.uwa.edu.au/~pbourke/mi...rpolation/ (Catmull-Rom 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 Catmull-Rom).

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...
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2009.01
Post: #5
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:Catmull-rom splines.

Perfect, exactly what I was looking for. I'm adding cardinal splines with a tension of .5 for the interpolation. Thanks Arekkusu!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Smooth acceleration in every direction. Honey Sharma 1 4,440 Aug 16, 2011 01:37 AM
Last Post: PoseMotion
  Smooth movement with the accelerometer? - Like a labyrinth game. DotSlashSlash 12 10,736 Jul 14, 2010 07:15 AM
Last Post: ThemsAllTook
  Depth Sorting algorithm Leroy 1 4,584 Jul 2, 2007 01:47 AM
Last Post: aegidian
  Algorithm for moving between two points on a plane... WhatMeWorry 4 4,791 Aug 23, 2005 11:36 AM
Last Post: unknown
  Minesweeper algorithm Coin 3 5,376 Jul 29, 2005 09:48 AM
Last Post: Coin