using System; using OpenTK; using SM.Base.Time; using SM.Base.Types; using SM.Base.Window; namespace SM.Base.Animation { /// /// A handle to control the interpolation process. /// public class InterpolationProcess : Timer { /// /// The CVector object, that is interpolated. /// public CVectorBase TargetVector { get; set; } /// /// From where the interpolation process started. /// public Vector4 From { get; } /// /// To where the interpolation is heading. /// public Vector4 To { get; } /// /// The direction towards the /// public Vector4 Direction { get; } /// /// Gets/Sets the interpolation curve. /// public BezierCurve InterpolationCurve { get; set; } internal InterpolationProcess(CVectorBase targetVector, TimeSpan timeSpan, Vector4 from, Vector4 to, BezierCurve interpolationCurve) : base(timeSpan) { TargetVector = targetVector; From = from; To = to; InterpolationCurve = interpolationCurve; Direction = to - from; } /// /// Stops the interpolation process. /// This keeps the state where the interpolation was. /// public new void Stop() { Stop(true); } /// /// Stops the interplation process. /// /// If true, it will not set the state to the state. public void Stop(bool keepState) { if (Active && !keepState) SetTarget(To); base.Stop(); } private protected override void Ticking(UpdateContext context) { base.Ticking(context); float posInCurve = InterpolationCurve.CalculatePoint(ElapsedNormalized).Y; Vector4 nextPos = From + (Direction * posInCurve); SetTarget(nextPos); } /// protected override void Stopping(UpdateContext context) { base.Stopping(context); SetTarget(To); } private void SetTarget(Vector4 vec) { TargetVector.Set(vec.X, vec.Y, vec.Z, vec.W); } } }