2018-06-08 00:42:41 +08:00
|
|
|
|
using System;
|
|
|
|
|
using SharpDX;
|
|
|
|
|
|
|
|
|
|
namespace CodeWalker.Core.Utils
|
|
|
|
|
{
|
|
|
|
|
public static class BoundingBoxExtensions
|
|
|
|
|
{
|
2024-01-07 02:41:10 +08:00
|
|
|
|
public static Vector3 Size(in this BoundingBox bounds)
|
2018-06-08 00:42:41 +08:00
|
|
|
|
{
|
|
|
|
|
return new Vector3(
|
|
|
|
|
Math.Abs(bounds.Maximum.X - bounds.Minimum.X),
|
|
|
|
|
Math.Abs(bounds.Maximum.Y - bounds.Minimum.Y),
|
|
|
|
|
Math.Abs(bounds.Maximum.Z - bounds.Minimum.Z));
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-07 02:41:10 +08:00
|
|
|
|
public static Vector3 Center(in this BoundingBox bounds)
|
2018-06-08 00:42:41 +08:00
|
|
|
|
{
|
|
|
|
|
return (bounds.Minimum + bounds.Maximum) * 0.5F;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-07 02:41:10 +08:00
|
|
|
|
public static BoundingBox Encapsulate(ref this BoundingBox box, ref BoundingBox bounds)
|
2018-06-08 00:42:41 +08:00
|
|
|
|
{
|
2024-01-07 02:41:10 +08:00
|
|
|
|
Vector3.Min(ref box.Minimum, ref bounds.Minimum, out box.Minimum);
|
|
|
|
|
Vector3.Max(ref box.Maximum, ref bounds.Maximum, out box.Maximum);
|
2018-06-08 00:42:41 +08:00
|
|
|
|
return box;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-07 02:41:10 +08:00
|
|
|
|
public static float Radius(in this BoundingBox box)
|
2018-06-08 00:42:41 +08:00
|
|
|
|
{
|
|
|
|
|
var extents = (box.Maximum - box.Minimum) * 0.5F;
|
|
|
|
|
return extents.Length();
|
|
|
|
|
}
|
2018-06-10 21:36:50 +08:00
|
|
|
|
|
2024-01-07 02:41:10 +08:00
|
|
|
|
public static BoundingBox Expand(in this BoundingBox b, float amount)
|
2018-06-10 21:36:50 +08:00
|
|
|
|
{
|
|
|
|
|
return new BoundingBox(b.Minimum - Vector3.One * amount, b.Maximum + Vector3.One * amount);
|
|
|
|
|
}
|
2018-06-08 00:42:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|