class_aabb.rst 22 KB

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