コード例 #1
0
        // see when the line (lineStart to lineEnd) intersects the barrier lines (barrierVertZero to barrierVertOne and the line barrierVertOne to barrierVertTwo)
        // return back the min length to these lines, or return the current length of the line if both barrier lines are u
        private static float CalculateMaxLineLengthXZ(Vector3 lineStart, Vector3 lineEnd, Vector3 barrierVertZero, Vector3 barrierVertOne, Vector3?barrierVertTwo = null)
        {
            lineStart.y = lineEnd.y = barrierVertZero.y = barrierVertOne.y = 0f;

            float   maxLineLength     = (lineStart - lineEnd).magnitude;
            bool    doesIntersect     = false;
            Vector3 intersectionPoint = VectorMath.SegmentIntersectionPointXZ(lineStart, lineEnd, barrierVertZero, barrierVertOne, out doesIntersect);

            if (doesIntersect)
            {
                maxLineLength = (intersectionPoint - lineStart).magnitude;
            }

            if (barrierVertTwo.HasValue) // if we want to test two barrier lines
            {
                Vector3 barrierVertTwoVal = barrierVertTwo.GetValueOrDefault();
                barrierVertTwoVal.y = 0f;
                intersectionPoint   = VectorMath.SegmentIntersectionPointXZ(lineStart, lineEnd, barrierVertOne, barrierVertTwoVal, out doesIntersect);
                if (doesIntersect)
                {
                    maxLineLength = Mathf.Min(maxLineLength, (intersectionPoint - lineStart).magnitude); // see if this barier is nearer than the previous
                }
            }
            return(maxLineLength);
        }
コード例 #2
0
 public static Vector3 SegmentIntersectionPoint(Vector3 start1, Vector3 end1, Vector3 start2, Vector3 end2, out bool intersects)
 {
     return(VectorMath.SegmentIntersectionPointXZ(start1, end1, start2, end2, out intersects));
 }