class_basis.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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/Basis.xml.
  6. .. _class_Basis:
  7. Basis
  8. =====
  9. 3×3 matrix datatype.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. 3×3 matrix used for 3D rotation and scale. Almost always used as an orthogonal basis for a Transform.
  14. Contains 3 vector fields X, Y and Z as its columns, which are typically interpreted as the local basis vectors of a transformation. For such use, it is composed of a scaling and a rotation matrix, in that order (M = R.S).
  15. Can also be accessed as array of 3D vectors. These vectors are normally orthogonal to each other, but are not necessarily normalized (due to scaling).
  16. For more information, read the "Matrices and transforms" documentation article.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - :doc:`Math tutorial index <../tutorials/math/index>`
  21. - :doc:`Matrices and transforms <../tutorials/math/matrices_and_transforms>`
  22. - :doc:`Using 3D transforms <../tutorials/3d/using_transforms>`
  23. - `Matrix Transform Demo <https://godotengine.org/asset-library/asset/584>`__
  24. - `3D Platformer Demo <https://godotengine.org/asset-library/asset/125>`__
  25. - `3D Voxel Demo <https://godotengine.org/asset-library/asset/676>`__
  26. - `2.5D Demo <https://godotengine.org/asset-library/asset/583>`__
  27. .. rst-class:: classref-reftable-group
  28. Properties
  29. ----------
  30. .. table::
  31. :widths: auto
  32. +-------------------------------+----------------------------------+------------------------+
  33. | :ref:`Vector3<class_Vector3>` | :ref:`x<class_Basis_property_x>` | ``Vector3( 1, 0, 0 )`` |
  34. +-------------------------------+----------------------------------+------------------------+
  35. | :ref:`Vector3<class_Vector3>` | :ref:`y<class_Basis_property_y>` | ``Vector3( 0, 1, 0 )`` |
  36. +-------------------------------+----------------------------------+------------------------+
  37. | :ref:`Vector3<class_Vector3>` | :ref:`z<class_Basis_property_z>` | ``Vector3( 0, 0, 1 )`` |
  38. +-------------------------------+----------------------------------+------------------------+
  39. .. rst-class:: classref-reftable-group
  40. Methods
  41. -------
  42. .. table::
  43. :widths: auto
  44. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_method_Basis>` **(** :ref:`Quat<class_Quat>` from **)** |
  46. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_method_Basis>` **(** :ref:`Vector3<class_Vector3>` from **)** |
  48. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_method_Basis>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |
  50. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_method_Basis>` **(** :ref:`Vector3<class_Vector3>` x_axis, :ref:`Vector3<class_Vector3>` y_axis, :ref:`Vector3<class_Vector3>` z_axis **)** |
  52. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`float<class_float>` | :ref:`determinant<class_Basis_method_determinant>` **(** **)** |
  54. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Vector3<class_Vector3>` | :ref:`get_euler<class_Basis_method_get_euler>` **(** **)** |
  56. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`int<class_int>` | :ref:`get_orthogonal_index<class_Basis_method_get_orthogonal_index>` **(** **)** |
  58. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`Quat<class_Quat>` | :ref:`get_rotation_quat<class_Basis_method_get_rotation_quat>` **(** **)** |
  60. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Vector3<class_Vector3>` | :ref:`get_scale<class_Basis_method_get_scale>` **(** **)** |
  62. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Basis<class_Basis>` | :ref:`inverse<class_Basis_method_inverse>` **(** **)** |
  64. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Basis_method_is_equal_approx>` **(** :ref:`Basis<class_Basis>` b, :ref:`float<class_float>` epsilon=1e-05 **)** |
  66. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`Basis<class_Basis>` | :ref:`orthonormalized<class_Basis_method_orthonormalized>` **(** **)** |
  68. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`Basis<class_Basis>` | :ref:`rotated<class_Basis_method_rotated>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |
  70. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`Basis<class_Basis>` | :ref:`scaled<class_Basis_method_scaled>` **(** :ref:`Vector3<class_Vector3>` scale **)** |
  72. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Basis<class_Basis>` | :ref:`slerp<class_Basis_method_slerp>` **(** :ref:`Basis<class_Basis>` to, :ref:`float<class_float>` weight **)** |
  74. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`float<class_float>` | :ref:`tdotx<class_Basis_method_tdotx>` **(** :ref:`Vector3<class_Vector3>` with **)** |
  76. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`float<class_float>` | :ref:`tdoty<class_Basis_method_tdoty>` **(** :ref:`Vector3<class_Vector3>` with **)** |
  78. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`float<class_float>` | :ref:`tdotz<class_Basis_method_tdotz>` **(** :ref:`Vector3<class_Vector3>` with **)** |
  80. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`Basis<class_Basis>` | :ref:`transposed<class_Basis_method_transposed>` **(** **)** |
  82. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`Vector3<class_Vector3>` | :ref:`xform<class_Basis_method_xform>` **(** :ref:`Vector3<class_Vector3>` v **)** |
  84. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | :ref:`Vector3<class_Vector3>` | :ref:`xform_inv<class_Basis_method_xform_inv>` **(** :ref:`Vector3<class_Vector3>` v **)** |
  86. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. .. rst-class:: classref-section-separator
  88. ----
  89. .. rst-class:: classref-descriptions-group
  90. Constants
  91. ---------
  92. .. _class_Basis_constant_IDENTITY:
  93. .. rst-class:: classref-constant
  94. **IDENTITY** = ``Basis( 1, 0, 0, 0, 1, 0, 0, 0, 1 )``
  95. The identity basis, with no rotation or scaling applied.
  96. This is identical to calling ``Basis()`` without any parameters. This constant can be used to make your code clearer, and for consistency with C#.
  97. .. _class_Basis_constant_FLIP_X:
  98. .. rst-class:: classref-constant
  99. **FLIP_X** = ``Basis( -1, 0, 0, 0, 1, 0, 0, 0, 1 )``
  100. The basis that will flip something along the X axis when used in a transformation.
  101. .. _class_Basis_constant_FLIP_Y:
  102. .. rst-class:: classref-constant
  103. **FLIP_Y** = ``Basis( 1, 0, 0, 0, -1, 0, 0, 0, 1 )``
  104. The basis that will flip something along the Y axis when used in a transformation.
  105. .. _class_Basis_constant_FLIP_Z:
  106. .. rst-class:: classref-constant
  107. **FLIP_Z** = ``Basis( 1, 0, 0, 0, 1, 0, 0, 0, -1 )``
  108. The basis that will flip something along the Z axis when used in a transformation.
  109. .. rst-class:: classref-section-separator
  110. ----
  111. .. rst-class:: classref-descriptions-group
  112. Property Descriptions
  113. ---------------------
  114. .. _class_Basis_property_x:
  115. .. rst-class:: classref-property
  116. :ref:`Vector3<class_Vector3>` **x** = ``Vector3( 1, 0, 0 )``
  117. The basis matrix's X vector (column 0). Equivalent to array index ``0``.
  118. .. rst-class:: classref-item-separator
  119. ----
  120. .. _class_Basis_property_y:
  121. .. rst-class:: classref-property
  122. :ref:`Vector3<class_Vector3>` **y** = ``Vector3( 0, 1, 0 )``
  123. The basis matrix's Y vector (column 1). Equivalent to array index ``1``.
  124. .. rst-class:: classref-item-separator
  125. ----
  126. .. _class_Basis_property_z:
  127. .. rst-class:: classref-property
  128. :ref:`Vector3<class_Vector3>` **z** = ``Vector3( 0, 0, 1 )``
  129. The basis matrix's Z vector (column 2). Equivalent to array index ``2``.
  130. .. rst-class:: classref-section-separator
  131. ----
  132. .. rst-class:: classref-descriptions-group
  133. Method Descriptions
  134. -------------------
  135. .. _class_Basis_method_Basis:
  136. .. rst-class:: classref-method
  137. :ref:`Basis<class_Basis>` **Basis** **(** :ref:`Quat<class_Quat>` from **)**
  138. Constructs a pure rotation basis matrix from the given quaternion.
  139. .. rst-class:: classref-item-separator
  140. ----
  141. .. rst-class:: classref-method
  142. :ref:`Basis<class_Basis>` **Basis** **(** :ref:`Vector3<class_Vector3>` from **)**
  143. Constructs a pure rotation basis matrix from the given Euler angles (in the YXZ convention: when \*composing\*, first Y, then X, and Z last), given in the vector format as (X angle, Y angle, Z angle).
  144. Consider using the :ref:`Quat<class_Quat>` constructor instead, which uses a quaternion instead of Euler angles.
  145. .. rst-class:: classref-item-separator
  146. ----
  147. .. rst-class:: classref-method
  148. :ref:`Basis<class_Basis>` **Basis** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)**
  149. Constructs a pure rotation basis matrix, rotated around the given ``axis`` by ``angle`` (in radians). The axis must be a normalized vector.
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. rst-class:: classref-method
  153. :ref:`Basis<class_Basis>` **Basis** **(** :ref:`Vector3<class_Vector3>` x_axis, :ref:`Vector3<class_Vector3>` y_axis, :ref:`Vector3<class_Vector3>` z_axis **)**
  154. Constructs a basis matrix from 3 axis vectors (matrix columns).
  155. .. rst-class:: classref-item-separator
  156. ----
  157. .. _class_Basis_method_determinant:
  158. .. rst-class:: classref-method
  159. :ref:`float<class_float>` **determinant** **(** **)**
  160. Returns the determinant of the basis matrix. If the basis is uniformly scaled, its determinant is the square of the scale.
  161. A negative determinant means the basis has a negative scale. A zero determinant means the basis isn't invertible, and is usually considered invalid.
  162. .. rst-class:: classref-item-separator
  163. ----
  164. .. _class_Basis_method_get_euler:
  165. .. rst-class:: classref-method
  166. :ref:`Vector3<class_Vector3>` **get_euler** **(** **)**
  167. Returns the basis's rotation in the form of Euler angles (in the YXZ convention: when decomposing, first Z, then X, and Y last). The returned vector contains the rotation angles in the format (X angle, Y angle, Z angle).
  168. Consider using the :ref:`get_rotation_quat<class_Basis_method_get_rotation_quat>` method instead, which returns a :ref:`Quat<class_Quat>` quaternion instead of Euler angles.
  169. .. rst-class:: classref-item-separator
  170. ----
  171. .. _class_Basis_method_get_orthogonal_index:
  172. .. rst-class:: classref-method
  173. :ref:`int<class_int>` **get_orthogonal_index** **(** **)**
  174. This function considers a discretization of rotations into 24 points on unit sphere, lying along the vectors (x,y,z) with each component being either -1, 0, or 1, and returns the index of the point best representing the orientation of the object. It is mainly used by the :ref:`GridMap<class_GridMap>` editor. For further details, refer to the Godot source code.
  175. .. rst-class:: classref-item-separator
  176. ----
  177. .. _class_Basis_method_get_rotation_quat:
  178. .. rst-class:: classref-method
  179. :ref:`Quat<class_Quat>` **get_rotation_quat** **(** **)**
  180. Returns the basis's rotation in the form of a quaternion. See :ref:`get_euler<class_Basis_method_get_euler>` if you need Euler angles, but keep in mind quaternions should generally be preferred to Euler angles.
  181. .. rst-class:: classref-item-separator
  182. ----
  183. .. _class_Basis_method_get_scale:
  184. .. rst-class:: classref-method
  185. :ref:`Vector3<class_Vector3>` **get_scale** **(** **)**
  186. Assuming that the matrix is the combination of a rotation and scaling, return the absolute value of scaling factors along each axis.
  187. .. rst-class:: classref-item-separator
  188. ----
  189. .. _class_Basis_method_inverse:
  190. .. rst-class:: classref-method
  191. :ref:`Basis<class_Basis>` **inverse** **(** **)**
  192. Returns the inverse of the matrix.
  193. .. rst-class:: classref-item-separator
  194. ----
  195. .. _class_Basis_method_is_equal_approx:
  196. .. rst-class:: classref-method
  197. :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Basis<class_Basis>` b, :ref:`float<class_float>` epsilon=1e-05 **)**
  198. Returns ``true`` if this basis and ``b`` are approximately equal, by calling ``is_equal_approx`` on each component.
  199. \ **Note:** For complicated reasons, the epsilon argument is always discarded. Don't use the epsilon argument, it does nothing.
  200. .. rst-class:: classref-item-separator
  201. ----
  202. .. _class_Basis_method_orthonormalized:
  203. .. rst-class:: classref-method
  204. :ref:`Basis<class_Basis>` **orthonormalized** **(** **)**
  205. Returns the orthonormalized version of the matrix (useful to call from time to time to avoid rounding error for orthogonal matrices). This performs a Gram-Schmidt orthonormalization on the basis of the matrix.
  206. .. rst-class:: classref-item-separator
  207. ----
  208. .. _class_Basis_method_rotated:
  209. .. rst-class:: classref-method
  210. :ref:`Basis<class_Basis>` **rotated** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)**
  211. Introduce an additional rotation around the given axis by ``angle`` (in radians). The axis must be a normalized vector.
  212. .. rst-class:: classref-item-separator
  213. ----
  214. .. _class_Basis_method_scaled:
  215. .. rst-class:: classref-method
  216. :ref:`Basis<class_Basis>` **scaled** **(** :ref:`Vector3<class_Vector3>` scale **)**
  217. Introduce an additional scaling specified by the given 3D scaling factor.
  218. .. rst-class:: classref-item-separator
  219. ----
  220. .. _class_Basis_method_slerp:
  221. .. rst-class:: classref-method
  222. :ref:`Basis<class_Basis>` **slerp** **(** :ref:`Basis<class_Basis>` to, :ref:`float<class_float>` weight **)**
  223. Assuming that the matrix is a proper rotation matrix, slerp performs a spherical-linear interpolation with another rotation matrix.
  224. .. rst-class:: classref-item-separator
  225. ----
  226. .. _class_Basis_method_tdotx:
  227. .. rst-class:: classref-method
  228. :ref:`float<class_float>` **tdotx** **(** :ref:`Vector3<class_Vector3>` with **)**
  229. Transposed dot product with the X axis of the matrix.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_Basis_method_tdoty:
  233. .. rst-class:: classref-method
  234. :ref:`float<class_float>` **tdoty** **(** :ref:`Vector3<class_Vector3>` with **)**
  235. Transposed dot product with the Y axis of the matrix.
  236. .. rst-class:: classref-item-separator
  237. ----
  238. .. _class_Basis_method_tdotz:
  239. .. rst-class:: classref-method
  240. :ref:`float<class_float>` **tdotz** **(** :ref:`Vector3<class_Vector3>` with **)**
  241. Transposed dot product with the Z axis of the matrix.
  242. .. rst-class:: classref-item-separator
  243. ----
  244. .. _class_Basis_method_transposed:
  245. .. rst-class:: classref-method
  246. :ref:`Basis<class_Basis>` **transposed** **(** **)**
  247. Returns the transposed version of the matrix.
  248. .. rst-class:: classref-item-separator
  249. ----
  250. .. _class_Basis_method_xform:
  251. .. rst-class:: classref-method
  252. :ref:`Vector3<class_Vector3>` **xform** **(** :ref:`Vector3<class_Vector3>` v **)**
  253. Returns a vector transformed (multiplied) by the matrix.
  254. .. rst-class:: classref-item-separator
  255. ----
  256. .. _class_Basis_method_xform_inv:
  257. .. rst-class:: classref-method
  258. :ref:`Vector3<class_Vector3>` **xform_inv** **(** :ref:`Vector3<class_Vector3>` v **)**
  259. Returns a vector transformed (multiplied) by the transposed basis matrix.
  260. \ **Note:** This results in a multiplication by the inverse of the matrix only if it represents a rotation-reflection.
  261. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  262. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  263. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  264. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`