Example #1
0
 /// <summary>
 /// Verifies <paramref name="action"/> is executed after setting the position of
 /// <paramref name="positionable"/> to <paramref name="temporalPosition"/> and then
 /// gets restored to <paramref name="originalPosition"/>.
 /// </summary>
 ///
 /// <remarks>
 /// This should be called within a <see cref="Received.InOrder(Action)"/> block.
 /// </remarks>
 ///
 /// <param name="positionable">The posibionable to verify.</param>
 /// <param name="originalPosition">The expected original position.</param>
 /// <param name="temporalPosition">The expected temporal position.</param>
 /// <param name="action">The action to be executed.</param>
 public static void VerifyDoAtPosition(this IPositionable positionable, long originalPosition, long temporalPosition, Action action)
 {
     positionable.GetPosition();
     positionable.SetPosition(temporalPosition);
     action.Invoke();
     positionable.SetPosition(originalPosition);
 }
Example #2
0
        /// <summary>
        /// Update any active transitions and move between lock states
        /// </summary>
        private void UpdateTransition(float elapsedTime)
        {
            // No Transition to update
            if (mode == CameraMode.LockedPos || mode == CameraMode.LockedTarget)
            {
                return;
            }

            transitionRemaining -= elapsedTime;

            if (transitionRemaining <= 0)
            {
                // End the transition
                switch (mode)
                {
                case CameraMode.TtTTransition:
                case CameraMode.VtTTransition:
                    //The new target is stored in target, simply change mode
                    mode = CameraMode.LockedTarget;
                    break;

                case CameraMode.TtVTransition:
                case CameraMode.VtVTransition:
                    //The new target is stored in targetPos, simply change mode
                    mode = CameraMode.LockedPos;
                    break;
                }
            }
            else
            {
                // Transition is still going, update the transitionPosition
                Vector2 initialPos, finalPos;
                switch (mode)
                {
                case CameraMode.TtTTransition:
                    initialPos = oldTarget.GetPosition();
                    finalPos   = target.GetPosition();
                    break;

                case CameraMode.VtTTransition:
                    initialPos = oldTargetPos;
                    finalPos   = target.GetPosition();
                    break;

                case CameraMode.TtVTransition:
                    initialPos = oldTarget.GetPosition();
                    finalPos   = targetPos;
                    break;

                case CameraMode.VtVTransition:
                    initialPos = oldTargetPos;
                    finalPos   = targetPos;
                    break;

                default:
                    initialPos = finalPos = Vector2.Zero;
                    break;
                }


                float pctTransitionRemaining = transitionRemaining / transitionTime;
                float pctTransitionComplete  = 1 - pctTransitionRemaining;
                float powerPctComplete       = (float)Math.Pow(pctTransitionComplete, 0.5);

                Vector2 deltaPos = finalPos - initialPos;
                transitionPos = initialPos + powerPctComplete * deltaPos;
            }
        }