Add BoundingBox.MakeScaled

This commit is contained in:
Wojtek Figat
2021-06-01 11:54:41 +02:00
parent f701e35c50
commit 9618a57432
2 changed files with 43 additions and 27 deletions

View File

@@ -469,6 +469,35 @@ namespace FlaxEngine
*/
}
/// <summary>
/// Creates the bounding box that is offseted by the given vector. Adds the offset value to minimum and maximum points.
/// </summary>
/// <param name="box">The box.</param>
/// <param name="offset">The bounds offset.</param>
/// <returns>The offsetted bounds.</returns>
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;
}
/// <summary>
/// Creates the bounding box that is scaled by the given factor. Applies scale to the size of the bounds.
/// </summary>
/// <param name="box">The box.</param>
/// <param name="scale">The bounds scale.</param>
/// <returns>The scaled bounds.</returns>
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);
}
/// <summary>
/// Transforms bounding box using the given transformation matrix.
/// </summary>