コード例 #1
0
        /// <summary>
        /// Create bound around points.
        /// </summary>
        /// <param name="point1">Point1.</param>
        /// <param name="point2">Point2.</param>
        /// <param name="result">Bound result.</param>
        public static void FromPoints(ref Vector3 point1, ref Vector3 point2, out Bound3 result)
        {
            result.left   = point1.x;
            result.right  = point1.x;
            result.bottom = point1.y;
            result.top    = point1.y;
            result.back   = point1.z;
            result.front  = point1.z;

            if (point2.x < result.left)
            {
                result.left = point2.x;
            }
            if (point2.x > result.right)
            {
                result.right = point2.x;
            }
            if (point2.y < result.bottom)
            {
                result.bottom = point2.y;
            }
            if (point2.y > result.top)
            {
                result.top = point2.y;
            }
            if (point2.z < result.back)
            {
                result.back = point2.z;
            }
            if (point2.z > result.front)
            {
                result.front = point2.z;
            }
        }
コード例 #2
0
        /// <summary>
        /// Get a line segment intersect point.
        /// </summary>
        /// <param name="vector">Point.</param>
        /// <param name="point1">Line Point 1.</param>
        /// <param name="point2">Line Point 2.</param>
        /// <returns>Return value.</returns>
        public static Vector3 IntersectLineSegment(this Vector3 vector, Vector3 point1, Vector3 point2)
        {
            var dir = point1 - point2;

            dir.Normalize();
            var    point = (dir * Vector3.Dot(vector - point1, dir)) + point1;
            Bound3 bound;

            Bound3.FromPoints(ref point1, ref point2, out bound);
            if (!bound.Intersects(point))
            {
                if ((vector - point1).magnitude <= (vector - point2).magnitude)
                {
                    return(point1);
                }
                else
                {
                    return(point2);
                }
            }

            return(point);
        }
コード例 #3
0
ファイル: Bound3.cs プロジェクト: lPinchol/Reign-Unity-Plugin
		/// <summary>
		/// Create bound around points.
		/// </summary>
		/// <param name="point1">Point1.</param>
		/// <param name="point2">Point2.</param>
		/// <param name="result">Bound result.</param>
		public static void FromPoints(ref Vector3 point1, ref Vector3 point2, out Bound3 result)
		{
			result.left = point1.x;
			result.right = point1.x;
			result.bottom = point1.y;
			result.top = point1.y;
			result.back = point1.z;
			result.front = point1.z;

			if (point2.x < result.left) result.left = point2.x;
			if (point2.x > result.right) result.right = point2.x;
			if (point2.y < result.bottom) result.bottom = point2.y;
			if (point2.y > result.top) result.top = point2.y;
			if (point2.z < result.back) result.back = point2.z;
			if (point2.z > result.front) result.front = point2.z;
		}