예제 #1
0
        public static float GetLengthAS(this SplineBase spline, int curve, float error)
        {
            Vector3[] v = new Vector3[4];

            v[0] = spline.GetControlPoint(curve * 3);
            v[1] = spline.GetControlPoint(curve * 3 + 1);
            v[2] = spline.GetControlPoint(curve * 3 + 2);
            v[3] = spline.GetControlPoint(curve * 3 + 3);

            float length = 0.0f;

            AddIfClose(v, ref length, error);                    /* kick off recursion */

            return(length);
        }
예제 #2
0
        public static Vector3[] Slice(this SplineBase spline, int curve, float t)
        {
            Vector3 p1 = spline.GetControlPoint(curve * 3);
            Vector3 p2 = spline.GetControlPoint(curve * 3 + 1);
            Vector3 p3 = spline.GetControlPoint(curve * 3 + 2);
            Vector3 p4 = spline.GetControlPoint(curve * 3 + 3);

            Vector3 p12   = (p2 - p1) * t + p1;
            Vector3 p23   = (p3 - p2) * t + p2;
            Vector3 p34   = (p4 - p3) * t + p3;
            Vector3 p123  = (p23 - p12) * t + p12;
            Vector3 p234  = (p34 - p23) * t + p23;
            Vector3 p1234 = (p234 - p123) * t + p123;

            return(new[] { p1, p12, p123, p1234, p234, p34, p4 });
        }
예제 #3
0
        public static float GetLengthAS(this SplineBase spline, float error)
        {
            float totalLength = 0.0f;

            Vector3[] v = new Vector3[4];

            int curveCount = spline.CurveCount;

            for (int curve = 0; curve < curveCount; ++curve)
            {
                v[0] = spline.GetControlPoint(curve * 3);
                v[1] = spline.GetControlPoint(curve * 3 + 1);
                v[2] = spline.GetControlPoint(curve * 3 + 2);
                v[3] = spline.GetControlPoint(curve * 3 + 3);

                float length = 0.0f;
                AddIfClose(v, ref length, error);
                totalLength += length;
            }
            return(totalLength);
        }
        private int HitTest(SplineBase spline, out float minDistance)
        {
            minDistance = float.PositiveInfinity;
            if (Camera == null)
            {
                Debug.LogError("Camera is null");
                return(-1);
            }

            if (RuntimeSelection.gameObjects == null)
            {
                return(-1);
            }

            Vector3[] controlPoints = new Vector3[spline.ControlPointCount];
            for (int j = 0; j < controlPoints.Length; j++)
            {
                controlPoints[j] = spline.GetControlPoint(j);
            }

            minDistance = SelectionMargin * SelectionMargin;
            int     selectedIndex = -1;
            Vector2 mousePositon  = Input.mousePosition;

            for (int i = 0; i < controlPoints.Length; ++i)
            {
                Vector3 ctrlPoint = controlPoints[i];
                if (spline.IsControlPointLocked(i))
                {
                    continue;
                }
                Vector2 pt  = Camera.WorldToScreenPoint(ctrlPoint);
                float   mag = (pt - mousePositon).sqrMagnitude;
                if (mag < minDistance)
                {
                    minDistance   = mag;
                    selectedIndex = i;
                }
            }

            return(selectedIndex);
        }