class_aabb.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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:`../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>` **(** :ref:`Vector3<class_Vector3>` position, :ref:`Vector3<class_Vector3>` size **)** |
  32. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`AABB<class_AABB>` | :ref:`abs<class_AABB_method_abs>` **(** **)** |
  34. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`bool<class_bool>` | :ref:`encloses<class_AABB_method_encloses>` **(** :ref:`AABB<class_AABB>` with **)** |
  36. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`AABB<class_AABB>` | :ref:`expand<class_AABB_method_expand>` **(** :ref:`Vector3<class_Vector3>` to_point **)** |
  38. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`float<class_float>` | :ref:`get_area<class_AABB_method_get_area>` **(** **)** |
  40. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Vector3<class_Vector3>` | :ref:`get_endpoint<class_AABB_method_get_endpoint>` **(** :ref:`int<class_int>` idx **)** |
  42. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Vector3<class_Vector3>` | :ref:`get_longest_axis<class_AABB_method_get_longest_axis>` **(** **)** |
  44. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`int<class_int>` | :ref:`get_longest_axis_index<class_AABB_method_get_longest_axis_index>` **(** **)** |
  46. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`float<class_float>` | :ref:`get_longest_axis_size<class_AABB_method_get_longest_axis_size>` **(** **)** |
  48. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Vector3<class_Vector3>` | :ref:`get_shortest_axis<class_AABB_method_get_shortest_axis>` **(** **)** |
  50. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`int<class_int>` | :ref:`get_shortest_axis_index<class_AABB_method_get_shortest_axis_index>` **(** **)** |
  52. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`float<class_float>` | :ref:`get_shortest_axis_size<class_AABB_method_get_shortest_axis_size>` **(** **)** |
  54. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Vector3<class_Vector3>` | :ref:`get_support<class_AABB_method_get_support>` **(** :ref:`Vector3<class_Vector3>` dir **)** |
  56. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`AABB<class_AABB>` | :ref:`grow<class_AABB_method_grow>` **(** :ref:`float<class_float>` by **)** |
  58. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`bool<class_bool>` | :ref:`has_no_area<class_AABB_method_has_no_area>` **(** **)** |
  60. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`bool<class_bool>` | :ref:`has_no_surface<class_AABB_method_has_no_surface>` **(** **)** |
  62. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`bool<class_bool>` | :ref:`has_point<class_AABB_method_has_point>` **(** :ref:`Vector3<class_Vector3>` point **)** |
  64. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`AABB<class_AABB>` | :ref:`intersection<class_AABB_method_intersection>` **(** :ref:`AABB<class_AABB>` with **)** |
  66. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`bool<class_bool>` | :ref:`intersects<class_AABB_method_intersects>` **(** :ref:`AABB<class_AABB>` with **)** |
  68. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`bool<class_bool>` | :ref:`intersects_plane<class_AABB_method_intersects_plane>` **(** :ref:`Plane<class_Plane>` plane **)** |
  70. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`bool<class_bool>` | :ref:`intersects_segment<class_AABB_method_intersects_segment>` **(** :ref:`Vector3<class_Vector3>` from, :ref:`Vector3<class_Vector3>` to **)** |
  72. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_AABB_method_is_equal_approx>` **(** :ref:`AABB<class_AABB>` aabb **)** |
  74. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`AABB<class_AABB>` | :ref:`merge<class_AABB_method_merge>` **(** :ref:`AABB<class_AABB>` with **)** |
  76. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  77. Property Descriptions
  78. ---------------------
  79. .. _class_AABB_property_end:
  80. - :ref:`Vector3<class_Vector3>` **end**
  81. +-----------+------------------------+
  82. | *Default* | ``Vector3( 0, 0, 0 )`` |
  83. +-----------+------------------------+
  84. Ending corner. This is calculated as ``position + size``. Setting this value will change the size.
  85. ----
  86. .. _class_AABB_property_position:
  87. - :ref:`Vector3<class_Vector3>` **position**
  88. +-----------+------------------------+
  89. | *Default* | ``Vector3( 0, 0, 0 )`` |
  90. +-----------+------------------------+
  91. Beginning corner. Typically has values lower than :ref:`end<class_AABB_property_end>`.
  92. ----
  93. .. _class_AABB_property_size:
  94. - :ref:`Vector3<class_Vector3>` **size**
  95. +-----------+------------------------+
  96. | *Default* | ``Vector3( 0, 0, 0 )`` |
  97. +-----------+------------------------+
  98. Size from :ref:`position<class_AABB_property_position>` to :ref:`end<class_AABB_property_end>`. Typically, all components are positive.
  99. If the size is negative, you can use :ref:`abs<class_AABB_method_abs>` to fix it.
  100. Method Descriptions
  101. -------------------
  102. .. _class_AABB_method_AABB:
  103. - :ref:`AABB<class_AABB>` **AABB** **(** :ref:`Vector3<class_Vector3>` position, :ref:`Vector3<class_Vector3>` size **)**
  104. Constructs an ``AABB`` from a position and size.
  105. ----
  106. .. _class_AABB_method_abs:
  107. - :ref:`AABB<class_AABB>` **abs** **(** **)**
  108. Returns an AABB with equivalent position and size, modified so that the most-negative corner is the origin and the size is positive.
  109. ----
  110. .. _class_AABB_method_encloses:
  111. - :ref:`bool<class_bool>` **encloses** **(** :ref:`AABB<class_AABB>` with **)**
  112. Returns ``true`` if this ``AABB`` completely encloses another one.
  113. ----
  114. .. _class_AABB_method_expand:
  115. - :ref:`AABB<class_AABB>` **expand** **(** :ref:`Vector3<class_Vector3>` to_point **)**
  116. Returns a copy of this ``AABB`` expanded to include a given point.
  117. **Example:**
  118. ::
  119. # position (-3, 2, 0), size (1, 1, 1)
  120. var box = AABB(Vector3(-3, 2, 0), Vector3(1, 1, 1))
  121. # position (-3, -1, 0), size (3, 4, 2), so we fit both the original AABB and Vector3(0, -1, 2)
  122. var box2 = box.expand(Vector3(0, -1, 2))
  123. ----
  124. .. _class_AABB_method_get_area:
  125. - :ref:`float<class_float>` **get_area** **(** **)**
  126. Returns the volume of the ``AABB``.
  127. ----
  128. .. _class_AABB_method_get_endpoint:
  129. - :ref:`Vector3<class_Vector3>` **get_endpoint** **(** :ref:`int<class_int>` idx **)**
  130. Gets the position of the 8 endpoints of the ``AABB`` in space.
  131. ----
  132. .. _class_AABB_method_get_longest_axis:
  133. - :ref:`Vector3<class_Vector3>` **get_longest_axis** **(** **)**
  134. Returns the normalized longest axis of the ``AABB``.
  135. ----
  136. .. _class_AABB_method_get_longest_axis_index:
  137. - :ref:`int<class_int>` **get_longest_axis_index** **(** **)**
  138. Returns the index of the longest axis of the ``AABB`` (according to :ref:`Vector3<class_Vector3>`'s ``AXIS_*`` constants).
  139. ----
  140. .. _class_AABB_method_get_longest_axis_size:
  141. - :ref:`float<class_float>` **get_longest_axis_size** **(** **)**
  142. Returns the scalar length of the longest axis of the ``AABB``.
  143. ----
  144. .. _class_AABB_method_get_shortest_axis:
  145. - :ref:`Vector3<class_Vector3>` **get_shortest_axis** **(** **)**
  146. Returns the normalized shortest axis of the ``AABB``.
  147. ----
  148. .. _class_AABB_method_get_shortest_axis_index:
  149. - :ref:`int<class_int>` **get_shortest_axis_index** **(** **)**
  150. Returns the index of the shortest axis of the ``AABB`` (according to :ref:`Vector3<class_Vector3>`::AXIS\* enum).
  151. ----
  152. .. _class_AABB_method_get_shortest_axis_size:
  153. - :ref:`float<class_float>` **get_shortest_axis_size** **(** **)**
  154. Returns the scalar length of the shortest axis of the ``AABB``.
  155. ----
  156. .. _class_AABB_method_get_support:
  157. - :ref:`Vector3<class_Vector3>` **get_support** **(** :ref:`Vector3<class_Vector3>` dir **)**
  158. Returns the support point in a given direction. This is useful for collision detection algorithms.
  159. ----
  160. .. _class_AABB_method_grow:
  161. - :ref:`AABB<class_AABB>` **grow** **(** :ref:`float<class_float>` by **)**
  162. Returns a copy of the ``AABB`` grown a given amount of units towards all the sides.
  163. ----
  164. .. _class_AABB_method_has_no_area:
  165. - :ref:`bool<class_bool>` **has_no_area** **(** **)**
  166. Returns ``true`` if the ``AABB`` is flat or empty.
  167. ----
  168. .. _class_AABB_method_has_no_surface:
  169. - :ref:`bool<class_bool>` **has_no_surface** **(** **)**
  170. Returns ``true`` if the ``AABB`` is empty.
  171. ----
  172. .. _class_AABB_method_has_point:
  173. - :ref:`bool<class_bool>` **has_point** **(** :ref:`Vector3<class_Vector3>` point **)**
  174. Returns ``true`` if the ``AABB`` contains a point.
  175. ----
  176. .. _class_AABB_method_intersection:
  177. - :ref:`AABB<class_AABB>` **intersection** **(** :ref:`AABB<class_AABB>` with **)**
  178. Returns the intersection between two ``AABB``. An empty AABB (size 0,0,0) is returned on failure.
  179. ----
  180. .. _class_AABB_method_intersects:
  181. - :ref:`bool<class_bool>` **intersects** **(** :ref:`AABB<class_AABB>` with **)**
  182. Returns ``true`` if the ``AABB`` overlaps with another.
  183. ----
  184. .. _class_AABB_method_intersects_plane:
  185. - :ref:`bool<class_bool>` **intersects_plane** **(** :ref:`Plane<class_Plane>` plane **)**
  186. Returns ``true`` if the ``AABB`` is on both sides of a plane.
  187. ----
  188. .. _class_AABB_method_intersects_segment:
  189. - :ref:`bool<class_bool>` **intersects_segment** **(** :ref:`Vector3<class_Vector3>` from, :ref:`Vector3<class_Vector3>` to **)**
  190. Returns ``true`` if the ``AABB`` intersects the line segment between ``from`` and ``to``.
  191. ----
  192. .. _class_AABB_method_is_equal_approx:
  193. - :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`AABB<class_AABB>` aabb **)**
  194. Returns ``true`` if this ``AABB`` and ``aabb`` are approximately equal, by calling :ref:`@GDScript.is_equal_approx<class_@GDScript_method_is_equal_approx>` on each component.
  195. ----
  196. .. _class_AABB_method_merge:
  197. - :ref:`AABB<class_AABB>` **merge** **(** :ref:`AABB<class_AABB>` with **)**
  198. Returns a larger ``AABB`` that contains both this ``AABB`` and ``with``.
  199. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  200. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  201. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`