I am creating a custom animation editor that lets users modify the animation curves of various components. One component I am having trouble with is the rotation of an object. I allow the user to edit the rotation’s euler components (actually just the z rotation since the editor is for 2D). When generating the final animation, I convert the euler animation curve to a set of four quaternion curves.
The problem is that the tangents of the euler curve do not seem to correspond to the quaternion.
Here is the animation curve for the z component of a curve:
If I calculate my quaternion curve by adding the keys the following way, the animation jumps around erratically (this example is adding the middle keyframe):
float time = 1.7f;
float rotationZ = 90.0f;
float inTangent = -500.0f;
float outTangent = 500.0f
q = Quaternion.Euler(0, 0, rotationZ);
localRotationXKeyframes.Add(new Keyframe(time, q.x, inTangent, outTangent));
localRotationYKeyframes.Add(new Keyframe(time, q.y, inTangent, outTangent));
localRotationZKeyframes.Add(new Keyframe(time, q.z, inTangent, outTangent));
localRotationWKeyframes.Add(new Keyframe(time, q.w, inTangent, outTangent));
If I add the quaternion key without using the euler z curve’s tangents, the animation interpolates smoothly, but doesn’t follow the swings of the curve:
float time = 1.7f;
float rotationZ = 90.0f;
q = Quaternion.Euler(0, 0, rotationZ);
localRotationXKeyframes.Add(new Keyframe(time, q.x));
localRotationYKeyframes.Add(new Keyframe(time, q.y));
localRotationZKeyframes.Add(new Keyframe(time, q.z));
localRotationWKeyframes.Add(new Keyframe(time, q.w));
Obviously the tangents of the euler curve do not correspond with the tangents of the calculated quaternion curve.
My question is how do I create a quaternion animation curve based on the euler animation curve, with properly translated tangents?