Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

AABB

A 3D axis-aligned bounding box.

描述

AABB consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.

It uses floating-point coordinates. The 2D counterpart to AABB is Rect2.

Negative values for size are not supported and will not work for most methods. Use abs to get an AABB with a positive size.

Note: Unlike Rect2, AABB does not have a variant that uses integer coordinates.

备注

There are notable differences when using this API with C#. See C# API 与 GDScript 的差异 for more information.

教程

属性

Vector3

end

Vector3(0, 0, 0)

Vector3

position

Vector3(0, 0, 0)

Vector3

size

Vector3(0, 0, 0)

构造函数

AABB

AABB ( )

AABB

AABB ( AABB from )

AABB

AABB ( Vector3 position, Vector3 size )

Methods

AABB

abs ( ) const

bool

encloses ( AABB with ) const

AABB

expand ( Vector3 to_point ) const

Vector3

get_center ( ) const

Vector3

get_endpoint ( int idx ) const

Vector3

get_longest_axis ( ) const

int

get_longest_axis_index ( ) const

float

get_longest_axis_size ( ) const

Vector3

get_shortest_axis ( ) const

int

get_shortest_axis_index ( ) const

float

get_shortest_axis_size ( ) const

Vector3

get_support ( Vector3 dir ) const

float

get_volume ( ) const

AABB

grow ( float by ) const

bool

has_point ( Vector3 point ) const

bool

has_surface ( ) const

bool

has_volume ( ) const

AABB

intersection ( AABB with ) const

bool

intersects ( AABB with ) const

bool

intersects_plane ( Plane plane ) const

Variant

intersects_ray ( Vector3 from, Vector3 dir ) const

Variant

intersects_segment ( Vector3 from, Vector3 to ) const

bool

is_equal_approx ( AABB aabb ) const

bool

is_finite ( ) const

AABB

merge ( AABB with ) const

运算符

bool

operator != ( AABB right )

AABB

operator * ( Transform3D right )

bool

operator == ( AABB right )


Property Descriptions

Vector3 end = Vector3(0, 0, 0)

Ending corner. This is calculated as position + size. Setting this value will change the size.


Vector3 position = Vector3(0, 0, 0)

Beginning corner. Typically has values lower than end.


Vector3 size = Vector3(0, 0, 0)

Size from position to end. Typically, all components are positive.

If the size is negative, you can use abs to fix it.


Constructor Descriptions

AABB AABB ( )

Constructs a default-initialized AABB with default (zero) values of position and size.


AABB AABB ( AABB from )

Constructs an AABB as a copy of the given AABB.


AABB AABB ( Vector3 position, Vector3 size )

Constructs an AABB from a position and size.


Method Descriptions

AABB abs ( ) const

Returns an AABB with equivalent position and size, modified so that the most-negative corner is the origin and the size is positive.


bool encloses ( AABB with ) const

Returns true if this AABB completely encloses another one.


AABB expand ( Vector3 to_point ) const

Returns a copy of this AABB expanded to include a given point.

Example:

# position (-3, 2, 0), size (1, 1, 1)
var box = AABB(Vector3(-3, 2, 0), Vector3(1, 1, 1))
# position (-3, -1, 0), size (3, 4, 2), so we fit both the original AABB and Vector3(0, -1, 2)
var box2 = box.expand(Vector3(0, -1, 2))

Vector3 get_center ( ) const

Returns the center of the AABB, which is equal to position + (size / 2).


Vector3 get_endpoint ( int idx ) const

Gets the position of the 8 endpoints of the AABB in space.


Vector3 get_longest_axis ( ) const

Returns the normalized longest axis of the AABB.


int get_longest_axis_index ( ) const

Returns the index of the longest axis of the AABB (according to Vector3's AXIS_* constants).


float get_longest_axis_size ( ) const

Returns the scalar length of the longest axis of the AABB.


Vector3 get_shortest_axis ( ) const

Returns the normalized shortest axis of the AABB.


int get_shortest_axis_index ( ) const

Returns the index of the shortest axis of the AABB (according to Vector3::AXIS* enum).


float get_shortest_axis_size ( ) const

Returns the scalar length of the shortest axis of the AABB.


Vector3 get_support ( Vector3 dir ) const

Returns the support point in a given direction. This is useful for collision detection algorithms.


float get_volume ( ) const

Returns the volume of the AABB.


AABB grow ( float by ) const

Returns a copy of the AABB grown a given number of units towards all the sides.


bool has_point ( Vector3 point ) const

Returns true if the AABB contains a point. Points on the faces of the AABB are considered included, though float-point precision errors may impact the accuracy of such checks.

Note: This method is not reliable for AABB with a negative size. Use abs to get a positive sized equivalent AABB to check for contained points.


bool has_surface ( ) const

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).


bool has_volume ( ) const

Returns true if the AABB has a volume, and false if the AABB is flat, empty, or has a negative size.


AABB intersection ( AABB with ) const

Returns the intersection between two AABB. An empty AABB (size (0, 0, 0)) is returned on failure.


bool intersects ( AABB with ) const

Returns true if the AABB overlaps with another.


bool intersects_plane ( Plane plane ) const

Returns true if the AABB is on both sides of a plane.


Variant intersects_ray ( Vector3 from, Vector3 dir ) const

Returns the point of intersection of the given ray with this AABB or null if there is no intersection. Ray length is infinite.


Variant intersects_segment ( Vector3 from, Vector3 to ) const

Returns the point of intersection between from and to with this AABB or null if there is no intersection.


bool is_equal_approx ( AABB aabb ) const

Returns true if this AABB and aabb are approximately equal, by calling @GlobalScope.is_equal_approx on each component.


bool is_finite ( ) const

Returns true if this AABB is finite, by calling @GlobalScope.is_finite on each component.


AABB merge ( AABB with ) const

Returns a larger AABB that contains both this AABB and with.


Operator Descriptions

bool operator != ( AABB right )

Returns true if the AABBs are not equal.

Note: Due to floating-point precision errors, consider using is_equal_approx instead, which is more reliable.


AABB operator * ( Transform3D right )

Inversely transforms (multiplies) the AABB by the given Transform3D transformation matrix.


bool operator == ( AABB right )

Returns true if the AABBs are exactly equal.

Note: Due to floating-point precision errors, consider using is_equal_approx instead, which is more reliable.