class_vector3.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the Vector3.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_Vector3:
  5. Vector3
  6. =======
  7. **Category:** Built-In Types
  8. Brief Description
  9. -----------------
  10. Vector class, which performs basic 3D vector math operations.
  11. Properties
  12. ----------
  13. +---------------------------+------------------------------------+
  14. | :ref:`float<class_float>` | :ref:`x<class_Vector3_property_x>` |
  15. +---------------------------+------------------------------------+
  16. | :ref:`float<class_float>` | :ref:`y<class_Vector3_property_y>` |
  17. +---------------------------+------------------------------------+
  18. | :ref:`float<class_float>` | :ref:`z<class_Vector3_property_z>` |
  19. +---------------------------+------------------------------------+
  20. Methods
  21. -------
  22. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`Vector3<class_Vector3>` | :ref:`Vector3<class_Vector3_method_Vector3>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y, :ref:`float<class_float>` z **)** |
  24. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`Vector3<class_Vector3>` | :ref:`abs<class_Vector3_method_abs>` **(** **)** |
  26. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`float<class_float>` | :ref:`angle_to<class_Vector3_method_angle_to>` **(** :ref:`Vector3<class_Vector3>` to **)** |
  28. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Vector3<class_Vector3>` | :ref:`bounce<class_Vector3_method_bounce>` **(** :ref:`Vector3<class_Vector3>` n **)** |
  30. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Vector3<class_Vector3>` | :ref:`ceil<class_Vector3_method_ceil>` **(** **)** |
  32. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Vector3<class_Vector3>` | :ref:`cross<class_Vector3_method_cross>` **(** :ref:`Vector3<class_Vector3>` b **)** |
  34. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Vector3<class_Vector3>` | :ref:`cubic_interpolate<class_Vector3_method_cubic_interpolate>` **(** :ref:`Vector3<class_Vector3>` b, :ref:`Vector3<class_Vector3>` pre_a, :ref:`Vector3<class_Vector3>` post_b, :ref:`float<class_float>` t **)** |
  36. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`float<class_float>` | :ref:`distance_squared_to<class_Vector3_method_distance_squared_to>` **(** :ref:`Vector3<class_Vector3>` b **)** |
  38. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`float<class_float>` | :ref:`distance_to<class_Vector3_method_distance_to>` **(** :ref:`Vector3<class_Vector3>` b **)** |
  40. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`float<class_float>` | :ref:`dot<class_Vector3_method_dot>` **(** :ref:`Vector3<class_Vector3>` b **)** |
  42. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Vector3<class_Vector3>` | :ref:`floor<class_Vector3_method_floor>` **(** **)** |
  44. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Vector3<class_Vector3>` | :ref:`inverse<class_Vector3_method_inverse>` **(** **)** |
  46. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`is_normalized<class_Vector3_method_is_normalized>` **(** **)** |
  48. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`float<class_float>` | :ref:`length<class_Vector3_method_length>` **(** **)** |
  50. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`float<class_float>` | :ref:`length_squared<class_Vector3_method_length_squared>` **(** **)** |
  52. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`Vector3<class_Vector3>` | :ref:`linear_interpolate<class_Vector3_method_linear_interpolate>` **(** :ref:`Vector3<class_Vector3>` b, :ref:`float<class_float>` t **)** |
  54. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`int<class_int>` | :ref:`max_axis<class_Vector3_method_max_axis>` **(** **)** |
  56. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`int<class_int>` | :ref:`min_axis<class_Vector3_method_min_axis>` **(** **)** |
  58. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`Vector3<class_Vector3>` | :ref:`normalized<class_Vector3_method_normalized>` **(** **)** |
  60. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Basis<class_Basis>` | :ref:`outer<class_Vector3_method_outer>` **(** :ref:`Vector3<class_Vector3>` b **)** |
  62. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Vector3<class_Vector3>` | :ref:`project<class_Vector3_method_project>` **(** :ref:`Vector3<class_Vector3>` b **)** |
  64. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Vector3<class_Vector3>` | :ref:`reflect<class_Vector3_method_reflect>` **(** :ref:`Vector3<class_Vector3>` n **)** |
  66. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`Vector3<class_Vector3>` | :ref:`rotated<class_Vector3_method_rotated>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` phi **)** |
  68. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`Vector3<class_Vector3>` | :ref:`round<class_Vector3_method_round>` **(** **)** |
  70. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`Vector3<class_Vector3>` | :ref:`slerp<class_Vector3_method_slerp>` **(** :ref:`Vector3<class_Vector3>` b, :ref:`float<class_float>` t **)** |
  72. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Vector3<class_Vector3>` | :ref:`slide<class_Vector3_method_slide>` **(** :ref:`Vector3<class_Vector3>` n **)** |
  74. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`Vector3<class_Vector3>` | :ref:`snapped<class_Vector3_method_snapped>` **(** :ref:`Vector3<class_Vector3>` by **)** |
  76. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`Basis<class_Basis>` | :ref:`to_diagonal_matrix<class_Vector3_method_to_diagonal_matrix>` **(** **)** |
  78. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. Constants
  80. ---------
  81. .. _class_Vector3_constant_AXIS_X:
  82. .. _class_Vector3_constant_AXIS_Y:
  83. .. _class_Vector3_constant_AXIS_Z:
  84. .. _class_Vector3_constant_ZERO:
  85. .. _class_Vector3_constant_ONE:
  86. .. _class_Vector3_constant_INF:
  87. .. _class_Vector3_constant_LEFT:
  88. .. _class_Vector3_constant_RIGHT:
  89. .. _class_Vector3_constant_UP:
  90. .. _class_Vector3_constant_DOWN:
  91. .. _class_Vector3_constant_FORWARD:
  92. .. _class_Vector3_constant_BACK:
  93. - **AXIS_X** = **0** --- Enumerated value for the X axis. Returned by :ref:`max_axis<class_Vector3_method_max_axis>` and :ref:`min_axis<class_Vector3_method_min_axis>`.
  94. - **AXIS_Y** = **1** --- Enumerated value for the Y axis.
  95. - **AXIS_Z** = **2** --- Enumerated value for the Z axis.
  96. - **ZERO** = **Vector3( 0, 0, 0 )** --- Zero vector.
  97. - **ONE** = **Vector3( 1, 1, 1 )** --- One vector.
  98. - **INF** = **Vector3( inf, inf, inf )** --- Infinite vector.
  99. - **LEFT** = **Vector3( -1, 0, 0 )** --- Left unit vector.
  100. - **RIGHT** = **Vector3( 1, 0, 0 )** --- Right unit vector.
  101. - **UP** = **Vector3( 0, 1, 0 )** --- Up unit vector.
  102. - **DOWN** = **Vector3( 0, -1, 0 )** --- Down unit vector.
  103. - **FORWARD** = **Vector3( 0, 0, -1 )** --- Forward unit vector.
  104. - **BACK** = **Vector3( 0, 0, 1 )** --- Back unit vector.
  105. Description
  106. -----------
  107. Vector3 is one of the core classes of the engine, and includes several built-in helper functions to perform basic vector math operations.
  108. Tutorials
  109. ---------
  110. - :doc:`../tutorials/math/index`
  111. Property Descriptions
  112. ---------------------
  113. .. _class_Vector3_property_x:
  114. - :ref:`float<class_float>` **x**
  115. The vector's x component. Also accessible by using the index position ``[0]``.
  116. .. _class_Vector3_property_y:
  117. - :ref:`float<class_float>` **y**
  118. The vector's y component. Also accessible by using the index position ``[1]``.
  119. .. _class_Vector3_property_z:
  120. - :ref:`float<class_float>` **z**
  121. The vector's z component. Also accessible by using the index position ``[2]``.
  122. Method Descriptions
  123. -------------------
  124. .. _class_Vector3_method_Vector3:
  125. - :ref:`Vector3<class_Vector3>` **Vector3** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y, :ref:`float<class_float>` z **)**
  126. Returns a Vector3 with the given components.
  127. .. _class_Vector3_method_abs:
  128. - :ref:`Vector3<class_Vector3>` **abs** **(** **)**
  129. Returns a new vector with all components in absolute values (i.e. positive).
  130. .. _class_Vector3_method_angle_to:
  131. - :ref:`float<class_float>` **angle_to** **(** :ref:`Vector3<class_Vector3>` to **)**
  132. Returns the minimum angle to the given vector.
  133. .. _class_Vector3_method_bounce:
  134. - :ref:`Vector3<class_Vector3>` **bounce** **(** :ref:`Vector3<class_Vector3>` n **)**
  135. Returns the vector "bounced off" from a plane defined by the given normal.
  136. .. _class_Vector3_method_ceil:
  137. - :ref:`Vector3<class_Vector3>` **ceil** **(** **)**
  138. Returns a new vector with all components rounded up.
  139. .. _class_Vector3_method_cross:
  140. - :ref:`Vector3<class_Vector3>` **cross** **(** :ref:`Vector3<class_Vector3>` b **)**
  141. Returns the cross product with ``b``.
  142. .. _class_Vector3_method_cubic_interpolate:
  143. - :ref:`Vector3<class_Vector3>` **cubic_interpolate** **(** :ref:`Vector3<class_Vector3>` b, :ref:`Vector3<class_Vector3>` pre_a, :ref:`Vector3<class_Vector3>` post_b, :ref:`float<class_float>` t **)**
  144. Performs a cubic interpolation between vectors ``pre_a``, ``a``, ``b``, ``post_b`` (``a`` is current), by the given amount ``t``. ``t`` is in the range of ``0.0 - 1.0``, representing the amount of interpolation.
  145. .. _class_Vector3_method_distance_squared_to:
  146. - :ref:`float<class_float>` **distance_squared_to** **(** :ref:`Vector3<class_Vector3>` b **)**
  147. Returns the squared distance to ``b``. Prefer this function over :ref:`distance_to<class_Vector3_method_distance_to>` if you need to sort vectors or need the squared distance for some formula.
  148. .. _class_Vector3_method_distance_to:
  149. - :ref:`float<class_float>` **distance_to** **(** :ref:`Vector3<class_Vector3>` b **)**
  150. Returns the distance to ``b``.
  151. .. _class_Vector3_method_dot:
  152. - :ref:`float<class_float>` **dot** **(** :ref:`Vector3<class_Vector3>` b **)**
  153. Returns the dot product with ``b``.
  154. .. _class_Vector3_method_floor:
  155. - :ref:`Vector3<class_Vector3>` **floor** **(** **)**
  156. Returns a new vector with all components rounded down.
  157. .. _class_Vector3_method_inverse:
  158. - :ref:`Vector3<class_Vector3>` **inverse** **(** **)**
  159. Returns the inverse of the vector. This is the same as ``Vector3( 1.0 / v.x, 1.0 / v.y, 1.0 / v.z )``.
  160. .. _class_Vector3_method_is_normalized:
  161. - :ref:`bool<class_bool>` **is_normalized** **(** **)**
  162. Returns ``true`` if the vector is normalized.
  163. .. _class_Vector3_method_length:
  164. - :ref:`float<class_float>` **length** **(** **)**
  165. Returns the vector's length.
  166. .. _class_Vector3_method_length_squared:
  167. - :ref:`float<class_float>` **length_squared** **(** **)**
  168. Returns the vector's length squared. Prefer this function over :ref:`length<class_Vector3_method_length>` if you need to sort vectors or need the squared length for some formula.
  169. .. _class_Vector3_method_linear_interpolate:
  170. - :ref:`Vector3<class_Vector3>` **linear_interpolate** **(** :ref:`Vector3<class_Vector3>` b, :ref:`float<class_float>` t **)**
  171. Returns the result of the linear interpolation between this vector and ``b`` by amount ``t``. ``t`` is in the range of ``0.0 - 1.0``, representing the amount of interpolation..
  172. .. _class_Vector3_method_max_axis:
  173. - :ref:`int<class_int>` **max_axis** **(** **)**
  174. Returns the axis of the vector's largest value. See ``AXIS_*`` constants.
  175. .. _class_Vector3_method_min_axis:
  176. - :ref:`int<class_int>` **min_axis** **(** **)**
  177. Returns the axis of the vector's smallest value. See ``AXIS_*`` constants.
  178. .. _class_Vector3_method_normalized:
  179. - :ref:`Vector3<class_Vector3>` **normalized** **(** **)**
  180. Returns the vector scaled to unit length. Equivalent to ``v / v.length()``.
  181. .. _class_Vector3_method_outer:
  182. - :ref:`Basis<class_Basis>` **outer** **(** :ref:`Vector3<class_Vector3>` b **)**
  183. Returns the outer product with ``b``.
  184. .. _class_Vector3_method_project:
  185. - :ref:`Vector3<class_Vector3>` **project** **(** :ref:`Vector3<class_Vector3>` b **)**
  186. Returns the vector projected onto the vector ``b``.
  187. .. _class_Vector3_method_reflect:
  188. - :ref:`Vector3<class_Vector3>` **reflect** **(** :ref:`Vector3<class_Vector3>` n **)**
  189. Returns the vector reflected from a plane defined by the given normal.
  190. .. _class_Vector3_method_rotated:
  191. - :ref:`Vector3<class_Vector3>` **rotated** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` phi **)**
  192. Rotates the vector around a given axis by ``phi`` radians. The axis must be a normalized vector.
  193. .. _class_Vector3_method_round:
  194. - :ref:`Vector3<class_Vector3>` **round** **(** **)**
  195. Returns the vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
  196. .. _class_Vector3_method_slerp:
  197. - :ref:`Vector3<class_Vector3>` **slerp** **(** :ref:`Vector3<class_Vector3>` b, :ref:`float<class_float>` t **)**
  198. Returns the result of SLERP between this vector and ``b``, by amount ``t``. ``t`` is in the range of ``0.0 - 1.0``, representing the amount of interpolation.
  199. Both vectors need to be normalized.
  200. .. _class_Vector3_method_slide:
  201. - :ref:`Vector3<class_Vector3>` **slide** **(** :ref:`Vector3<class_Vector3>` n **)**
  202. Returns the component of the vector along a plane defined by the given normal.
  203. .. _class_Vector3_method_snapped:
  204. - :ref:`Vector3<class_Vector3>` **snapped** **(** :ref:`Vector3<class_Vector3>` by **)**
  205. Returns a copy of the vector, snapped to the lowest neared multiple.
  206. .. _class_Vector3_method_to_diagonal_matrix:
  207. - :ref:`Basis<class_Basis>` **to_diagonal_matrix** **(** **)**
  208. Returns a diagonal matrix with the vector as main diagonal.