class_quat.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Quat.xml.
  6. .. _class_Quat:
  7. Quat
  8. ====
  9. Quaternion.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. A unit quaternion used for representing 3D rotations. Quaternions need to be normalized to be used for rotation.
  14. It is similar to Basis, which implements matrix representation of rotations, and can be parametrized using both an axis-angle pair or Euler angles. Basis stores rotation, scale, and shearing, while Quat only stores rotation.
  15. Due to its compactness and the way it is stored in memory, certain operations (obtaining axis-angle and performing SLERP, in particular) are more efficient and robust against floating-point errors.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - `Using 3D transforms <../tutorials/3d/using_transforms.html#interpolating-with-quaternions>`__
  20. - `Third Person Shooter Demo <https://godotengine.org/asset-library/asset/678>`__
  21. .. rst-class:: classref-reftable-group
  22. Properties
  23. ----------
  24. .. table::
  25. :widths: auto
  26. +---------------------------+---------------------------------+---------+
  27. | :ref:`float<class_float>` | :ref:`w<class_Quat_property_w>` | ``1.0`` |
  28. +---------------------------+---------------------------------+---------+
  29. | :ref:`float<class_float>` | :ref:`x<class_Quat_property_x>` | ``0.0`` |
  30. +---------------------------+---------------------------------+---------+
  31. | :ref:`float<class_float>` | :ref:`y<class_Quat_property_y>` | ``0.0`` |
  32. +---------------------------+---------------------------------+---------+
  33. | :ref:`float<class_float>` | :ref:`z<class_Quat_property_z>` | ``0.0`` |
  34. +---------------------------+---------------------------------+---------+
  35. .. rst-class:: classref-reftable-group
  36. Methods
  37. -------
  38. .. table::
  39. :widths: auto
  40. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Quat<class_Quat>` | :ref:`Quat<class_Quat_method_Quat>` **(** :ref:`Basis<class_Basis>` from **)** |
  42. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Quat<class_Quat>` | :ref:`Quat<class_Quat_method_Quat>` **(** :ref:`Vector3<class_Vector3>` euler **)** |
  44. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Quat<class_Quat>` | :ref:`Quat<class_Quat_method_Quat>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |
  46. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Quat<class_Quat>` | :ref:`Quat<class_Quat_method_Quat>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y, :ref:`float<class_float>` z, :ref:`float<class_float>` w **)** |
  48. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`float<class_float>` | :ref:`angle_to<class_Quat_method_angle_to>` **(** :ref:`Quat<class_Quat>` to **)** |
  50. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Quat<class_Quat>` | :ref:`cubic_slerp<class_Quat_method_cubic_slerp>` **(** :ref:`Quat<class_Quat>` b, :ref:`Quat<class_Quat>` pre_a, :ref:`Quat<class_Quat>` post_b, :ref:`float<class_float>` weight **)** |
  52. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`float<class_float>` | :ref:`dot<class_Quat_method_dot>` **(** :ref:`Quat<class_Quat>` b **)** |
  54. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Vector3<class_Vector3>` | :ref:`get_euler<class_Quat_method_get_euler>` **(** **)** |
  56. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`Quat<class_Quat>` | :ref:`inverse<class_Quat_method_inverse>` **(** **)** |
  58. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Quat_method_is_equal_approx>` **(** :ref:`Quat<class_Quat>` quat **)** |
  60. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`bool<class_bool>` | :ref:`is_normalized<class_Quat_method_is_normalized>` **(** **)** |
  62. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`float<class_float>` | :ref:`length<class_Quat_method_length>` **(** **)** |
  64. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`float<class_float>` | :ref:`length_squared<class_Quat_method_length_squared>` **(** **)** |
  66. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`Quat<class_Quat>` | :ref:`normalized<class_Quat_method_normalized>` **(** **)** |
  68. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`set_axis_angle<class_Quat_method_set_axis_angle>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |
  70. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`set_euler<class_Quat_method_set_euler>` **(** :ref:`Vector3<class_Vector3>` euler **)** |
  72. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Quat<class_Quat>` | :ref:`slerp<class_Quat_method_slerp>` **(** :ref:`Quat<class_Quat>` to, :ref:`float<class_float>` weight **)** |
  74. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`Quat<class_Quat>` | :ref:`slerpni<class_Quat_method_slerpni>` **(** :ref:`Quat<class_Quat>` to, :ref:`float<class_float>` weight **)** |
  76. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`Vector3<class_Vector3>` | :ref:`xform<class_Quat_method_xform>` **(** :ref:`Vector3<class_Vector3>` v **)** |
  78. +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. .. rst-class:: classref-section-separator
  80. ----
  81. .. rst-class:: classref-descriptions-group
  82. Constants
  83. ---------
  84. .. _class_Quat_constant_IDENTITY:
  85. .. rst-class:: classref-constant
  86. **IDENTITY** = ``Quat( 0, 0, 0, 1 )``
  87. The identity quaternion, representing no rotation. Equivalent to an identity :ref:`Basis<class_Basis>` matrix. If a vector is transformed by an identity quaternion, it will not change.
  88. .. rst-class:: classref-section-separator
  89. ----
  90. .. rst-class:: classref-descriptions-group
  91. Property Descriptions
  92. ---------------------
  93. .. _class_Quat_property_w:
  94. .. rst-class:: classref-property
  95. :ref:`float<class_float>` **w** = ``1.0``
  96. W component of the quaternion (real part).
  97. Quaternion components should usually not be manipulated directly.
  98. .. rst-class:: classref-item-separator
  99. ----
  100. .. _class_Quat_property_x:
  101. .. rst-class:: classref-property
  102. :ref:`float<class_float>` **x** = ``0.0``
  103. X component of the quaternion (imaginary ``i`` axis part).
  104. Quaternion components should usually not be manipulated directly.
  105. .. rst-class:: classref-item-separator
  106. ----
  107. .. _class_Quat_property_y:
  108. .. rst-class:: classref-property
  109. :ref:`float<class_float>` **y** = ``0.0``
  110. Y component of the quaternion (imaginary ``j`` axis part).
  111. Quaternion components should usually not be manipulated directly.
  112. .. rst-class:: classref-item-separator
  113. ----
  114. .. _class_Quat_property_z:
  115. .. rst-class:: classref-property
  116. :ref:`float<class_float>` **z** = ``0.0``
  117. Z component of the quaternion (imaginary ``k`` axis part).
  118. Quaternion components should usually not be manipulated directly.
  119. .. rst-class:: classref-section-separator
  120. ----
  121. .. rst-class:: classref-descriptions-group
  122. Method Descriptions
  123. -------------------
  124. .. _class_Quat_method_Quat:
  125. .. rst-class:: classref-method
  126. :ref:`Quat<class_Quat>` **Quat** **(** :ref:`Basis<class_Basis>` from **)**
  127. Constructs a quaternion from the given :ref:`Basis<class_Basis>`.
  128. .. rst-class:: classref-item-separator
  129. ----
  130. .. rst-class:: classref-method
  131. :ref:`Quat<class_Quat>` **Quat** **(** :ref:`Vector3<class_Vector3>` euler **)**
  132. Constructs a quaternion that will perform a rotation specified by Euler angles (in the YXZ convention: when decomposing, first Z, then X, and Y last), given in the vector format as (X angle, Y angle, Z angle).
  133. .. rst-class:: classref-item-separator
  134. ----
  135. .. rst-class:: classref-method
  136. :ref:`Quat<class_Quat>` **Quat** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)**
  137. Constructs a quaternion that will rotate around the given axis by the specified angle. The axis must be a normalized vector.
  138. .. rst-class:: classref-item-separator
  139. ----
  140. .. rst-class:: classref-method
  141. :ref:`Quat<class_Quat>` **Quat** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y, :ref:`float<class_float>` z, :ref:`float<class_float>` w **)**
  142. Constructs a quaternion defined by the given values.
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _class_Quat_method_angle_to:
  146. .. rst-class:: classref-method
  147. :ref:`float<class_float>` **angle_to** **(** :ref:`Quat<class_Quat>` to **)**
  148. Returns the angle between this quaternion and ``to``. This is the magnitude of the angle you would need to rotate by to get from one to the other.
  149. \ **Note:** This method has an abnormally high amount of floating-point error, so methods such as :ref:`@GDScript.is_zero_approx<class_@GDScript_method_is_zero_approx>` will not work reliably.
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. _class_Quat_method_cubic_slerp:
  153. .. rst-class:: classref-method
  154. :ref:`Quat<class_Quat>` **cubic_slerp** **(** :ref:`Quat<class_Quat>` b, :ref:`Quat<class_Quat>` pre_a, :ref:`Quat<class_Quat>` post_b, :ref:`float<class_float>` weight **)**
  155. Performs a cubic spherical interpolation between quaternions ``pre_a``, this vector, ``b``, and ``post_b``, by the given amount ``weight``.
  156. .. rst-class:: classref-item-separator
  157. ----
  158. .. _class_Quat_method_dot:
  159. .. rst-class:: classref-method
  160. :ref:`float<class_float>` **dot** **(** :ref:`Quat<class_Quat>` b **)**
  161. Returns the dot product of two quaternions.
  162. .. rst-class:: classref-item-separator
  163. ----
  164. .. _class_Quat_method_get_euler:
  165. .. rst-class:: classref-method
  166. :ref:`Vector3<class_Vector3>` **get_euler** **(** **)**
  167. Returns Euler angles (in the YXZ convention: when decomposing, first Z, then X, and Y last) corresponding to the rotation represented by the unit quaternion. Returned vector contains the rotation angles in the format (X angle, Y angle, Z angle).
  168. .. rst-class:: classref-item-separator
  169. ----
  170. .. _class_Quat_method_inverse:
  171. .. rst-class:: classref-method
  172. :ref:`Quat<class_Quat>` **inverse** **(** **)**
  173. Returns the inverse of the quaternion.
  174. .. rst-class:: classref-item-separator
  175. ----
  176. .. _class_Quat_method_is_equal_approx:
  177. .. rst-class:: classref-method
  178. :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Quat<class_Quat>` quat **)**
  179. Returns ``true`` if this quaternion and ``quat`` are approximately equal, by running :ref:`@GDScript.is_equal_approx<class_@GDScript_method_is_equal_approx>` on each component.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_Quat_method_is_normalized:
  183. .. rst-class:: classref-method
  184. :ref:`bool<class_bool>` **is_normalized** **(** **)**
  185. Returns whether the quaternion is normalized or not.
  186. .. rst-class:: classref-item-separator
  187. ----
  188. .. _class_Quat_method_length:
  189. .. rst-class:: classref-method
  190. :ref:`float<class_float>` **length** **(** **)**
  191. Returns the length of the quaternion.
  192. .. rst-class:: classref-item-separator
  193. ----
  194. .. _class_Quat_method_length_squared:
  195. .. rst-class:: classref-method
  196. :ref:`float<class_float>` **length_squared** **(** **)**
  197. Returns the length of the quaternion, squared.
  198. .. rst-class:: classref-item-separator
  199. ----
  200. .. _class_Quat_method_normalized:
  201. .. rst-class:: classref-method
  202. :ref:`Quat<class_Quat>` **normalized** **(** **)**
  203. Returns a copy of the quaternion, normalized to unit length.
  204. .. rst-class:: classref-item-separator
  205. ----
  206. .. _class_Quat_method_set_axis_angle:
  207. .. rst-class:: classref-method
  208. void **set_axis_angle** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)**
  209. Sets the quaternion to a rotation which rotates around axis by the specified angle, in radians. The axis must be a normalized vector.
  210. .. rst-class:: classref-item-separator
  211. ----
  212. .. _class_Quat_method_set_euler:
  213. .. rst-class:: classref-method
  214. void **set_euler** **(** :ref:`Vector3<class_Vector3>` euler **)**
  215. Sets the quaternion to a rotation specified by Euler angles (in the YXZ convention: when decomposing, first Z, then X, and Y last), given in the vector format as (X angle, Y angle, Z angle).
  216. .. rst-class:: classref-item-separator
  217. ----
  218. .. _class_Quat_method_slerp:
  219. .. rst-class:: classref-method
  220. :ref:`Quat<class_Quat>` **slerp** **(** :ref:`Quat<class_Quat>` to, :ref:`float<class_float>` weight **)**
  221. Returns the result of the spherical linear interpolation between this quaternion and ``to`` by amount ``weight``.
  222. \ **Note:** Both quaternions must be normalized.
  223. .. rst-class:: classref-item-separator
  224. ----
  225. .. _class_Quat_method_slerpni:
  226. .. rst-class:: classref-method
  227. :ref:`Quat<class_Quat>` **slerpni** **(** :ref:`Quat<class_Quat>` to, :ref:`float<class_float>` weight **)**
  228. Returns the result of the spherical linear interpolation between this quaternion and ``to`` by amount ``weight``, but without checking if the rotation path is not bigger than 90 degrees.
  229. .. rst-class:: classref-item-separator
  230. ----
  231. .. _class_Quat_method_xform:
  232. .. rst-class:: classref-method
  233. :ref:`Vector3<class_Vector3>` **xform** **(** :ref:`Vector3<class_Vector3>` v **)**
  234. Returns a vector transformed (multiplied) by this quaternion.
  235. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  236. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  237. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  238. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`