This is what I’m trying to do:
I have a set of Transform instances, which specify position and orientation of waypoints. I want to interpolate between those positions and rotations using a spline.
Spline interpolation (using a cardinal spline) between positions is easy, but spline interpolations between rotations is not, and I can’t seem to hack together a good solution myself.
Has anyone done this before?
When you say you want to interpolate rotations, do you mean getting the direction of the curve at a given parameter value or something more complicated?
I’ll reduce my question to something more specific.
Given 4 Transforms, and a parameter P (0.0 to 1.0), how do I specify a rotation which moves smoothly between the Transforms?
I don’t think there is any obvious way to make the speed of rotation follow the speed of the curve (except where you are rotating an object to follow the line of the curve) but you could slerp between the rotations as the parameter increases. Basically, you need to find the parameter values at which the interpolated points occur and record them. Say if the first point occurs at t=0.19 then you would divide the parameter by 0.19 and use the result as the parameter for slerping the quaternions. When the main parameter goes above 0.19, work out the slerp parameter for the next stretch of curve, and so on.
EDIT: actually, it’s just occurred to me that a cardinal spline is similar to a Catmull-Rom - four points affect each curve segment, but the segments only extend between the middle two points. For the rotation slerps, you could just use the same parameter value that you have to calculate anyway to interpolate between the two points.