`while (t >= kt[iKeyFrame+1]) iKeyFrame++;`

Then we come across a slight snag - we need the value of u for the spline to work correctly. This is calculated as
u = (t - kt(i)) / (kt(i+1) - kt(i)).
The value (kt(i+1) - kt(i)) is actually used three times per interpolation, so I give it its own name, dx.
u = (t - kt(i)) / dx.
Of course, we've now scaled time, so while k(t) will hold, the tangent values k'(t) will be scaled by the same amount. We must replace k'() in the Catmull-Rom interpolation by k'() x dx. At first glance it may seem that this is the inverse operation to that performed when calculating the tangents, but it is not; both operations are necessary.
You now have your interpolated value of k(t). Apply this to your Euler angles, or your sleek slerped quaternions, and you will see some real smooth animation. Enjoy!
[size="5"]Glossary
k(t)
[bquote]The value of a keyframe at time t (one number, so several may be used to represent a complete orientation).[/bquote] k(u)
[bquote]The interpolated value between two values k(t) and k(t+1) (assuming a spacing of 1). u always takes a value in the range 0 to 1.[/bquote] k'(t)
[bquote]The "gradient" of a keyframe - this is not set by the user, as is the case with splines in many graphics programs, but is calculated as an average of the gradients of lines to the keyframes on either side.[/bquote] kt(i)
[bquote]The time value t for keyframe number i. It must always be the case that kt(i) < kt(i+1).[/bquote] dx
[bquote]The time interval between two particular keyframes. In most keyframing systems, dx is 1, or some constant value. In this system, dx can take any value, and can vary throughout the animation.[/bquote]
Sign in to follow this

Followers
0

#
Smooth interpolation of irregularly spaced keyframes

General and Gameplay Programming

0

Report Article

Sign in to follow this

Followers
0