public override void AdvanceAnimation(Animation animation, float delta) { var previousTime = animation.TimeInternal; var currentTime = previousTime + delta; animation.TimeInternal = currentTime; if (!animation.NextMarkerOrTriggerTime.HasValue) { var frameIndex = AnimationUtils.SecondsToFrames(currentTime); var frameTime = AnimationUtils.SecondsPerFrame * frameIndex; var stepOverFrame = previousTime <= frameTime && frameTime <= currentTime; animation.NextMarkerOrTriggerTime = GetNextMarkerOrTriggerTime(animation, frameIndex + (stepOverFrame ? 0 : 1)); } if (!animation.NextMarkerOrTriggerTime.HasValue || currentTime <= animation.NextMarkerOrTriggerTime.Value) { ApplyAnimators(animation, invokeTriggers: false); } else { var frameTime = animation.NextMarkerOrTriggerTime.Value; var frameIndex = AnimationUtils.SecondsToFrames(frameTime); animation.NextMarkerOrTriggerTime = null; var currentMarker = animation.Markers.GetByFrame(frameIndex); if (currentMarker != null) { ProcessMarker(animation, currentMarker); } ApplyAnimators(animation, invokeTriggers: true, animationTimeCorrection: previousTime - frameTime); if (!animation.IsRunning) { animation.RaiseStopped(); } } }
private void CacheInterpolationParameters(double time) { int count = ReadonlyKeys.Count; if (count == 0) { Value2 = default(T); minTime = -float.MaxValue; maxTime = float.MaxValue; function = KeyFunction.Steep; return; } var i = keyIndex; if (i >= count) { i = count - 1; } int frame = AnimationUtils.SecondsToFrames(time); // find rightmost key on the left from the given frame while (i < count - 1 && frame > ReadonlyKeys[i].Frame) { i++; } while (i >= 0 && frame < ReadonlyKeys[i].Frame) { i--; } keyIndex = i; int minFrame, maxFrame; if (i < 0) { keyIndex = 0; maxFrame = ReadonlyKeys[0].Frame; minFrame = int.MinValue; Value2 = ReadonlyKeys[0].Value; function = KeyFunction.Steep; } else if (i == count - 1) { minFrame = ReadonlyKeys[i].Frame; maxFrame = int.MaxValue; Value2 = ReadonlyKeys[i].Value; function = KeyFunction.Steep; } else { var key1 = ReadonlyKeys[i]; var key2 = ReadonlyKeys[i + 1]; minFrame = key1.Frame; maxFrame = key2.Frame; Value2 = key1.Value; Value3 = key2.Value; function = key1.Function; if (function == KeyFunction.Spline) { Value1 = ReadonlyKeys[i < 1 ? 0 : i - 1].Value; Value4 = ReadonlyKeys[i + 1 >= count - 1 ? count - 1 : i + 2].Value; } else if (function == KeyFunction.ClosedSpline) { Value1 = ReadonlyKeys[i < 1 ? count - 2 : i - 1].Value; Value4 = ReadonlyKeys[i + 1 >= count - 1 ? 1 : i + 2].Value; } } minTime = minFrame * AnimationUtils.SecondsPerFrame; maxTime = maxFrame * AnimationUtils.SecondsPerFrame; }
private static int FixFrame(int frame, double fps = 30) { return(AnimationUtils.SecondsToFrames(frame / fps)); }