private void InternalStep(TimeSpan time) { DoPlayStates(); var delayEndpoint = _delay; var iterationEndpoint = delayEndpoint + _duration; var iterationTime = time; //determine if time is currently in the first iteration. if (time >= TimeSpan.Zero & time <= iterationEndpoint) { _currentIteration = 1; } else if (time > iterationEndpoint) { //Subtract first iteration to properly get the subsequent iteration time iterationTime -= iterationEndpoint; if (!_iterationDelay & delayEndpoint > TimeSpan.Zero) { delayEndpoint = TimeSpan.Zero; iterationEndpoint = _duration; } //Calculate the current iteration number _currentIteration = Math.Min(_repeatCount, (int)Math.Floor((double)((double)iterationTime.Ticks / iterationEndpoint.Ticks)) + 2); } else { return; } // Determine if the current iteration should have its normalized time inverted. bool isCurIterReverse = _animationDirection == PlaybackDirection.Normal ? false : _animationDirection == PlaybackDirection.Alternate ? (_currentIteration % 2 == 0) ? false : true : _animationDirection == PlaybackDirection.AlternateReverse ? (_currentIteration % 2 == 0) ? true : false : _animationDirection == PlaybackDirection.Reverse ? true : false; if (!_isLooping) { var totalTime = _iterationDelay ? _repeatCount * (_duration.Ticks + _delay.Ticks) : _repeatCount * _duration.Ticks + _delay.Ticks; if (time.Ticks >= totalTime) { var easedTime = _easeFunc.Ease(isCurIterReverse ? 0.0 : 1.0); _lastInterpValue = _interpolator(easedTime, _neutralValue); DoComplete(); return; } } iterationTime = TimeSpan.FromTicks((long)(iterationTime.Ticks % iterationEndpoint.Ticks)); if (delayEndpoint > TimeSpan.Zero & iterationTime < delayEndpoint) { DoDelay(); } else { // Offset the delay time iterationTime -= delayEndpoint; iterationEndpoint -= delayEndpoint; // Normalize time var interpVal = (double)iterationTime.Ticks / iterationEndpoint.Ticks; if (isCurIterReverse) { interpVal = 1 - interpVal; } // Ease and interpolate var easedTime = _easeFunc.Ease(interpVal); _lastInterpValue = _interpolator(easedTime, _neutralValue); PublishNext(_lastInterpValue); } }
private void InternalStep(TimeSpan systemTime) { DoPlayStatesAndTime(systemTime); var time = _internalClock - _firstFrameCount; var delayEndpoint = _delay; var iterationEndpoint = delayEndpoint + _duration; //determine if time is currently in the first iteration. if (time >= TimeSpan.Zero & time <= iterationEndpoint) { _currentIteration = 1; } else if (time > iterationEndpoint) { //Subtract first iteration to properly get the subsequent iteration time time -= iterationEndpoint; if (!_iterationDelay & delayEndpoint > TimeSpan.Zero) { delayEndpoint = TimeSpan.Zero; iterationEndpoint = _duration; } //Calculate the current iteration number _currentIteration = (int)Math.Floor((double)time.Ticks / iterationEndpoint.Ticks) + 2; } else { _previousClock = systemTime; return; } time = TimeSpan.FromTicks(time.Ticks % iterationEndpoint.Ticks); if (!_isLooping) { if (_currentIteration > _repeatCount) { DoComplete(); } if (time > iterationEndpoint) { DoComplete(); } } // Determine if the current iteration should have its normalized time inverted. bool isCurIterReverse = _animationDirection == PlaybackDirection.Normal ? false : _animationDirection == PlaybackDirection.Alternate ? (_currentIteration % 2 == 0) ? false : true : _animationDirection == PlaybackDirection.AlternateReverse ? (_currentIteration % 2 == 0) ? true : false : _animationDirection == PlaybackDirection.Reverse ? true : false; if (delayEndpoint > TimeSpan.Zero & time < delayEndpoint) { DoDelay(); } else { // Offset the delay time time -= delayEndpoint; iterationEndpoint -= delayEndpoint; // Normalize time var interpVal = (double)time.Ticks / iterationEndpoint.Ticks; if (isCurIterReverse) { interpVal = 1 - interpVal; } // Ease and interpolate var easedTime = _easeFunc.Ease(interpVal); _lastInterpValue = _interpolator(easedTime, _neutralValue); PublishNext(_lastInterpValue); } }
private void InternalStep(TimeSpan time) { DoPlayStates(); FetchProperties(); // Scale timebases according to speedratio. var indexTime = time.Ticks; var iterDuration = _duration.Ticks * _speedRatioConv; var iterDelay = _iterationDelay.Ticks * _speedRatioConv; var initDelay = _initialDelay.Ticks * _speedRatioConv; if (indexTime > 0 & indexTime <= initDelay) { DoDelay(); } else { // Calculate timebases. var iterationTime = iterDuration + iterDelay; var opsTime = indexTime - initDelay; var playbackTime = opsTime % iterationTime; _currentIteration = (ulong)(opsTime / iterationTime); // Stop animation when the current iteration is beyond the iteration count // and snap the last iteration value to exact values. if ((_currentIteration + 1) > _iterationCount) { var easedTime = _easeFunc.Ease(_playbackReversed ? 0.0 : 1.0); _lastInterpValue = _interpolator(easedTime, _neutralValue); DoComplete(); } if (playbackTime <= iterDuration) { // Normalize time for interpolation. var normalizedTime = playbackTime / iterDuration; // Check if normalized time needs to be reversed according to PlaybackDirection switch (_playbackDirection) { case PlaybackDirection.Normal: _playbackReversed = false; break; case PlaybackDirection.Reverse: _playbackReversed = true; break; case PlaybackDirection.Alternate: _playbackReversed = (_currentIteration % 2 == 0) ? false : true; break; case PlaybackDirection.AlternateReverse: _playbackReversed = (_currentIteration % 2 == 0) ? true : false; break; default: throw new InvalidOperationException($"Animation direction value is unknown: {_playbackDirection}"); } if (_playbackReversed) { normalizedTime = 1 - normalizedTime; } // Ease and interpolate var easedTime = _easeFunc.Ease(normalizedTime); _lastInterpValue = _interpolator(easedTime, _neutralValue); PublishNext(_lastInterpValue); } else if (playbackTime > iterDuration & playbackTime <= iterationTime & iterDelay > 0) { // The last iteration's trailing delay should be skipped. if ((_currentIteration + 1) < _iterationCount) { DoDelay(); } else { DoComplete(); } } } }