コード例 #1
0
        public static void DrawGizmoForCurve(BezierComponent bc, GizmoType gizmoType)
        {
            BezierCPComponent[] CPS = bc.controlPoints;
            if (CPS == null || CPS.Length == 0)
            {
                return;
            }

            int N = CurveCount(bc);

            // Draw curve
            Vector3 cp;
            Vector3 pp = BezierSystem.Evaluate(0, bc);

            Gizmos.color = bc.curveColor;
            for (float t = bc.drawDelta; t < N; t += bc.drawDelta)
            {
                cp = BezierSystem.Evaluate(t, bc);
                Gizmos.DrawLine(pp, cp);
                pp = cp;
            }
            cp = BezierSystem.Evaluate(N - 0.0002f, bc);
            Gizmos.DrawLine(pp, cp);

            // Draw CP lines
            Gizmos.color = bc.tangentColor;
            for (int i = 0; i < N; i++)
            {
                int s = 4 * i;
                Gizmos.DrawLine(CPS[s].transform.position, CPS[s + 1].transform.position);
                Gizmos.DrawLine(CPS[s + 2].transform.position, CPS[s + 3].transform.position);
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns the Arc Length of the curve.
        /// Currently, its mostly a bruteforce approach and therefore
        /// the paramter dt is important for efficiency. If you want
        /// to evaulate the entire curve, use FastArcLength instead.
        /// </summary>
        /// <param name="t0">starting param</param>
        /// <param name="t1">end param</param>
        /// <param name="bc">BezierComponent to eval.</param>
        /// <param name="dt">delta param. This controls the steps algo takes.
        /// Its important to understand the lower the number, the more accurate
        /// but the more expensive it becomes.
        /// </param>
        /// <returns>The Arclength of curve between t0 and t1</returns>
        public static float ArcLength(float t0, float t1, BezierComponent bc, float dt = 0.01f)
        {
            float   length = 0;
            float   t      = t0 + dt;
            Vector3 pp     = BezierSystem.Evaluate(t0, bc);
            Vector3 cp;

            while (t < t1)
            {
                cp      = BezierSystem.Evaluate(t, bc);
                length += (cp - pp).magnitude;
                pp      = cp;
                t      += dt;
            }

            cp      = BezierSystem.Evaluate(t1, bc);
            length += (cp - pp).magnitude;
            return(length);
        }