Struct Aabb
- Namespace
- Godot
- Assembly
- GodotSharp.dll
Axis-Aligned Bounding Box. AABB consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.
public struct Aabb : IEquatable<Aabb>
- Implements
- Inherited Members
Constructors
Aabb(Vector3, Vector3)
Constructs an Aabb from a position and size.
public Aabb(Vector3 position, Vector3 size)
Parameters
Aabb(Vector3, float, float, float)
Constructs an Aabb from a position
,
width
, height
, and depth
.
public Aabb(Vector3 position, float width, float height, float depth)
Parameters
position
Vector3The position.
width
floatThe width, typically positive.
height
floatThe height, typically positive.
depth
floatThe depth, typically positive.
Aabb(float, float, float, Vector3)
Constructs an Aabb from x
,
y
, z
, and size
.
public Aabb(float x, float y, float z, Vector3 size)
Parameters
x
floatThe position's X coordinate.
y
floatThe position's Y coordinate.
z
floatThe position's Z coordinate.
size
Vector3The size, typically positive.
Aabb(float, float, float, float, float, float)
Constructs an Aabb from x
,
y
, z
, width
,
height
, and depth
.
public Aabb(float x, float y, float z, float width, float height, float depth)
Parameters
x
floatThe position's X coordinate.
y
floatThe position's Y coordinate.
z
floatThe position's Z coordinate.
width
floatThe width, typically positive.
height
floatThe height, typically positive.
depth
floatThe depth, typically positive.
Properties
End
public Vector3 End { readonly get; set; }
Property Value
- Vector3
Getting is equivalent to
value
= Position + Size, setting is equivalent to Size =value
- Position
Position
Beginning corner. Typically has values lower than End.
public Vector3 Position { readonly get; set; }
Property Value
- Vector3
Directly uses a private field.
Size
Size from Position to End. Typically all components are positive. If the size is negative, you can use Abs() to fix it.
public Vector3 Size { readonly get; set; }
Property Value
- Vector3
Directly uses a private field.
Volume
The volume of this Aabb. See also HasVolume().
public readonly float Volume { get; }
Property Value
Methods
Abs()
Returns an Aabb with equivalent position and size, modified so that the most-negative corner is the origin and the size is positive.
public readonly Aabb Abs()
Returns
Encloses(Aabb)
public readonly bool Encloses(Aabb with)
Parameters
Returns
Equals(Aabb)
Returns true if the AABBs are exactly equal. Note: Due to floating-point precision errors, consider using IsEqualApprox(Aabb) instead, which is more reliable.
public readonly bool Equals(Aabb other)
Parameters
other
AabbThe other AABB.
Returns
- bool
Whether or not the AABBs are exactly equal.
Equals(object)
Returns true if the AABB is exactly equal
to the given object (obj
).
Note: Due to floating-point precision errors, consider using
IsEqualApprox(Aabb) instead, which is more reliable.
public override readonly bool Equals(object obj)
Parameters
obj
objectThe object to compare with.
Returns
- bool
Whether or not the AABB and the object are equal.
Expand(Vector3)
Returns this Aabb expanded to include a given point.
public readonly Aabb Expand(Vector3 point)
Parameters
point
Vector3The point to include.
Returns
GetCenter()
public readonly Vector3 GetCenter()
Returns
- Vector3
The center.
GetEndpoint(int)
Gets the position of one of the 8 endpoints of the Aabb.
public readonly Vector3 GetEndpoint(int idx)
Parameters
idx
intWhich endpoint to get.
Returns
Exceptions
- ArgumentOutOfRangeException
idx
is less than 0 or greater than 7.
GetHashCode()
Serves as the hash function for Aabb.
public override readonly int GetHashCode()
Returns
- int
A hash code for this AABB.
GetLongestAxis()
Returns the normalized longest axis of the Aabb.
public readonly Vector3 GetLongestAxis()
Returns
GetLongestAxisIndex()
Returns the Vector3.Axis index of the longest axis of the Aabb.
public readonly Vector3.Axis GetLongestAxisIndex()
Returns
- Vector3.Axis
A Vector3.Axis index for which axis is longest.
GetLongestAxisSize()
Returns the scalar length of the longest axis of the Aabb.
public readonly float GetLongestAxisSize()
Returns
GetShortestAxis()
Returns the normalized shortest axis of the Aabb.
public readonly Vector3 GetShortestAxis()
Returns
GetShortestAxisIndex()
Returns the Vector3.Axis index of the shortest axis of the Aabb.
public readonly Vector3.Axis GetShortestAxisIndex()
Returns
- Vector3.Axis
A Vector3.Axis index for which axis is shortest.
GetShortestAxisSize()
Returns the scalar length of the shortest axis of the Aabb.
public readonly float GetShortestAxisSize()
Returns
GetSupport(Vector3)
Returns the support point in a given direction. This is useful for collision detection algorithms.
public readonly Vector3 GetSupport(Vector3 dir)
Parameters
dir
Vector3The direction to find support for.
Returns
- Vector3
A vector representing the support.
Grow(float)
Returns a copy of the Aabb grown a given amount of units towards all the sides.
public readonly Aabb Grow(float by)
Parameters
by
floatThe amount to grow by.
Returns
HasPoint(Vector3)
public readonly bool HasPoint(Vector3 point)
Parameters
point
Vector3The point to check.
Returns
HasSurface()
Returns true if the Aabb has a surface or a length, and false if the Aabb is empty (all components of Size are zero or negative).
public readonly bool HasSurface()
Returns
HasVolume()
Returns true if the Aabb has area, and false if the Aabb is linear, empty, or has a negative Size. See also Volume.
public readonly bool HasVolume()
Returns
Intersection(Aabb)
Returns the intersection of this Aabb and with
.
public readonly Aabb Intersection(Aabb with)
Parameters
Returns
Intersects(Aabb)
public readonly bool Intersects(Aabb with)
Parameters
Returns
IntersectsPlane(Plane)
public readonly bool IntersectsPlane(Plane plane)
Parameters
Returns
IntersectsSegment(Vector3, Vector3)
public readonly bool IntersectsSegment(Vector3 from, Vector3 to)
Parameters
Returns
IsEqualApprox(Aabb)
Returns true if this AABB and other
are approximately equal,
by running IsEqualApprox(Vector3) on each component.
public readonly bool IsEqualApprox(Aabb other)
Parameters
other
AabbThe other AABB to compare.
Returns
- bool
Whether or not the AABBs structures are approximately equal.
IsFinite()
Returns true if this Aabb is finite, by calling IsFinite(float) on each component.
public readonly bool IsFinite()
Returns
- bool
Whether this vector is finite or not.
Merge(Aabb)
public readonly Aabb Merge(Aabb with)
Parameters
Returns
ToString()
Converts this Aabb to a string.
public override readonly string ToString()
Returns
- string
A string representation of this AABB.
ToString(string)
Converts this Aabb to a string with the given format
.
public readonly string ToString(string format)
Parameters
format
string
Returns
- string
A string representation of this AABB.
Operators
operator ==(Aabb, Aabb)
Returns true if the AABBs are exactly equal. Note: Due to floating-point precision errors, consider using IsEqualApprox(Aabb) instead, which is more reliable.
public static bool operator ==(Aabb left, Aabb right)
Parameters
Returns
- bool
Whether or not the AABBs are exactly equal.
operator !=(Aabb, Aabb)
Returns true if the AABBs are not equal. Note: Due to floating-point precision errors, consider using IsEqualApprox(Aabb) instead, which is more reliable.
public static bool operator !=(Aabb left, Aabb right)
Parameters
Returns
- bool
Whether or not the AABBs are not equal.