/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> /// <param name="updateState"></param> /// <param name="animationState"></param> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { if (_checkFunction()) { this.NotifyAnimationFinished(); } }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> /// <param name="updateState"></param> /// <param name="animationState"></param> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { if (animationState.RunningAnimationsIndex == 0) { base.NotifyAnimationFinished(); } }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> /// <param name="updateState"></param> /// <param name="animationState"></param> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { //how does Slerp work: --> http://en.wikipedia.org/wiki/Slerp var changeFactor = this.CurrentTime.Ticks / (float)this.FixedTime.Ticks; var slerpQuaternion = Quaternion.Slerp(_startQuaternion, _targetQuaternion, changeFactor); _targetObject.RotationQuaternion = slerpQuaternion; }
/// <summary> /// Called for each update step of this animation. /// </summary> /// <param name="updateState">The current state of the update pass.</param> /// <param name="animationState">The current state of the animation.</param> public AnimationUpdateResult Update(IAnimationUpdateState updateState, AnimationState animationState) { _animation ??= _animationCreator(); if (_animation == null) { return(AnimationUpdateResult.EMPTY); } return(_animation.Update(updateState, animationState)); }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { float currentLocationPercent = (float)(base.CurrentTime.TotalMilliseconds / base.FixedTime.TotalMilliseconds); int toIncreaseTotal = (int)(m_increaseTotal * currentLocationPercent); int toIncrease = toIncreaseTotal - m_alreadyIncreased; m_setValueAction(m_getValueFunc() + toIncrease); m_alreadyIncreased = toIncreaseTotal; }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { var currentLocationPercent = (float)(this.CurrentTime.TotalMilliseconds / this.FixedTime.TotalMilliseconds); var toIncreaseTotal = (int)(_increaseTotal * currentLocationPercent); var toIncrease = toIncreaseTotal - _alreadyIncreased; _setValueAction(_getValueFunc() + toIncrease); _alreadyIncreased = toIncreaseTotal; }
protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { base.OnCurrentTimeUpdated(updateState, animationState); if (_taskToWaitFor.IsCanceled || _taskToWaitFor.IsCompleted || _taskToWaitFor.IsFaulted) { this.NotifyAnimationFinished(); } }
/// <summary> /// Called for each update step of this animation. /// </summary> /// <param name="updateState">The current state of the update pass.</param> /// <param name="animationState">The current state of the animation.</param> public AnimationUpdateResult Update(IAnimationUpdateState updateState, AnimationState animationState) { if (m_animation == null) { m_animation = m_animationCreator(); } if (m_animation == null) { return(AnimationUpdateResult.Empty); } return(m_animation.Update(updateState, animationState)); }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> /// <param name="updateState">The current state of update processing.</param> /// <param name="animationState">The current state of the animation.</param> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { base.OnCurrentTimeUpdated(updateState, animationState); // Calculate factor by what to transform all coordinates double maxMilliseconds = base.FixedTime.TotalMilliseconds; double currentMillis = base.CurrentTime.TotalMilliseconds; float actFrameFactor = (float)(currentMillis / maxMilliseconds); // Transform position and rotation Vector3 moveVector = m_viewPointTarget.Position - m_viewPointSource.Position; Vector2 rotationVector = m_viewPointTarget.Rotation - m_viewPointSource.Rotation; m_camera.Position = m_viewPointSource.Position + (moveVector * actFrameFactor); m_camera.TargetRotation = m_viewPointSource.Rotation + (rotationVector * actFrameFactor); // Special handling for orthographics cameras if (m_cameraOrthographic != null) { float zoomValue = m_viewPointTarget.OrthographicZoomFactor - m_viewPointSource.OrthographicZoomFactor; m_cameraOrthographic.ZoomFactor = m_viewPointSource.OrthographicZoomFactor + (zoomValue * actFrameFactor); } }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> /// <param name="updateState">The current state of update processing.</param> /// <param name="animationState">The current state of the animation.</param> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { base.OnCurrentTimeUpdated(updateState, animationState); // Calculate factor by what to transform all coordinates var maxMilliseconds = this.FixedTime.TotalMilliseconds; var currentMillis = this.CurrentTime.TotalMilliseconds; var actFrameFactor = (float)(currentMillis / maxMilliseconds); // Transform position and rotation var moveVector = _viewPointTarget.Position - _viewPointSource.Position; var rotationVector = _viewPointTarget.Rotation - _viewPointSource.Rotation; _camera.Position = _viewPointSource.Position + moveVector * actFrameFactor; _camera.TargetRotation = _viewPointSource.Rotation + rotationVector * actFrameFactor; // Special handling for orthographic cameras if (_cameraOrthographic != null) { var zoomValue = _viewPointTarget.OrthographicZoomFactor - _viewPointSource.OrthographicZoomFactor; _cameraOrthographic.ZoomFactor = _viewPointSource.OrthographicZoomFactor + zoomValue * actFrameFactor; } }
/// <summary> /// Updates all animations within the given animation queue. /// Returns true if any animation was finished or canceled. /// </summary> /// <param name="updateState">Current update state.</param> /// <param name="animationState">Current animation state.</param> /// <param name="animationQueue">The queue which should be updated.</param> private bool UpdateQueueInternal(IAnimationUpdateState updateState, AnimationState animationState, Queue <IAnimation> animationQueue) { bool anyFinishedOrCanceled = false; AnimationState animationStateInner = new AnimationState(); int actIndex = 0; TimeSpan actMaxTime = TimeSpan.Zero; // Loop over all animations and update them till next blocking animation foreach (IAnimation actAnimation in animationQueue) { if (actAnimation.Canceled) { continue; } if (actAnimation.Finished) { continue; } try { animationStateInner.RunningAnimationsIndex = actIndex; actIndex++; // Call update of the animation updateState.IgnorePauseState = actAnimation.IgnorePauseState; actAnimation.Update(updateState, animationStateInner); // Decrement current animation index if the current one is finished now if (actAnimation.Finished || actAnimation.Canceled) { actIndex--; anyFinishedOrCanceled = true; } // Break on blocking animations if (actAnimation.IsBlockingAnimation) { break; } } catch (Exception ex) { //Log error AnimationHandler animHandler = this as AnimationHandler; // Raise the animation failed event AnimationFailed.Raise(this, new AnimationFailedEventArgs(actAnimation, ex)); //Query for reaction AnimationFailedReaction reaction = OnAnimationFailed(actAnimation, ex); switch (reaction) { case AnimationFailedReaction.ThrowException: throw; //Remove the animation and case AnimationFailedReaction.RemoveAndContinue: actAnimation.Canceled = true; anyFinishedOrCanceled = true; break; } } } return(anyFinishedOrCanceled); }
/// <summary> /// Called for each update step of this animation. /// </summary> /// <param name="updateState">The current state of the update pass.</param> /// <param name="animationState">The current state of the animation.</param> public AnimationUpdateResult Update(IAnimationUpdateState updateState, AnimationState animationState) { int countAnimationsFinished = 0; bool prevIgnorePauseState = updateState.IgnorePauseState; PreCheckExecutionInternal(); try { // Execute all pre-update actions if (m_preUpdateActionsCount > 0) { PerformPreupdateActionsInternal(); } // Cancel here if there are no animations at all if ((m_runningAnimationsCount == 0) && (m_runningSecondaryAnimationsCount == 0)) { m_timeTillNextPartFinished = Constants.UPDATE_STATE_MAX_TIME; return(AnimationUpdateResult.Empty); } // Check collection counters for plausibility if ((m_runningAnimationsCount < 0) || (m_runningSecondaryAnimationsCount < 0) || (m_preUpdateActionsCount < 0)) { throw new SeeingSharpGraphicsException("Internal error: Invalid animation count errors in Animation handler!"); } bool anySubAnimationFinishedOrCanceled = false; // Animation update loop for primary animations if (m_runningAnimationsCount > 0) { anySubAnimationFinishedOrCanceled |= UpdateQueueInternal(updateState, animationState, m_runningAnimations); } // Animation update loop for secondary animations if (m_runningSecondaryAnimationsCount > 0) { foreach (Queue <IAnimation> actSecondaryQueue in m_runningSecondaryAnimations) { anySubAnimationFinishedOrCanceled |= UpdateQueueInternal(updateState, animationState, actSecondaryQueue); } } // Dequeue all finished animations // Do also calculate time till next finished animation here while (anySubAnimationFinishedOrCanceled && (m_runningAnimationsCount > 0)) { if (m_runningAnimations.First().IsFinishedOrCanceled()) { anySubAnimationFinishedOrCanceled = true; countAnimationsFinished++; IAnimation currentAnimation = m_runningAnimations.Dequeue(); if (currentAnimation != null) { Interlocked.Decrement(ref m_runningAnimationsCount); } } else { break; } } if (anySubAnimationFinishedOrCanceled && (m_runningSecondaryAnimationsCount > 0)) { foreach (Queue <IAnimation> actSecondaryQueue in m_runningSecondaryAnimations) { while (actSecondaryQueue.Count > 0) { if (actSecondaryQueue.Peek().IsFinishedOrCanceled()) { anySubAnimationFinishedOrCanceled = true; countAnimationsFinished++; actSecondaryQueue.Dequeue(); } else { break; } } } } // Clear all secondary animations which are finished completely while ((m_runningSecondaryAnimationsCount > 0) && (m_runningSecondaryAnimations.Peek().Count == 0)) { Queue <IAnimation> dummy = m_runningSecondaryAnimations.Dequeue(); Interlocked.Decrement(ref m_runningSecondaryAnimationsCount); } // Calculate time till next partial animation step if (anySubAnimationFinishedOrCanceled) { UpdateTimeTillNextPartFinished(); } else { m_timeTillNextPartFinished = m_timeTillNextPartFinished - updateState.UpdateTime; if (m_timeTillNextPartFinished < m_defaultCycleTime) { m_timeTillNextPartFinished = m_defaultCycleTime; } } } finally { updateState.IgnorePauseState = prevIgnorePauseState; PostCheckExecutionInternal(); } // Return some diagnostics about the executed animation AnimationUpdateResult result = new AnimationUpdateResult(); result.CountFinishedAnimations = countAnimationsFinished; return(result); }
/// <summary> /// Updates all animations contained by this animation sequence. /// </summary> /// <param name="updateState">Current state of update process.</param> public AnimationUpdateResult Update(IAnimationUpdateState updateState) { return(this.Update(updateState, null)); }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { float changeFactor = (float)base.CurrentTime.Ticks / (float)base.FixedTime.Ticks; m_targetObject.AccentuationFactor = m_startAccentuation + m_moveAccentuation * changeFactor; }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { float scaleFactor = (float)base.CurrentTime.Ticks / (float)base.FixedTime.Ticks; m_targetObject.Scaling = m_startScaleVector + m_differenceVector * scaleFactor; }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { m_targetObject.Position = m_startVector + m_moveHelper.GetPartialMoveDistance(base.CurrentTime); }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { var changeFactor = this.CurrentTime.Ticks / (float)this.FixedTime.Ticks; _targetObject.AccentuationFactor = _startAccentuation + _moveAccentuation * changeFactor; }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { var changeFactor = this.CurrentTime.Ticks / (float)this.FixedTime.Ticks; _targetObject.Scaling = _startScaling + _moveScaling * changeFactor; }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { var percentagePassed = this.CurrentTime.Ticks / (float)_duration.Ticks; _targetObject.RotationEuler = _startRotation + _changeRotation * percentagePassed; }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { float percentagePassed = (float)base.CurrentTime.Ticks / (float)m_duration.Ticks; m_targetObject.RotationEuler = m_startRotation + m_changeRotation * percentagePassed; }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> protected virtual void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { _targetObject.Position = _startVector + _moveHelper !.GetPartialMoveDistance(this.CurrentTime); }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { float changeFactor = (float)base.CurrentTime.Ticks / (float)base.FixedTime.Ticks; m_targetObject.Opacity = m_startOpacity + m_moveOpacity * changeFactor; }
/// <summary> /// Called each time the CurrentTime value gets updated. /// </summary> protected override void OnCurrentTimeUpdated(IAnimationUpdateState updateState, AnimationState animationState) { var scaleFactor = this.CurrentTime.Ticks / (float)this.FixedTime.Ticks; _targetObject.Scaling = _startScaleVector + _differenceVector * scaleFactor; }
/// <summary> /// Called for each update step. /// </summary> /// <param name="animationState">The current state of the animation.</param> /// <param name="updateState">The current state of the update pass.</param> public AnimationUpdateResult Update(IAnimationUpdateState updateState, AnimationState animationState) { // Call start animation if m_currentTime is zero HandleStartAnimation(); switch (m_animationType) { // Update logic for FixedTime animations case AnimationType.FixedTime: if (m_fixedTime <= TimeSpan.Zero) { OnStartAnimation(); OnFixedTimeAnimationFinished(); m_finished = true; } if (m_currentTime < m_fixedTime) { m_currentTime = m_currentTime.Add(updateState.UpdateTime); if (m_currentTime >= m_fixedTime) { m_currentTime = m_fixedTime; OnCurrentTimeUpdated(updateState, animationState); OnFixedTimeAnimationFinished(); m_finished = true; } else { OnCurrentTimeUpdated(updateState, animationState); } } break; // Update logic for FinishedByEvent animations case AnimationType.FinishedByEvent: m_currentTime += updateState.UpdateTime; //Call update method OnCurrentTimeUpdated(updateState, animationState); break; // Update logic for async calls case AnimationType.AsyncCall: m_currentTime += updateState.UpdateTime; if (m_asyncTask == null) { m_asyncTask = OnAsyncAnimationStart(); } else if (m_asyncTask.IsFaulted) { throw new SeeingSharpGraphicsException("Async animation raised an exception!", m_asyncTask.Exception); } else if (m_asyncTask.IsCompleted || m_asyncTask.IsCanceled || m_asyncTask.IsFaulted) { m_finished = true; } break; } return(AnimationUpdateResult.Empty); }
/// <summary> /// Updates all animations within the given animation queue. /// Returns true if any animation was finished or canceled. /// </summary> /// <param name="updateState">Current update state.</param> /// <param name="animationQueue">The queue which should be updated.</param> private bool UpdateQueueInternal(IAnimationUpdateState updateState, IEnumerable <IAnimation> animationQueue) { var anyFinishedOrCanceled = false; var animationStateInner = new AnimationState(); var actIndex = 0; // Loop over all animations and update them till next blocking animation foreach (var actAnimation in animationQueue) { if (actAnimation.Canceled) { continue; } if (actAnimation.Finished) { continue; } try { animationStateInner.RunningAnimationsIndex = actIndex; actIndex++; // Call update of the animation updateState.IgnorePauseState = actAnimation.IgnorePauseState; actAnimation.Update(updateState, animationStateInner); // Decrement current animation index if the current one is finished now if (actAnimation.Finished || actAnimation.Canceled) { actIndex--; anyFinishedOrCanceled = true; } // Break on blocking animations if (actAnimation.IsBlockingAnimation) { break; } } catch (Exception ex) { // Raise the animation failed event this.AnimationFailed.Raise(this, new AnimationFailedEventArgs(actAnimation, ex)); // Query for reaction var reaction = this.OnAnimationFailed(actAnimation, ex); switch (reaction) { case AnimationFailedReaction.ThrowException: throw; // RemoveObject the animation and case AnimationFailedReaction.RemoveAndContinue: actAnimation.Canceled = true; anyFinishedOrCanceled = true; break; default: throw new SeeingSharpException($"Unknown {nameof(AnimationFailedReaction)}: {reaction}"); } } } return(anyFinishedOrCanceled); }