mirror of
https://github.com/godotengine/godot-docs.git
synced 2025-12-31 17:49:03 +03:00
777 lines
34 KiB
ReStructuredText
777 lines
34 KiB
ReStructuredText
:github_url: hide
|
|
|
|
.. DO NOT EDIT THIS FILE!!!
|
|
.. Generated automatically from Godot engine sources.
|
|
.. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py.
|
|
.. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/AABB.xml.
|
|
|
|
.. _class_AABB:
|
|
|
|
AABB
|
|
====
|
|
|
|
A 3D axis-aligned bounding box.
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
Description
|
|
-----------
|
|
|
|
The **AABB** built-in :ref:`Variant<class_Variant>` type represents an axis-aligned bounding box in a 3D space. It is defined by its :ref:`position<class_AABB_property_position>` and :ref:`size<class_AABB_property_size>`, which are :ref:`Vector3<class_Vector3>`. It is frequently used for fast overlap tests (see :ref:`intersects<class_AABB_method_intersects>`). Although **AABB** itself is axis-aligned, it can be combined with :ref:`Transform3D<class_Transform3D>` to represent a rotated or skewed bounding box.
|
|
|
|
It uses floating-point coordinates. The 2D counterpart to **AABB** is :ref:`Rect2<class_Rect2>`. There is no version of **AABB** that uses integer coordinates.
|
|
|
|
\ **Note:** Negative values for :ref:`size<class_AABB_property_size>` are not supported. With negative size, most **AABB** methods do not work correctly. Use :ref:`abs<class_AABB_method_abs>` to get an equivalent **AABB** with a non-negative size.
|
|
|
|
\ **Note:** In a boolean context, a **AABB** evaluates to ``false`` if both :ref:`position<class_AABB_property_position>` and :ref:`size<class_AABB_property_size>` are zero (equal to :ref:`Vector3.ZERO<class_Vector3_constant_ZERO>`). Otherwise, it always evaluates to ``true``.
|
|
|
|
.. note::
|
|
|
|
There are notable differences when using this API with C#. See :ref:`doc_c_sharp_differences` for more information.
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
Tutorials
|
|
---------
|
|
|
|
- :doc:`Math documentation index <../tutorials/math/index>`
|
|
|
|
- :doc:`Vector math <../tutorials/math/vector_math>`
|
|
|
|
- :doc:`Advanced vector math <../tutorials/math/vectors_advanced>`
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
Properties
|
|
----------
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+-------------------------------+-----------------------------------------------+----------------------+
|
|
| :ref:`Vector3<class_Vector3>` | :ref:`end<class_AABB_property_end>` | ``Vector3(0, 0, 0)`` |
|
|
+-------------------------------+-----------------------------------------------+----------------------+
|
|
| :ref:`Vector3<class_Vector3>` | :ref:`position<class_AABB_property_position>` | ``Vector3(0, 0, 0)`` |
|
|
+-------------------------------+-----------------------------------------------+----------------------+
|
|
| :ref:`Vector3<class_Vector3>` | :ref:`size<class_AABB_property_size>` | ``Vector3(0, 0, 0)`` |
|
|
+-------------------------------+-----------------------------------------------+----------------------+
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
Constructors
|
|
------------
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+-------------------------+---------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`AABB<class_AABB>` | :ref:`AABB<class_AABB_constructor_AABB>` **(** **)** |
|
|
+-------------------------+---------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`AABB<class_AABB>` | :ref:`AABB<class_AABB_constructor_AABB>` **(** :ref:`AABB<class_AABB>` from **)** |
|
|
+-------------------------+---------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`AABB<class_AABB>` | :ref:`AABB<class_AABB_constructor_AABB>` **(** :ref:`Vector3<class_Vector3>` position, :ref:`Vector3<class_Vector3>` size **)** |
|
|
+-------------------------+---------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
Methods
|
|
-------
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`AABB<class_AABB>` | :ref:`abs<class_AABB_method_abs>` **(** **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`encloses<class_AABB_method_encloses>` **(** :ref:`AABB<class_AABB>` with **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`AABB<class_AABB>` | :ref:`expand<class_AABB_method_expand>` **(** :ref:`Vector3<class_Vector3>` to_point **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Vector3<class_Vector3>` | :ref:`get_center<class_AABB_method_get_center>` **(** **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Vector3<class_Vector3>` | :ref:`get_endpoint<class_AABB_method_get_endpoint>` **(** :ref:`int<class_int>` idx **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Vector3<class_Vector3>` | :ref:`get_longest_axis<class_AABB_method_get_longest_axis>` **(** **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_longest_axis_index<class_AABB_method_get_longest_axis_index>` **(** **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`get_longest_axis_size<class_AABB_method_get_longest_axis_size>` **(** **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Vector3<class_Vector3>` | :ref:`get_shortest_axis<class_AABB_method_get_shortest_axis>` **(** **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_shortest_axis_index<class_AABB_method_get_shortest_axis_index>` **(** **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`get_shortest_axis_size<class_AABB_method_get_shortest_axis_size>` **(** **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Vector3<class_Vector3>` | :ref:`get_support<class_AABB_method_get_support>` **(** :ref:`Vector3<class_Vector3>` dir **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`get_volume<class_AABB_method_get_volume>` **(** **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`AABB<class_AABB>` | :ref:`grow<class_AABB_method_grow>` **(** :ref:`float<class_float>` by **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`has_point<class_AABB_method_has_point>` **(** :ref:`Vector3<class_Vector3>` point **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`has_surface<class_AABB_method_has_surface>` **(** **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`has_volume<class_AABB_method_has_volume>` **(** **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`AABB<class_AABB>` | :ref:`intersection<class_AABB_method_intersection>` **(** :ref:`AABB<class_AABB>` with **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`intersects<class_AABB_method_intersects>` **(** :ref:`AABB<class_AABB>` with **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`intersects_plane<class_AABB_method_intersects_plane>` **(** :ref:`Plane<class_Plane>` plane **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Variant<class_Variant>` | :ref:`intersects_ray<class_AABB_method_intersects_ray>` **(** :ref:`Vector3<class_Vector3>` from, :ref:`Vector3<class_Vector3>` dir **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Variant<class_Variant>` | :ref:`intersects_segment<class_AABB_method_intersects_segment>` **(** :ref:`Vector3<class_Vector3>` from, :ref:`Vector3<class_Vector3>` to **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_AABB_method_is_equal_approx>` **(** :ref:`AABB<class_AABB>` aabb **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`is_finite<class_AABB_method_is_finite>` **(** **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`AABB<class_AABB>` | :ref:`merge<class_AABB_method_merge>` **(** :ref:`AABB<class_AABB>` with **)** |const| |
|
|
+-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
Operators
|
|
---------
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+-------------------------+----------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator !=<class_AABB_operator_neq_AABB>` **(** :ref:`AABB<class_AABB>` right **)** |
|
|
+-------------------------+----------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`AABB<class_AABB>` | :ref:`operator *<class_AABB_operator_mul_Transform3D>` **(** :ref:`Transform3D<class_Transform3D>` right **)** |
|
|
+-------------------------+----------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator ==<class_AABB_operator_eq_AABB>` **(** :ref:`AABB<class_AABB>` right **)** |
|
|
+-------------------------+----------------------------------------------------------------------------------------------------------------+
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
Property Descriptions
|
|
---------------------
|
|
|
|
.. _class_AABB_property_end:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`Vector3<class_Vector3>` **end** = ``Vector3(0, 0, 0)``
|
|
|
|
The ending point. This is usually the corner on the top-right and forward of the bounding box, and is equivalent to ``position + size``. Setting this point affects the :ref:`size<class_AABB_property_size>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_property_position:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`Vector3<class_Vector3>` **position** = ``Vector3(0, 0, 0)``
|
|
|
|
The origin point. This is usually the corner on the bottom-left and back of the bounding box.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_property_size:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`Vector3<class_Vector3>` **size** = ``Vector3(0, 0, 0)``
|
|
|
|
The bounding box's width, height, and depth starting from :ref:`position<class_AABB_property_position>`. Setting this value also affects the :ref:`end<class_AABB_property_end>` point.
|
|
|
|
\ **Note:** It's recommended setting the width, height, and depth to non-negative values. This is because most methods in Godot assume that the :ref:`position<class_AABB_property_position>` is the bottom-left-back corner, and the :ref:`end<class_AABB_property_end>` is the top-right-forward corner. To get an equivalent bounding box with non-negative size, use :ref:`abs<class_AABB_method_abs>`.
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
Constructor Descriptions
|
|
------------------------
|
|
|
|
.. _class_AABB_constructor_AABB:
|
|
|
|
.. rst-class:: classref-constructor
|
|
|
|
:ref:`AABB<class_AABB>` **AABB** **(** **)**
|
|
|
|
Constructs an **AABB** with its :ref:`position<class_AABB_property_position>` and :ref:`size<class_AABB_property_size>` set to :ref:`Vector3.ZERO<class_Vector3_constant_ZERO>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-constructor
|
|
|
|
:ref:`AABB<class_AABB>` **AABB** **(** :ref:`AABB<class_AABB>` from **)**
|
|
|
|
Constructs an **AABB** as a copy of the given **AABB**.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-constructor
|
|
|
|
:ref:`AABB<class_AABB>` **AABB** **(** :ref:`Vector3<class_Vector3>` position, :ref:`Vector3<class_Vector3>` size **)**
|
|
|
|
Constructs an **AABB** by ``position`` and ``size``.
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
Method Descriptions
|
|
-------------------
|
|
|
|
.. _class_AABB_method_abs:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`AABB<class_AABB>` **abs** **(** **)** |const|
|
|
|
|
Returns an **AABB** equivalent to this bounding box, with its width, height, and depth modified to be non-negative values.
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: gdscript
|
|
|
|
var box = AABB(Vector3(5, 0, 5), Vector3(-20, -10, -5))
|
|
var absolute = box.abs()
|
|
print(absolute.position) # Prints (-15, -10, 0)
|
|
print(absolute.size) # Prints (20, 10, 5)
|
|
|
|
.. code-tab:: csharp
|
|
|
|
var box = new Aabb(new Vector3(5, 0, 5), new Vector3(-20, -10, -5));
|
|
var absolute = box.Abs();
|
|
GD.Print(absolute.Position); // Prints (-15, -10, 0)
|
|
GD.Print(absolute.Size); // Prints (20, 10, 5)
|
|
|
|
|
|
|
|
\ **Note:** It's recommended to use this method when :ref:`size<class_AABB_property_size>` is negative, as most other methods in Godot assume that the :ref:`size<class_AABB_property_size>`'s components are greater than ``0``.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_encloses:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`bool<class_bool>` **encloses** **(** :ref:`AABB<class_AABB>` with **)** |const|
|
|
|
|
Returns ``true`` if this bounding box *completely* encloses the ``with`` box. The edges of both boxes are included.
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: gdscript
|
|
|
|
var a = AABB(Vector3(0, 0, 0), Vector3(4, 4, 4))
|
|
var b = AABB(Vector3(1, 1, 1), Vector3(3, 3, 3))
|
|
var c = AABB(Vector3(2, 2, 2), Vector3(8, 8, 8))
|
|
|
|
print(a.encloses(a)) # Prints true
|
|
print(a.encloses(b)) # Prints true
|
|
print(a.encloses(c)) # Prints false
|
|
|
|
.. code-tab:: csharp
|
|
|
|
var a = new Aabb(new Vector3(0, 0, 0), new Vector3(4, 4, 4));
|
|
var b = new Aabb(new Vector3(1, 1, 1), new Vector3(3, 3, 3));
|
|
var c = new Aabb(new Vector3(2, 2, 2), new Vector3(8, 8, 8));
|
|
|
|
GD.Print(a.Encloses(a)); // Prints True
|
|
GD.Print(a.Encloses(b)); // Prints True
|
|
GD.Print(a.Encloses(c)); // Prints False
|
|
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_expand:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`AABB<class_AABB>` **expand** **(** :ref:`Vector3<class_Vector3>` to_point **)** |const|
|
|
|
|
Returns a copy of this bounding box expanded to align the edges with the given ``to_point``, if necessary.
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: gdscript
|
|
|
|
var box = AABB(Vector3(0, 0, 0), Vector3(5, 2, 5))
|
|
|
|
box = box.expand(Vector3(10, 0, 0))
|
|
print(box.position) # Prints (0, 0, 0)
|
|
print(box.size) # Prints (10, 2, 5)
|
|
|
|
box = box.expand(Vector3(-5, 0, 5))
|
|
print(box.position) # Prints (-5, 0, 0)
|
|
print(box.size) # Prints (15, 2, 5)
|
|
|
|
.. code-tab:: csharp
|
|
|
|
var box = new Aabb(new Vector3(0, 0, 0), new Vector3(5, 2, 5));
|
|
|
|
box = box.Expand(new Vector3(10, 0, 0));
|
|
GD.Print(box.Position); // Prints (0, 0, 0)
|
|
GD.Print(box.Size); // Prints (10, 2, 5)
|
|
|
|
box = box.Expand(new Vector3(-5, 0, 5));
|
|
GD.Print(box.Position); // Prints (-5, 0, 0)
|
|
GD.Print(box.Size); // Prints (15, 2, 5)
|
|
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_get_center:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Vector3<class_Vector3>` **get_center** **(** **)** |const|
|
|
|
|
Returns the center point of the bounding box. This is the same as ``position + (size / 2.0)``.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_get_endpoint:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Vector3<class_Vector3>` **get_endpoint** **(** :ref:`int<class_int>` idx **)** |const|
|
|
|
|
Returns the position of one of the 8 vertices that compose this bounding box. With a ``idx`` of ``0`` this is the same as :ref:`position<class_AABB_property_position>`, and a ``idx`` of ``7`` is the same as :ref:`end<class_AABB_property_end>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_get_longest_axis:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Vector3<class_Vector3>` **get_longest_axis** **(** **)** |const|
|
|
|
|
Returns the longest normalized axis of this bounding box's :ref:`size<class_AABB_property_size>`, as a :ref:`Vector3<class_Vector3>` (:ref:`Vector3.RIGHT<class_Vector3_constant_RIGHT>`, :ref:`Vector3.UP<class_Vector3_constant_UP>`, or :ref:`Vector3.BACK<class_Vector3_constant_BACK>`).
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: gdscript
|
|
|
|
var box = AABB(Vector3(0, 0, 0), Vector3(2, 4, 8))
|
|
|
|
print(box.get_longest_axis()) # Prints (0, 0, 1)
|
|
print(box.get_longest_axis_index()) # Prints 2
|
|
print(box.get_longest_axis_size()) # Prints 8
|
|
|
|
.. code-tab:: csharp
|
|
|
|
var box = new Aabb(new Vector3(0, 0, 0), new Vector3(2, 4, 8));
|
|
|
|
GD.Print(box.GetLongestAxis()); // Prints (0, 0, 1)
|
|
GD.Print(box.GetLongestAxisIndex()); // Prints 2
|
|
GD.Print(box.GetLongestAxisSize()); // Prints 8
|
|
|
|
|
|
|
|
See also :ref:`get_longest_axis_index<class_AABB_method_get_longest_axis_index>` and :ref:`get_longest_axis_size<class_AABB_method_get_longest_axis_size>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_get_longest_axis_index:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`int<class_int>` **get_longest_axis_index** **(** **)** |const|
|
|
|
|
Returns the index to the longest axis of this bounding box's :ref:`size<class_AABB_property_size>` (see :ref:`Vector3.AXIS_X<class_Vector3_constant_AXIS_X>`, :ref:`Vector3.AXIS_Y<class_Vector3_constant_AXIS_Y>`, and :ref:`Vector3.AXIS_Z<class_Vector3_constant_AXIS_Z>`).
|
|
|
|
For an example, see :ref:`get_longest_axis<class_AABB_method_get_longest_axis>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_get_longest_axis_size:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`float<class_float>` **get_longest_axis_size** **(** **)** |const|
|
|
|
|
Returns the longest dimension of this bounding box's :ref:`size<class_AABB_property_size>`.
|
|
|
|
For an example, see :ref:`get_longest_axis<class_AABB_method_get_longest_axis>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_get_shortest_axis:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Vector3<class_Vector3>` **get_shortest_axis** **(** **)** |const|
|
|
|
|
Returns the shortest normaalized axis of this bounding box's :ref:`size<class_AABB_property_size>`, as a :ref:`Vector3<class_Vector3>` (:ref:`Vector3.RIGHT<class_Vector3_constant_RIGHT>`, :ref:`Vector3.UP<class_Vector3_constant_UP>`, or :ref:`Vector3.BACK<class_Vector3_constant_BACK>`).
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: gdscript
|
|
|
|
var box = AABB(Vector3(0, 0, 0), Vector3(2, 4, 8))
|
|
|
|
print(box.get_shortest_axis()) # Prints (1, 0, 0)
|
|
print(box.get_shortest_axis_index()) # Prints 0
|
|
print(box.get_shortest_axis_size()) # Prints 2
|
|
|
|
.. code-tab:: csharp
|
|
|
|
var box = new Aabb(new Vector3(0, 0, 0), new Vector3(2, 4, 8));
|
|
|
|
GD.Print(box.GetShortestAxis()); // Prints (1, 0, 0)
|
|
GD.Print(box.GetShortestAxisIndex()); // Prints 0
|
|
GD.Print(box.GetShortestAxisSize()); // Prints 2
|
|
|
|
|
|
|
|
See also :ref:`get_shortest_axis_index<class_AABB_method_get_shortest_axis_index>` and :ref:`get_shortest_axis_size<class_AABB_method_get_shortest_axis_size>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_get_shortest_axis_index:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`int<class_int>` **get_shortest_axis_index** **(** **)** |const|
|
|
|
|
Returns the index to the shortest axis of this bounding box's :ref:`size<class_AABB_property_size>` (see :ref:`Vector3.AXIS_X<class_Vector3_constant_AXIS_X>`, :ref:`Vector3.AXIS_Y<class_Vector3_constant_AXIS_Y>`, and :ref:`Vector3.AXIS_Z<class_Vector3_constant_AXIS_Z>`).
|
|
|
|
For an example, see :ref:`get_shortest_axis<class_AABB_method_get_shortest_axis>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_get_shortest_axis_size:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`float<class_float>` **get_shortest_axis_size** **(** **)** |const|
|
|
|
|
Returns the shortest dimension of this bounding box's :ref:`size<class_AABB_property_size>`.
|
|
|
|
For an example, see :ref:`get_shortest_axis<class_AABB_method_get_shortest_axis>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_get_support:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Vector3<class_Vector3>` **get_support** **(** :ref:`Vector3<class_Vector3>` dir **)** |const|
|
|
|
|
Returns the vertex's position of this bounding box that's the farthest in the given direction. This point is commonly known as the support point in collision detection algorithms.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_get_volume:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`float<class_float>` **get_volume** **(** **)** |const|
|
|
|
|
Returns the bounding box's volume. This is equivalent to ``size.x * size.y * size.z``. See also :ref:`has_volume<class_AABB_method_has_volume>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_grow:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`AABB<class_AABB>` **grow** **(** :ref:`float<class_float>` by **)** |const|
|
|
|
|
Returns a copy of this bounding box extended on all sides by the given amount ``by``. A negative amount shrinks the box instead.
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: gdscript
|
|
|
|
var a = AABB(Vector3(4, 4, 4), Vector3(8, 8, 8)).grow(4)
|
|
print(a.position) # Prints (0, 0, 0)
|
|
print(a.size) # Prints (16, 16, 16)
|
|
|
|
var b = AABB(Vector3(0, 0, 0), Vector3(8, 4, 2)).grow(2)
|
|
print(b.position) # Prints (-2, -2, -2)
|
|
print(b.size) # Prints (12, 8, 6)
|
|
|
|
.. code-tab:: csharp
|
|
|
|
var a = new Aabb(new Vector3(4, 4, 4), new Vector3(8, 8, 8)).Grow(4);
|
|
GD.Print(a.Position); // Prints (0, 0, 0)
|
|
GD.Print(a.Size); // Prints (16, 16, 16)
|
|
|
|
var b = new Aabb(new Vector3(0, 0, 0), new Vector3(8, 4, 2)).Grow(2);
|
|
GD.Print(b.Position); // Prints (-2, -2, -2)
|
|
GD.Print(b.Size); // Prints (12, 8, 6)
|
|
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_has_point:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`bool<class_bool>` **has_point** **(** :ref:`Vector3<class_Vector3>` point **)** |const|
|
|
|
|
Returns ``true`` if the bounding box contains the given ``point``. By convention, points exactly on the right, top, and front sides are **not** included.
|
|
|
|
\ **Note:** This method is not reliable for **AABB** with a *negative* :ref:`size<class_AABB_property_size>`. Use :ref:`abs<class_AABB_method_abs>` first to get a valid bounding box.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_has_surface:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`bool<class_bool>` **has_surface** **(** **)** |const|
|
|
|
|
Returns ``true`` if this bounding box has a surface or a length, that is, at least one component of :ref:`size<class_AABB_property_size>` is greater than ``0``. Otherwise, returns ``false``.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_has_volume:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`bool<class_bool>` **has_volume** **(** **)** |const|
|
|
|
|
Returns ``true`` if this bounding box's width, height, and depth are all positive. See also :ref:`get_volume<class_AABB_method_get_volume>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_intersection:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`AABB<class_AABB>` **intersection** **(** :ref:`AABB<class_AABB>` with **)** |const|
|
|
|
|
Returns the intersection between this bounding box and ``with``. If the boxes do not intersect, returns an empty **AABB**. If the boxes intersect at the edge, returns a flat **AABB** with no volume (see :ref:`has_surface<class_AABB_method_has_surface>` and :ref:`has_volume<class_AABB_method_has_volume>`).
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: gdscript
|
|
|
|
var box1 = AABB(Vector3(0, 0, 0), Vector3(5, 2, 8))
|
|
var box2 = AABB(Vector3(2, 0, 2), Vector3(8, 4, 4))
|
|
|
|
var intersection = box1.intersection(box2)
|
|
print(intersection.position) # Prints (2, 0, 2)
|
|
print(intersection.size) # Prints (3, 2, 4)
|
|
|
|
.. code-tab:: csharp
|
|
|
|
var box1 = new Aabb(new Vector3(0, 0, 0), new Vector3(5, 2, 8));
|
|
var box2 = new Aabb(new Vector3(2, 0, 2), new Vector3(8, 4, 4));
|
|
|
|
var intersection = box1.Intersection(box2);
|
|
GD.Print(intersection.Position); // Prints (2, 0, 2)
|
|
GD.Print(intersection.Size); // Prints (3, 2, 4)
|
|
|
|
|
|
|
|
\ **Note:** If you only need to know whether two bounding boxes are intersecting, use :ref:`intersects<class_AABB_method_intersects>`, instead.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_intersects:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`bool<class_bool>` **intersects** **(** :ref:`AABB<class_AABB>` with **)** |const|
|
|
|
|
Returns ``true`` if this bounding box overlaps with the box ``with``. The edges of both boxes are *always* excluded.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_intersects_plane:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`bool<class_bool>` **intersects_plane** **(** :ref:`Plane<class_Plane>` plane **)** |const|
|
|
|
|
Returns ``true`` if this bounding box is on both sides of the given ``plane``.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_intersects_ray:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Variant<class_Variant>` **intersects_ray** **(** :ref:`Vector3<class_Vector3>` from, :ref:`Vector3<class_Vector3>` dir **)** |const|
|
|
|
|
Returns the first point where this bounding box and the given ray intersect, as a :ref:`Vector3<class_Vector3>`. If no intersection occurs, returns ``null``.
|
|
|
|
The ray begin at ``from``, faces ``dir`` and extends towards infinity.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_intersects_segment:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`Variant<class_Variant>` **intersects_segment** **(** :ref:`Vector3<class_Vector3>` from, :ref:`Vector3<class_Vector3>` to **)** |const|
|
|
|
|
Returns the first point where this bounding box and the given segment intersect, as a :ref:`Vector3<class_Vector3>`. If no intersection occurs, returns ``null``.
|
|
|
|
The segment begins at ``from`` and ends at ``to``.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_is_equal_approx:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`AABB<class_AABB>` aabb **)** |const|
|
|
|
|
Returns ``true`` if this bounding box and ``aabb`` are approximately equal, by calling :ref:`Vector2.is_equal_approx<class_Vector2_method_is_equal_approx>` on the :ref:`position<class_AABB_property_position>` and the :ref:`size<class_AABB_property_size>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_is_finite:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`bool<class_bool>` **is_finite** **(** **)** |const|
|
|
|
|
Returns ``true`` if this bounding box's values are finite, by calling :ref:`Vector2.is_finite<class_Vector2_method_is_finite>` on the :ref:`position<class_AABB_property_position>` and the :ref:`size<class_AABB_property_size>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_method_merge:
|
|
|
|
.. rst-class:: classref-method
|
|
|
|
:ref:`AABB<class_AABB>` **merge** **(** :ref:`AABB<class_AABB>` with **)** |const|
|
|
|
|
Returns an **AABB** that encloses both this bounding box and ``with`` around the edges. See also :ref:`encloses<class_AABB_method_encloses>`.
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
Operator Descriptions
|
|
---------------------
|
|
|
|
.. _class_AABB_operator_neq_AABB:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator !=** **(** :ref:`AABB<class_AABB>` right **)**
|
|
|
|
Returns ``true`` if the :ref:`position<class_AABB_property_position>` or :ref:`size<class_AABB_property_size>` of both bounding boxes are not equal.
|
|
|
|
\ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_AABB_method_is_equal_approx>` instead, which is more reliable.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_operator_mul_Transform3D:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`AABB<class_AABB>` **operator *** **(** :ref:`Transform3D<class_Transform3D>` right **)**
|
|
|
|
Inversely transforms (multiplies) the **AABB** by the given :ref:`Transform3D<class_Transform3D>` transformation matrix, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not).
|
|
|
|
\ ``aabb * transform`` is equivalent to ``transform.inverse() * aabb``. See :ref:`Transform3D.inverse<class_Transform3D_method_inverse>`.
|
|
|
|
For transforming by inverse of an affine transformation (e.g. with scaling) ``transform.affine_inverse() * aabb`` can be used instead. See :ref:`Transform3D.affine_inverse<class_Transform3D_method_affine_inverse>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_AABB_operator_eq_AABB:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator ==** **(** :ref:`AABB<class_AABB>` right **)**
|
|
|
|
Returns ``true`` if both :ref:`position<class_AABB_property_position>` and :ref:`size<class_AABB_property_size>` of the bounding boxes are exactly equal, respectively.
|
|
|
|
\ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_AABB_method_is_equal_approx>` instead, which is more reliable.
|
|
|
|
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
|
|
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
|
|
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
|
|
.. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
|
|
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
|
|
.. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
|
|
.. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
|