private Vector2d ComputeSpline(Vector2d begin, Vector2d control1, Vector2d control2, Vector2d end, double tween) { if (curveType == Key.KeyType.Custom) { Vector2d A1 = Vector2d.Lerp(begin, control1, tween); Vector2d A2 = Vector2d.Lerp(control1, control2, tween); Vector2d A3 = Vector2d.Lerp(control2, end, tween); Vector2d B1 = Vector2d.Lerp(A1, A2, tween); Vector2d B2 = Vector2d.Lerp(A2, A3, tween); return(Vector2d.Lerp(B1, B2, tween)); } else { return(new Vector2d(tween, Key.EaseCurve(curveType, tween, control1.X, control1.Y, control2.X, control2.Y))); } }
public double Tween(double tweenFactor) { Key first = Keys[0]; Key last = Keys[0]; //walk list and tween keys foreach (Key key in Keys.Values) { if (key.Time > first.Time && key.Time < tweenFactor) { first = key; last = first; } if (key.Time >= tweenFactor) { last = key; break; } } if (last.Time < tweenFactor) { first = last; } //todo add support for multiple curves double keyTween = 0; if (last.Time != first.Time) { keyTween = (tweenFactor - first.Time) / (last.Time - first.Time); } keyTween = last.EaseCurve(keyTween); switch (last.BaseTweenType) { case BaseTweenType.Constant: return(first.Value); case BaseTweenType.Power: return(Math.Pow(2, Math.Log(last.Value, 2) * keyTween + Math.Log(first.Value, 2) * (1.0 - keyTween))); case BaseTweenType.Linear: break; case BaseTweenType.Log: break; case BaseTweenType.Boolean: break; case BaseTweenType.PlanetID: return(last.Value == first.Value ? last.Value : 20); default: break; } return((first.Value * (1 - keyTween)) + (last.Value * keyTween)); }