Ejemplo n.º 1
0
    /// <summary>
    /// Interpolates position for a local F
    /// </summary>
    /// <param name="localF">a local F in the range 0..1</param>
    /// <param name="interpolation">the interpolation to use</param>
    /// <returns>the interpolated position</returns>
    public Vector3 Interpolate(float localF, CurvyInterpolation interpolation)
    {
        localF = Mathf.Clamp01(localF);
        switch (interpolation)
        {
        case CurvyInterpolation.Bezier:
            return(CurvySpline.Bezier(HandleOutScaled, Transform.position, NextTransform.position, NextControlPoint.HandleInScaled, localF));

        case CurvyInterpolation.CatmulRom:
            //return CurvySpline.CatmulRom(PreviousTransform.position, Transform.position, NextTransform.position, NextControlPoint.NextTransform.position, localF);
            return(CurvySpline.CatmulRom(GetPrevPosition(), Transform.position, GetNextPosition(), GetNextNextPosition(), localF));

        case CurvyInterpolation.TCB:
            float t0 = StartTension; float t1 = EndTension;
            float c0 = StartContinuity; float c1 = EndContinuity;
            float b0 = StartBias; float b1 = EndBias;

            if (!OverrideGlobalTension)
            {
                t0 = t1 = Spline.Tension;
            }
            if (!OverrideGlobalContinuity)
            {
                c0 = c1 = Spline.Continuity;
            }
            if (!OverrideGlobalBias)
            {
                b0 = b1 = Spline.Bias;
            }
            return(CurvySpline.TCB(PreviousTransform.position, Transform.position, NextTransform.position, NextControlPoint.NextTransform.position, localF, t0, c0, b0, t1, c1, b1));

        default:     // LINEAR
            return(Vector3.Lerp(Transform.position, NextTransform.position, localF));
        }
    }