Ejemplo n.º 1
0
        public virtual void Update(float dt)
        {
            _shaker.Update(dt, this);

            position.X = movementInterpolation.Apply(position.X, target.X, Speed);
            position.Y = movementInterpolation.Apply(position.Y, target.Y, Speed);

            rotation = movementInterpolation.Apply(rotation, targetRotation, Speed);
            scale    = movementInterpolation.Apply(scale, targetScale, ZoomSpeed);
            scale    = MathHelper.Clamp(scale, MaxZoom, MinZoom);

            if (_useBoundary)
            {
                if (-position.X + center.X > _boundary.Right)
                {
                    position.X = -_boundary.Right + center.X;
                }
                if (-position.X - center.X < _boundary.Left)
                {
                    position.X = -_boundary.Left - center.X;
                }
                if (-position.Y + center.Y > _boundary.Bottom)
                {
                    position.Y = -_boundary.Bottom + center.Y;
                }
                if (-position.Y - center.Y < _boundary.Top)
                {
                    position.Y = -_boundary.Top - center.Y;
                }
            }
        }
Ejemplo n.º 2
0
        public void DrawInterpolated(Interpolation interpolation, float progress, Frame next, SpriteBatch spriteBatch, DynamicTextureAtlasManager atlas, Frame frame, Color color, bool flipped)
        {
            for (int i = 0; i < Parts.Count; i++)
            {
                var part       = Parts[i];
                var targetPart = next.Parts[i];

                part.DrawAt(
                    new Vector2(
                        interpolation.Apply(part.Position.X, targetPart.Position.X, progress),
                        interpolation.Apply(part.Position.Y, targetPart.Position.Y, progress)),
                    Utils.MathUtils.AngleLerp(interpolation, part.Rotation, targetPart.Rotation, progress),
                    spriteBatch,
                    atlas,
                    color,
                    flipped);
            }
        }
Ejemplo n.º 3
0
        public static void AnimationLoop(string name, Action <float> onAnimate, float duration = 1, float interval = UPS_20, Interpolation.Kind interpolationKind = Interpolation.Kind.Linear)
        {
            var startTime = Time.time;

            ConditionalCall(name, () =>
            {
                var t = Time.time - startTime;
                t    %= duration;
                onAnimate(Interpolation.Apply(interpolationKind, t / duration));
                return(false);
            }, null, interval);
        }
Ejemplo n.º 4
0
        //----------------------------------------------------------------------------------------------------------------------------------------------

        public static void AnimationPingPong(Action <float> onAnimate, float duration = 1, float interval = UPS_20, Interpolation.Kind interpolationKind = Interpolation.Kind.Linear)
        {
            var startTime = Time.time;

            ConditionalCall(() =>
            {
                var t = Time.time - startTime;
                var i = (int)(t / duration);
                t    %= duration;
                t     = i % 2 == 0 ? t : duration - t;
                onAnimate(Interpolation.Apply(interpolationKind, t / duration));
                return(false);
            }, null, interval);
        }
Ejemplo n.º 5
0
        public static float AngleLerp(Interpolation interpolation, float nowrap, float wraps, float lerp)
        {
            float c, d;

            if (wraps < nowrap)
            {
                c = wraps + (float)(Math.PI * 2);
                //c > nowrap > wraps
                d = c - nowrap > nowrap - wraps
                    ? interpolation.Apply(nowrap, wraps, lerp)
                    : interpolation.Apply(nowrap, c, lerp);
            }
            else if (wraps > nowrap)
            {
                c = wraps - (float)(Math.PI * 2);
                //wraps > nowrap > c
                d = wraps - nowrap > nowrap - c
                    ? interpolation.Apply(nowrap, c, lerp)
                    : interpolation.Apply(nowrap, wraps, lerp);
            }
            else
            {
                return(nowrap);
            }                       //Same angle already

            // wrap
            while (MathHelper.ToDegrees(d) < 0)
            {
                d += MathHelper.ToRadians(360f);
            }
            while (MathHelper.ToDegrees(d) > 360f)
            {
                d -= MathHelper.ToRadians(360f);
            }

            return(d);
        }
Ejemplo n.º 6
0
        public static void Animation(string name, Action <float> onAnimate, float duration = 1, Action onDone = null, float interval = UPS_20, Interpolation.Kind interpolationKind = Interpolation.Kind.Linear)
        {
            var startTime = Time.time;

            ConditionalCall(name, () =>
            {
                var t = Time.time - startTime;
                if (t >= duration)
                {
                    onAnimate(1); return(true);
                }
                onAnimate(Interpolation.Apply(interpolationKind, t / duration));
                return(false);
            }, onDone, interval);
        }
Ejemplo n.º 7
0
    public override void _Process(float delta)
    {
        _robot.tcp.Transform    = new Transform(tcp.rot, tcp.pos);
        _robot.origin.Transform = new Transform(origin.rot, origin.pos);

        if (currentInterpolation != null)
        {
            currentInterpolation.Step(delta);
            currentInterpolation.Apply(this);
        }
        else
        {
            isMoving = false;
        }

        Array.Copy(this.q, _robot.q, 6);
    }
Ejemplo n.º 8
0
        public override bool Act(float delta)
        {
            if (_complete)
            {
                return(true);
            }

            Pool pool = Pool;

            Pool = null;

            try {
                if (Time == 0)
                {
                    Begin();
                }
                Time += delta;

                _complete = Time >= Duration;
                float percent = 1;

                if (!_complete)
                {
                    percent = Time / Duration;
                    if (Interpolation != null)
                    {
                        percent = Interpolation.Apply(percent);
                    }
                }

                Update(IsReverse ? 1 - percent : percent);
                if (_complete)
                {
                    End();
                }

                return(_complete);
            }
            finally {
                Pool = pool;
            }
        }