예제 #1
0
        /// <summary>
        /// Initialize.
        /// </summary>
        /// <param name="fromValue">The fromValue.</param>
        /// <param name="toValue">The toValue.</param>
        /// <param name="behavior">The behavior.</param>
        public void Initialize(float fromValue, float toValue, LerpBehaviors behavior)
        {
            from  = fromValue;
            to    = toValue;
            range = to - from;

            if (behavior.HasFlag(LerpBehaviors.Rotation))
            {
                var angle = from;
                if (behavior.HasFlag(LerpBehaviors.RotationRadians))
                {
                    angle *= Degree;
                }

                if (angle < 0d)
                {
                    angle = 360f + angle;
                }

                var r = angle + range;
                var d = r - angle;
                var a = Abs(d);

                range = a >= 180f ? (360f - a) * (d > 0f ? -1f : 1f) : d;
            }
        }
예제 #2
0
        /// <summary>
        /// The interpolate.
        /// </summary>
        /// <param name="t">The t.</param>
        /// <param name="currentValue">The currentValue.</param>
        /// <param name="behavior">The behavior.</param>
        /// <returns>The <see cref="object"/>.</returns>
        public object Interpolate(float t, object currentValue, LerpBehaviors behavior)
        {
            var value = from + (range * t);

            if (behavior.HasFlag(LerpBehaviors.Rotation))
            {
                if (behavior.HasFlag(LerpBehaviors.RotationRadians))
                {
                    value *= Degree;
                }

                value %= 360f;

                if (value < 0)
                {
                    value += 360f;
                }

                if (behavior.HasFlag(LerpBehaviors.RotationRadians))
                {
                    value *= Radian;
                }
            }

            if (behavior.HasFlag(LerpBehaviors.Round))
            {
                value = Round(value);
            }

            var type = currentValue?.GetType() ?? default;

            return(Convert.ChangeType(value, type !, CultureInfo.InvariantCulture));
        }
예제 #3
0
        /// <summary>
        /// Initialize.
        /// </summary>
        /// <param name="fromValue">The fromValue.</param>
        /// <param name="toValue">The toValue.</param>
        /// <param name="behavior">The behavior.</param>
        public void Initialize(object fromValue, object toValue, LerpBehaviors behavior)
        {
            from  = Convert.ToSingle(fromValue, CultureInfo.InvariantCulture);
            to    = Convert.ToSingle(toValue, CultureInfo.InvariantCulture);
            range = to - from;

            if (behavior.HasFlag(LerpBehaviors.Rotation))
            {
                var angle = from;
                if (behavior.HasFlag(LerpBehaviors.RotationRadians))
                {
                    angle *= Degree;
                }

                if (angle < 0d)
                {
                    angle = 360f + angle;
                }

                var r = angle + range;
                var d = r - angle;
                var a = Abs(d);

                range = a >= 180f ? (360f - a) * (d > 0f ? -1f : 1f) : d;
            }
        }
예제 #4
0
 /// <summary>
 /// Initialize.
 /// </summary>
 /// <param name="fromValue">The fromValue.</param>
 /// <param name="toValue">The toValue.</param>
 /// <param name="behavior">The behavior.</param>
 public void Initialize(Vector2 fromValue, Vector2 toValue, LerpBehaviors behavior)
 {
     _     = behavior;
     from  = fromValue;
     to    = toValue;
     range = new Vector2(to.X - from.X, to.Y - from.Y);
 }
예제 #5
0
파일: Tween.cs 프로젝트: Shkyrockett/Primer
        /// <summary>
        /// Whether this tween handles rotation.
        /// </summary>
        /// <returns>A reference to this.</returns>
        public ITweenable Rotation(RotationUnit unit = RotationUnit.Degrees)
        {
            behavior |= LerpBehaviors.Rotation;
            behavior |= (unit == RotationUnit.Degrees) ? LerpBehaviors.RotationDegrees : LerpBehaviors.RotationRadians;

            return(this);
        }
예제 #6
0
 /// <summary>
 /// Initialize.
 /// </summary>
 /// <param name="fromValue">The fromValue.</param>
 /// <param name="toValue">The toValue.</param>
 /// <param name="behavior">The behavior.</param>
 public void Initialize(PointF fromValue, PointF toValue, LerpBehaviors behavior)
 {
     _     = behavior;
     from  = fromValue;
     to    = toValue;
     range = new PointF(to.X - from.X, to.Y - from.Y);
 }
예제 #7
0
 /// <summary>
 /// Initialize.
 /// </summary>
 /// <param name="fromValue">The fromValue.</param>
 /// <param name="toValue">The toValue.</param>
 /// <param name="behavior">The behavior.</param>
 public void Initialize(SizeF fromValue, SizeF toValue, LerpBehaviors behavior)
 {
     _     = behavior;
     from  = fromValue;
     to    = toValue;
     range = new SizeF(to.Width - from.Width, to.Height - from.Height);
 }
예제 #8
0
 /// <summary>
 /// Initialize.
 /// </summary>
 /// <param name="fromValue">The fromValue.</param>
 /// <param name="toValue">The toValue.</param>
 /// <param name="behavior">The behavior.</param>
 public void Initialize(object fromValue, object toValue, LerpBehaviors behavior)
 {
     _     = behavior;
     from  = (SizeF)fromValue;
     to    = (SizeF)toValue;
     range = new SizeF(to.Width - from.Width, to.Height - from.Height);
 }
예제 #9
0
        /// <summary>
        /// The interpolate.
        /// </summary>
        /// <param name="t">The t.</param>
        /// <param name="currentValue">The currentValue.</param>
        /// <param name="behavior">The behavior.</param>
        /// <returns>The <see cref="object"/>.</returns>
        public object Interpolate(float t, object currentValue, LerpBehaviors behavior)
        {
            var i = from.X + (range.X * t);
            var j = from.Y + (range.Y * t);

            if (behavior.HasFlag(LerpBehaviors.Round))
            {
                i = Round(i);
                j = Round(j);
            }

            var current = (Vector2)currentValue;

            return(new Vector2(
                       (Abs(range.X) < float.Epsilon) ? current.X : i,
                       (Abs(range.Y) < float.Epsilon) ? current.Y : j));
        }
예제 #10
0
        /// <summary>
        /// The interpolate.
        /// </summary>
        /// <param name="t">The t.</param>
        /// <param name="currentValue">The currentValue.</param>
        /// <param name="behavior">The behavior.</param>
        /// <returns>The <see cref="object"/>.</returns>
        public object Interpolate(float t, object currentValue, LerpBehaviors behavior)
        {
            var x = from.X + (range.X * t);
            var y = from.Y + (range.Y * t);

            if (behavior.HasFlag(LerpBehaviors.Round))
            {
                x = Round(x);
                y = Round(y);
            }

            var current = (PointF)currentValue;

            return(new PointF(
                       (Abs(range.X) < float.Epsilon) ? current.X : x,
                       (Abs(range.Y) < float.Epsilon) ? current.X : y));
        }
예제 #11
0
        /// <summary>
        /// The interpolate.
        /// </summary>
        /// <param name="t">The t.</param>
        /// <param name="currentValue">The currentValue.</param>
        /// <param name="behavior">The behavior.</param>
        /// <returns>The <see cref="object"/>.</returns>
        public object Interpolate(float t, object currentValue, LerpBehaviors behavior)
        {
            var width  = from.Width + (range.Width * t);
            var height = from.Height + (range.Height * t);

            if (behavior.HasFlag(LerpBehaviors.Round))
            {
                width  = Round(width);
                height = Round(height);
            }

            var current = (SizeF)currentValue;

            return(new SizeF(
                       (Abs(range.Width) < float.Epsilon) ? current.Width : width,
                       (Abs(range.Height) < float.Epsilon) ? current.Height : height));
        }
예제 #12
0
파일: Tween.cs 프로젝트: Shkyrockett/Primer
        /// <summary>
        /// Initializes a new instance of the <see cref="Tween"/> class.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="duration">The duration.</param>
        /// <param name="delay">The delay.</param>
        /// <param name="parent">The parent.</param>
        internal Tween(object?target, float duration, float delay, Tweener parent)
        {
            ease     = null;
            begin    = null;
            update   = null;
            complete = null;

            Target        = target ?? default !;
            this.duration = duration;
            this.delay    = delay;
            this.parent   = parent;
            Remover       = parent;

            firstUpdate = true;

            varHash  = new();
            vars     = new();
            lerpers  = new();
            start    = new();
            end      = new();
            behavior = LerpBehaviors.None;
        }
예제 #13
0
 /// <summary>
 /// Initialize.
 /// </summary>
 /// <param name="fromValue">The fromValue.</param>
 /// <param name="toValue">The toValue.</param>
 /// <param name="behavior">The behavior.</param>
 public void Initialize(object fromValue, object toValue, LerpBehaviors behavior)
 {
     from  = (Vector2)fromValue;
     to    = (Vector2)toValue;
     range = new Vector2(to.X - from.X, to.Y - from.Y);
 }
예제 #14
0
 /// <summary>
 /// Initialize.
 /// </summary>
 /// <param name="fromValue">The fromValue.</param>
 /// <param name="toValue">The toValue.</param>
 /// <param name="behavior">The behavior.</param>
 public void Initialize(object fromValue, object toValue, LerpBehaviors behavior)
 {
     from  = (PointF)fromValue;
     to    = (PointF)toValue;
     range = new PointF(to.X - from.X, to.Y - from.Y);
 }
예제 #15
0
파일: Tween.cs 프로젝트: Shkyrockett/Primer
 /// <summary>
 /// Whether tweened values should be rounded to integer values.
 /// </summary>
 /// <returns>A reference to this.</returns>
 public ITweenable Round()
 {
     behavior |= LerpBehaviors.Round;
     return(this);
 }
예제 #16
0
파일: Tween.cs 프로젝트: Shkyrockett/Primer
 /// <summary>
 /// Sets the tween to reverse every other time it repeats. Repeating must be enabled for this to have any effect.
 /// </summary>
 /// <returns>A reference to this.</returns>
 public ITweenable Reflect()
 {
     behavior |= LerpBehaviors.Reflect;
     return(this);
 }