/// <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="SharpDX.OrientedBoundingBox"/> to merge into it.</param> /// <param name="B">The <see cref="SharpDX.OrientedBoundingBox"/> 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 OrientedBoundingBox A, ref OrientedBoundingBox B, bool NoMatrixScaleApplied = false) { Matrix AtoB_Matrix = GetBoxToBoxMatrix(ref A, ref B, NoMatrixScaleApplied); //Get B corners in A Space var bCorners = B.GetLocalCorners(); Vector3.TransformCoordinate(bCorners, ref AtoB_Matrix, bCorners); //Get A local Bounding Box var A_LocalBB = new BoundingBox(-A.Extents, A.Extents); //Find B BoundingBox in A Space var B_LocalBB = BoundingBox.FromPoints(bCorners); //Merger A and B local Bounding Boxes BoundingBox mergedBB; BoundingBox.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; Vector3.TransformCoordinate(ref newCenter, ref A.Transformation, out newCenter); A.Transformation.TranslationVector = newCenter; }
/// <summary> /// Get the axis-aligned <see cref="SharpDX.BoundingBox"/> which contains all <see cref="SharpDX.OrientedBoundingBox"/> corners. /// </summary> /// <returns>The axis-aligned BoundingBox of this OrientedBoundingBox.</returns> public BoundingBox GetBoundingBox() { return(BoundingBox.FromPoints(GetCorners())); }