Example #1
0
 public static Vector3 Velocity(Path pts, float t, Easing.EaseType easeType = Easing.EaseType.linear)
 {
     t = Easing.ease(easeType, t);
     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.Velocity(pts[0], pts[2], pts[1], t));
     }
     else if (pts.Length == 4)
     {
         return(CubicBez.Velocity(pts[0], pts[3], pts[1], pts[2], t));
     }
     else
     {
         return(CRSpline.Velocity(Wrap(pts), t));
     }
 }
Example #2
0
 public static Vector3 InterpConstantSpeed(Spline.Path pts, float t, Easing.EaseType easeType = Easing.EaseType.linear)
 {
     t = Easing.ease(easeType, t, 0f, 1f);
     if (pts.Length == 0)
     {
         return(Vector3.zero);
     }
     if (pts.Length == 1)
     {
         return(pts[0]);
     }
     if (pts.Length == 2)
     {
         return(Vector3.Lerp(pts[0], pts[1], t));
     }
     if (pts.Length == 3)
     {
         return(QuadBez.Interp(pts[0], pts[2], pts[1], t));
     }
     if (pts.Length == 4)
     {
         return(CubicBez.Interp(pts[0], pts[3], pts[1], pts[2], t));
     }
     return(CRSpline.InterpConstantSpeed(Spline.Wrap(pts), t));
 }
Example #3
0
 public static Vector3 Velocity(Path pts, float t, EasingType ease = EasingType.Linear, bool easeIn = true, bool easeOut = true)
 {
     t = Ease(t);
     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.Velocity(pts[0], pts[2], pts[1], t));
     }
     else if (pts.Length == 4)
     {
         return(CubicBez.Velocity(pts[0], pts[3], pts[1], pts[2], t));
     }
     else
     {
         return(CRSpline.Velocity(Wrap(pts), t));
     }
 }
Example #4
0
    public static Vector3 InterpConstantSpeed(Path pts, float t, EasingType ease, bool easeIn, bool easeOut)
    {
        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.InterpConstantSpeed(Wrap(pts), t));
        }
    }
Example #5
0
    public static void GizmoDraw(Vector3 st, Vector3 en, Vector3 ctrl1, Vector3 ctrl2, float t)
    {
        Gizmos.color = Color.red;
        Gizmos.DrawLine(st, ctrl1);
        Gizmos.DrawLine(ctrl2, en);
        Gizmos.color = Color.white;
        Vector3 to = st;

        for (int i = 1; i <= 20; i++)
        {
            float   t2     = (float)i / 20f;
            Vector3 vector = CubicBez.Interp(st, en, ctrl1, ctrl2, t2);
            Gizmos.DrawLine(vector, to);
            to = vector;
        }
        Gizmos.color = Color.blue;
        Vector3 vector2 = CubicBez.Interp(st, en, ctrl1, ctrl2, t);

        Gizmos.DrawLine(vector2, vector2 + CubicBez.Velocity(st, en, ctrl1, ctrl2, t));
    }