public override KeyFrame GetInterpolatedKeyFrame( float time, KeyFrame kf )
{
// note: this is an un-attached keyframe
TransformKeyFrame result = (TransformKeyFrame)kf;
result.Time = time;
// Keyframe pointers
KeyFrame kBase1, kBase2;
TransformKeyFrame k1, k2;
short firstKeyIndex;
float t = GetKeyFramesAtTime( time, out kBase1, out kBase2, out firstKeyIndex );
k1 = (TransformKeyFrame)kBase1;
k2 = (TransformKeyFrame)kBase2;
if ( t == 0.0f )
{
// just use k1
result.Rotation = k1.Rotation;
result.Translate = k1.Translate;
result.Scale = k1.Scale;
}
else
{
// interpolate by t
InterpolationMode mode = parent.InterpolationMode;
RotationInterpolationMode rim = parent.RotationInterpolationMode;
switch ( mode )
{
case InterpolationMode.Linear:
{
// linear interoplation
// Rotation
// Interpolate to nearest rotation if mUseShortestPath set
if ( rim == RotationInterpolationMode.Linear )
result.Rotation = Quaternion.Nlerp( t, k1.Rotation, k2.Rotation, useShortestPath );
else // RotationInterpolationMode.Spherical
result.Rotation = Quaternion.Slerp( t, k1.Rotation, k2.Rotation, useShortestPath );
result.Translate = k1.Translate + ( ( k2.Translate - k1.Translate ) * t );
result.Scale = k1.Scale + ( ( k2.Scale - k1.Scale ) * t );
}
break;
case InterpolationMode.Spline:
{
// spline interpolation
if ( isSplineRebuildNeeded )
{
BuildInterpolationSplines();
}
result.Rotation = rotationSpline.Interpolate( firstKeyIndex, t, useShortestPath );
result.Translate = positionSpline.Interpolate( firstKeyIndex, t );
result.Scale = scaleSpline.Interpolate( firstKeyIndex, t );
}
break;
}
}
// return the resulting keyframe
return result;
}