Exemple #1
0
        void DrawGizmos()
        {
            var spline = (Spline)target;
            var cps    = spline.cps;

            System.Func <int, Vector3> GetCP = spline.GetCP;

            if (cps == null || cps.Length < 2)
            {
                return;
            }

            var dt   = 1f / GIZMO_SMOOTH_LEVEL;
            var kMin = float.MaxValue;
            var kMax = 0f;

            for (var i = 0; i < cps.Length; i++)
            {
                var t = (float)i;
                for (var j = 0; j < GIZMO_SMOOTH_LEVEL; j++)
                {
                    var k = CatmullSplineUtil.Curvature(t, spline.GetCP);
                    k = Mathf.Clamp(k, JET_K_MIN, JET_K_MAX);
                    if (k < kMin)
                    {
                        kMin = k;
                    }
                    else if (kMax < k)
                    {
                        kMax = k;
                    }
                    t += dt;
                }
            }

            var jetA     = 0.66666f / (kMin - kMax);
            var jetB     = -jetA * kMax;
            var startPos = CatmullSplineUtil.Position(0f, GetCP);

            for (var i = 0; i < cps.Length; i++)
            {
                var t = (float)i;
                for (var j = 0; j < GIZMO_SMOOTH_LEVEL; j++)
                {
                    var k = CatmullSplineUtil.Curvature(t, spline.GetCP);
                    k             = Mathf.Clamp(k, kMin, kMax);
                    Handles.color = Color.HSVToRGB(jetA * k + jetB, 1f, 1f);

                    var endPos = CatmullSplineUtil.Position(t += dt, GetCP);
                    Handles.DrawLine(startPos, endPos);
                    startPos = endPos;
                }
            }
        }
Exemple #2
0
 public Vector3 Velosity(float t)
 {
     return(CatmullSplineUtil.Velosity(t, GetCP));
 }
Exemple #3
0
 public Vector3 Position(float t)
 {
     return(CatmullSplineUtil.Position(t, GetCP));
 }