Exemplo n.º 1
0
    public static Vector3 GetTangent(List <Waypoint> keyframes, double time, bool normalize = false, bool handleCriticalPoints = false)
    {
        if (keyframes.Count == 0)
        {
            return(new Vector3(0.25f, 0, 0));
        }

        Vector3 tangent = Vector3.zero;
        InterpolationSet <Waypoint> interpolationData = Interpolate(keyframes, time);

        if (interpolationData != null)
        {
            return(CalculateTangent(interpolationData.first, interpolationData.second, interpolationData.value, normalize));
        }

        if (handleCriticalPoints && Mathf.Approximately(tangent.magnitude, 0.0f))
        {
            float maxTime   = (float)keyframes[keyframes.Count - 1].time;
            float timef     = Mathf.Clamp((float)time, 0.0f, maxTime);
            float startTime = Mathf.Clamp(timef - 0.1f, 0.0f, maxTime);
            float endTime   = Mathf.Clamp(timef + 0.1f, 0.0f, maxTime);

            Vector3 startPosition = GetPosition(keyframes, startTime, Vector3.zero);
            Vector3 endPosition   = GetPosition(keyframes, endTime, Vector3.zero);
            Vector3 delta         = (endPosition - startPosition);
            tangent = normalize ? delta.normalized : delta;
        }

        return(tangent);
    }
Exemplo n.º 2
0
    private static Vector3 FindPosition(List <Waypoint> keyframes, double time, Vector3 defaultPosition)
    {
        InterpolationSet <Waypoint> interpolationData = Interpolate(keyframes, time);

        if (interpolationData != null)
        {
            return(EvaluateBezier(interpolationData.first, interpolationData.second, interpolationData.value));
        }

        if (keyframes.Count > 0)
        {
            if (time < keyframes[0].time)
            {
                return(keyframes[0].Position);
            }
            else
            {
                return(keyframes[keyframes.Count - 1].Position);
            }
        }

        return(defaultPosition);
    }
Exemplo n.º 3
0
    public static Color GetColor(List <ColorKeyframe> keyframes, double time, Color defaultColor)
    {
        InterpolationSet <ColorKeyframe> interpolationData = Interpolate(keyframes, time);

        if (interpolationData != null)
        {
            return(Color.Lerp(interpolationData.first.LightColor, interpolationData.second.LightColor, interpolationData.value));
        }

        if (keyframes.Count > 0)
        {
            if (time < keyframes[0].time)
            {
                return(keyframes[0].LightColor);
            }
            else
            {
                return(keyframes[keyframes.Count - 1].LightColor);
            }
        }

        return(defaultColor);
    }
 public void TestExponentialInterpolationInvalidParameters(InterpolationSet set)
 {
     Assert.That(() => new InterpolationCalculator().CalculateExponential(set),
                 Throws.TypeOf <ArgumentOutOfRangeException>());
 }
 public void TestExponentialInterpolation(InterpolationSet set, double expectedResult)
 {
     Assert.AreEqual(expectedResult, new InterpolationCalculator().CalculateExponential(set));
 }