2
0

class_basis.rst 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  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/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Basis.xml.
  6. .. _class_Basis:
  7. Basis
  8. =====
  9. A 3×3 matrix for representing 3D rotation and scale.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. A 3×3 matrix used for representing 3D rotation and scale. Usually used as an orthogonal basis for a :ref:`Transform3D<class_Transform3D>`.
  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. Basis can also be accessed as an array of 3D vectors. These vectors are usually orthogonal to each other, but are not necessarily normalized (due to scaling).
  16. For a general introduction, see the :doc:`Matrices and transforms <../tutorials/math/matrices_and_transforms>` tutorial.
  17. .. note::
  18. There are notable differences when using this API with C#. See :ref:`doc_c_sharp_differences` for more information.
  19. .. rst-class:: classref-introduction-group
  20. Tutorials
  21. ---------
  22. - :doc:`Math documentation index <../tutorials/math/index>`
  23. - :doc:`Matrices and transforms <../tutorials/math/matrices_and_transforms>`
  24. - :doc:`Using 3D transforms <../tutorials/3d/using_transforms>`
  25. - `Matrix Transform Demo <https://godotengine.org/asset-library/asset/584>`__
  26. - `3D Platformer Demo <https://godotengine.org/asset-library/asset/125>`__
  27. - `3D Voxel Demo <https://godotengine.org/asset-library/asset/676>`__
  28. - `2.5D Demo <https://godotengine.org/asset-library/asset/583>`__
  29. .. rst-class:: classref-reftable-group
  30. Properties
  31. ----------
  32. .. table::
  33. :widths: auto
  34. +-------------------------------+----------------------------------+----------------------+
  35. | :ref:`Vector3<class_Vector3>` | :ref:`x<class_Basis_property_x>` | ``Vector3(1, 0, 0)`` |
  36. +-------------------------------+----------------------------------+----------------------+
  37. | :ref:`Vector3<class_Vector3>` | :ref:`y<class_Basis_property_y>` | ``Vector3(0, 1, 0)`` |
  38. +-------------------------------+----------------------------------+----------------------+
  39. | :ref:`Vector3<class_Vector3>` | :ref:`z<class_Basis_property_z>` | ``Vector3(0, 0, 1)`` |
  40. +-------------------------------+----------------------------------+----------------------+
  41. .. rst-class:: classref-reftable-group
  42. Constructors
  43. ------------
  44. .. table::
  45. :widths: auto
  46. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_constructor_Basis>` **(** **)** |
  48. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_constructor_Basis>` **(** :ref:`Basis<class_Basis>` from **)** |
  50. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_constructor_Basis>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |
  52. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_constructor_Basis>` **(** :ref:`Quaternion<class_Quaternion>` from **)** |
  54. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_constructor_Basis>` **(** :ref:`Vector3<class_Vector3>` x_axis, :ref:`Vector3<class_Vector3>` y_axis, :ref:`Vector3<class_Vector3>` z_axis **)** |
  56. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. .. rst-class:: classref-reftable-group
  58. Methods
  59. -------
  60. .. table::
  61. :widths: auto
  62. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`float<class_float>` | :ref:`determinant<class_Basis_method_determinant>` **(** **)** |const| |
  64. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Basis<class_Basis>` | :ref:`from_euler<class_Basis_method_from_euler>` **(** :ref:`Vector3<class_Vector3>` euler, :ref:`int<class_int>` order=2 **)** |static| |
  66. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`Basis<class_Basis>` | :ref:`from_scale<class_Basis_method_from_scale>` **(** :ref:`Vector3<class_Vector3>` scale **)** |static| |
  68. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`Vector3<class_Vector3>` | :ref:`get_euler<class_Basis_method_get_euler>` **(** :ref:`int<class_int>` order=2 **)** |const| |
  70. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`Quaternion<class_Quaternion>` | :ref:`get_rotation_quaternion<class_Basis_method_get_rotation_quaternion>` **(** **)** |const| |
  72. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Vector3<class_Vector3>` | :ref:`get_scale<class_Basis_method_get_scale>` **(** **)** |const| |
  74. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`Basis<class_Basis>` | :ref:`inverse<class_Basis_method_inverse>` **(** **)** |const| |
  76. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`bool<class_bool>` | :ref:`is_conformal<class_Basis_method_is_conformal>` **(** **)** |const| |
  78. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Basis_method_is_equal_approx>` **(** :ref:`Basis<class_Basis>` b **)** |const| |
  80. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`bool<class_bool>` | :ref:`is_finite<class_Basis_method_is_finite>` **(** **)** |const| |
  82. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`Basis<class_Basis>` | :ref:`looking_at<class_Basis_method_looking_at>` **(** :ref:`Vector3<class_Vector3>` target, :ref:`Vector3<class_Vector3>` up=Vector3(0, 1, 0), :ref:`bool<class_bool>` use_model_front=false **)** |static| |
  84. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | :ref:`Basis<class_Basis>` | :ref:`orthonormalized<class_Basis_method_orthonormalized>` **(** **)** |const| |
  86. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | :ref:`Basis<class_Basis>` | :ref:`rotated<class_Basis_method_rotated>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |const| |
  88. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | :ref:`Basis<class_Basis>` | :ref:`scaled<class_Basis_method_scaled>` **(** :ref:`Vector3<class_Vector3>` scale **)** |const| |
  90. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`Basis<class_Basis>` | :ref:`slerp<class_Basis_method_slerp>` **(** :ref:`Basis<class_Basis>` to, :ref:`float<class_float>` weight **)** |const| |
  92. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`float<class_float>` | :ref:`tdotx<class_Basis_method_tdotx>` **(** :ref:`Vector3<class_Vector3>` with **)** |const| |
  94. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`float<class_float>` | :ref:`tdoty<class_Basis_method_tdoty>` **(** :ref:`Vector3<class_Vector3>` with **)** |const| |
  96. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :ref:`float<class_float>` | :ref:`tdotz<class_Basis_method_tdotz>` **(** :ref:`Vector3<class_Vector3>` with **)** |const| |
  98. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`Basis<class_Basis>` | :ref:`transposed<class_Basis_method_transposed>` **(** **)** |const| |
  100. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. .. rst-class:: classref-reftable-group
  102. Operators
  103. ---------
  104. .. table::
  105. :widths: auto
  106. +-------------------------------+-----------------------------------------------------------------------------------------------------+
  107. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Basis_operator_neq_Basis>` **(** :ref:`Basis<class_Basis>` right **)** |
  108. +-------------------------------+-----------------------------------------------------------------------------------------------------+
  109. | :ref:`Basis<class_Basis>` | :ref:`operator *<class_Basis_operator_mul_Basis>` **(** :ref:`Basis<class_Basis>` right **)** |
  110. +-------------------------------+-----------------------------------------------------------------------------------------------------+
  111. | :ref:`Vector3<class_Vector3>` | :ref:`operator *<class_Basis_operator_mul_Vector3>` **(** :ref:`Vector3<class_Vector3>` right **)** |
  112. +-------------------------------+-----------------------------------------------------------------------------------------------------+
  113. | :ref:`Basis<class_Basis>` | :ref:`operator *<class_Basis_operator_mul_float>` **(** :ref:`float<class_float>` right **)** |
  114. +-------------------------------+-----------------------------------------------------------------------------------------------------+
  115. | :ref:`Basis<class_Basis>` | :ref:`operator *<class_Basis_operator_mul_int>` **(** :ref:`int<class_int>` right **)** |
  116. +-------------------------------+-----------------------------------------------------------------------------------------------------+
  117. | :ref:`Basis<class_Basis>` | :ref:`operator /<class_Basis_operator_div_float>` **(** :ref:`float<class_float>` right **)** |
  118. +-------------------------------+-----------------------------------------------------------------------------------------------------+
  119. | :ref:`Basis<class_Basis>` | :ref:`operator /<class_Basis_operator_div_int>` **(** :ref:`int<class_int>` right **)** |
  120. +-------------------------------+-----------------------------------------------------------------------------------------------------+
  121. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Basis_operator_eq_Basis>` **(** :ref:`Basis<class_Basis>` right **)** |
  122. +-------------------------------+-----------------------------------------------------------------------------------------------------+
  123. | :ref:`Vector3<class_Vector3>` | :ref:`operator []<class_Basis_operator_idx_int>` **(** :ref:`int<class_int>` index **)** |
  124. +-------------------------------+-----------------------------------------------------------------------------------------------------+
  125. .. rst-class:: classref-section-separator
  126. ----
  127. .. rst-class:: classref-descriptions-group
  128. Constants
  129. ---------
  130. .. _class_Basis_constant_IDENTITY:
  131. .. rst-class:: classref-constant
  132. **IDENTITY** = ``Basis(1, 0, 0, 0, 1, 0, 0, 0, 1)``
  133. The identity basis, with no rotation or scaling applied.
  134. This is identical to creating :ref:`Basis<class_Basis_constructor_Basis>` without any parameters. This constant can be used to make your code clearer, and for consistency with C#.
  135. .. _class_Basis_constant_FLIP_X:
  136. .. rst-class:: classref-constant
  137. **FLIP_X** = ``Basis(-1, 0, 0, 0, 1, 0, 0, 0, 1)``
  138. The basis that will flip something along the X axis when used in a transformation.
  139. .. _class_Basis_constant_FLIP_Y:
  140. .. rst-class:: classref-constant
  141. **FLIP_Y** = ``Basis(1, 0, 0, 0, -1, 0, 0, 0, 1)``
  142. The basis that will flip something along the Y axis when used in a transformation.
  143. .. _class_Basis_constant_FLIP_Z:
  144. .. rst-class:: classref-constant
  145. **FLIP_Z** = ``Basis(1, 0, 0, 0, 1, 0, 0, 0, -1)``
  146. The basis that will flip something along the Z axis when used in a transformation.
  147. .. rst-class:: classref-section-separator
  148. ----
  149. .. rst-class:: classref-descriptions-group
  150. Property Descriptions
  151. ---------------------
  152. .. _class_Basis_property_x:
  153. .. rst-class:: classref-property
  154. :ref:`Vector3<class_Vector3>` **x** = ``Vector3(1, 0, 0)``
  155. The basis matrix's X vector (column 0). Equivalent to array index ``0``.
  156. .. rst-class:: classref-item-separator
  157. ----
  158. .. _class_Basis_property_y:
  159. .. rst-class:: classref-property
  160. :ref:`Vector3<class_Vector3>` **y** = ``Vector3(0, 1, 0)``
  161. The basis matrix's Y vector (column 1). Equivalent to array index ``1``.
  162. .. rst-class:: classref-item-separator
  163. ----
  164. .. _class_Basis_property_z:
  165. .. rst-class:: classref-property
  166. :ref:`Vector3<class_Vector3>` **z** = ``Vector3(0, 0, 1)``
  167. The basis matrix's Z vector (column 2). Equivalent to array index ``2``.
  168. .. rst-class:: classref-section-separator
  169. ----
  170. .. rst-class:: classref-descriptions-group
  171. Constructor Descriptions
  172. ------------------------
  173. .. _class_Basis_constructor_Basis:
  174. .. rst-class:: classref-constructor
  175. :ref:`Basis<class_Basis>` **Basis** **(** **)**
  176. Constructs a default-initialized **Basis** set to :ref:`IDENTITY<class_Basis_constant_IDENTITY>`.
  177. .. rst-class:: classref-item-separator
  178. ----
  179. .. rst-class:: classref-constructor
  180. :ref:`Basis<class_Basis>` **Basis** **(** :ref:`Basis<class_Basis>` from **)**
  181. Constructs a **Basis** as a copy of the given **Basis**.
  182. .. rst-class:: classref-item-separator
  183. ----
  184. .. rst-class:: classref-constructor
  185. :ref:`Basis<class_Basis>` **Basis** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)**
  186. Constructs a pure rotation basis matrix, rotated around the given ``axis`` by ``angle`` (in radians). The axis must be a normalized vector.
  187. .. rst-class:: classref-item-separator
  188. ----
  189. .. rst-class:: classref-constructor
  190. :ref:`Basis<class_Basis>` **Basis** **(** :ref:`Quaternion<class_Quaternion>` from **)**
  191. Constructs a pure rotation basis matrix from the given quaternion.
  192. .. rst-class:: classref-item-separator
  193. ----
  194. .. rst-class:: classref-constructor
  195. :ref:`Basis<class_Basis>` **Basis** **(** :ref:`Vector3<class_Vector3>` x_axis, :ref:`Vector3<class_Vector3>` y_axis, :ref:`Vector3<class_Vector3>` z_axis **)**
  196. Constructs a basis matrix from 3 axis vectors (matrix columns).
  197. .. rst-class:: classref-section-separator
  198. ----
  199. .. rst-class:: classref-descriptions-group
  200. Method Descriptions
  201. -------------------
  202. .. _class_Basis_method_determinant:
  203. .. rst-class:: classref-method
  204. :ref:`float<class_float>` **determinant** **(** **)** |const|
  205. Returns the determinant of the basis matrix. If the basis is uniformly scaled, its determinant is the square of the scale.
  206. A negative determinant means the basis has a negative scale. A zero determinant means the basis isn't invertible, and is usually considered invalid.
  207. .. rst-class:: classref-item-separator
  208. ----
  209. .. _class_Basis_method_from_euler:
  210. .. rst-class:: classref-method
  211. :ref:`Basis<class_Basis>` **from_euler** **(** :ref:`Vector3<class_Vector3>` euler, :ref:`int<class_int>` order=2 **)** |static|
  212. Constructs a pure rotation Basis matrix from Euler angles in the specified Euler rotation order. By default, use YXZ order (most common). See the :ref:`EulerOrder<enum_@GlobalScope_EulerOrder>` enum for possible values.
  213. .. tabs::
  214. .. code-tab:: gdscript
  215. # Creates a Basis whose z axis points down.
  216. var my_basis = Basis.from_euler(Vector3(TAU / 4, 0, 0))
  217. print(my_basis.z) # Prints (0, -1, 0).
  218. .. code-tab:: csharp
  219. // Creates a Basis whose z axis points down.
  220. var myBasis = Basis.FromEuler(new Vector3(Mathf.Tau / 4.0f, 0.0f, 0.0f));
  221. GD.Print(myBasis.Z); // Prints (0, -1, 0).
  222. .. rst-class:: classref-item-separator
  223. ----
  224. .. _class_Basis_method_from_scale:
  225. .. rst-class:: classref-method
  226. :ref:`Basis<class_Basis>` **from_scale** **(** :ref:`Vector3<class_Vector3>` scale **)** |static|
  227. Constructs a pure scale basis matrix with no rotation or shearing. The scale values are set as the diagonal of the matrix, and the other parts of the matrix are zero.
  228. .. tabs::
  229. .. code-tab:: gdscript
  230. var my_basis = Basis.from_scale(Vector3(2, 4, 8))
  231. print(my_basis.x) # Prints (2, 0, 0).
  232. print(my_basis.y) # Prints (0, 4, 0).
  233. print(my_basis.z) # Prints (0, 0, 8).
  234. .. code-tab:: csharp
  235. var myBasis = Basis.FromScale(new Vector3(2.0f, 4.0f, 8.0f));
  236. GD.Print(myBasis.X); // Prints (2, 0, 0).
  237. GD.Print(myBasis.Y); // Prints (0, 4, 0).
  238. GD.Print(myBasis.Z); // Prints (0, 0, 8).
  239. .. rst-class:: classref-item-separator
  240. ----
  241. .. _class_Basis_method_get_euler:
  242. .. rst-class:: classref-method
  243. :ref:`Vector3<class_Vector3>` **get_euler** **(** :ref:`int<class_int>` order=2 **)** |const|
  244. Returns the basis's rotation in the form of Euler angles. The Euler order depends on the ``order`` parameter, by default it uses 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).
  245. Consider using the :ref:`get_rotation_quaternion<class_Basis_method_get_rotation_quaternion>` method instead, which returns a :ref:`Quaternion<class_Quaternion>` quaternion instead of Euler angles.
  246. .. rst-class:: classref-item-separator
  247. ----
  248. .. _class_Basis_method_get_rotation_quaternion:
  249. .. rst-class:: classref-method
  250. :ref:`Quaternion<class_Quaternion>` **get_rotation_quaternion** **(** **)** |const|
  251. 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.
  252. .. rst-class:: classref-item-separator
  253. ----
  254. .. _class_Basis_method_get_scale:
  255. .. rst-class:: classref-method
  256. :ref:`Vector3<class_Vector3>` **get_scale** **(** **)** |const|
  257. Assuming that the matrix is the combination of a rotation and scaling, return the absolute value of scaling factors along each axis.
  258. .. tabs::
  259. .. code-tab:: gdscript
  260. var my_basis = Basis(
  261. Vector3(2, 0, 0),
  262. Vector3(0, 4, 0),
  263. Vector3(0, 0, 8)
  264. )
  265. # Rotating the Basis in any way preserves its scale.
  266. my_basis = my_basis.rotated(Vector3.UP, TAU / 2)
  267. my_basis = my_basis.rotated(Vector3.RIGHT, TAU / 4)
  268. print(my_basis.get_scale()) # Prints (2, 4, 8).
  269. .. code-tab:: csharp
  270. var myBasis = new Basis(
  271. Vector3(2.0f, 0.0f, 0.0f),
  272. Vector3(0.0f, 4.0f, 0.0f),
  273. Vector3(0.0f, 0.0f, 8.0f)
  274. );
  275. // Rotating the Basis in any way preserves its scale.
  276. myBasis = myBasis.Rotated(Vector3.Up, Mathf.Tau / 2.0f);
  277. myBasis = myBasis.Rotated(Vector3.Right, Mathf.Tau / 4.0f);
  278. GD.Print(myBasis.Scale); // Prints (2, 4, 8).
  279. .. rst-class:: classref-item-separator
  280. ----
  281. .. _class_Basis_method_inverse:
  282. .. rst-class:: classref-method
  283. :ref:`Basis<class_Basis>` **inverse** **(** **)** |const|
  284. Returns the inverse of the matrix.
  285. .. rst-class:: classref-item-separator
  286. ----
  287. .. _class_Basis_method_is_conformal:
  288. .. rst-class:: classref-method
  289. :ref:`bool<class_bool>` **is_conformal** **(** **)** |const|
  290. Returns ``true`` if the basis is conformal, meaning it preserves angles and distance ratios, and may only be composed of rotation and uniform scale. Returns ``false`` if the basis has non-uniform scale or shear/skew. This can be used to validate if the basis is non-distorted, which is important for physics and other use cases.
  291. .. rst-class:: classref-item-separator
  292. ----
  293. .. _class_Basis_method_is_equal_approx:
  294. .. rst-class:: classref-method
  295. :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Basis<class_Basis>` b **)** |const|
  296. Returns ``true`` if this basis and ``b`` are approximately equal, by calling :ref:`@GlobalScope.is_equal_approx<class_@GlobalScope_method_is_equal_approx>` on all vector components.
  297. .. rst-class:: classref-item-separator
  298. ----
  299. .. _class_Basis_method_is_finite:
  300. .. rst-class:: classref-method
  301. :ref:`bool<class_bool>` **is_finite** **(** **)** |const|
  302. Returns ``true`` if this basis is finite, by calling :ref:`@GlobalScope.is_finite<class_@GlobalScope_method_is_finite>` on all vector components.
  303. .. rst-class:: classref-item-separator
  304. ----
  305. .. _class_Basis_method_looking_at:
  306. .. rst-class:: classref-method
  307. :ref:`Basis<class_Basis>` **looking_at** **(** :ref:`Vector3<class_Vector3>` target, :ref:`Vector3<class_Vector3>` up=Vector3(0, 1, 0), :ref:`bool<class_bool>` use_model_front=false **)** |static|
  308. Creates a Basis with a rotation such that the forward axis (-Z) points towards the ``target`` position.
  309. The up axis (+Y) points as close to the ``up`` vector as possible while staying perpendicular to the forward axis. The resulting Basis is orthonormalized. The ``target`` and ``up`` vectors cannot be zero, and cannot be parallel to each other.
  310. If ``use_model_front`` is ``true``, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the ``target`` position. By default, the -Z axis (camera forward) is treated as forward (implies +X is right).
  311. .. rst-class:: classref-item-separator
  312. ----
  313. .. _class_Basis_method_orthonormalized:
  314. .. rst-class:: classref-method
  315. :ref:`Basis<class_Basis>` **orthonormalized** **(** **)** |const|
  316. 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.
  317. .. tabs::
  318. .. code-tab:: gdscript
  319. # Rotate this Node3D every frame.
  320. func _process(delta):
  321. basis = basis.rotated(Vector3.UP, TAU * delta)
  322. basis = basis.rotated(Vector3.RIGHT, TAU * delta)
  323. basis = basis.orthonormalized()
  324. .. code-tab:: csharp
  325. // Rotate this Node3D every frame.
  326. public override void _Process(double delta)
  327. {
  328. Basis = Basis.Rotated(Vector3.Up, Mathf.Tau * (float)delta)
  329. .Rotated(Vector3.Right, Mathf.Tau * (float)delta)
  330. .Orthonormalized();
  331. }
  332. .. rst-class:: classref-item-separator
  333. ----
  334. .. _class_Basis_method_rotated:
  335. .. rst-class:: classref-method
  336. :ref:`Basis<class_Basis>` **rotated** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |const|
  337. Introduce an additional rotation around the given axis by ``angle`` (in radians). The axis must be a normalized vector.
  338. .. tabs::
  339. .. code-tab:: gdscript
  340. var my_basis = Basis.IDENTITY
  341. var angle = TAU / 2
  342. my_basis = my_basis.rotated(Vector3.UP, angle) # Rotate around the up axis (yaw).
  343. my_basis = my_basis.rotated(Vector3.RIGHT, angle) # Rotate around the right axis (pitch).
  344. my_basis = my_basis.rotated(Vector3.BACK, angle) # Rotate around the back axis (roll).
  345. .. code-tab:: csharp
  346. var myBasis = Basis.Identity;
  347. var angle = Mathf.Tau / 2.0f;
  348. myBasis = myBasis.Rotated(Vector3.Up, angle); // Rotate around the up axis (yaw).
  349. myBasis = myBasis.Rotated(Vector3.Right, angle); // Rotate around the right axis (pitch).
  350. myBasis = myBasis.Rotated(Vector3.Back, angle); // Rotate around the back axis (roll).
  351. .. rst-class:: classref-item-separator
  352. ----
  353. .. _class_Basis_method_scaled:
  354. .. rst-class:: classref-method
  355. :ref:`Basis<class_Basis>` **scaled** **(** :ref:`Vector3<class_Vector3>` scale **)** |const|
  356. Introduce an additional scaling specified by the given 3D scaling factor.
  357. .. tabs::
  358. .. code-tab:: gdscript
  359. var my_basis = Basis(
  360. Vector3(1, 1, 1),
  361. Vector3(2, 2, 2),
  362. Vector3(3, 3, 3)
  363. )
  364. my_basis = my_basis.scaled(Vector3(0, 2, -2))
  365. print(my_basis.x) # Prints (0, 2, -2).
  366. print(my_basis.y) # Prints (0, 4, -4).
  367. print(my_basis.z) # Prints (0, 6, -6).
  368. .. code-tab:: csharp
  369. var myBasis = new Basis(
  370. new Vector3(1.0f, 1.0f, 1.0f),
  371. new Vector3(2.0f, 2.0f, 2.0f),
  372. new Vector3(3.0f, 3.0f, 3.0f)
  373. );
  374. myBasis = myBasis.Scaled(new Vector3(0.0f, 2.0f, -2.0f));
  375. GD.Print(myBasis.X); // Prints (0, 2, -2).
  376. GD.Print(myBasis.Y); // Prints (0, 4, -4).
  377. GD.Print(myBasis.Z); // Prints (0, 6, -6).
  378. .. rst-class:: classref-item-separator
  379. ----
  380. .. _class_Basis_method_slerp:
  381. .. rst-class:: classref-method
  382. :ref:`Basis<class_Basis>` **slerp** **(** :ref:`Basis<class_Basis>` to, :ref:`float<class_float>` weight **)** |const|
  383. Assuming that the matrix is a proper rotation matrix, slerp performs a spherical-linear interpolation with another rotation matrix.
  384. .. rst-class:: classref-item-separator
  385. ----
  386. .. _class_Basis_method_tdotx:
  387. .. rst-class:: classref-method
  388. :ref:`float<class_float>` **tdotx** **(** :ref:`Vector3<class_Vector3>` with **)** |const|
  389. Transposed dot product with the X axis of the matrix.
  390. .. rst-class:: classref-item-separator
  391. ----
  392. .. _class_Basis_method_tdoty:
  393. .. rst-class:: classref-method
  394. :ref:`float<class_float>` **tdoty** **(** :ref:`Vector3<class_Vector3>` with **)** |const|
  395. Transposed dot product with the Y axis of the matrix.
  396. .. rst-class:: classref-item-separator
  397. ----
  398. .. _class_Basis_method_tdotz:
  399. .. rst-class:: classref-method
  400. :ref:`float<class_float>` **tdotz** **(** :ref:`Vector3<class_Vector3>` with **)** |const|
  401. Transposed dot product with the Z axis of the matrix.
  402. .. rst-class:: classref-item-separator
  403. ----
  404. .. _class_Basis_method_transposed:
  405. .. rst-class:: classref-method
  406. :ref:`Basis<class_Basis>` **transposed** **(** **)** |const|
  407. Returns the transposed version of the matrix.
  408. .. tabs::
  409. .. code-tab:: gdscript
  410. var my_basis = Basis(
  411. Vector3(1, 2, 3),
  412. Vector3(4, 5, 6),
  413. Vector3(7, 8, 9)
  414. )
  415. my_basis = my_basis.transposed()
  416. print(my_basis.x) # Prints (1, 4, 7).
  417. print(my_basis.y) # Prints (2, 5, 8).
  418. print(my_basis.z) # Prints (3, 6, 9).
  419. .. code-tab:: csharp
  420. var myBasis = new Basis(
  421. new Vector3(1.0f, 2.0f, 3.0f),
  422. new Vector3(4.0f, 5.0f, 6.0f),
  423. new Vector3(7.0f, 8.0f, 9.0f)
  424. );
  425. myBasis = myBasis.Transposed();
  426. GD.Print(myBasis.X); // Prints (1, 4, 7).
  427. GD.Print(myBasis.Y); // Prints (2, 5, 8).
  428. GD.Print(myBasis.Z); // Prints (3, 6, 9).
  429. .. rst-class:: classref-section-separator
  430. ----
  431. .. rst-class:: classref-descriptions-group
  432. Operator Descriptions
  433. ---------------------
  434. .. _class_Basis_operator_neq_Basis:
  435. .. rst-class:: classref-operator
  436. :ref:`bool<class_bool>` **operator !=** **(** :ref:`Basis<class_Basis>` right **)**
  437. Returns ``true`` if the **Basis** matrices are not equal.
  438. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Basis_method_is_equal_approx>` instead, which is more reliable.
  439. .. rst-class:: classref-item-separator
  440. ----
  441. .. _class_Basis_operator_mul_Basis:
  442. .. rst-class:: classref-operator
  443. :ref:`Basis<class_Basis>` **operator *** **(** :ref:`Basis<class_Basis>` right **)**
  444. Composes these two basis matrices by multiplying them together. This has the effect of transforming the second basis (the child) by the first basis (the parent).
  445. .. rst-class:: classref-item-separator
  446. ----
  447. .. _class_Basis_operator_mul_Vector3:
  448. .. rst-class:: classref-operator
  449. :ref:`Vector3<class_Vector3>` **operator *** **(** :ref:`Vector3<class_Vector3>` right **)**
  450. Transforms (multiplies) the :ref:`Vector3<class_Vector3>` by the given **Basis** matrix.
  451. .. rst-class:: classref-item-separator
  452. ----
  453. .. _class_Basis_operator_mul_float:
  454. .. rst-class:: classref-operator
  455. :ref:`Basis<class_Basis>` **operator *** **(** :ref:`float<class_float>` right **)**
  456. This operator multiplies all components of the **Basis**, which scales it uniformly.
  457. .. rst-class:: classref-item-separator
  458. ----
  459. .. _class_Basis_operator_mul_int:
  460. .. rst-class:: classref-operator
  461. :ref:`Basis<class_Basis>` **operator *** **(** :ref:`int<class_int>` right **)**
  462. This operator multiplies all components of the **Basis**, which scales it uniformly.
  463. .. rst-class:: classref-item-separator
  464. ----
  465. .. _class_Basis_operator_div_float:
  466. .. rst-class:: classref-operator
  467. :ref:`Basis<class_Basis>` **operator /** **(** :ref:`float<class_float>` right **)**
  468. This operator divides all components of the **Basis**, which inversely scales it uniformly.
  469. .. rst-class:: classref-item-separator
  470. ----
  471. .. _class_Basis_operator_div_int:
  472. .. rst-class:: classref-operator
  473. :ref:`Basis<class_Basis>` **operator /** **(** :ref:`int<class_int>` right **)**
  474. This operator divides all components of the **Basis**, which inversely scales it uniformly.
  475. .. rst-class:: classref-item-separator
  476. ----
  477. .. _class_Basis_operator_eq_Basis:
  478. .. rst-class:: classref-operator
  479. :ref:`bool<class_bool>` **operator ==** **(** :ref:`Basis<class_Basis>` right **)**
  480. Returns ``true`` if the **Basis** matrices are exactly equal.
  481. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Basis_method_is_equal_approx>` instead, which is more reliable.
  482. .. rst-class:: classref-item-separator
  483. ----
  484. .. _class_Basis_operator_idx_int:
  485. .. rst-class:: classref-operator
  486. :ref:`Vector3<class_Vector3>` **operator []** **(** :ref:`int<class_int>` index **)**
  487. Access basis components using their index. ``b[0]`` is equivalent to ``b.x``, ``b[1]`` is equivalent to ``b.y``, and ``b[2]`` is equivalent to ``b.z``.
  488. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  489. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  490. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  491. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  492. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  493. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  494. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`