Class OrientedBoundingBox
Oriented Bounding Box (OBB) is a rectangular block, much like an AABB (Bounding Box) but with an arbitrary orientation in 3D space.
Inheritance
Implements
Namespace: FlaxEngine
Assembly: FlaxEngine.CSharp.dll
Syntax
[Unmanaged]
public sealed class OrientedBoundingBox : ValueType, IEquatable<OrientedBoundingBox>, IFormattable
Constructors
OrientedBoundingBox(BoundingBox)
Creates an OrientedBoundingBox from a BoundingBox.
Declaration
public OrientedBoundingBox(BoundingBox bb)
Parameters
BoundingBox
bb
The BoundingBox to create from. |
Remarks
Initially, the OBB is axis-aligned box, but it can be rotated and transformed later.
OrientedBoundingBox(Vector3, Matrix)
Initializes a new instance of the OrientedBoundingBox struct.
Declaration
public OrientedBoundingBox(Vector3 extents, Matrix transformation)
Parameters
Vector3
extents
The half lengths of the box along each axis. |
Matrix
transformation
The matrix which aligns and scales the box, and its translation vector represents the center of the box. |
OrientedBoundingBox(Vector3, Vector3)
Creates an OrientedBoundingBox which contained between two minimum and maximum points.
Declaration
public OrientedBoundingBox(Vector3 minimum, Vector3 maximum)
Parameters
Vector3
minimum
The minimum vertex of the bounding box. |
Vector3
maximum
The maximum vertex of the bounding box. |
Remarks
Initially, the OrientedBoundingBox is axis-aligned box, but it can be rotated and transformed later.
OrientedBoundingBox(Vector3[])
Creates an OrientedBoundingBox that fully contains the given points.
Declaration
public OrientedBoundingBox(Vector3[] points)
Parameters
Vector3[]
points
The points that will be contained by the box. |
Remarks
This method is not for computing the best tight-fitting OrientedBoundingBox. And initially, the OrientedBoundingBox is axis-aligned box, but it can be rotated and transformed later.
Fields
Extents
Transformation
The transformation which aligns and scales the box, and its translation vector represents the center of the box.
Declaration
public Transform Transformation
Field Value
Transform
|
Properties
Center
Returns the center of the OrientedBoundingBox.
Declaration
public Vector3 Center { get; }
Property Value
Vector3
|
Default
The default OrientedBoundingBox.
Declaration
public static OrientedBoundingBox Default { get; }
Property Value
OrientedBoundingBox
|
Size
The size of the OrientedBoundingBox if no scaling is applied to the transformation matrix.
Declaration
public Vector3 Size { get; }
Property Value
Vector3
|
Remarks
The property will return the actual size even if the scaling is applied using Scale method, but if the scaling is applied to transformation matrix, use GetSize Function instead.
Methods
Contains(BoundingSphere, Boolean)
Determines whether a OrientedBoundingBox contains a BoundingSphere.
Declaration
public ContainmentType Contains(BoundingSphere sphere, bool ignoreScale = false)
Parameters
BoundingSphere
sphere
The sphere to test. |
System.Boolean
ignoreScale
Optimize the check operation by assuming that OrientedBoundingBox has no scaling applied. |
Returns
ContainmentType
The type of containment the two objects have. |
Remarks
This method is not designed for OrientedBoundingBox which has a non-uniform scaling applied to its transformation matrix. But any type of scaling applied using Scale method will keep this method accurate.
Contains(Vector3)
Determines whether a OrientedBoundingBox contains a point.
Declaration
public ContainmentType Contains(Vector3 point)
Parameters
Vector3
point
The point to test. |
Returns
ContainmentType
The type of containment the two objects have. |
Contains(ref Vector3)
Determines whether a OrientedBoundingBox contains a point.
Declaration
public ContainmentType Contains(ref Vector3 point)
Parameters
Vector3
point
The point to test. |
Returns
ContainmentType
The type of containment the two objects have. |
Equals(OrientedBoundingBox)
Determines whether the specified Vector4 is equal to this instance.
Declaration
public bool Equals(OrientedBoundingBox value)
Parameters
OrientedBoundingBox
value
The Vector4 to compare with this instance. |
Returns
System.Boolean
|
Equals(ref OrientedBoundingBox)
Determines whether the specified Vector4 is equal to this instance.
Declaration
public bool Equals(ref OrientedBoundingBox value)
Parameters
OrientedBoundingBox
value
The Vector4 to compare with this instance. |
Returns
System.Boolean
|
Equals(Object)
Determines whether the specified System.Object is equal to this instance.
Declaration
public override bool Equals(object value)
Parameters
System.Object
value
The System.Object to compare with this instance. |
Returns
System.Boolean
|
GetBoundingBox()
Get the axis-aligned BoundingBox which contains all OrientedBoundingBox corners.
Declaration
public BoundingBox GetBoundingBox()
Returns
BoundingBox
The axis-aligned BoundingBox of this OrientedBoundingBox. |
GetCorners()
Retrieves the eight corners of the bounding box.
Declaration
public Vector3[] GetCorners()
Returns
Vector3[]
An array of points representing the eight corners of the bounding box. |
GetCorners(Vector3*)
Retrieves the eight corners of the bounding box.
Declaration
public void GetCorners(Vector3*corners)
Parameters
Vector3*
corners
An array of points representing the eight corners of the bounding box. |
GetCorners(Vector3[])
Retrieves the eight corners of the bounding box.
Declaration
public void GetCorners(Vector3[] corners)
Parameters
Vector3[]
corners
An array of points representing the eight corners of the bounding box. |
GetCorners(List<Vector3>)
Retrieves the eight corners of the bounding box.
Declaration
public void GetCorners(List<Vector3> corners)
Parameters
System.Collections.Generic.List<Vector3>
corners
An collection to add the corners of the bounding box. |
GetHashCode()
Returns a hash code for this instance.
Declaration
public override int GetHashCode()
Returns
System.Int32
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
GetSize()
Returns the size of the OrientedBoundingBox taking into consideration the scaling applied to the transformation matrix.
Declaration
public Vector3 GetSize()
Returns
Vector3
The size of the consideration |
Remarks
This method is computationally expensive, so if no scale is applied to the transformation matrix use Size property instead.
GetSizeSquared()
Returns the square size of the OrientedBoundingBox taking into consideration the scaling applied to the transformation matrix.
Declaration
public Vector3 GetSizeSquared()
Returns
Vector3
The size of the consideration |
Intersects(ref Ray)
Determines whether there is an intersection between a Ray and a OrientedBoundingBox.
Declaration
public bool Intersects(ref Ray ray)
Parameters
Ray
ray
The ray to test. |
Returns
System.Boolean
Whether the two objects intersected. |
Intersects(ref Ray, out Vector3)
Determines whether there is an intersection between a Ray and a OrientedBoundingBox.
Declaration
public bool Intersects(ref Ray ray, out Vector3 point)
Parameters
Ray
ray
The ray to test. |
Vector3
point
When the method completes, contains the point of intersection, or Zero if there was no intersection. |
Returns
System.Boolean
Whether the two objects intersected. |
Intersects(ref Ray, out Single)
Determines whether there is an intersection between a Ray and a OrientedBoundingBox.
Declaration
public bool Intersects(ref Ray ray, out float distance)
Parameters
Ray
ray
The ray to test. |
System.Single
distance
When the method completes, contains the distance of intersection from the ray start, or 0 if there was no intersection. |
Returns
System.Boolean
Whether the two objects intersected. |
Scale(Vector3)
Scales the OrientedBoundingBox by scaling its Extents without affecting the Transformation matrix, By keeping Transformation matrix scaling-free, the collision detection methods will be more accurate.
Declaration
public void Scale(Vector3 scaling)
Parameters
Vector3
scaling
|
Scale(ref Vector3)
Scales the OrientedBoundingBox by scaling its Extents without affecting the Transformation matrix, By keeping Transformation matrix scaling-free, the collision detection methods will be more accurate.
Declaration
public void Scale(ref Vector3 scaling)
Parameters
Vector3
scaling
|
Scale(Single)
Scales the OrientedBoundingBox by scaling its Extents without affecting the Transformation matrix, By keeping Transformation matrix scaling-free, the collision detection methods will be more accurate.
Declaration
public void Scale(float scaling)
Parameters
System.Single
scaling
|
ToString()
Returns a System.String that represents this instance.
Declaration
public override string ToString()
Returns
System.String
A System.String that represents this instance. |
ToString(IFormatProvider)
Returns a System.String that represents this instance.
Declaration
public string ToString(IFormatProvider formatProvider)
Parameters
System.IFormatProvider
formatProvider
The format provider. |
Returns
System.String
A System.String that represents this instance. |
ToString(String)
Returns a System.String that represents this instance.
Declaration
public string ToString(string format)
Parameters
System.String
format
The format. |
Returns
System.String
A System.String that represents this instance. |
ToString(String, IFormatProvider)
Returns a System.String that represents this instance.
Declaration
public string ToString(string format, IFormatProvider formatProvider)
Parameters
System.String
format
The format. |
System.IFormatProvider
formatProvider
The format provider. |
Returns
System.String
A System.String that represents this instance. |
Transform(Matrix)
Transforms this box using a transformation matrix.
Declaration
public void Transform(Matrix mat)
Parameters
Matrix
mat
The transformation matrix. |
Remarks
While any kind of transformation can be applied, it is recommended to apply scaling using scale method instead, which scales the Extents and keeps the Transformation matrix for rotation only, and that preserves collision detection accuracy.
Transform(ref Matrix)
Transforms this box using a transformation matrix.
Declaration
public void Transform(ref Matrix mat)
Parameters
Matrix
mat
The transformation matrix. |
Remarks
While any kind of transformation can be applied, it is recommended to apply scaling using scale method instead, which scales the Extents and keeps the Transformation matrix for rotation only, and that preserves collision detection accuracy.
Transform(ref Transform)
Transforms this box using a transformation.
Declaration
public void Transform(ref Transform transform)
Parameters
Transform
transform
The transformation. |
Remarks
While any kind of transformation can be applied, it is recommended to apply scaling using scale method instead, which scales the Extents and keeps the Transformation for rotation only, and that preserves collision detection accuracy.
Translate(Vector3)
Translates the OrientedBoundingBox to a new position using a translation vector;
Declaration
public void Translate(Vector3 translation)
Parameters
Vector3
translation
the translation vector. |
Translate(ref Vector3)
Translates the OrientedBoundingBox to a new position using a translation vector;
Declaration
public void Translate(ref Vector3 translation)
Parameters
Vector3
translation
the translation vector. |
Operators
Equality(OrientedBoundingBox, OrientedBoundingBox)
Tests for equality between two objects.
Declaration
public static bool operator ==(OrientedBoundingBox left, OrientedBoundingBox right)
Parameters
OrientedBoundingBox
left
The first value to compare. |
OrientedBoundingBox
right
The second value to compare. |
Returns
System.Boolean
|
Inequality(OrientedBoundingBox, OrientedBoundingBox)
Tests for inequality between two objects.
Declaration
public static bool operator !=(OrientedBoundingBox left, OrientedBoundingBox right)
Parameters
OrientedBoundingBox
left
The first value to compare. |
OrientedBoundingBox
right
The second value to compare. |
Returns
System.Boolean
|
Multiply(OrientedBoundingBox, Matrix)
Transforms bounding box using the given transformation matrix.
Declaration
public static OrientedBoundingBox operator *(OrientedBoundingBox box, Matrix transform)
Parameters
OrientedBoundingBox
box
The bounding box to transform. |
Matrix
transform
The transformation matrix. |
Returns
OrientedBoundingBox
The result of the transformation. |
Multiply(OrientedBoundingBox, Transform)
Transforms bounding box using the given transformation.
Declaration
public static OrientedBoundingBox operator *(OrientedBoundingBox box, Transform transform)
Parameters
OrientedBoundingBox
box
The bounding box to transform. |
Transform
transform
The transformation. |
Returns
OrientedBoundingBox
The result of the transformation. |