CRSpline.Interp C# (CSharp) Method

Interp() public static method

public static Interp ( Vector3 pts, float t ) : Vector3
pts Vector3
t float
return Vector3
    public static Vector3 Interp(Vector3[] pts, float t)
    {
        int numSections = pts.Length - 3;
        int currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1);
        float u = t * (float) numSections - (float) currPt;

        Vector3 a = pts[currPt];
        Vector3 b = pts[currPt + 1];
        Vector3 c = pts[currPt + 2];
        Vector3 d = pts[currPt + 3];

        return .5f * (
            (-a + 3f * b - 3f * c + d) * (u * u * u)
            + (2f * a - 5f * b + 4f * c - d) * (u * u)
            + (-a + c) * u
            + 2f * b
        );
    }

Usage Example

Example #1
0
    public static Vector3 Interp(Path pts, float t, EasingType ease = EasingType.Linear, bool easeIn = true, bool easeOut = true)
    {
        t = Ease(t, ease, easeIn, easeOut);

        if (pts.Length == 0)
        {
            return(Vector3.zero);
        }
        else if (pts.Length == 1)
        {
            return(pts[0]);
        }
        else if (pts.Length == 2)
        {
            return(Vector3.Lerp(pts[0], pts[1], t));
        }
        else if (pts.Length == 3)
        {
            return(QuadBez.Interp(pts[0], pts[2], pts[1], t));
        }
        else if (pts.Length == 4)
        {
            return(CubicBez.Interp(pts[0], pts[3], pts[1], pts[2], t));
        }
        else
        {
            return(CRSpline.Interp(Wrap(pts), t));
        }
    }
All Usage Examples Of CRSpline::Interp