class_basis.rst 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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. The **Basis** built-in :ref:`Variant<class_Variant>` type is a 3×3 `matrix <https://en.wikipedia.org/wiki/Matrix_(mathematics)>`__ used to represent 3D rotation, scale, and shear. It is frequently used within a :ref:`Transform3D<class_Transform3D>`.
  14. A **Basis** is composed by 3 axis vectors, each representing a column of the matrix: :ref:`x<class_Basis_property_x>`, :ref:`y<class_Basis_property_y>`, and :ref:`z<class_Basis_property_z>`. The length of each axis (:ref:`Vector3.length()<class_Vector3_method_length>`) influences the basis's scale, while the direction of all axes influence the rotation. Usually, these axes are perpendicular to one another. However, when you rotate any axis individually, the basis becomes sheared. Applying a sheared basis to a 3D model will make the model appear distorted.
  15. A **Basis** is:
  16. - **Orthogonal** if its axes are perpendicular to each other.
  17. - **Normalized** if the length of every axis is ``1.0``.
  18. - **Uniform** if all axes share the same length (see :ref:`get_scale()<class_Basis_method_get_scale>`).
  19. - **Orthonormal** if it is both orthogonal and normalized, which allows it to only represent rotations (see :ref:`orthonormalized()<class_Basis_method_orthonormalized>`).
  20. - **Conformal** if it is both orthogonal and uniform, which ensures it is not distorted.
  21. For a general introduction, see the :doc:`Matrices and transforms <../tutorials/math/matrices_and_transforms>` tutorial.
  22. \ **Note:** Godot uses a `right-handed coordinate system <https://en.wikipedia.org/wiki/Right-hand_rule>`__, which is a common standard. For directions, the convention for built-in types like :ref:`Camera3D<class_Camera3D>` is for -Z to point forward (+X is right, +Y is up, and +Z is back). Other objects may use different direction conventions. For more information, see the `3D asset direction conventions <../tutorials/assets_pipeline/importing_3d_scenes/model_export_considerations.html#d-asset-direction-conventions>`__ tutorial.
  23. \ **Note:** The basis matrices are exposed as `column-major <https://www.mindcontrol.org/~hplus/graphics/matrix-layout.html>`__ order, which is the same as OpenGL. However, they are stored internally in row-major order, which is the same as DirectX.
  24. .. note::
  25. There are notable differences when using this API with C#. See :ref:`doc_c_sharp_differences` for more information.
  26. .. rst-class:: classref-introduction-group
  27. Tutorials
  28. ---------
  29. - :doc:`Math documentation index <../tutorials/math/index>`
  30. - :doc:`Matrices and transforms <../tutorials/math/matrices_and_transforms>`
  31. - :doc:`Using 3D transforms <../tutorials/3d/using_transforms>`
  32. - `Matrix Transform Demo <https://godotengine.org/asset-library/asset/2787>`__
  33. - `3D Platformer Demo <https://godotengine.org/asset-library/asset/2748>`__
  34. - `3D Voxel Demo <https://godotengine.org/asset-library/asset/2755>`__
  35. - `2.5D Game Demo <https://godotengine.org/asset-library/asset/2783>`__
  36. .. rst-class:: classref-reftable-group
  37. Properties
  38. ----------
  39. .. table::
  40. :widths: auto
  41. +-------------------------------+----------------------------------+----------------------+
  42. | :ref:`Vector3<class_Vector3>` | :ref:`x<class_Basis_property_x>` | ``Vector3(1, 0, 0)`` |
  43. +-------------------------------+----------------------------------+----------------------+
  44. | :ref:`Vector3<class_Vector3>` | :ref:`y<class_Basis_property_y>` | ``Vector3(0, 1, 0)`` |
  45. +-------------------------------+----------------------------------+----------------------+
  46. | :ref:`Vector3<class_Vector3>` | :ref:`z<class_Basis_property_z>` | ``Vector3(0, 0, 1)`` |
  47. +-------------------------------+----------------------------------+----------------------+
  48. .. rst-class:: classref-reftable-group
  49. Constructors
  50. ------------
  51. .. table::
  52. :widths: auto
  53. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_constructor_Basis>`\ (\ ) |
  55. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_constructor_Basis>`\ (\ from\: :ref:`Basis<class_Basis>`\ ) |
  57. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_constructor_Basis>`\ (\ axis\: :ref:`Vector3<class_Vector3>`, angle\: :ref:`float<class_float>`\ ) |
  59. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_constructor_Basis>`\ (\ from\: :ref:`Quaternion<class_Quaternion>`\ ) |
  61. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Basis<class_Basis>` | :ref:`Basis<class_Basis_constructor_Basis>`\ (\ x_axis\: :ref:`Vector3<class_Vector3>`, y_axis\: :ref:`Vector3<class_Vector3>`, z_axis\: :ref:`Vector3<class_Vector3>`\ ) |
  63. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. .. rst-class:: classref-reftable-group
  65. Methods
  66. -------
  67. .. table::
  68. :widths: auto
  69. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`float<class_float>` | :ref:`determinant<class_Basis_method_determinant>`\ (\ ) |const| |
  71. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`Basis<class_Basis>` | :ref:`from_euler<class_Basis_method_from_euler>`\ (\ euler\: :ref:`Vector3<class_Vector3>`, order\: :ref:`int<class_int>` = 2\ ) |static| |
  73. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`Basis<class_Basis>` | :ref:`from_scale<class_Basis_method_from_scale>`\ (\ scale\: :ref:`Vector3<class_Vector3>`\ ) |static| |
  75. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`Vector3<class_Vector3>` | :ref:`get_euler<class_Basis_method_get_euler>`\ (\ order\: :ref:`int<class_int>` = 2\ ) |const| |
  77. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`Quaternion<class_Quaternion>` | :ref:`get_rotation_quaternion<class_Basis_method_get_rotation_quaternion>`\ (\ ) |const| |
  79. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`Vector3<class_Vector3>` | :ref:`get_scale<class_Basis_method_get_scale>`\ (\ ) |const| |
  81. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`Basis<class_Basis>` | :ref:`inverse<class_Basis_method_inverse>`\ (\ ) |const| |
  83. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`bool<class_bool>` | :ref:`is_conformal<class_Basis_method_is_conformal>`\ (\ ) |const| |
  85. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Basis_method_is_equal_approx>`\ (\ b\: :ref:`Basis<class_Basis>`\ ) |const| |
  87. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`bool<class_bool>` | :ref:`is_finite<class_Basis_method_is_finite>`\ (\ ) |const| |
  89. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`Basis<class_Basis>` | :ref:`looking_at<class_Basis_method_looking_at>`\ (\ target\: :ref:`Vector3<class_Vector3>`, up\: :ref:`Vector3<class_Vector3>` = Vector3(0, 1, 0), use_model_front\: :ref:`bool<class_bool>` = false\ ) |static| |
  91. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`Basis<class_Basis>` | :ref:`orthonormalized<class_Basis_method_orthonormalized>`\ (\ ) |const| |
  93. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`Basis<class_Basis>` | :ref:`rotated<class_Basis_method_rotated>`\ (\ axis\: :ref:`Vector3<class_Vector3>`, angle\: :ref:`float<class_float>`\ ) |const| |
  95. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`Basis<class_Basis>` | :ref:`scaled<class_Basis_method_scaled>`\ (\ scale\: :ref:`Vector3<class_Vector3>`\ ) |const| |
  97. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`Basis<class_Basis>` | :ref:`scaled_local<class_Basis_method_scaled_local>`\ (\ scale\: :ref:`Vector3<class_Vector3>`\ ) |const| |
  99. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`Basis<class_Basis>` | :ref:`slerp<class_Basis_method_slerp>`\ (\ to\: :ref:`Basis<class_Basis>`, weight\: :ref:`float<class_float>`\ ) |const| |
  101. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`float<class_float>` | :ref:`tdotx<class_Basis_method_tdotx>`\ (\ with\: :ref:`Vector3<class_Vector3>`\ ) |const| |
  103. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`float<class_float>` | :ref:`tdoty<class_Basis_method_tdoty>`\ (\ with\: :ref:`Vector3<class_Vector3>`\ ) |const| |
  105. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`float<class_float>` | :ref:`tdotz<class_Basis_method_tdotz>`\ (\ with\: :ref:`Vector3<class_Vector3>`\ ) |const| |
  107. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`Basis<class_Basis>` | :ref:`transposed<class_Basis_method_transposed>`\ (\ ) |const| |
  109. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. .. rst-class:: classref-reftable-group
  111. Operators
  112. ---------
  113. .. table::
  114. :widths: auto
  115. +-------------------------------+--------------------------------------------------------------------------------------------------+
  116. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Basis_operator_neq_Basis>`\ (\ right\: :ref:`Basis<class_Basis>`\ ) |
  117. +-------------------------------+--------------------------------------------------------------------------------------------------+
  118. | :ref:`Basis<class_Basis>` | :ref:`operator *<class_Basis_operator_mul_Basis>`\ (\ right\: :ref:`Basis<class_Basis>`\ ) |
  119. +-------------------------------+--------------------------------------------------------------------------------------------------+
  120. | :ref:`Vector3<class_Vector3>` | :ref:`operator *<class_Basis_operator_mul_Vector3>`\ (\ right\: :ref:`Vector3<class_Vector3>`\ ) |
  121. +-------------------------------+--------------------------------------------------------------------------------------------------+
  122. | :ref:`Basis<class_Basis>` | :ref:`operator *<class_Basis_operator_mul_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  123. +-------------------------------+--------------------------------------------------------------------------------------------------+
  124. | :ref:`Basis<class_Basis>` | :ref:`operator *<class_Basis_operator_mul_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  125. +-------------------------------+--------------------------------------------------------------------------------------------------+
  126. | :ref:`Basis<class_Basis>` | :ref:`operator /<class_Basis_operator_div_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  127. +-------------------------------+--------------------------------------------------------------------------------------------------+
  128. | :ref:`Basis<class_Basis>` | :ref:`operator /<class_Basis_operator_div_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  129. +-------------------------------+--------------------------------------------------------------------------------------------------+
  130. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Basis_operator_eq_Basis>`\ (\ right\: :ref:`Basis<class_Basis>`\ ) |
  131. +-------------------------------+--------------------------------------------------------------------------------------------------+
  132. | :ref:`Vector3<class_Vector3>` | :ref:`operator []<class_Basis_operator_idx_int>`\ (\ index\: :ref:`int<class_int>`\ ) |
  133. +-------------------------------+--------------------------------------------------------------------------------------------------+
  134. .. rst-class:: classref-section-separator
  135. ----
  136. .. rst-class:: classref-descriptions-group
  137. Constants
  138. ---------
  139. .. _class_Basis_constant_IDENTITY:
  140. .. rst-class:: classref-constant
  141. **IDENTITY** = ``Basis(1, 0, 0, 0, 1, 0, 0, 0, 1)`` :ref:`🔗<class_Basis_constant_IDENTITY>`
  142. The identity **Basis**. This is an orthonormal basis with no rotation, no shear, and a scale of :ref:`Vector3.ONE<class_Vector3_constant_ONE>`. This also means that:
  143. - The :ref:`x<class_Basis_property_x>` points right (:ref:`Vector3.RIGHT<class_Vector3_constant_RIGHT>`);
  144. - The :ref:`y<class_Basis_property_y>` points up (:ref:`Vector3.UP<class_Vector3_constant_UP>`);
  145. - The :ref:`z<class_Basis_property_z>` points back (:ref:`Vector3.BACK<class_Vector3_constant_BACK>`).
  146. ::
  147. var basis = Basis.IDENTITY
  148. print("| X | Y | Z")
  149. print("| %.f | %.f | %.f" % [basis.x.x, basis.y.x, basis.z.x])
  150. print("| %.f | %.f | %.f" % [basis.x.y, basis.y.y, basis.z.y])
  151. print("| %.f | %.f | %.f" % [basis.x.z, basis.y.z, basis.z.z])
  152. # Prints:
  153. # | X | Y | Z
  154. # | 1 | 0 | 0
  155. # | 0 | 1 | 0
  156. # | 0 | 0 | 1
  157. If a :ref:`Vector3<class_Vector3>` or another **Basis** is transformed (multiplied) by this constant, no transformation occurs.
  158. \ **Note:** In GDScript, this constant is equivalent to creating a :ref:`Basis<class_Basis_constructor_Basis>` without any arguments. It can be used to make your code clearer, and for consistency with C#.
  159. .. _class_Basis_constant_FLIP_X:
  160. .. rst-class:: classref-constant
  161. **FLIP_X** = ``Basis(-1, 0, 0, 0, 1, 0, 0, 0, 1)`` :ref:`🔗<class_Basis_constant_FLIP_X>`
  162. When any basis is multiplied by :ref:`FLIP_X<class_Basis_constant_FLIP_X>`, it negates all components of the :ref:`x<class_Basis_property_x>` axis (the X column).
  163. When :ref:`FLIP_X<class_Basis_constant_FLIP_X>` is multiplied by any basis, it negates the :ref:`Vector3.x<class_Vector3_property_x>` component of all axes (the X row).
  164. .. _class_Basis_constant_FLIP_Y:
  165. .. rst-class:: classref-constant
  166. **FLIP_Y** = ``Basis(1, 0, 0, 0, -1, 0, 0, 0, 1)`` :ref:`🔗<class_Basis_constant_FLIP_Y>`
  167. When any basis is multiplied by :ref:`FLIP_Y<class_Basis_constant_FLIP_Y>`, it negates all components of the :ref:`y<class_Basis_property_y>` axis (the Y column).
  168. When :ref:`FLIP_Y<class_Basis_constant_FLIP_Y>` is multiplied by any basis, it negates the :ref:`Vector3.y<class_Vector3_property_y>` component of all axes (the Y row).
  169. .. _class_Basis_constant_FLIP_Z:
  170. .. rst-class:: classref-constant
  171. **FLIP_Z** = ``Basis(1, 0, 0, 0, 1, 0, 0, 0, -1)`` :ref:`🔗<class_Basis_constant_FLIP_Z>`
  172. When any basis is multiplied by :ref:`FLIP_Z<class_Basis_constant_FLIP_Z>`, it negates all components of the :ref:`z<class_Basis_property_z>` axis (the Z column).
  173. When :ref:`FLIP_Z<class_Basis_constant_FLIP_Z>` is multiplied by any basis, it negates the :ref:`Vector3.z<class_Vector3_property_z>` component of all axes (the Z row).
  174. .. rst-class:: classref-section-separator
  175. ----
  176. .. rst-class:: classref-descriptions-group
  177. Property Descriptions
  178. ---------------------
  179. .. _class_Basis_property_x:
  180. .. rst-class:: classref-property
  181. :ref:`Vector3<class_Vector3>` **x** = ``Vector3(1, 0, 0)`` :ref:`🔗<class_Basis_property_x>`
  182. The basis's X axis, and the column ``0`` of the matrix.
  183. On the identity basis, this vector points right (:ref:`Vector3.RIGHT<class_Vector3_constant_RIGHT>`).
  184. .. rst-class:: classref-item-separator
  185. ----
  186. .. _class_Basis_property_y:
  187. .. rst-class:: classref-property
  188. :ref:`Vector3<class_Vector3>` **y** = ``Vector3(0, 1, 0)`` :ref:`🔗<class_Basis_property_y>`
  189. The basis's Y axis, and the column ``1`` of the matrix.
  190. On the identity basis, this vector points up (:ref:`Vector3.UP<class_Vector3_constant_UP>`).
  191. .. rst-class:: classref-item-separator
  192. ----
  193. .. _class_Basis_property_z:
  194. .. rst-class:: classref-property
  195. :ref:`Vector3<class_Vector3>` **z** = ``Vector3(0, 0, 1)`` :ref:`🔗<class_Basis_property_z>`
  196. The basis's Z axis, and the column ``2`` of the matrix.
  197. On the identity basis, this vector points back (:ref:`Vector3.BACK<class_Vector3_constant_BACK>`).
  198. .. rst-class:: classref-section-separator
  199. ----
  200. .. rst-class:: classref-descriptions-group
  201. Constructor Descriptions
  202. ------------------------
  203. .. _class_Basis_constructor_Basis:
  204. .. rst-class:: classref-constructor
  205. :ref:`Basis<class_Basis>` **Basis**\ (\ ) :ref:`🔗<class_Basis_constructor_Basis>`
  206. Constructs a **Basis** identical to :ref:`IDENTITY<class_Basis_constant_IDENTITY>`.
  207. \ **Note:** In C#, this constructs a **Basis** with all of its components set to :ref:`Vector3.ZERO<class_Vector3_constant_ZERO>`.
  208. .. rst-class:: classref-item-separator
  209. ----
  210. .. rst-class:: classref-constructor
  211. :ref:`Basis<class_Basis>` **Basis**\ (\ from\: :ref:`Basis<class_Basis>`\ )
  212. Constructs a **Basis** as a copy of the given **Basis**.
  213. .. rst-class:: classref-item-separator
  214. ----
  215. .. rst-class:: classref-constructor
  216. :ref:`Basis<class_Basis>` **Basis**\ (\ axis\: :ref:`Vector3<class_Vector3>`, angle\: :ref:`float<class_float>`\ )
  217. Constructs a **Basis** that only represents rotation, rotated around the ``axis`` by the given ``angle``, in radians. The axis must be a normalized vector.
  218. \ **Note:** This is the same as using :ref:`rotated()<class_Basis_method_rotated>` on the :ref:`IDENTITY<class_Basis_constant_IDENTITY>` basis. With more than one angle consider using :ref:`from_euler()<class_Basis_method_from_euler>`, instead.
  219. .. rst-class:: classref-item-separator
  220. ----
  221. .. rst-class:: classref-constructor
  222. :ref:`Basis<class_Basis>` **Basis**\ (\ from\: :ref:`Quaternion<class_Quaternion>`\ )
  223. Constructs a **Basis** that only represents rotation from the given :ref:`Quaternion<class_Quaternion>`.
  224. \ **Note:** Quaternions *only* store rotation, not scale. Because of this, conversions from **Basis** to :ref:`Quaternion<class_Quaternion>` cannot always be reversed.
  225. .. rst-class:: classref-item-separator
  226. ----
  227. .. rst-class:: classref-constructor
  228. :ref:`Basis<class_Basis>` **Basis**\ (\ x_axis\: :ref:`Vector3<class_Vector3>`, y_axis\: :ref:`Vector3<class_Vector3>`, z_axis\: :ref:`Vector3<class_Vector3>`\ )
  229. Constructs a **Basis** from 3 axis vectors. These are the columns of the basis matrix.
  230. .. rst-class:: classref-section-separator
  231. ----
  232. .. rst-class:: classref-descriptions-group
  233. Method Descriptions
  234. -------------------
  235. .. _class_Basis_method_determinant:
  236. .. rst-class:: classref-method
  237. :ref:`float<class_float>` **determinant**\ (\ ) |const| :ref:`🔗<class_Basis_method_determinant>`
  238. Returns the `determinant <https://en.wikipedia.org/wiki/Determinant>`__ of this basis's matrix. For advanced math, this number can be used to determine a few attributes:
  239. - If the determinant is exactly ``0.0``, the basis is not invertible (see :ref:`inverse()<class_Basis_method_inverse>`).
  240. - If the determinant is a negative number, the basis represents a negative scale.
  241. \ **Note:** If the basis's scale is the same for every axis, its determinant is always that scale by the power of 2.
  242. .. rst-class:: classref-item-separator
  243. ----
  244. .. _class_Basis_method_from_euler:
  245. .. rst-class:: classref-method
  246. :ref:`Basis<class_Basis>` **from_euler**\ (\ euler\: :ref:`Vector3<class_Vector3>`, order\: :ref:`int<class_int>` = 2\ ) |static| :ref:`🔗<class_Basis_method_from_euler>`
  247. Constructs a new **Basis** that only represents rotation from the given :ref:`Vector3<class_Vector3>` of `Euler angles <https://en.wikipedia.org/wiki/Euler_angles>`__, in radians.
  248. - The :ref:`Vector3.x<class_Vector3_property_x>` should contain the angle around the :ref:`x<class_Basis_property_x>` axis (pitch);
  249. - The :ref:`Vector3.y<class_Vector3_property_y>` should contain the angle around the :ref:`y<class_Basis_property_y>` axis (yaw);
  250. - The :ref:`Vector3.z<class_Vector3_property_z>` should contain the angle around the :ref:`z<class_Basis_property_z>` axis (roll).
  251. .. tabs::
  252. .. code-tab:: gdscript
  253. # Creates a Basis whose z axis points down.
  254. var my_basis = Basis.from_euler(Vector3(TAU / 4, 0, 0))
  255. print(my_basis.z) # Prints (0.0, -1.0, 0.0)
  256. .. code-tab:: csharp
  257. // Creates a Basis whose z axis points down.
  258. var myBasis = Basis.FromEuler(new Vector3(Mathf.Tau / 4.0f, 0.0f, 0.0f));
  259. GD.Print(myBasis.Z); // Prints (0, -1, 0)
  260. The order of each consecutive rotation can be changed with ``order`` (see :ref:`EulerOrder<enum_@GlobalScope_EulerOrder>` constants). By default, the YXZ convention is used (:ref:`@GlobalScope.EULER_ORDER_YXZ<class_@GlobalScope_constant_EULER_ORDER_YXZ>`): the basis rotates first around the Y axis (yaw), then X (pitch), and lastly Z (roll). When using the opposite method :ref:`get_euler()<class_Basis_method_get_euler>`, this order is reversed.
  261. .. rst-class:: classref-item-separator
  262. ----
  263. .. _class_Basis_method_from_scale:
  264. .. rst-class:: classref-method
  265. :ref:`Basis<class_Basis>` **from_scale**\ (\ scale\: :ref:`Vector3<class_Vector3>`\ ) |static| :ref:`🔗<class_Basis_method_from_scale>`
  266. Constructs a new **Basis** that only represents scale, with no rotation or shear, from the given ``scale`` vector.
  267. .. tabs::
  268. .. code-tab:: gdscript
  269. var my_basis = Basis.from_scale(Vector3(2, 4, 8))
  270. print(my_basis.x) # Prints (2.0, 0.0, 0.0)
  271. print(my_basis.y) # Prints (0.0, 4.0, 0.0)
  272. print(my_basis.z) # Prints (0.0, 0.0, 8.0)
  273. .. code-tab:: csharp
  274. var myBasis = Basis.FromScale(new Vector3(2.0f, 4.0f, 8.0f));
  275. GD.Print(myBasis.X); // Prints (2, 0, 0)
  276. GD.Print(myBasis.Y); // Prints (0, 4, 0)
  277. GD.Print(myBasis.Z); // Prints (0, 0, 8)
  278. \ **Note:** In linear algebra, the matrix of this basis is also known as a `diagonal matrix <https://en.wikipedia.org/wiki/Diagonal_matrix>`__.
  279. .. rst-class:: classref-item-separator
  280. ----
  281. .. _class_Basis_method_get_euler:
  282. .. rst-class:: classref-method
  283. :ref:`Vector3<class_Vector3>` **get_euler**\ (\ order\: :ref:`int<class_int>` = 2\ ) |const| :ref:`🔗<class_Basis_method_get_euler>`
  284. Returns this basis's rotation as a :ref:`Vector3<class_Vector3>` of `Euler angles <https://en.wikipedia.org/wiki/Euler_angles>`__, in radians. For the returned value:
  285. - The :ref:`Vector3.x<class_Vector3_property_x>` contains the angle around the :ref:`x<class_Basis_property_x>` axis (pitch);
  286. - The :ref:`Vector3.y<class_Vector3_property_y>` contains the angle around the :ref:`y<class_Basis_property_y>` axis (yaw);
  287. - The :ref:`Vector3.z<class_Vector3_property_z>` contains the angle around the :ref:`z<class_Basis_property_z>` axis (roll).
  288. The order of each consecutive rotation can be changed with ``order`` (see :ref:`EulerOrder<enum_@GlobalScope_EulerOrder>` constants). By default, the YXZ convention is used (:ref:`@GlobalScope.EULER_ORDER_YXZ<class_@GlobalScope_constant_EULER_ORDER_YXZ>`): Z (roll) is calculated first, then X (pitch), and lastly Y (yaw). When using the opposite method :ref:`from_euler()<class_Basis_method_from_euler>`, this order is reversed.
  289. \ **Note:** For this method to return correctly, the basis needs to be *orthonormal* (see :ref:`orthonormalized()<class_Basis_method_orthonormalized>`).
  290. \ **Note:** Euler angles are much more intuitive but are not suitable for 3D math. Because of this, consider using the :ref:`get_rotation_quaternion()<class_Basis_method_get_rotation_quaternion>` method instead, which returns a :ref:`Quaternion<class_Quaternion>`.
  291. \ **Note:** In the Inspector dock, a basis's rotation is often displayed in Euler angles (in degrees), as is the case with the :ref:`Node3D.rotation<class_Node3D_property_rotation>` property.
  292. .. rst-class:: classref-item-separator
  293. ----
  294. .. _class_Basis_method_get_rotation_quaternion:
  295. .. rst-class:: classref-method
  296. :ref:`Quaternion<class_Quaternion>` **get_rotation_quaternion**\ (\ ) |const| :ref:`🔗<class_Basis_method_get_rotation_quaternion>`
  297. Returns this basis's rotation as a :ref:`Quaternion<class_Quaternion>`.
  298. \ **Note:** Quaternions are much more suitable for 3D math but are less intuitive. For user interfaces, consider using the :ref:`get_euler()<class_Basis_method_get_euler>` method, which returns Euler angles.
  299. .. rst-class:: classref-item-separator
  300. ----
  301. .. _class_Basis_method_get_scale:
  302. .. rst-class:: classref-method
  303. :ref:`Vector3<class_Vector3>` **get_scale**\ (\ ) |const| :ref:`🔗<class_Basis_method_get_scale>`
  304. Returns the length of each axis of this basis, as a :ref:`Vector3<class_Vector3>`. If the basis is not sheared, this value is the scaling factor. It is not affected by rotation.
  305. .. tabs::
  306. .. code-tab:: gdscript
  307. var my_basis = Basis(
  308. Vector3(2, 0, 0),
  309. Vector3(0, 4, 0),
  310. Vector3(0, 0, 8)
  311. )
  312. # Rotating the Basis in any way preserves its scale.
  313. my_basis = my_basis.rotated(Vector3.UP, TAU / 2)
  314. my_basis = my_basis.rotated(Vector3.RIGHT, TAU / 4)
  315. print(my_basis.get_scale()) # Prints (2.0, 4.0, 8.0)
  316. .. code-tab:: csharp
  317. var myBasis = new Basis(
  318. Vector3(2.0f, 0.0f, 0.0f),
  319. Vector3(0.0f, 4.0f, 0.0f),
  320. Vector3(0.0f, 0.0f, 8.0f)
  321. );
  322. // Rotating the Basis in any way preserves its scale.
  323. myBasis = myBasis.Rotated(Vector3.Up, Mathf.Tau / 2.0f);
  324. myBasis = myBasis.Rotated(Vector3.Right, Mathf.Tau / 4.0f);
  325. GD.Print(myBasis.Scale); // Prints (2, 4, 8)
  326. \ **Note:** If the value returned by :ref:`determinant()<class_Basis_method_determinant>` is negative, the scale is also negative.
  327. .. rst-class:: classref-item-separator
  328. ----
  329. .. _class_Basis_method_inverse:
  330. .. rst-class:: classref-method
  331. :ref:`Basis<class_Basis>` **inverse**\ (\ ) |const| :ref:`🔗<class_Basis_method_inverse>`
  332. Returns the `inverse of this basis's matrix <https://en.wikipedia.org/wiki/Invertible_matrix>`__.
  333. .. rst-class:: classref-item-separator
  334. ----
  335. .. _class_Basis_method_is_conformal:
  336. .. rst-class:: classref-method
  337. :ref:`bool<class_bool>` **is_conformal**\ (\ ) |const| :ref:`🔗<class_Basis_method_is_conformal>`
  338. Returns ``true`` if this basis is conformal. A conformal basis is both *orthogonal* (the axes are perpendicular to each other) and *uniform* (the axes share the same length). This method can be especially useful during physics calculations.
  339. .. rst-class:: classref-item-separator
  340. ----
  341. .. _class_Basis_method_is_equal_approx:
  342. .. rst-class:: classref-method
  343. :ref:`bool<class_bool>` **is_equal_approx**\ (\ b\: :ref:`Basis<class_Basis>`\ ) |const| :ref:`🔗<class_Basis_method_is_equal_approx>`
  344. 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.
  345. .. rst-class:: classref-item-separator
  346. ----
  347. .. _class_Basis_method_is_finite:
  348. .. rst-class:: classref-method
  349. :ref:`bool<class_bool>` **is_finite**\ (\ ) |const| :ref:`🔗<class_Basis_method_is_finite>`
  350. Returns ``true`` if this basis is finite, by calling :ref:`@GlobalScope.is_finite()<class_@GlobalScope_method_is_finite>` on all vector components.
  351. .. rst-class:: classref-item-separator
  352. ----
  353. .. _class_Basis_method_looking_at:
  354. .. rst-class:: classref-method
  355. :ref:`Basis<class_Basis>` **looking_at**\ (\ target\: :ref:`Vector3<class_Vector3>`, up\: :ref:`Vector3<class_Vector3>` = Vector3(0, 1, 0), use_model_front\: :ref:`bool<class_bool>` = false\ ) |static| :ref:`🔗<class_Basis_method_looking_at>`
  356. Creates a new **Basis** with a rotation such that the forward axis (-Z) points towards the ``target`` position.
  357. By default, the -Z axis (camera forward) is treated as forward (implies +X is right). 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.
  358. The up axis (+Y) points as close to the ``up`` vector as possible while staying perpendicular to the forward axis. The returned basis is orthonormalized (see :ref:`orthonormalized()<class_Basis_method_orthonormalized>`).
  359. The ``target`` and the ``up`` cannot be :ref:`Vector3.ZERO<class_Vector3_constant_ZERO>`, and shouldn't be colinear to avoid unintended rotation around local Z axis.
  360. .. rst-class:: classref-item-separator
  361. ----
  362. .. _class_Basis_method_orthonormalized:
  363. .. rst-class:: classref-method
  364. :ref:`Basis<class_Basis>` **orthonormalized**\ (\ ) |const| :ref:`🔗<class_Basis_method_orthonormalized>`
  365. Returns the orthonormalized version of this basis. An orthonormal basis is both *orthogonal* (the axes are perpendicular to each other) and *normalized* (the axes have a length of ``1.0``), which also means it can only represent a rotation.
  366. It is often useful to call this method to avoid rounding errors on a rotating basis:
  367. .. tabs::
  368. .. code-tab:: gdscript
  369. # Rotate this Node3D every frame.
  370. func _process(delta):
  371. basis = basis.rotated(Vector3.UP, TAU * delta)
  372. basis = basis.rotated(Vector3.RIGHT, TAU * delta)
  373. basis = basis.orthonormalized()
  374. .. code-tab:: csharp
  375. // Rotate this Node3D every frame.
  376. public override void _Process(double delta)
  377. {
  378. Basis = Basis.Rotated(Vector3.Up, Mathf.Tau * (float)delta)
  379. .Rotated(Vector3.Right, Mathf.Tau * (float)delta)
  380. .Orthonormalized();
  381. }
  382. .. rst-class:: classref-item-separator
  383. ----
  384. .. _class_Basis_method_rotated:
  385. .. rst-class:: classref-method
  386. :ref:`Basis<class_Basis>` **rotated**\ (\ axis\: :ref:`Vector3<class_Vector3>`, angle\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Basis_method_rotated>`
  387. Returns a copy of this basis rotated around the given ``axis`` by the given ``angle`` (in radians).
  388. The ``axis`` must be a normalized vector (see :ref:`Vector3.normalized()<class_Vector3_method_normalized>`). If ``angle`` is positive, the basis is rotated counter-clockwise around the axis.
  389. .. tabs::
  390. .. code-tab:: gdscript
  391. var my_basis = Basis.IDENTITY
  392. var angle = TAU / 2
  393. my_basis = my_basis.rotated(Vector3.UP, angle) # Rotate around the up axis (yaw).
  394. my_basis = my_basis.rotated(Vector3.RIGHT, angle) # Rotate around the right axis (pitch).
  395. my_basis = my_basis.rotated(Vector3.BACK, angle) # Rotate around the back axis (roll).
  396. .. code-tab:: csharp
  397. var myBasis = Basis.Identity;
  398. var angle = Mathf.Tau / 2.0f;
  399. myBasis = myBasis.Rotated(Vector3.Up, angle); // Rotate around the up axis (yaw).
  400. myBasis = myBasis.Rotated(Vector3.Right, angle); // Rotate around the right axis (pitch).
  401. myBasis = myBasis.Rotated(Vector3.Back, angle); // Rotate around the back axis (roll).
  402. .. rst-class:: classref-item-separator
  403. ----
  404. .. _class_Basis_method_scaled:
  405. .. rst-class:: classref-method
  406. :ref:`Basis<class_Basis>` **scaled**\ (\ scale\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_Basis_method_scaled>`
  407. Returns this basis with each axis's components scaled by the given ``scale``'s components.
  408. The basis matrix's rows are multiplied by ``scale``'s components. This operation is a global scale (relative to the parent).
  409. .. tabs::
  410. .. code-tab:: gdscript
  411. var my_basis = Basis(
  412. Vector3(1, 1, 1),
  413. Vector3(2, 2, 2),
  414. Vector3(3, 3, 3)
  415. )
  416. my_basis = my_basis.scaled(Vector3(0, 2, -2))
  417. print(my_basis.x) # Prints (0.0, 2.0, -2.0)
  418. print(my_basis.y) # Prints (0.0, 4.0, -4.0)
  419. print(my_basis.z) # Prints (0.0, 6.0, -6.0)
  420. .. code-tab:: csharp
  421. var myBasis = new Basis(
  422. new Vector3(1.0f, 1.0f, 1.0f),
  423. new Vector3(2.0f, 2.0f, 2.0f),
  424. new Vector3(3.0f, 3.0f, 3.0f)
  425. );
  426. myBasis = myBasis.Scaled(new Vector3(0.0f, 2.0f, -2.0f));
  427. GD.Print(myBasis.X); // Prints (0, 2, -2)
  428. GD.Print(myBasis.Y); // Prints (0, 4, -4)
  429. GD.Print(myBasis.Z); // Prints (0, 6, -6)
  430. .. rst-class:: classref-item-separator
  431. ----
  432. .. _class_Basis_method_scaled_local:
  433. .. rst-class:: classref-method
  434. :ref:`Basis<class_Basis>` **scaled_local**\ (\ scale\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_Basis_method_scaled_local>`
  435. Returns this basis with each axis scaled by the corresponding component in the given ``scale``.
  436. The basis matrix's columns are multiplied by ``scale``'s components. This operation is a local scale (relative to self).
  437. .. tabs::
  438. .. code-tab:: gdscript
  439. var my_basis = Basis(
  440. Vector3(1, 1, 1),
  441. Vector3(2, 2, 2),
  442. Vector3(3, 3, 3)
  443. )
  444. my_basis = my_basis.scaled_local(Vector3(0, 2, -2))
  445. print(my_basis.x) # Prints (0.0, 0.0, 0.0)
  446. print(my_basis.y) # Prints (4.0, 4.0, 4.0)
  447. print(my_basis.z) # Prints (-6.0, -6.0, -6.0)
  448. .. code-tab:: csharp
  449. var myBasis = new Basis(
  450. new Vector3(1.0f, 1.0f, 1.0f),
  451. new Vector3(2.0f, 2.0f, 2.0f),
  452. new Vector3(3.0f, 3.0f, 3.0f)
  453. );
  454. myBasis = myBasis.ScaledLocal(new Vector3(0.0f, 2.0f, -2.0f));
  455. GD.Print(myBasis.X); // Prints (0, 0, 0)
  456. GD.Print(myBasis.Y); // Prints (4, 4, 4)
  457. GD.Print(myBasis.Z); // Prints (-6, -6, -6)
  458. .. rst-class:: classref-item-separator
  459. ----
  460. .. _class_Basis_method_slerp:
  461. .. rst-class:: classref-method
  462. :ref:`Basis<class_Basis>` **slerp**\ (\ to\: :ref:`Basis<class_Basis>`, weight\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Basis_method_slerp>`
  463. Performs a spherical-linear interpolation with the ``to`` basis, given a ``weight``. Both this basis and ``to`` should represent a rotation.
  464. \ **Example:** Smoothly rotate a :ref:`Node3D<class_Node3D>` to the target basis over time, with a :ref:`Tween<class_Tween>`:
  465. ::
  466. var start_basis = Basis.IDENTITY
  467. var target_basis = Basis.IDENTITY.rotated(Vector3.UP, TAU / 2)
  468. func _ready():
  469. create_tween().tween_method(interpolate, 0.0, 1.0, 5.0).set_trans(Tween.TRANS_EXPO)
  470. func interpolate(weight):
  471. basis = start_basis.slerp(target_basis, weight)
  472. .. rst-class:: classref-item-separator
  473. ----
  474. .. _class_Basis_method_tdotx:
  475. .. rst-class:: classref-method
  476. :ref:`float<class_float>` **tdotx**\ (\ with\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_Basis_method_tdotx>`
  477. Returns the transposed dot product between ``with`` and the :ref:`x<class_Basis_property_x>` axis (see :ref:`transposed()<class_Basis_method_transposed>`).
  478. This is equivalent to ``basis.x.dot(vector)``.
  479. .. rst-class:: classref-item-separator
  480. ----
  481. .. _class_Basis_method_tdoty:
  482. .. rst-class:: classref-method
  483. :ref:`float<class_float>` **tdoty**\ (\ with\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_Basis_method_tdoty>`
  484. Returns the transposed dot product between ``with`` and the :ref:`y<class_Basis_property_y>` axis (see :ref:`transposed()<class_Basis_method_transposed>`).
  485. This is equivalent to ``basis.y.dot(vector)``.
  486. .. rst-class:: classref-item-separator
  487. ----
  488. .. _class_Basis_method_tdotz:
  489. .. rst-class:: classref-method
  490. :ref:`float<class_float>` **tdotz**\ (\ with\: :ref:`Vector3<class_Vector3>`\ ) |const| :ref:`🔗<class_Basis_method_tdotz>`
  491. Returns the transposed dot product between ``with`` and the :ref:`z<class_Basis_property_z>` axis (see :ref:`transposed()<class_Basis_method_transposed>`).
  492. This is equivalent to ``basis.z.dot(vector)``.
  493. .. rst-class:: classref-item-separator
  494. ----
  495. .. _class_Basis_method_transposed:
  496. .. rst-class:: classref-method
  497. :ref:`Basis<class_Basis>` **transposed**\ (\ ) |const| :ref:`🔗<class_Basis_method_transposed>`
  498. Returns the transposed version of this basis. This turns the basis matrix's columns into rows, and its rows into columns.
  499. .. tabs::
  500. .. code-tab:: gdscript
  501. var my_basis = Basis(
  502. Vector3(1, 2, 3),
  503. Vector3(4, 5, 6),
  504. Vector3(7, 8, 9)
  505. )
  506. my_basis = my_basis.transposed()
  507. print(my_basis.x) # Prints (1.0, 4.0, 7.0)
  508. print(my_basis.y) # Prints (2.0, 5.0, 8.0)
  509. print(my_basis.z) # Prints (3.0, 6.0, 9.0)
  510. .. code-tab:: csharp
  511. var myBasis = new Basis(
  512. new Vector3(1.0f, 2.0f, 3.0f),
  513. new Vector3(4.0f, 5.0f, 6.0f),
  514. new Vector3(7.0f, 8.0f, 9.0f)
  515. );
  516. myBasis = myBasis.Transposed();
  517. GD.Print(myBasis.X); // Prints (1, 4, 7)
  518. GD.Print(myBasis.Y); // Prints (2, 5, 8)
  519. GD.Print(myBasis.Z); // Prints (3, 6, 9)
  520. .. rst-class:: classref-section-separator
  521. ----
  522. .. rst-class:: classref-descriptions-group
  523. Operator Descriptions
  524. ---------------------
  525. .. _class_Basis_operator_neq_Basis:
  526. .. rst-class:: classref-operator
  527. :ref:`bool<class_bool>` **operator !=**\ (\ right\: :ref:`Basis<class_Basis>`\ ) :ref:`🔗<class_Basis_operator_neq_Basis>`
  528. Returns ``true`` if the components of both **Basis** matrices are not equal.
  529. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx()<class_Basis_method_is_equal_approx>` instead, which is more reliable.
  530. .. rst-class:: classref-item-separator
  531. ----
  532. .. _class_Basis_operator_mul_Basis:
  533. .. rst-class:: classref-operator
  534. :ref:`Basis<class_Basis>` **operator ***\ (\ right\: :ref:`Basis<class_Basis>`\ ) :ref:`🔗<class_Basis_operator_mul_Basis>`
  535. Transforms (multiplies) the ``right`` basis by this basis.
  536. This is the operation performed between parent and child :ref:`Node3D<class_Node3D>`\ s.
  537. .. rst-class:: classref-item-separator
  538. ----
  539. .. _class_Basis_operator_mul_Vector3:
  540. .. rst-class:: classref-operator
  541. :ref:`Vector3<class_Vector3>` **operator ***\ (\ right\: :ref:`Vector3<class_Vector3>`\ ) :ref:`🔗<class_Basis_operator_mul_Vector3>`
  542. Transforms (multiplies) the ``right`` vector by this basis, returning a :ref:`Vector3<class_Vector3>`.
  543. .. tabs::
  544. .. code-tab:: gdscript
  545. # Basis that swaps the X/Z axes and doubles the scale.
  546. var my_basis = Basis(Vector3(0, 2, 0), Vector3(2, 0, 0), Vector3(0, 0, 2))
  547. print(my_basis * Vector3(1, 2, 3)) # Prints (4.0, 2.0, 6.0)
  548. .. code-tab:: csharp
  549. // Basis that swaps the X/Z axes and doubles the scale.
  550. var myBasis = new Basis(new Vector3(0, 2, 0), new Vector3(2, 0, 0), new Vector3(0, 0, 2));
  551. GD.Print(myBasis * new Vector3(1, 2, 3)); // Prints (4, 2, 6)
  552. .. rst-class:: classref-item-separator
  553. ----
  554. .. _class_Basis_operator_mul_float:
  555. .. rst-class:: classref-operator
  556. :ref:`Basis<class_Basis>` **operator ***\ (\ right\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Basis_operator_mul_float>`
  557. Multiplies all components of the **Basis** by the given :ref:`float<class_float>`. This affects the basis's scale uniformly, resizing all 3 axes by the ``right`` value.
  558. .. rst-class:: classref-item-separator
  559. ----
  560. .. _class_Basis_operator_mul_int:
  561. .. rst-class:: classref-operator
  562. :ref:`Basis<class_Basis>` **operator ***\ (\ right\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Basis_operator_mul_int>`
  563. Multiplies all components of the **Basis** by the given :ref:`int<class_int>`. This affects the basis's scale uniformly, resizing all 3 axes by the ``right`` value.
  564. .. rst-class:: classref-item-separator
  565. ----
  566. .. _class_Basis_operator_div_float:
  567. .. rst-class:: classref-operator
  568. :ref:`Basis<class_Basis>` **operator /**\ (\ right\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Basis_operator_div_float>`
  569. Divides all components of the **Basis** by the given :ref:`float<class_float>`. This affects the basis's scale uniformly, resizing all 3 axes by the ``right`` value.
  570. .. rst-class:: classref-item-separator
  571. ----
  572. .. _class_Basis_operator_div_int:
  573. .. rst-class:: classref-operator
  574. :ref:`Basis<class_Basis>` **operator /**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Basis_operator_div_int>`
  575. Divides all components of the **Basis** by the given :ref:`int<class_int>`. This affects the basis's scale uniformly, resizing all 3 axes by the ``right`` value.
  576. .. rst-class:: classref-item-separator
  577. ----
  578. .. _class_Basis_operator_eq_Basis:
  579. .. rst-class:: classref-operator
  580. :ref:`bool<class_bool>` **operator ==**\ (\ right\: :ref:`Basis<class_Basis>`\ ) :ref:`🔗<class_Basis_operator_eq_Basis>`
  581. Returns ``true`` if the components of both **Basis** matrices are exactly equal.
  582. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx()<class_Basis_method_is_equal_approx>` instead, which is more reliable.
  583. .. rst-class:: classref-item-separator
  584. ----
  585. .. _class_Basis_operator_idx_int:
  586. .. rst-class:: classref-operator
  587. :ref:`Vector3<class_Vector3>` **operator []**\ (\ index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Basis_operator_idx_int>`
  588. Accesses each axis (column) of this basis by their index. Index ``0`` is the same as :ref:`x<class_Basis_property_x>`, index ``1`` is the same as :ref:`y<class_Basis_property_y>`, and index ``2`` is the same as :ref:`z<class_Basis_property_z>`.
  589. \ **Note:** In C++, this operator accesses the rows of the basis matrix, *not* the columns. For the same behavior as scripting languages, use the ``set_column`` and ``get_column`` methods.
  590. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  591. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  592. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  593. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  594. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  595. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  596. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  597. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  598. .. |void| replace:: :abbr:`void (No return value.)`