public ThirdPersonController(ThirdPersonControllerDesc desc)
        {
            _character           = desc.Character;
            _collitionController = desc.CollitionController;
            _walk = desc.Walk;
            _idle = desc.Idle;

            _turn90Speed  = Numerics.PI / 2 / desc.TransitionTime;
            _turn180Speed = Numerics.PI / desc.TransitionTime;

            _cameraMaxDistance = desc.CameraMaxDistance;
            _cameraMinDistance = desc.CameraMinDistance;
            _cameraMaxPich     = desc.CameraMaxPich;
            _cameraMinPich     = desc.CameraMinPich;
            _camera            = desc.Camera;

            _resetter = new BonesResetter(_character);

            _idleWalk = new AnimationTransition(_idle, _walk, desc.TransitionTime);
            _walkIdle = new AnimationTransition(_walk, _idle, desc.TransitionTime);

            _walk.FirstPlayback.Animation.Sample(_walk.FirstPlayback.Cursor.StartTime);
            _initialForwardPositon = _character.LocalPosition;

            _walk.FirstPlayback.Animation.Sample(_walk.FirstPlayback.Cursor.StartTime + desc.TransitionTime);
            _lastAnimPosition = _character.LocalPosition;
            _walkForwardSpeed = _character.LocalPosition - _initialForwardPositon;

            _resetter.Reset();
            _initialHeading = _character.Heading;

            CreateStates();

            _cameraBindedToCharacter = _camera.Affector == _character;
        }
        /// <summary>
        /// Flips the view over time.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="transition">Transition.</param>
        /// <param name="direction">Direction.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="onFinished">On finished.</param>
        public static void Flip(this UIElement view, AnimationTransition transition, AnimationDirection direction, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
        {
            double minTransform = 0;
            double maxTransform = 0;
            var    isIn         = transition == AnimationTransition.In;
            var    isHorizontal = direction == AnimationDirection.Left || direction == AnimationDirection.Right;

            if (direction == AnimationDirection.Right || direction == AnimationDirection.Up)
            {
                minTransform = isIn ? 90 : 270;
                maxTransform = isIn ? 0 : 360;
            }
            else
            {
                minTransform = isIn ? -90 : 440;
                maxTransform = isIn ? 0 : 360;
            }

            var transform = new PlaneProjection();

            view.RenderTransform = null;
            view.Projection      = transform;

            CreateStoryboard(view, duration, transition)
            .CreateDoubleAnimation(transform, isHorizontal ? "RotationY" : "RotationX", minTransform, maxTransform, transition)
            .Begin();
        }
        /// <summary>
        /// Slides the view over time.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="transition">Transition.</param>
        /// <param name="direction">Direction.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="onFinished">On finished.</param>
        public static void Slide(this UIView view, AnimationTransition transition, AnimationDirection direction, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
        {
            var isIn         = transition == AnimationTransition.In;
            var isLtr        = (transition == AnimationTransition.In && (direction == AnimationDirection.Down || direction == AnimationDirection.Left)) || (transition == AnimationTransition.Out && (direction == AnimationDirection.Up || direction == AnimationDirection.Right));
            var isVertical   = direction == AnimationDirection.Up || direction == AnimationDirection.Down;
            var isHorizontal = direction == AnimationDirection.Left || direction == AnimationDirection.Right;

            var minAlpha     = (nfloat)0.0f;
            var maxAlpha     = (nfloat)1.0f;
            var minTransform = CGAffineTransform.MakeTranslation(
                (isHorizontal ? (isLtr ? 1 : -1) : 0) * view.Bounds.Width,
                (isVertical ? (isLtr ? 1 : -1) : 0) * view.Bounds.Height);
            var maxTransform = CGAffineTransform.MakeIdentity();

            view.Alpha     = isIn ? minAlpha : maxAlpha;
            view.Transform = isIn ? minTransform : maxTransform;
            UIView.Animate(duration, 0, UIViewAnimationOptions.CurveEaseInOut,
                           () =>
            {
                view.Alpha     = isIn ? maxAlpha : minAlpha;
                view.Transform = isIn ? maxTransform : minTransform;
            },
                           onFinished
                           );
        }
        /// <summary>
        /// Flips the view over time.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="transition">Transition.</param>
        /// <param name="direction">Direction.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="onFinished">On finished.</param>
        public static void Flip(this UIView view, AnimationTransition transition, AnimationDirection direction, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
        {
            var isVertical   = direction == AnimationDirection.Up || direction == AnimationDirection.Down;
            var isHorizontal = direction == AnimationDirection.Left || direction == AnimationDirection.Right;
            var isIn         = transition == AnimationTransition.In;
            var isLtr        = (transition == AnimationTransition.In && (direction == AnimationDirection.Down || direction == AnimationDirection.Left)) || (transition == AnimationTransition.Out && (direction == AnimationDirection.Up || direction == AnimationDirection.Right));

            var minTransform = CATransform3D.Identity;

            minTransform.m34 = (nfloat)AnimationConstants.M34;
            minTransform     = minTransform.Rotate((nfloat)((isLtr ? 1 : -1) * Math.PI * 0.5), (nfloat)(isVertical ? 1.0f : 0.0f), (nfloat)(isHorizontal ? 1.0f : 0.0f), (nfloat)0.0f);
            var maxTransform = CATransform3D.Identity;

            maxTransform.m34 = (nfloat)AnimationConstants.M34;

            view.Alpha           = isIn ? (nfloat)AnimationConstants.MinAlpha : (nfloat)AnimationConstants.MaxAlpha;
            view.Layer.Transform = isIn ? minTransform : maxTransform;
            UIView.Animate(duration, 0, UIViewAnimationOptions.CurveEaseInOut,
                           () =>
            {
                view.Layer.AnchorPoint = new CGPoint((nfloat)0.5, (nfloat)0.5f);
                view.Layer.Transform   = isIn ? maxTransform : minTransform;
                view.Alpha             = isIn ? (nfloat)AnimationConstants.MaxAlpha : (nfloat)AnimationConstants.MinAlpha;
            },
                           onFinished
                           );
        }
        /// <summary>
        /// Fades the view over time.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="transition">Transition.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="onFinished">On finished.</param>
        public static void Fade(this UIElement view, AnimationTransition transition, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
        {
            view.RenderTransform = null;
            view.Projection      = null;

            CreateStoryboard(view, duration, transition).Begin();
        }
Esempio n. 6
0
    /// <summary>
    /// Starts the animations using the specified transition.
    /// </summary>
    /// <param name="animationInstance">The animation instance.</param>
    /// <param name="transition">
    /// The animation transition. (Can be <see langword="null"/>, in which case
    /// <see cref="AnimationTransitions.SnapshotAndReplace()"/> will be used.)
    /// </param>
    internal void StartAnimation(AnimationInstance animationInstance, AnimationTransition transition)
    {
      if (transition == null)
        transition = AnimationTransitions.SnapshotAndReplace();

      transition.AnimationInstance = animationInstance;
      Add(transition);
    }
Esempio n. 7
0
        /// <summary>
        /// Removes the specified animation transition.
        /// </summary>
        /// <param name="transition">The animation transition.</param>
        internal void Remove(AnimationTransition transition)
        {
            bool removed = _transitions.Remove(transition);

            if (removed)
            {
                transition.Uninitialize(this);
            }
        }
        /// <summary>
        /// Rotates the view over time.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="transition">Transition.</param>
        /// <param name="direction">Direction.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="onFinished">On finished.</param>
        public static void Rotate(this UIElement view, AnimationTransition transition, AnimationDirection direction, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
        {
            var transform = new RotateTransform();

            view.Projection            = null;
            view.RenderTransform       = transform;
            view.RenderTransformOrigin = new Windows.Foundation.Point(0.5, 0.5);

            CreateStoryboard(view, duration, transition)
            .CreateDoubleAnimation(transform, "Angle", (direction == AnimationDirection.Right ? -1 : 1) * AnimationConstants.RotationAngle / 3, 0, transition)
            .Begin();
        }
 /// <summary>
 /// Fades the view over time.
 /// </summary>
 /// <param name="view">View.</param>
 /// <param name="transition">Transition.</param>
 /// <param name="duration">Duration.</param>
 /// <param name="onFinished">On finished.</param>
 public static void Fade(this UIView view, AnimationTransition transition, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
 {
     view.Alpha     = transition == AnimationTransition.In ? (nfloat)AnimationConstants.MinAlpha : (nfloat)AnimationConstants.MaxAlpha;
     view.Transform = CGAffineTransform.MakeIdentity();
     UIView.Animate(duration, 0, UIViewAnimationOptions.CurveEaseInOut,
                    () =>
     {
         view.Alpha = transition == AnimationTransition.In ? (nfloat)AnimationConstants.MaxAlpha : (nfloat)AnimationConstants.MinAlpha;
     },
                    onFinished
                    );
 }
Esempio n. 10
0
        /// <summary>
        /// Fades the view over time.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="transition">Transition.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="onFinished">On finished.</param>
        public static void Fade(this View view, AnimationTransition transition, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
        {
            var isIn = transition == AnimationTransition.In;

            view.Alpha        = (float)(isIn ? AnimationConstants.MinAlpha : AnimationConstants.MaxAlpha);
            view.ScaleX       = view.ScaleY = 1;
            view.TranslationX = view.TranslationY = 0;

            view.Animate()
            .SetDuration((int)(duration * 1000))
            .Alpha((float)(isIn ? AnimationConstants.MaxAlpha : AnimationConstants.MinAlpha));
        }
        /// <summary>
        /// Scales the view over time.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="transition">Transition.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="onFinished">On finished.</param>
        public static void Scale(this UIElement view, AnimationTransition transition, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
        {
            var transform = new ScaleTransform();

            view.Projection            = null;
            view.RenderTransform       = transform;
            view.RenderTransformOrigin = new Windows.Foundation.Point(0.5, 0.5);

            CreateStoryboard(view, duration, transition)
            .CreateDoubleAnimation(transform, "ScaleX", AnimationConstants.MinScale, AnimationConstants.MaxScale, transition)
            .CreateDoubleAnimation(transform, "ScaleY", AnimationConstants.MinScale, AnimationConstants.MaxScale, transition)
            .Begin();
        }
Esempio n. 12
0
        /// <summary>
        /// Starts the animation using the specified transition.
        /// </summary>
        /// <param name="transition">
        /// The transition that determines how the new animation is applied. The class
        /// <see cref="AnimationTransitions"/> provides a set of predefined animation transitions.
        /// </param>
        /// <inheritdoc cref="Start()"/>
        /// <exception cref="AnimationException">
        /// Cannot start animation. The animation instance associated with the current animation
        /// controller is already running or has already been recycled and the animation controller is
        /// no longer valid.
        /// </exception>
        public void Start(AnimationTransition transition)
        {
            if (!IsValid)
            {
                throw new AnimationException("Cannot start animation. The animation instance associated with the current animation controller has already been recycled.");
            }

            if (State != AnimationState.Stopped)
            {
                throw new AnimationException("Cannot start animation. The animation instance associated with the current animation controller is already running.");
            }

            _animationManager.StartAnimation(_animationInstance, transition);
        }
Esempio n. 13
0
        public AnimationState AddTransition(AnimationState target, RangedFloat transitionRange, bool bufferInput = true, BoolMethod canEnter = null)
        {
            AnimationTransition transition = new AnimationTransition();

            transition.target          = target;
            transition.transitionRange = transitionRange;
            transition.bufferInput     = bufferInput;
            if (canEnter != null)
            {
                transition.canEnter = canEnter;
            }

            _transitions.Add(transition);
            return(this);
        }
Esempio n. 14
0
    public AnimationState AddTransition(AnimationState target, RangedFloat transitionRange, bool bufferInput = true, Func <bool> canEnter = null)
    {
        AnimationTransition transition = new AnimationTransition
        {
            target          = target,
            transitionRange = transitionRange,
            bufferInput     = bufferInput
        };

        if (canEnter != null)
        {
            transition.canEnter = canEnter;
        }

        _transitions.Add(transition);
        return(this);
    }
Esempio n. 15
0
        /// <summary>
        /// Rotates the view over time.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="transition">Transition.</param>
        /// <param name="direction">Direction.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="onFinished">On finished.</param>
        public static void Rotate(this View view, AnimationTransition transition, AnimationDirection direction, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
        {
            var isIn = transition == AnimationTransition.In;

            var minAngle = (float)((direction == AnimationDirection.Right ? -1 : 1) * AnimationConstants.RotationAngle);
            var maxAngle = 0.0f;

            view.Alpha        = (float)(isIn ? AnimationConstants.MinAlpha : AnimationConstants.MaxAlpha);
            view.Rotation     = (float)((isIn ? minAngle : maxAngle) / Math.PI);
            view.ScaleX       = view.ScaleY = 1;
            view.TranslationX = view.TranslationY = 0;

            view.Animate()
            .SetDuration((int)(duration * 1000))
            .Alpha((float)(isIn ? AnimationConstants.MaxAlpha : AnimationConstants.MinAlpha))
            .Rotation((float)((isIn ? maxAngle : minAngle) / Math.PI));
        }
        /// <summary>
        /// Zooms the specified view over time.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="transition">Transition.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="onFinished">On finished.</param>
        public static void Zoom(this UIView view, AnimationTransition transition, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
        {
            var isIn = transition == AnimationTransition.In;

            var minTransform = CGAffineTransform.MakeScale((nfloat)2.0, (nfloat)2.0);
            var maxTransform = CGAffineTransform.MakeScale((nfloat)1, (nfloat)1);

            view.Alpha     = isIn ? (nfloat)AnimationConstants.MinAlpha : (nfloat)AnimationConstants.MaxAlpha;
            view.Transform = isIn ? minTransform : maxTransform;
            UIView.Animate(duration, 0, UIViewAnimationOptions.CurveEaseInOut,
                           () =>
            {
                view.Alpha     = isIn ? (nfloat)AnimationConstants.MaxAlpha : (nfloat)AnimationConstants.MinAlpha;
                view.Transform = isIn ? maxTransform : minTransform;
            },
                           onFinished
                           );
        }
        /// <summary>
        /// Rotates the view over time.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="transition">Transition.</param>
        /// <param name="direction">Direction.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="onFinished">On finished.</param>
        public static void Rotate(this UIView view, AnimationTransition transition, AnimationDirection direction, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
        {
            var minTransform = CGAffineTransform.MakeRotation((nfloat)((direction == AnimationDirection.Right ? -1 : 1) * AnimationConstants.RotationAngle));
            var maxTransform = CGAffineTransform.MakeRotation((nfloat)0.0);

            var isIn = transition == AnimationTransition.In;

            view.Alpha     = isIn ? (nfloat)AnimationConstants.MinAlpha : (nfloat)AnimationConstants.MaxAlpha;
            view.Transform = isIn ? minTransform : maxTransform;
            UIView.Animate(duration, 0, UIViewAnimationOptions.CurveEaseInOut,
                           () =>
            {
                view.Alpha     = isIn ? (nfloat)AnimationConstants.MaxAlpha : (nfloat)AnimationConstants.MinAlpha;
                view.Transform = isIn ? maxTransform : minTransform;
            },
                           onFinished
                           );
        }
Esempio n. 18
0
        /*
         * void WalkingState(bool state)
         * {
         *  if (isWalking && !state)
         *  {
         *      isWalking = false;
         *      if (animator)
         *      {
         *          animator.AnimationData = idle;
         *          animator.Play();
         *      }
         *  }
         *  else if (!isWalking && state)
         *  {
         *      isWalking = true;
         *      if (animator)
         *      {
         *          animator.AnimationData = walk;
         *          animator.Play();
         *      }
         *  }
         *
         * }
         *
         */


        void CreateAnimationController()
        {
            animator = Node.GetComponent <Animator>();



            var idle    = new AnimationNode(ResourcesManager.LoadAsset <Animation>(@"Assets\Animations\02.vmd"));
            var walk    = new AnimationNode(ResourcesManager.LoadAsset <Animation>(@"Assets\Animations\walk001.vmd"));
            var sitDown = new AnimationNode(ResourcesManager.LoadAsset <Animation>(@"Assets\Animations\SitDownMumi.vmd"));
            var sitIdle = new AnimationNode(ResourcesManager.LoadAsset <Animation>(@"Assets\Animations\SitIdleMumi.vmd"));
            var standUp = new AnimationNode(ResourcesManager.LoadAsset <Animation>(@"Assets\Animations\StandUpMumi.vmd"));

            idle.Name    = "Idle";
            walk.Name    = "Walk";
            sitDown.Name = "Sitdown";
            sitIdle.Name = "Sit Idle";
            standUp.Name = "Standup";

            sitDown.Repeat        = false;
            standUp.Repeat        = false;
            sitDown.NextAnimation = sitIdle;
            standUp.NextAnimation = idle;

            AnimController = new AnimationController(idle);
            var idleWalkTransit = new AnimationTransition((anim) => anim.GetFloat("speed") > 0, walk);
            var walkIdleTransit = new AnimationTransition((anim) => anim.GetFloat("speed") == 0, idle);
            var idleSitTransit  = new AnimationTransition((anim) => anim.GetBool("sit"), sitDown);

            sitIdle.Transitions.Add(new AnimationTransition((anim) => !anim.GetBool("sit"), standUp));
            idle.Transitions.Add(idleWalkTransit);
            idle.Transitions.Add(idleSitTransit);
            walk.Transitions.Add(walkIdleTransit);

            AnimController.AddAnimation(idle);
            AnimController.AddAnimation(walk);
            AnimController.AddAnimation(sitDown);
            AnimController.AddAnimation(sitIdle);
            AnimController.AddAnimation(standUp);

            animator.Controller = AnimController;
        }
Esempio n. 19
0
        /// <summary>
        /// Slides the view over time.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="transition">Transition.</param>
        /// <param name="direction">Direction.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="onFinished">On finished.</param>
        public static void Slide(this View view, AnimationTransition transition, AnimationDirection direction, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
        {
            var isIn         = transition == AnimationTransition.In;
            var isLtr        = (transition == AnimationTransition.In && (direction == AnimationDirection.Down || direction == AnimationDirection.Left)) || (transition == AnimationTransition.Out && (direction == AnimationDirection.Up || direction == AnimationDirection.Right));
            var isVertical   = direction == AnimationDirection.Up || direction == AnimationDirection.Down;
            var isHorizontal = direction == AnimationDirection.Left || direction == AnimationDirection.Right;

            var minTransformX = (isHorizontal ? (isLtr ? 1 : -1) : 0) * view.Width;
            var minTransformY = (isVertical ? (!isLtr ? 1 : -1) : 0) * view.Height;
            var maxTransformX = 0;
            var maxTransformY = 0;

            view.Alpha        = (float)(isIn ? AnimationConstants.MinAlpha : AnimationConstants.MaxAlpha);
            view.TranslationX = isIn ? minTransformX : maxTransformX;
            view.TranslationY = isIn ? minTransformY : maxTransformY;
            view.ScaleX       = view.ScaleY = 1;

            view.Animate()
            .SetDuration((int)(duration * 1000))
            .Alpha((float)(isIn ? AnimationConstants.MaxAlpha : AnimationConstants.MinAlpha))
            .TranslationX(isIn ? maxTransformX : minTransformX)
            .TranslationY(isIn ? maxTransformY : minTransformY);
        }
        /// <summary>
        /// Slides the view over time.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="transition">Transition.</param>
        /// <param name="direction">Direction.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="onFinished">On finished.</param>
        public static void Slide(this UIElement view, AnimationTransition transition, AnimationDirection direction, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
        {
            var isIn         = transition == AnimationTransition.In;
            var isLtr        = (transition == AnimationTransition.In && (direction == AnimationDirection.Down || direction == AnimationDirection.Left)) || (transition == AnimationTransition.Out && (direction == AnimationDirection.Up || direction == AnimationDirection.Right));
            var isVertical   = direction == AnimationDirection.Up || direction == AnimationDirection.Down;
            var isHorizontal = direction == AnimationDirection.Left || direction == AnimationDirection.Right;

            var minTransformX = (isHorizontal ? (isLtr ? 1 : -1) : 0) * view.RenderSize.Width;
            var minTransformY = (isVertical ? (!isLtr ? 1 : -1) : 0) * view.RenderSize.Height;
            var maxTransformX = 0;
            var maxTransformY = 0;

            var transform = new TranslateTransform();

            view.Projection            = null;
            view.RenderTransform       = transform;
            view.RenderTransformOrigin = new Windows.Foundation.Point(0.5, 0.5);

            CreateStoryboard(view, duration, transition)
            .CreateDoubleAnimation(transform, "X", minTransformX, maxTransformX, transition)
            .CreateDoubleAnimation(transform, "Y", minTransformY, maxTransformY, transition)
            .Begin();
        }
Esempio n. 21
0
    /// <inheritdoc/>
    public AnimationController StartAnimation(ITimeline animation, IAnimatableProperty targetProperty, AnimationTransition transition)
    {
      if (targetProperty == null)
        throw new ArgumentNullException("targetProperty");
      if (animation == null)
        throw new ArgumentNullException("animation");

      var animationInstance = animation.CreateInstance();
      animationInstance.AssignTo(targetProperty);
      StartAnimation(animationInstance, transition);
      return new AnimationController(this, animationInstance);
    }
Esempio n. 22
0
 /// <summary>
 /// Flips the view over time.
 /// </summary>
 /// <param name="view">View.</param>
 /// <param name="transition">Transition.</param>
 /// <param name="direction">Direction.</param>
 /// <param name="duration">Duration.</param>
 /// <param name="onFinished">On finished.</param>
 public static void Flip(this View view, AnimationTransition transition, AnimationDirection direction, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
 {
 }
        private static Storyboard CreateStoryboard(DependencyObject element, double duration, AnimationTransition transition)
        {
            Storyboard sb = new Storyboard()
            {
                Duration = new Duration(TimeSpan.FromSeconds(duration)),
            };

            sb.CreateDoubleAnimation(element, "Opacity", AnimationConstants.MinAlpha, AnimationConstants.MaxAlpha, transition);

            return(sb);
        }
        private static Storyboard CreateDoubleAnimation(this Storyboard sb, DependencyObject element, string name, double from, double to, AnimationTransition transition)
        {
            var min = (float)(transition == AnimationTransition.In ? from : to);
            var max = (float)(transition == AnimationTransition.In ? to : from);

            DoubleAnimation anim = new DoubleAnimation();

            anim.From           = min;
            anim.To             = max;
            anim.Duration       = sb.Duration;
            anim.EasingFunction = new QuadraticEase()
            {
                EasingMode = EasingMode.EaseInOut
            };
            Storyboard.SetTarget(anim, element);
            Storyboard.SetTargetProperty(anim, name);
            sb.Children.Add(anim);

            return(sb);
        }
Esempio n. 25
0
        public void Automata_Idle_Walk()
        {
            SceneTests.InitializeScene();

            const float startTimeWalk = 34f / 30f;
            const float endTimeWalk   = 63f / 30f;
            const float durationWalk  = endTimeWalk - startTimeWalk;
            const float startTimeIdle = 0;
            const float endTimeIdle   = 0;
            const float durationIdle  = endTimeIdle;
            const float blendDuration = 0.25f;

            Vector3 speedVector = new Vector3(0, 0, -1f);

            ContentImporter.Import(SceneManager.Scene, @"C:\Users\ansel\Documents\3dsmax\export\lighting_shadowed.DAE")
            .OnSceneAttach(SceneManager.Scene);
            Frame cameraNode = SceneManager.Scene.FindNode("camera1");

            Frame         root     = SceneManager.Scene.EnumerateNodesPosOrden().First(x => x.Type == FrameType.Bone);
            BonesResetter resetter = new BonesResetter(root);

            Vector3 translation = root.LocalPosition;
            var     iniHeading  = root.Heading;

            var animation = SceneManager.Scene.AnimManager.Animations[0];

            animation.Sample(startTimeWalk);
            var iniKeyValue = root.LocalPosition;

            animation.Sample(endTimeWalk);
            var lastKeyValue = root.LocalPosition;

            Vector3 lastAnimTrans = root.LocalPosition; //new Vector3();
            bool    update        = false;
            float   deltaH        = 0;

            KeyFrameAnimationPlayback idle     = new KeyFrameAnimationPlayback(animation, startTimeIdle, durationIdle, AnimationLooping.Loop);
            KeyFrameAnimationPlayback walk     = new KeyFrameAnimationPlayback(animation, startTimeWalk, durationWalk, AnimationLooping.Loop);
            AnimationTransition       idleWalk = new AnimationTransition(idle, walk, blendDuration);
            AnimationTransition       walkIdle = new AnimationTransition(walk, idle, blendDuration);

            var walkCursor = walk.GetCursor(animation);

            Action <float> updateAction = (deltaT) =>
            {
                walk.Update(deltaT);

                if (!update)
                {
                    lastAnimTrans = root.LocalPosition;
                    update        = true;
                    return;
                }

                var cursor = walkCursor;
                if (!cursor.TimeRestart)
                {
                    _disp = root.LocalPosition - lastAnimTrans;
                }
                else
                {
                    _disp = root.LocalPosition - (cursor.PlayDirection > 0 ? iniKeyValue : lastKeyValue);
                }

                _disp = Vector3.TransformCoordinates(_disp, Matrix.RotationY(deltaH));

                translation  += _disp;
                lastAnimTrans = root.LocalPosition;
            };

            Automata stateMachine = new Automata()
                                    .AddState("idle", x =>
                                              idle.Update(x))
                                    .AddState("idle-walk", dt =>
            {
                idleWalk.Update(dt);
                _disp = new Vector3();
                if (Engine.KeyBoard.IsKeyPressed(Keys.Uparrow))
                {
                    _disp = speedVector;
                }
                else
                {
                    _disp = -speedVector;
                }
                _disp = Vector3.TransformCoordinates(_disp, Matrix.RotationY(deltaH));
            })
                                    .AddState("walk", updateAction)
                                    .AddState("walk-idle", x =>
                                              walkIdle.Update(x))
                                    .AddTransition("idle", "idle-walk", x =>
            {
                if (Engine.KeyBoard.IsKeyPressed(Keys.Uparrow))
                {
                    walk.FirstPlayback.Cursor.PlayDirection = 1;
                    update = false;
                    return(true);
                }
                else if (Engine.KeyBoard.IsKeyPressed(Keys.Downarrow))
                {
                    walk.FirstPlayback.Cursor.PlayDirection = -1;
                    update = false;
                    return(true);
                }
                return(false);
            })
                                    .AddTransition("idle-walk", "walk", x =>
                                                   idleWalk.TransitionComplete)
                                    .AddTransition("walk", "walk-idle", x =>
                                                   !Engine.KeyBoard.IsKeyPressed(Keys.Uparrow) && !Engine.KeyBoard.IsKeyPressed(Keys.Downarrow))
                                    .AddTransition("walk-idle", "idle", x =>
                                                   walkIdle.TransitionComplete);

            SceneManager.Scene.Dynamics.Add(new Dynamic(deltaT =>
            {
                //store position previus animation
                var localPosition = root.LocalPosition;
                _disp             = new Vector3();

                float rotSpeed = Numerics.ToRadians(90f);

                if (Engine.KeyBoard.IsKeyPressed(Keys.Leftarrow))
                {
                    deltaH -= rotSpeed * deltaT;
                }
                else if (Engine.KeyBoard.IsKeyPressed(Keys.Rightarrow))
                {
                    deltaH += rotSpeed * deltaT;
                }

                resetter.Reset();
                stateMachine.Update(deltaT);

                //root.Tx = translation.X;
                //root.Tz = translation.Z;
                root.X       = localPosition.X + _disp.X;
                root.Z       = localPosition.Z + _disp.Z;
                root.Heading = iniHeading + deltaH;

                root.ComputeLocalPose();
                root.CommitChanges();

                //var displacement = root.GlobalPose.Translation - localPosition;
                //cameraNode.Tx += displacement.X;
                //cameraNode.Tz += displacement.Z;
                cameraNode.X += _disp.X;
                cameraNode.Z += _disp.Z;
                cameraNode.CommitChanges();
            }));
        }
Esempio n. 26
0
 /// <summary>
 /// Adds the specified animation transition.
 /// </summary>
 /// <param name="transition">The animation transition.</param>
 internal void Add(AnimationTransition transition)
 {
   _transitions.Add(transition);
   transition.Initialize(this);
 }
Esempio n. 27
0
    /// <inheritdoc/>
    public AnimationController StartAnimation(ITimeline animation, IEnumerable<IAnimatableObject> targetObjects, AnimationTransition transition)
    {
      if (targetObjects == null)
        throw new ArgumentNullException("targetObjects");
      if (animation == null)
        throw new ArgumentNullException("animation");

      var animationInstance = animation.CreateInstance();
      animationInstance.AssignTo(targetObjects);
      StartAnimation(animationInstance, transition);
      return new AnimationController(this, animationInstance);
    }
Esempio n. 28
0
        /// <inheritdoc/>
        public AnimationController StartAnimation(ITimeline animation, IAnimatableObject targetObject, AnimationTransition transition)
        {
            if (targetObject == null)
            {
                throw new ArgumentNullException("targetObject");
            }
            if (animation == null)
            {
                throw new ArgumentNullException("animation");
            }

            var animationInstance = animation.CreateInstance();

            animationInstance.AssignTo(targetObject);
            StartAnimation(animationInstance, transition);
            return(new AnimationController(this, animationInstance));
        }