class_aabb.rst 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the AABB.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_AABB:
  6. AABB
  7. ====
  8. Axis-Aligned Bounding Box.
  9. Description
  10. -----------
  11. ``AABB`` consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.
  12. It uses floating-point coordinates. The 2D counterpart to ``AABB`` is :ref:`Rect2<class_Rect2>`.
  13. Negative values for :ref:`size<class_AABB_property_size>` are not supported and will not work for most methods. Use :ref:`abs<class_AABB_method_abs>` to get an AABB with a positive size.
  14. \ **Note:** Unlike :ref:`Rect2<class_Rect2>`, ``AABB`` does not have a variant that uses integer coordinates.
  15. Tutorials
  16. ---------
  17. - :doc:`Math documentation index <../tutorials/math/index>`
  18. - :doc:`Vector math <../tutorials/math/vector_math>`
  19. - :doc:`Advanced vector math <../tutorials/math/vectors_advanced>`
  20. Properties
  21. ----------
  22. +-------------------------------+-----------------------------------------------+----------------------+
  23. | :ref:`Vector3<class_Vector3>` | :ref:`end<class_AABB_property_end>` | ``Vector3(0, 0, 0)`` |
  24. +-------------------------------+-----------------------------------------------+----------------------+
  25. | :ref:`Vector3<class_Vector3>` | :ref:`position<class_AABB_property_position>` | ``Vector3(0, 0, 0)`` |
  26. +-------------------------------+-----------------------------------------------+----------------------+
  27. | :ref:`Vector3<class_Vector3>` | :ref:`size<class_AABB_property_size>` | ``Vector3(0, 0, 0)`` |
  28. +-------------------------------+-----------------------------------------------+----------------------+
  29. Constructors
  30. ------------
  31. +-------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`AABB<class_AABB>` | :ref:`AABB<class_AABB_constructor_AABB>` **(** **)** |
  33. +-------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`AABB<class_AABB>` | :ref:`AABB<class_AABB_constructor_AABB>` **(** :ref:`AABB<class_AABB>` from **)** |
  35. +-------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`AABB<class_AABB>` | :ref:`AABB<class_AABB_constructor_AABB>` **(** :ref:`Vector3<class_Vector3>` position, :ref:`Vector3<class_Vector3>` size **)** |
  37. +-------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  38. Methods
  39. -------
  40. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`AABB<class_AABB>` | :ref:`abs<class_AABB_method_abs>` **(** **)** |const| |
  42. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`encloses<class_AABB_method_encloses>` **(** :ref:`AABB<class_AABB>` with **)** |const| |
  44. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`AABB<class_AABB>` | :ref:`expand<class_AABB_method_expand>` **(** :ref:`Vector3<class_Vector3>` to_point **)** |const| |
  46. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Vector3<class_Vector3>` | :ref:`get_center<class_AABB_method_get_center>` **(** **)** |const| |
  48. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Vector3<class_Vector3>` | :ref:`get_endpoint<class_AABB_method_get_endpoint>` **(** :ref:`int<class_int>` idx **)** |const| |
  50. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Vector3<class_Vector3>` | :ref:`get_longest_axis<class_AABB_method_get_longest_axis>` **(** **)** |const| |
  52. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`int<class_int>` | :ref:`get_longest_axis_index<class_AABB_method_get_longest_axis_index>` **(** **)** |const| |
  54. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`float<class_float>` | :ref:`get_longest_axis_size<class_AABB_method_get_longest_axis_size>` **(** **)** |const| |
  56. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`Vector3<class_Vector3>` | :ref:`get_shortest_axis<class_AABB_method_get_shortest_axis>` **(** **)** |const| |
  58. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`int<class_int>` | :ref:`get_shortest_axis_index<class_AABB_method_get_shortest_axis_index>` **(** **)** |const| |
  60. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`float<class_float>` | :ref:`get_shortest_axis_size<class_AABB_method_get_shortest_axis_size>` **(** **)** |const| |
  62. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Vector3<class_Vector3>` | :ref:`get_support<class_AABB_method_get_support>` **(** :ref:`Vector3<class_Vector3>` dir **)** |const| |
  64. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`float<class_float>` | :ref:`get_volume<class_AABB_method_get_volume>` **(** **)** |const| |
  66. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`AABB<class_AABB>` | :ref:`grow<class_AABB_method_grow>` **(** :ref:`float<class_float>` by **)** |const| |
  68. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`bool<class_bool>` | :ref:`has_no_surface<class_AABB_method_has_no_surface>` **(** **)** |const| |
  70. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`bool<class_bool>` | :ref:`has_no_volume<class_AABB_method_has_no_volume>` **(** **)** |const| |
  72. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`bool<class_bool>` | :ref:`has_point<class_AABB_method_has_point>` **(** :ref:`Vector3<class_Vector3>` point **)** |const| |
  74. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`AABB<class_AABB>` | :ref:`intersection<class_AABB_method_intersection>` **(** :ref:`AABB<class_AABB>` with **)** |const| |
  76. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`bool<class_bool>` | :ref:`intersects<class_AABB_method_intersects>` **(** :ref:`AABB<class_AABB>` with **)** |const| |
  78. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`bool<class_bool>` | :ref:`intersects_plane<class_AABB_method_intersects_plane>` **(** :ref:`Plane<class_Plane>` plane **)** |const| |
  80. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`Variant<class_Variant>` | :ref:`intersects_ray<class_AABB_method_intersects_ray>` **(** :ref:`Vector3<class_Vector3>` from, :ref:`Vector3<class_Vector3>` dir **)** |const| |
  82. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`Variant<class_Variant>` | :ref:`intersects_segment<class_AABB_method_intersects_segment>` **(** :ref:`Vector3<class_Vector3>` from, :ref:`Vector3<class_Vector3>` to **)** |const| |
  84. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_AABB_method_is_equal_approx>` **(** :ref:`AABB<class_AABB>` aabb **)** |const| |
  86. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | :ref:`AABB<class_AABB>` | :ref:`merge<class_AABB_method_merge>` **(** :ref:`AABB<class_AABB>` with **)** |const| |
  88. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. Operators
  90. ---------
  91. +-------------------------+---------------------------------------------------------------------------------------------------------+
  92. | :ref:`bool<class_bool>` | :ref:`operator !=<class_AABB_operator_neq_bool>` **(** **)** |
  93. +-------------------------+---------------------------------------------------------------------------------------------------------+
  94. | :ref:`bool<class_bool>` | :ref:`operator !=<class_AABB_operator_neq_bool>` **(** :ref:`AABB<class_AABB>` right **)** |
  95. +-------------------------+---------------------------------------------------------------------------------------------------------+
  96. | :ref:`AABB<class_AABB>` | :ref:`operator *<class_AABB_operator_mul_AABB>` **(** :ref:`Transform3D<class_Transform3D>` right **)** |
  97. +-------------------------+---------------------------------------------------------------------------------------------------------+
  98. | :ref:`bool<class_bool>` | :ref:`operator ==<class_AABB_operator_eq_bool>` **(** **)** |
  99. +-------------------------+---------------------------------------------------------------------------------------------------------+
  100. | :ref:`bool<class_bool>` | :ref:`operator ==<class_AABB_operator_eq_bool>` **(** :ref:`AABB<class_AABB>` right **)** |
  101. +-------------------------+---------------------------------------------------------------------------------------------------------+
  102. Property Descriptions
  103. ---------------------
  104. .. _class_AABB_property_end:
  105. - :ref:`Vector3<class_Vector3>` **end**
  106. +-----------+----------------------+
  107. | *Default* | ``Vector3(0, 0, 0)`` |
  108. +-----------+----------------------+
  109. Ending corner. This is calculated as ``position + size``. Setting this value will change the size.
  110. ----
  111. .. _class_AABB_property_position:
  112. - :ref:`Vector3<class_Vector3>` **position**
  113. +-----------+----------------------+
  114. | *Default* | ``Vector3(0, 0, 0)`` |
  115. +-----------+----------------------+
  116. Beginning corner. Typically has values lower than :ref:`end<class_AABB_property_end>`.
  117. ----
  118. .. _class_AABB_property_size:
  119. - :ref:`Vector3<class_Vector3>` **size**
  120. +-----------+----------------------+
  121. | *Default* | ``Vector3(0, 0, 0)`` |
  122. +-----------+----------------------+
  123. Size from :ref:`position<class_AABB_property_position>` to :ref:`end<class_AABB_property_end>`. Typically, all components are positive.
  124. If the size is negative, you can use :ref:`abs<class_AABB_method_abs>` to fix it.
  125. Constructor Descriptions
  126. ------------------------
  127. .. _class_AABB_constructor_AABB:
  128. - :ref:`AABB<class_AABB>` **AABB** **(** **)**
  129. Constructs a default-initialized ``AABB`` with default (zero) values of :ref:`position<class_AABB_property_position>` and :ref:`size<class_AABB_property_size>`.
  130. ----
  131. - :ref:`AABB<class_AABB>` **AABB** **(** :ref:`AABB<class_AABB>` from **)**
  132. Constructs an ``AABB`` as a copy of the given ``AABB``.
  133. ----
  134. - :ref:`AABB<class_AABB>` **AABB** **(** :ref:`Vector3<class_Vector3>` position, :ref:`Vector3<class_Vector3>` size **)**
  135. Constructs an ``AABB`` from a position and size.
  136. Method Descriptions
  137. -------------------
  138. .. _class_AABB_method_abs:
  139. - :ref:`AABB<class_AABB>` **abs** **(** **)** |const|
  140. Returns an AABB with equivalent position and size, modified so that the most-negative corner is the origin and the size is positive.
  141. ----
  142. .. _class_AABB_method_encloses:
  143. - :ref:`bool<class_bool>` **encloses** **(** :ref:`AABB<class_AABB>` with **)** |const|
  144. Returns ``true`` if this ``AABB`` completely encloses another one.
  145. ----
  146. .. _class_AABB_method_expand:
  147. - :ref:`AABB<class_AABB>` **expand** **(** :ref:`Vector3<class_Vector3>` to_point **)** |const|
  148. Returns a copy of this ``AABB`` expanded to include a given point.
  149. \ **Example:**\
  150. .. tabs::
  151. .. code-tab:: gdscript
  152. # position (-3, 2, 0), size (1, 1, 1)
  153. var box = AABB(Vector3(-3, 2, 0), Vector3(1, 1, 1))
  154. # position (-3, -1, 0), size (3, 4, 2), so we fit both the original AABB and Vector3(0, -1, 2)
  155. var box2 = box.expand(Vector3(0, -1, 2))
  156. .. code-tab:: csharp
  157. // position (-3, 2, 0), size (1, 1, 1)
  158. var box = new AABB(new Vector3(-3, 2, 0), new Vector3(1, 1, 1));
  159. // position (-3, -1, 0), size (3, 4, 2), so we fit both the original AABB and Vector3(0, -1, 2)
  160. var box2 = box.Expand(new Vector3(0, -1, 2));
  161. ----
  162. .. _class_AABB_method_get_center:
  163. - :ref:`Vector3<class_Vector3>` **get_center** **(** **)** |const|
  164. Returns the center of the ``AABB``, which is equal to :ref:`position<class_AABB_property_position>` + (:ref:`size<class_AABB_property_size>` / 2).
  165. ----
  166. .. _class_AABB_method_get_endpoint:
  167. - :ref:`Vector3<class_Vector3>` **get_endpoint** **(** :ref:`int<class_int>` idx **)** |const|
  168. Gets the position of the 8 endpoints of the ``AABB`` in space.
  169. ----
  170. .. _class_AABB_method_get_longest_axis:
  171. - :ref:`Vector3<class_Vector3>` **get_longest_axis** **(** **)** |const|
  172. Returns the normalized longest axis of the ``AABB``.
  173. ----
  174. .. _class_AABB_method_get_longest_axis_index:
  175. - :ref:`int<class_int>` **get_longest_axis_index** **(** **)** |const|
  176. Returns the index of the longest axis of the ``AABB`` (according to :ref:`Vector3<class_Vector3>`'s ``AXIS_*`` constants).
  177. ----
  178. .. _class_AABB_method_get_longest_axis_size:
  179. - :ref:`float<class_float>` **get_longest_axis_size** **(** **)** |const|
  180. Returns the scalar length of the longest axis of the ``AABB``.
  181. ----
  182. .. _class_AABB_method_get_shortest_axis:
  183. - :ref:`Vector3<class_Vector3>` **get_shortest_axis** **(** **)** |const|
  184. Returns the normalized shortest axis of the ``AABB``.
  185. ----
  186. .. _class_AABB_method_get_shortest_axis_index:
  187. - :ref:`int<class_int>` **get_shortest_axis_index** **(** **)** |const|
  188. Returns the index of the shortest axis of the ``AABB`` (according to :ref:`Vector3<class_Vector3>`::AXIS\* enum).
  189. ----
  190. .. _class_AABB_method_get_shortest_axis_size:
  191. - :ref:`float<class_float>` **get_shortest_axis_size** **(** **)** |const|
  192. Returns the scalar length of the shortest axis of the ``AABB``.
  193. ----
  194. .. _class_AABB_method_get_support:
  195. - :ref:`Vector3<class_Vector3>` **get_support** **(** :ref:`Vector3<class_Vector3>` dir **)** |const|
  196. Returns the support point in a given direction. This is useful for collision detection algorithms.
  197. ----
  198. .. _class_AABB_method_get_volume:
  199. - :ref:`float<class_float>` **get_volume** **(** **)** |const|
  200. Returns the volume of the ``AABB``.
  201. ----
  202. .. _class_AABB_method_grow:
  203. - :ref:`AABB<class_AABB>` **grow** **(** :ref:`float<class_float>` by **)** |const|
  204. Returns a copy of the ``AABB`` grown a given amount of units towards all the sides.
  205. ----
  206. .. _class_AABB_method_has_no_surface:
  207. - :ref:`bool<class_bool>` **has_no_surface** **(** **)** |const|
  208. Returns ``true`` if the ``AABB`` is empty.
  209. ----
  210. .. _class_AABB_method_has_no_volume:
  211. - :ref:`bool<class_bool>` **has_no_volume** **(** **)** |const|
  212. Returns ``true`` if the ``AABB`` is flat or empty.
  213. ----
  214. .. _class_AABB_method_has_point:
  215. - :ref:`bool<class_bool>` **has_point** **(** :ref:`Vector3<class_Vector3>` point **)** |const|
  216. 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.
  217. \ **Note:** This method is not reliable for ``AABB`` with a *negative size*. Use :ref:`abs<class_AABB_method_abs>` to get a positive sized equivalent ``AABB`` to check for contained points.
  218. ----
  219. .. _class_AABB_method_intersection:
  220. - :ref:`AABB<class_AABB>` **intersection** **(** :ref:`AABB<class_AABB>` with **)** |const|
  221. Returns the intersection between two ``AABB``. An empty AABB (size ``(0, 0, 0)``) is returned on failure.
  222. ----
  223. .. _class_AABB_method_intersects:
  224. - :ref:`bool<class_bool>` **intersects** **(** :ref:`AABB<class_AABB>` with **)** |const|
  225. Returns ``true`` if the ``AABB`` overlaps with another.
  226. ----
  227. .. _class_AABB_method_intersects_plane:
  228. - :ref:`bool<class_bool>` **intersects_plane** **(** :ref:`Plane<class_Plane>` plane **)** |const|
  229. Returns ``true`` if the ``AABB`` is on both sides of a plane.
  230. ----
  231. .. _class_AABB_method_intersects_ray:
  232. - :ref:`Variant<class_Variant>` **intersects_ray** **(** :ref:`Vector3<class_Vector3>` from, :ref:`Vector3<class_Vector3>` dir **)** |const|
  233. ----
  234. .. _class_AABB_method_intersects_segment:
  235. - :ref:`Variant<class_Variant>` **intersects_segment** **(** :ref:`Vector3<class_Vector3>` from, :ref:`Vector3<class_Vector3>` to **)** |const|
  236. Returns ``true`` if the ``AABB`` intersects the line segment between ``from`` and ``to``.
  237. ----
  238. .. _class_AABB_method_is_equal_approx:
  239. - :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`AABB<class_AABB>` aabb **)** |const|
  240. Returns ``true`` if this ``AABB`` and ``aabb`` are approximately equal, by calling :ref:`@GlobalScope.is_equal_approx<class_@GlobalScope_method_is_equal_approx>` on each component.
  241. ----
  242. .. _class_AABB_method_merge:
  243. - :ref:`AABB<class_AABB>` **merge** **(** :ref:`AABB<class_AABB>` with **)** |const|
  244. Returns a larger ``AABB`` that contains both this ``AABB`` and ``with``.
  245. Operator Descriptions
  246. ---------------------
  247. .. _class_AABB_operator_neq_bool:
  248. - :ref:`bool<class_bool>` **operator !=** **(** **)**
  249. ----
  250. - :ref:`bool<class_bool>` **operator !=** **(** :ref:`AABB<class_AABB>` right **)**
  251. Returns ``true`` if the vectors are not equal.
  252. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_AABB_method_is_equal_approx>` instead, which is more reliable.
  253. ----
  254. .. _class_AABB_operator_mul_AABB:
  255. - :ref:`AABB<class_AABB>` **operator *** **(** :ref:`Transform3D<class_Transform3D>` right **)**
  256. Inversely transforms (multiplies) the ``AABB`` by the given :ref:`Transform3D<class_Transform3D>` transformation matrix.
  257. ----
  258. .. _class_AABB_operator_eq_bool:
  259. - :ref:`bool<class_bool>` **operator ==** **(** **)**
  260. ----
  261. - :ref:`bool<class_bool>` **operator ==** **(** :ref:`AABB<class_AABB>` right **)**
  262. Returns ``true`` if the AABBs are exactly equal.
  263. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_AABB_method_is_equal_approx>` instead, which is more reliable.
  264. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  265. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  266. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  267. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  268. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  269. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`