class_aabb.rst 21 KB

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