diff --git a/Source/Engine/Core/Math/BoundingBox.cs b/Source/Engine/Core/Math/BoundingBox.cs index 784f39930..6538f7995 100644 --- a/Source/Engine/Core/Math/BoundingBox.cs +++ b/Source/Engine/Core/Math/BoundingBox.cs @@ -469,6 +469,35 @@ namespace FlaxEngine */ } + /// + /// Creates the bounding box that is offseted by the given vector. Adds the offset value to minimum and maximum points. + /// + /// The box. + /// The bounds offset. + /// The offsetted bounds. + public static BoundingBox MakeOffsetted(ref BoundingBox box, ref Vector3 offset) + { + BoundingBox result; + Vector3.Add(ref box.Minimum, ref offset, out result.Minimum); + Vector3.Add(ref box.Maximum, ref offset, out result.Maximum); + return result; + } + + /// + /// Creates the bounding box that is scaled by the given factor. Applies scale to the size of the bounds. + /// + /// The box. + /// The bounds scale. + /// The scaled bounds. + public static BoundingBox MakeScaled(ref BoundingBox box, float scale) + { + Vector3.Subtract(ref box.Maximum, ref box.Minimum, out var size); + Vector3 sizeHalf = size * 0.5f; + Vector3 center = box.Minimum + sizeHalf; + sizeHalf = sizeHalf * scale; + return new BoundingBox(center - sizeHalf, center + sizeHalf); + } + /// /// Transforms bounding box using the given transformation matrix. /// diff --git a/Source/Engine/Core/Math/BoundingBox.h b/Source/Engine/Core/Math/BoundingBox.h index 8a349e022..92dd3bcc3 100644 --- a/Source/Engine/Core/Math/BoundingBox.h +++ b/Source/Engine/Core/Math/BoundingBox.h @@ -254,12 +254,7 @@ public: /// The points that will be contained by the box. /// The amount of points to use. /// The constructed bounding box. - static BoundingBox FromPoints(const Vector3* points, int32 pointsCount) - { - BoundingBox result; - FromPoints(points, pointsCount, result); - return result; - } + static BoundingBox FromPoints(const Vector3* points, int32 pointsCount); /// /// Constructs a Bounding Box from a given sphere. @@ -273,12 +268,7 @@ public: /// /// The sphere that will designate the extents of the box. /// The constructed bounding box. - static BoundingBox FromSphere(const BoundingSphere& sphere) - { - BoundingBox result; - FromSphere(sphere, result); - return result; - } + static BoundingBox FromSphere(const BoundingSphere& sphere); /// /// Constructs a Bounding Box that is as large as the total combined area of the two specified boxes. @@ -298,26 +288,23 @@ public: /// The box. /// The matrix. /// The result transformed box. - static BoundingBox Transform(const BoundingBox& box, const Matrix& matrix) - { - BoundingBox result; - Transform(box, matrix, result); - return result; - } + static BoundingBox Transform(const BoundingBox& box, const Matrix& matrix); /// /// Creates the bounding box that is offseted by the given vector. Adds the offset value to minimum and maximum points. /// /// The box. - /// The offset. - /// The result. - static BoundingBox MakeOffsetted(const BoundingBox& box, const Vector3& offset) - { - BoundingBox result; - result.Minimum = box.Minimum + offset; - result.Maximum = box.Maximum + offset; - return result; - } + /// The bounds offset. + /// The offsetted bounds. + static BoundingBox MakeOffsetted(const BoundingBox& box, const Vector3& offset); + + /// + /// Creates the bounding box that is scaled by the given factor. Applies scale to the size of the bounds. + /// + /// The box. + /// The bounds scale. + /// The scaled bounds. + static BoundingBox MakeScaled(const BoundingBox& box, float scale); /// /// Transforms the bounding box using the specified matrix.