Ejemplo n.º 1
0
        public float GetValue(float sparam, float time)
        {
            //1 item, 1 value
            if (Items.Count == 1)
            {
                return(Items [0].GetValue(time));
            }
            //Find 2 keyframes to interpolate between
            AlchemyCurve c1 = null, c2 = null;

            for (int i = 0; i < Items.Count - 1; i++)
            {
                if (sparam >= Items [i].SParam && sparam <= Items [i + 1].SParam)
                {
                    c1 = Items [i];
                    c2 = Items [i + 1];
                }
            }
            //We're at the end
            if (c1 == null)
            {
                return(Items [Items.Count - 1].GetValue(time));
            }
            //Interpolate between SParams
            var v1 = c1.GetValue(time);
            var v2 = c2.GetValue(time);

            return(AlchemyEasing.Ease(Type, sparam, c1.SParam, c2.SParam, v1, v2));
        }
Ejemplo n.º 2
0
        public float GetValue(float time)
        {
            //Only have one keyframe? Just return it.
            if (Data.Length == 1)
            {
                return(Data [0].Item2);
            }
            //Locate the keyframes to interpolate between
            float t1 = float.NegativeInfinity;
            float t2 = 0, v1 = 0, v2 = 0;

            for (int i = 0; i < Data.Length - 1; i++)
            {
                if (time >= Data [i].Item1 && time <= Data [i + 1].Item1)
                {
                    t1 = Data [i].Item1;
                    t2 = Data [i + 1].Item1;
                    v1 = Data [i].Item2;
                    v2 = Data [i + 1].Item2;
                }
            }
            //Time wasn't between any values. Return max.
            if (t1 == float.NegativeInfinity)
            {
                return(Data [Data.Length - 1].Item2);
            }
            //Interpolate!
            return(AlchemyEasing.Ease(Type, time, t1, t2, v1, v2));
        }
Ejemplo n.º 3
0
		public float GetValue(float time) {
			if (Keyframes == null)
				return Value;
			if (Keyframes.Count == 1)
				return Keyframes [0].Value;
			if (time <= Keyframes[0].Time)
				return Keyframes[0].Value;
			if (time >= Keyframes[Keyframes.Count - 1].Time)
			{
				switch (Flags)
				{
					case LoopFlags.PlayOnce:
						return Keyframes[Keyframes.Count - 1].Value;
                    case LoopFlags.Repeat:
                        time = time % Keyframes[Keyframes.Count - 1].Value;
                        break;
                    default:
                        return Keyframes[Keyframes.Count - 1].Value;
				}
				
			}
			for (int i = 0; i < Keyframes.Count - 1; i++)
			{
				var a = Keyframes[i];
				var b = Keyframes[i + 1];
                //TODO: Actually do this properly with InTangent and OutTangent
                if (time >= a.Time && time <= b.Time)
                    return AlchemyEasing.Ease(EasingTypes.Linear, time, a.Time, b.Time, a.Value, b.Value);
			}
			throw new Exception("Malformed AlchemyCurve");
		}
Ejemplo n.º 4
0
        void GenerateFunction(CurveKeyframe a, CurveKeyframe b)
        {
            var key = new Vector2(a.Time, b.Time);

            if (beziers.ContainsKey(key))
            {
                return;
            }
            float p1y = AlchemyEasing.Ease(EasingTypes.Linear, b.InTangent, a.Value, b.Value, 0, 1);

            float p2y = AlchemyEasing.Ease(EasingTypes.Linear, a.OutTangent, a.Value, b.Value, 0, 1);

            beziers.Add(key, CubicBezier.Bezier(0.5, p1y, 0.5, 1 - p2y));
        }
        public float GetValue(float time)
        {
            if (Keyframes == null)
            {
                return(Value);
            }
            if (Keyframes.Count == 1)
            {
                return(Keyframes [0].Value);
            }
            if (time <= Keyframes[0].Time)
            {
                return(Keyframes[0].Value);
            }
            if (time >= Keyframes[Keyframes.Count - 1].Time)
            {
                switch (Flags)
                {
                case LoopFlags.PlayOnce:
                    return(Keyframes[Keyframes.Count - 1].Value);

                case LoopFlags.Repeat:
                    time = time % Keyframes[Keyframes.Count - 1].Time;
                    break;

                default:
                    return(Keyframes[Keyframes.Count - 1].Value);
                }
            }
            for (int i = 0; i < Keyframes.Count - 1; i++)
            {
                var a = Keyframes[i];
                var b = Keyframes[i + 1];
                //TODO: Actually do this properly with InTangent and OutTangent
                if (time >= a.Time && time <= b.Time)
                {
                    return(AlchemyEasing.Ease(EasingTypes.Linear, time, a.Time, b.Time, a.Value, b.Value));
                }
            }
            //This should be an error at some stage, but the implementation is broken.
            return(Keyframes[Keyframes.Count - 1].Value);
            //throw new Exception("Malformed AlchemyCurve");
        }
Ejemplo n.º 6
0
 public float GetValue(float time)
 {
     if (Keyframes == null)
     {
         return(Value);
     }
     if (Keyframes.Count == 1)
     {
         return(Keyframes [0].Value);
     }
     if (beziers == null)
     {
         GenerateBezierFunctions();
     }
     if (time <= tmin)
     {
         return(Keyframes[0].Value);
     }
     if (time >= tmax)
     {
         switch (Flags)
         {
         case LoopFlags.PlayOnce:
             return(Keyframes[Keyframes.Count - 1].Value);
         }
         return(Keyframes[Keyframes.Count - 1].Value);
     }
     for (int i = 0; i < Keyframes.Count - 1; i++)
     {
         var a = Keyframes[i];
         var b = Keyframes[i + 1];
         if (time < b.Time && time > a.Time)
         {
             var t      = (time - a.Time) / (b.Time - a.Time);
             var amount = beziers[new Vector2(a.Time, b.Time)](t);
             return(AlchemyEasing.Ease(EasingTypes.Linear, (float)amount, 0, 1, a.Value, b.Value));
         }
     }
     throw new Exception("Malformed AlchemyCurve");
 }