Пример #1
0
        /// <summary>
        /// Merge an OrientedBoundingBox B into another OrientedBoundingBox A, by expanding A to contain B and keeping A orientation.
        /// </summary>
        /// <param name="A">The <see cref="MyOrientedBoundingBox"/> to merge into it.</param>
        /// <param name="B">The <see cref="MyOrientedBoundingBox"/> to be merged</param>
        /// <param name="NoMatrixScaleApplied">
        /// If true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation matrix of the OrientedBoundingBox.
        /// </param>
        /// <remarks>
        /// Unlike merging axis aligned boxes, The operation is not interchangeable, because it keeps A orientation and merge B into it.
        /// </remarks>
        public static void Merge(ref MyOrientedBoundingBox A, ref MyOrientedBoundingBox B, bool NoMatrixScaleApplied = false)
        {
            MyMatrix AtoB_Matrix = GetBoxToBoxMatrix(ref A, ref B, NoMatrixScaleApplied);

            //Get B corners in A Space
            var bCorners = B.GetLocalCorners();
            MyVector3.TransformCoordinate(bCorners, ref AtoB_Matrix, bCorners);

            //Get A local Bounding Box
            var A_LocalBB = new MyBoundingBox(-A.Extents, A.Extents);

            //Find B BoundingBox in A Space
            var B_LocalBB = MyBoundingBox.FromPoints(bCorners);

            //Merger A and B local Bounding Boxes
            MyBoundingBox mergedBB;
            MyBoundingBox.Merge(ref B_LocalBB, ref A_LocalBB, out mergedBB);

            //Find the new Extents and Center, Transform Center back to world
            var newCenter = mergedBB.Minimum + (mergedBB.Maximum - mergedBB.Minimum) / 2f;
            A.Extents = mergedBB.Maximum - newCenter;
            MyVector3.TransformCoordinate(ref newCenter, ref A.Transformation, out newCenter);
            A.Transformation.TranslationVector = newCenter;
        }
Пример #2
0
 /// <summary>
 /// Get the axis-aligned <see cref="MyBoundingBox"/> which contains all <see cref="MyOrientedBoundingBox"/> corners.
 /// </summary>
 /// <returns>The axis-aligned BoundingBox of this OrientedBoundingBox.</returns>
 public MyBoundingBox GetBoundingBox()
 {
     return MyBoundingBox.FromPoints(GetCorners());
 }