Exemplo n.º 1
0
 public static void DrawPointsPath(BezierCurveV3D curve)
 {
     for (var i = 0; i < curve.Positions.Count - 1; i++)
     {
         Gizmos.DrawLine(curve.Positions[i], curve.Positions[i + 1]);
     }
 }
Exemplo n.º 2
0
 public static void DrawPath(BezierCurveV3D curve, float resolution = 0.1f)
 {
     for (float i = 0; i < 1f; i += resolution)
     {
         Gizmos.DrawLine(Lerps.BezierLerp.Lerp(curve, i), Lerps.BezierLerp.Lerp(curve, i + resolution));
     }
 }
Exemplo n.º 3
0
            public static Vector3 Lerp(BezierCurveV3D curve, float time)
            {
                switch (curve.Positions.Count)
                {
                case 0:
                    return(Vector3.zero);

                case 1:
                    return(curve.Positions[0]);

                case 2:
                    return(Lerps.Lerp(curve.Positions[0], curve.Positions[1], time));

                case 3:
                    return(Lerp(curve.Positions[0], curve.Positions[1], curve.Positions[2], time));

                case 4:
                    return(Lerp(curve.Positions[0], curve.Positions[1], curve.Positions[2], curve.Positions[3], time));

                case 5:
                    return(Lerp(curve.Positions[0], curve.Positions[1], curve.Positions[2], Lerps.Lerp(curve.Positions[3], curve.Positions[4], time), time));
                }

                //FROM HERE IS IS SAFE
                //For there to be at leat 5 hard coded positions
                int count = curve.Positions.Count;

                var posOne   = Lerps.Lerp(curve.Positions[0], curve.Positions[1], time);
                var posTwo   = Lerps.Lerp(curve.Positions[1], curve.Positions[2], time);
                var posThree = Lerps.Lerp(curve.Positions[2], curve.Positions[3], time);

                for (var i = 4; i < count - 1; i++)
                {
                    posOne   = Lerps.Lerp(posOne, posTwo, time);
                    posTwo   = Lerps.Lerp(posTwo, posThree, time);
                    posThree = Lerps.Lerp(curve.Positions[i], curve.Positions[i + 1], time);
                }

                posOne = Lerps.Lerp(posOne, posTwo, time);
                posTwo = Lerps.Lerp(posTwo, posThree, time);

                return(posOne + ((posTwo - posOne) * time));
            }