Esempio n. 1
0
 /// <summary>
 /// Spline 上の位置 t における速度を算出します。
 /// </summary>
 /// <param name="t">
 /// Spline 上の位置 t.
 /// </param>
 /// <returns>
 /// Spline 上の位置 t における速度。
 /// </returns>
 public Vector3 Velosity(float t)
 {
     return(CatmullSplineUtil.Velocity(t, GetControlPoint));
 }
Esempio n. 2
0
 /// <summary>
 /// Catmull Spline 上の位置 t における回転を算出します。
 /// </summary>
 /// <param name="t">
 /// Spline 上の位置 t.
 /// </param>
 /// <returns>
 /// Spline 上の位置 t における回転。
 /// </returns>
 public Vector3 Rotation(float t)
 {
     return(CatmullSplineUtil.Rotation(t, GetControlPoint));
 }
Esempio n. 3
0
        /// <summary>
        /// SceneView に Spline 曲線を描画します。
        /// </summary>
        void DrawLines()
        {
            const int CURVE_SMOOTH_LEVEL = 10;

            var spline        = (Spline)target;
            var controlPoints = spline.controlPoints;

            Func <int, ControlPoint> getCtrlPointFunc = spline.GetControlPoint;

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

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

            for (var i = 0; i < controlPoints.Length; i++)
            {
                var t = (float)i;

                for (var j = 0; j < CURVE_SMOOTH_LEVEL; j++)
                {
                    var k = CatmullSplineUtil.Curvature(t, getCtrlPointFunc);
                    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, getCtrlPointFunc);

            for (var i = 0; i < controlPoints.Length; i++)
            {
                var t = (float)i;

                for (var j = 0; j < CURVE_SMOOTH_LEVEL; j++)
                {
                    var k = CatmullSplineUtil.Curvature(t, getCtrlPointFunc);
                    k = Mathf.Clamp(k, kMin, kMax);

                    Handles.color = Color.HSVToRGB(jetA * k + jetB, 1f, 1f);

                    var endPos = CatmullSplineUtil.Position(t += dt, getCtrlPointFunc);

                    Handles.DrawLine(startPos, endPos);

                    startPos = endPos;
                }
            }
        }