/// <summary> /// Internal constructor, to prevent from using new outside of the engine. /// <p/> /// Animations should be created within objects that can own them (skeletons, scene managers, etc). /// </summary> internal Animation(string name, float length) { this.name = name; this.length = length; // use the default interpolation modes this.interpolationMode = Animation.DefaultInterpolationMode; this.rotationInterpolationMode = Animation.DefaultRotationInterpolationMode; // Create the track lists this.nodeTrackList = new Dictionary <ushort, NodeAnimationTrack>(); this.numericTrackList = new Dictionary <ushort, NumericAnimationTrack>(); this.vertexTrackList = new Dictionary <ushort, VertexAnimationTrack>(); }
private static extern void Animation_setRotationInterpolationMode(IntPtr animation, RotationInterpolationMode im);
/// <summary> /// Tells the animation how to interpolate rotations. /// <para> /// By default, animations interpolate linearly between rotations. This is /// fast but not necessarily completely accurate. If you want more accurate /// interpolation, use spherical interpolation, but be aware that it will /// incur a higher cost. /// </para> /// </summary> /// <param name="im">The interpolation mode to set.</param> public void setRotationInterpolationMode(RotationInterpolationMode im) { Animation_setRotationInterpolationMode(animation, im); }
/// <summary> /// Internal constructor, to prevent from using new outside of the engine. /// <p/> /// Animations should be created within objects that can own them (skeletons, scene managers, etc). /// </summary> internal Animation( string name, float length ) { this.name = name; this.length = length; // use the default interpolation modes this.interpolationMode = Animation.DefaultInterpolationMode; this.rotationInterpolationMode = Animation.DefaultRotationInterpolationMode; // Create the track lists this.nodeTrackList = new Dictionary<ushort, NodeAnimationTrack>(); this.numericTrackList = new Dictionary<ushort, NumericAnimationTrack>(); this.vertexTrackList = new Dictionary<ushort, VertexAnimationTrack>(); }
/// <summary>Static constructor.</summary> static Animation() { // set default interpolation mode to Spline (mmm....spline) defaultInterpolationMode = InterpolationMode.Spline; defaultRotationInterpolationMode = RotationInterpolationMode.Linear; }
/// <summary>Static constructor.</summary> static Animation() { // set default interpolation mode to Linear defaultInterpolationMode = InterpolationMode.Linear; defaultRotationInterpolationMode = RotationInterpolationMode.Linear; }
/// <summary> /// Gets a KeyFrame object which contains the interpolated transforms at the time index specified. /// </summary> /// <remarks> /// The KeyFrame objects held by this class are transformation snapshots at /// discrete points in time. Normally however, you want to interpolate between these /// keyframes to produce smooth movement, and this method allows you to do this easily. /// In animation terminology this is called 'tweening'. /// </remarks> /// <param name="time">The time (in relation to the whole animation sequence).</param> /// <returns> /// A new keyframe object containing the interpolated transforms. Note that the /// position and scaling transforms are linearly interpolated (lerp), whilst the rotation is /// spherically linearly interpolated (slerp) for the most natural result. /// </returns> public override KeyFrame GetInterpolatedKeyFrame(float time, KeyFrame kf) { // note: this is an un-attached keyframe TransformKeyFrame result = (TransformKeyFrame)kf; // Keyframe pointers KeyFrame kBase1, kBase2; TransformKeyFrame k1, k2; ushort 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) { Quaternion.NlerpRef(ref result.rotation, t, ref k1.rotation, ref k2.rotation, useShortestPath); } else // RotationInterpolationMode.Spherical { result.rotation = Quaternion.Slerp(t, k1.rotation, k2.rotation, useShortestPath); } result.translate.x = k1.translate.x + ((k2.translate.x - k1.translate.x) * t); result.translate.y = k1.translate.y + ((k2.translate.y - k1.translate.y) * t); result.translate.z = k1.translate.z + ((k2.translate.z - k1.translate.z) * t); result.scale.x = k1.scale.x + ((k2.scale.x - k1.scale.x) * t); result.scale.y = k1.scale.y + ((k2.scale.y - k1.scale.y) * t); result.scale.z = k1.scale.z + ((k2.scale.z - k1.scale.z) * t); result.Changed(); } 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); }