Table of Contents

Struct BoundingBox

Namespace
Microsoft.Xna.Framework
Assembly
MonoGame.Framework.dll

Represents an axis-aligned bounding box (AABB) in 3D space.

[DataContract]
public struct BoundingBox : IEquatable<BoundingBox>
Implements
Inherited Members

Constructors

BoundingBox(Vector3, Vector3)

Create a BoundingBox.

public BoundingBox(Vector3 min, Vector3 max)

Parameters

min Vector3

The minimum extent of the BoundingBox.

max Vector3

The maximum extent of the BoundingBox.

Fields

CornerCount

The number of corners in a BoundingBox. This is equal to 8.

public const int CornerCount = 8

Field Value

int

Max

The maximum extent of this BoundingBox.

[DataMember]
public Vector3 Max

Field Value

Vector3

Min

The minimum extent of this BoundingBox.

[DataMember]
public Vector3 Min

Field Value

Vector3

Methods

Contains(BoundingBox)

Check if this BoundingBox contains another BoundingBox.

public ContainmentType Contains(BoundingBox box)

Parameters

box BoundingBox

The BoundingBox to test for overlap.

Returns

ContainmentType

A value indicating if this BoundingBox contains, intersects with or is disjoint with box.

Contains(ref BoundingBox, out ContainmentType)

Check if this BoundingBox contains another BoundingBox.

public void Contains(ref BoundingBox box, out ContainmentType result)

Parameters

box BoundingBox

The BoundingBox to test for overlap.

result ContainmentType

A value indicating if this BoundingBox contains, intersects with or is disjoint with box.

Contains(BoundingFrustum)

Check if this BoundingBox contains a BoundingFrustum.

public ContainmentType Contains(BoundingFrustum frustum)

Parameters

frustum BoundingFrustum

The BoundingFrustum to test for overlap.

Returns

ContainmentType

A value indicating if this BoundingBox contains, intersects with or is disjoint with frustum.

Contains(BoundingSphere)

Check if this BoundingBox contains a BoundingSphere.

public ContainmentType Contains(BoundingSphere sphere)

Parameters

sphere BoundingSphere

The BoundingSphere to test for overlap.

Returns

ContainmentType

A value indicating if this BoundingBox contains, intersects with or is disjoint with sphere.

Contains(ref BoundingSphere, out ContainmentType)

Check if this BoundingBox contains a BoundingSphere.

public void Contains(ref BoundingSphere sphere, out ContainmentType result)

Parameters

sphere BoundingSphere

The BoundingSphere to test for overlap.

result ContainmentType

A value indicating if this BoundingBox contains, intersects with or is disjoint with sphere.

Contains(Vector3)

Check if this BoundingBox contains a point.

public ContainmentType Contains(Vector3 point)

Parameters

point Vector3

The Vector3 to test.

Returns

ContainmentType

Contains if this BoundingBox contains point or Disjoint if it does not.

Contains(ref Vector3, out ContainmentType)

Check if this BoundingBox contains a point.

public void Contains(ref Vector3 point, out ContainmentType result)

Parameters

point Vector3

The Vector3 to test.

result ContainmentType

Contains if this BoundingBox contains point or Disjoint if it does not.

CreateFromPoints(Vector3[], int, int)

Create a bounding box from the given list of points.

public static BoundingBox CreateFromPoints(Vector3[] points, int index = 0, int count = -1)

Parameters

points Vector3[]

The array of Vector3 instances defining the point cloud to bound

index int

The base index to start iterating from

count int

The number of points to iterate

Returns

BoundingBox

A bounding box that encapsulates the given point cloud.

Exceptions

ArgumentException

Thrown if the given array is null or has no points.

CreateFromPoints(IEnumerable<Vector3>)

Create the enclosing BoundingBox from the given list of points.

public static BoundingBox CreateFromPoints(IEnumerable<Vector3> points)

Parameters

points IEnumerable<Vector3>

The list of Vector3 instances defining the point cloud to bound.

Returns

BoundingBox

A BoundingBox that encloses the given point cloud.

Exceptions

ArgumentException

Thrown if the given list has no points.

CreateFromPoints(List<Vector3>, int, int)

Create a bounding box from the given list of points.

public static BoundingBox CreateFromPoints(List<Vector3> points, int index = 0, int count = -1)

Parameters

points List<Vector3>

The list of Vector3 instances defining the point cloud to bound

index int

The base index to start iterating from

count int

The number of points to iterate

Returns

BoundingBox

A bounding box that encapsulates the given point cloud.

Exceptions

ArgumentException

Thrown if the given list is null or has no points.

CreateFromSphere(BoundingSphere)

Create the enclosing BoundingBox of a BoundingSphere.

public static BoundingBox CreateFromSphere(BoundingSphere sphere)

Parameters

sphere BoundingSphere

The BoundingSphere to enclose.

Returns

BoundingBox

A BoundingBox enclosing sphere.

CreateFromSphere(ref BoundingSphere, out BoundingBox)

Create the enclosing BoundingBox of a BoundingSphere.

public static void CreateFromSphere(ref BoundingSphere sphere, out BoundingBox result)

Parameters

sphere BoundingSphere

The BoundingSphere to enclose.

result BoundingBox

A BoundingBox enclosing sphere.

CreateMerged(BoundingBox, BoundingBox)

Create the BoundingBox enclosing two other BoundingBox instances.

public static BoundingBox CreateMerged(BoundingBox original, BoundingBox additional)

Parameters

original BoundingBox

A BoundingBox to enclose.

additional BoundingBox

A BoundingBox to enclose.

Returns

BoundingBox

The BoundingBox enclosing original and additional.

CreateMerged(ref BoundingBox, ref BoundingBox, out BoundingBox)

Create the BoundingBox enclosing two other BoundingBox instances.

public static void CreateMerged(ref BoundingBox original, ref BoundingBox additional, out BoundingBox result)

Parameters

original BoundingBox

A BoundingBox to enclose.

additional BoundingBox

A BoundingBox to enclose.

result BoundingBox

The BoundingBox enclosing original and additional.

Deconstruct(out Vector3, out Vector3)

Deconstruction method for BoundingBox.

public void Deconstruct(out Vector3 min, out Vector3 max)

Parameters

min Vector3
max Vector3

Equals(BoundingBox)

Check if two BoundingBox instances are equal.

public bool Equals(BoundingBox other)

Parameters

other BoundingBox

The BoundingBox to compare with this BoundingBox.

Returns

bool
true
if other is equal to this BoundingBox,
false
if it is not.

Equals(object)

Check if two BoundingBox instances are equal.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with this BoundingBox.

Returns

bool
true
if obj is equal to this BoundingBox,
false
if it is not.

GetCorners()

Get an array of Vector3 containing the corners of this BoundingBox.

public Vector3[] GetCorners()

Returns

Vector3[]

An array of Vector3 containing the corners of this BoundingBox.

GetCorners(Vector3[])

Fill the first 8 places of an array of Vector3 with the corners of this BoundingBox.

public void GetCorners(Vector3[] corners)

Parameters

corners Vector3[]

The array to fill.

Exceptions

ArgumentNullException

If corners is

null
.
ArgumentOutOfRangeException

If corners has a length of less than 8.

GetHashCode()

Get the hash code for this BoundingBox.

public override int GetHashCode()

Returns

int

A hash code for this BoundingBox.

Intersects(BoundingBox)

Check if this BoundingBox intersects another BoundingBox.

public bool Intersects(BoundingBox box)

Parameters

box BoundingBox

The BoundingBox to test for intersection.

Returns

bool
true
if this BoundingBox intersects box,
false
if it does not.

Intersects(ref BoundingBox, out bool)

Check if this BoundingBox intersects another BoundingBox.

public void Intersects(ref BoundingBox box, out bool result)

Parameters

box BoundingBox

The BoundingBox to test for intersection.

result bool
true
if this BoundingBox intersects box,
false
if it does not.

Intersects(BoundingFrustum)

Check if this BoundingBox intersects a BoundingFrustum.

public bool Intersects(BoundingFrustum frustum)

Parameters

frustum BoundingFrustum

The BoundingFrustum to test for intersection.

Returns

bool
true
if this BoundingBox intersects frustum,
false
if it does not.

Intersects(BoundingSphere)

Check if this BoundingBox intersects a BoundingFrustum.

public bool Intersects(BoundingSphere sphere)

Parameters

sphere BoundingSphere

The BoundingFrustum to test for intersection.

Returns

bool
true
if this BoundingBox intersects sphere,
false
if it does not.

Intersects(ref BoundingSphere, out bool)

Check if this BoundingBox intersects a BoundingFrustum.

public void Intersects(ref BoundingSphere sphere, out bool result)

Parameters

sphere BoundingSphere

The BoundingFrustum to test for intersection.

result bool
true
if this BoundingBox intersects sphere,
false
if it does not.

Intersects(Plane)

Check if this BoundingBox intersects a Plane.

public PlaneIntersectionType Intersects(Plane plane)

Parameters

plane Plane

The Plane to test for intersection.

Returns

PlaneIntersectionType
true
if this BoundingBox intersects plane,
false
if it does not.

Intersects(ref Plane, out PlaneIntersectionType)

Check if this BoundingBox intersects a Plane.

public void Intersects(ref Plane plane, out PlaneIntersectionType result)

Parameters

plane Plane

The Plane to test for intersection.

result PlaneIntersectionType
true
if this BoundingBox intersects plane,
false
if it does not.

Intersects(Ray)

Check if this BoundingBox intersects a Ray.

public float? Intersects(Ray ray)

Parameters

ray Ray

The Ray to test for intersection.

Returns

float?

The distance along the Ray to the intersection point or

null
if the Ray does not intesect this BoundingBox.

Intersects(ref Ray, out float?)

Check if this BoundingBox intersects a Ray.

public void Intersects(ref Ray ray, out float? result)

Parameters

ray Ray

The Ray to test for intersection.

result float?

The distance along the Ray to the intersection point or

null
if the Ray does not intesect this BoundingBox.

ToString()

Get a string representation of this BoundingBox.

public override string ToString()

Returns

string

A string representation of this BoundingBox.

Operators

operator ==(BoundingBox, BoundingBox)

Check if two BoundingBox instances are equal.

public static bool operator ==(BoundingBox a, BoundingBox b)

Parameters

a BoundingBox

A BoundingBox to compare the other.

b BoundingBox

A BoundingBox to compare the other.

Returns

bool
true
if a is equal to this b,
false
if it is not.

operator !=(BoundingBox, BoundingBox)

Check if two BoundingBox instances are not equal.

public static bool operator !=(BoundingBox a, BoundingBox b)

Parameters

a BoundingBox

A BoundingBox to compare the other.

b BoundingBox

A BoundingBox to compare the other.

Returns

bool
true
if a is not equal to this b,
false
if it is.