class_transform2d.rst 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  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/4.3/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.3/doc/classes/Transform2D.xml.
  6. .. _class_Transform2D:
  7. Transform2D
  8. ===========
  9. A 2×3 matrix representing a 2D transformation.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. The **Transform2D** built-in :ref:`Variant<class_Variant>` type is a 2×3 `matrix <https://en.wikipedia.org/wiki/Matrix_(mathematics)>`__ representing a transformation in 2D space. It contains three :ref:`Vector2<class_Vector2>` values: :ref:`x<class_Transform2D_property_x>`, :ref:`y<class_Transform2D_property_y>`, and :ref:`origin<class_Transform2D_property_origin>`. Together, they can represent translation, rotation, scale, and skew.
  14. The :ref:`x<class_Transform2D_property_x>` and :ref:`y<class_Transform2D_property_y>` axes form a 2×2 matrix, known as the transform's **basis**. The length of each axis (:ref:`Vector2.length<class_Vector2_method_length>`) influences the transform's scale, while the direction of all axes influence the rotation. Usually, both axes are perpendicular to one another. However, when you rotate one axis individually, the transform becomes skewed. Applying a skewed transform to a 2D sprite will make the sprite appear distorted.
  15. For a general introduction, see the :doc:`Matrices and transforms <../tutorials/math/matrices_and_transforms>` tutorial.
  16. \ **Note:** Unlike :ref:`Transform3D<class_Transform3D>`, there is no 2D equivalent to the :ref:`Basis<class_Basis>` type. All mentions of "basis" refer to the :ref:`x<class_Transform2D_property_x>` and :ref:`y<class_Transform2D_property_y>` components of **Transform2D**.
  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. - `Matrix Transform Demo <https://godotengine.org/asset-library/asset/2787>`__
  25. - `2.5D Game Demo <https://godotengine.org/asset-library/asset/2783>`__
  26. .. rst-class:: classref-reftable-group
  27. Properties
  28. ----------
  29. .. table::
  30. :widths: auto
  31. +-------------------------------+--------------------------------------------------+-------------------+
  32. | :ref:`Vector2<class_Vector2>` | :ref:`origin<class_Transform2D_property_origin>` | ``Vector2(0, 0)`` |
  33. +-------------------------------+--------------------------------------------------+-------------------+
  34. | :ref:`Vector2<class_Vector2>` | :ref:`x<class_Transform2D_property_x>` | ``Vector2(1, 0)`` |
  35. +-------------------------------+--------------------------------------------------+-------------------+
  36. | :ref:`Vector2<class_Vector2>` | :ref:`y<class_Transform2D_property_y>` | ``Vector2(0, 1)`` |
  37. +-------------------------------+--------------------------------------------------+-------------------+
  38. .. rst-class:: classref-reftable-group
  39. Constructors
  40. ------------
  41. .. table::
  42. :widths: auto
  43. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`Transform2D<class_Transform2D>` | :ref:`Transform2D<class_Transform2D_constructor_Transform2D>`\ (\ ) |
  45. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Transform2D<class_Transform2D>` | :ref:`Transform2D<class_Transform2D_constructor_Transform2D>`\ (\ from\: :ref:`Transform2D<class_Transform2D>`\ ) |
  47. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`Transform2D<class_Transform2D>` | :ref:`Transform2D<class_Transform2D_constructor_Transform2D>`\ (\ rotation\: :ref:`float<class_float>`, position\: :ref:`Vector2<class_Vector2>`\ ) |
  49. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Transform2D<class_Transform2D>` | :ref:`Transform2D<class_Transform2D_constructor_Transform2D>`\ (\ rotation\: :ref:`float<class_float>`, scale\: :ref:`Vector2<class_Vector2>`, skew\: :ref:`float<class_float>`, position\: :ref:`Vector2<class_Vector2>`\ ) |
  51. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Transform2D<class_Transform2D>` | :ref:`Transform2D<class_Transform2D_constructor_Transform2D>`\ (\ x_axis\: :ref:`Vector2<class_Vector2>`, y_axis\: :ref:`Vector2<class_Vector2>`, origin\: :ref:`Vector2<class_Vector2>`\ ) |
  53. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. .. rst-class:: classref-reftable-group
  55. Methods
  56. -------
  57. .. table::
  58. :widths: auto
  59. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Transform2D<class_Transform2D>` | :ref:`affine_inverse<class_Transform2D_method_affine_inverse>`\ (\ ) |const| |
  61. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Vector2<class_Vector2>` | :ref:`basis_xform<class_Transform2D_method_basis_xform>`\ (\ v\: :ref:`Vector2<class_Vector2>`\ ) |const| |
  63. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`Vector2<class_Vector2>` | :ref:`basis_xform_inv<class_Transform2D_method_basis_xform_inv>`\ (\ v\: :ref:`Vector2<class_Vector2>`\ ) |const| |
  65. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`float<class_float>` | :ref:`determinant<class_Transform2D_method_determinant>`\ (\ ) |const| |
  67. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`Vector2<class_Vector2>` | :ref:`get_origin<class_Transform2D_method_get_origin>`\ (\ ) |const| |
  69. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`float<class_float>` | :ref:`get_rotation<class_Transform2D_method_get_rotation>`\ (\ ) |const| |
  71. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`Vector2<class_Vector2>` | :ref:`get_scale<class_Transform2D_method_get_scale>`\ (\ ) |const| |
  73. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`float<class_float>` | :ref:`get_skew<class_Transform2D_method_get_skew>`\ (\ ) |const| |
  75. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`Transform2D<class_Transform2D>` | :ref:`interpolate_with<class_Transform2D_method_interpolate_with>`\ (\ xform\: :ref:`Transform2D<class_Transform2D>`, weight\: :ref:`float<class_float>`\ ) |const| |
  77. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`Transform2D<class_Transform2D>` | :ref:`inverse<class_Transform2D_method_inverse>`\ (\ ) |const| |
  79. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`bool<class_bool>` | :ref:`is_conformal<class_Transform2D_method_is_conformal>`\ (\ ) |const| |
  81. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Transform2D_method_is_equal_approx>`\ (\ xform\: :ref:`Transform2D<class_Transform2D>`\ ) |const| |
  83. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`bool<class_bool>` | :ref:`is_finite<class_Transform2D_method_is_finite>`\ (\ ) |const| |
  85. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`Transform2D<class_Transform2D>` | :ref:`looking_at<class_Transform2D_method_looking_at>`\ (\ target\: :ref:`Vector2<class_Vector2>` = Vector2(0, 0)\ ) |const| |
  87. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`Transform2D<class_Transform2D>` | :ref:`orthonormalized<class_Transform2D_method_orthonormalized>`\ (\ ) |const| |
  89. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`Transform2D<class_Transform2D>` | :ref:`rotated<class_Transform2D_method_rotated>`\ (\ angle\: :ref:`float<class_float>`\ ) |const| |
  91. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`Transform2D<class_Transform2D>` | :ref:`rotated_local<class_Transform2D_method_rotated_local>`\ (\ angle\: :ref:`float<class_float>`\ ) |const| |
  93. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`Transform2D<class_Transform2D>` | :ref:`scaled<class_Transform2D_method_scaled>`\ (\ scale\: :ref:`Vector2<class_Vector2>`\ ) |const| |
  95. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`Transform2D<class_Transform2D>` | :ref:`scaled_local<class_Transform2D_method_scaled_local>`\ (\ scale\: :ref:`Vector2<class_Vector2>`\ ) |const| |
  97. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`Transform2D<class_Transform2D>` | :ref:`translated<class_Transform2D_method_translated>`\ (\ offset\: :ref:`Vector2<class_Vector2>`\ ) |const| |
  99. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`Transform2D<class_Transform2D>` | :ref:`translated_local<class_Transform2D_method_translated_local>`\ (\ offset\: :ref:`Vector2<class_Vector2>`\ ) |const| |
  101. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. .. rst-class:: classref-reftable-group
  103. Operators
  104. ---------
  105. .. table::
  106. :widths: auto
  107. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Transform2D_operator_neq_Transform2D>`\ (\ right\: :ref:`Transform2D<class_Transform2D>`\ ) |
  109. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  110. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`operator *<class_Transform2D_operator_mul_PackedVector2Array>`\ (\ right\: :ref:`PackedVector2Array<class_PackedVector2Array>`\ ) |
  111. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  112. | :ref:`Rect2<class_Rect2>` | :ref:`operator *<class_Transform2D_operator_mul_Rect2>`\ (\ right\: :ref:`Rect2<class_Rect2>`\ ) |
  113. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  114. | :ref:`Transform2D<class_Transform2D>` | :ref:`operator *<class_Transform2D_operator_mul_Transform2D>`\ (\ right\: :ref:`Transform2D<class_Transform2D>`\ ) |
  115. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  116. | :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_Transform2D_operator_mul_Vector2>`\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) |
  117. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  118. | :ref:`Transform2D<class_Transform2D>` | :ref:`operator *<class_Transform2D_operator_mul_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  119. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  120. | :ref:`Transform2D<class_Transform2D>` | :ref:`operator *<class_Transform2D_operator_mul_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  121. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  122. | :ref:`Transform2D<class_Transform2D>` | :ref:`operator /<class_Transform2D_operator_div_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  123. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  124. | :ref:`Transform2D<class_Transform2D>` | :ref:`operator /<class_Transform2D_operator_div_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  125. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  126. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Transform2D_operator_eq_Transform2D>`\ (\ right\: :ref:`Transform2D<class_Transform2D>`\ ) |
  127. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  128. | :ref:`Vector2<class_Vector2>` | :ref:`operator []<class_Transform2D_operator_idx_int>`\ (\ index\: :ref:`int<class_int>`\ ) |
  129. +-----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  130. .. rst-class:: classref-section-separator
  131. ----
  132. .. rst-class:: classref-descriptions-group
  133. Constants
  134. ---------
  135. .. _class_Transform2D_constant_IDENTITY:
  136. .. rst-class:: classref-constant
  137. **IDENTITY** = ``Transform2D(1, 0, 0, 1, 0, 0)`` :ref:`🔗<class_Transform2D_constant_IDENTITY>`
  138. The identity **Transform2D**. A transform with no translation, no rotation, and its scale being ``1``. When multiplied by another :ref:`Variant<class_Variant>` such as :ref:`Rect2<class_Rect2>` or another **Transform2D**, no transformation occurs. This means that:
  139. - The :ref:`x<class_Transform2D_property_x>` points right (:ref:`Vector2.RIGHT<class_Vector2_constant_RIGHT>`);
  140. - The :ref:`y<class_Transform2D_property_y>` points up (:ref:`Vector2.UP<class_Vector2_constant_UP>`).
  141. ::
  142. var transform = Transform2D.IDENTITY
  143. print("| X | Y | Origin")
  144. print("| %s | %s | %s" % [transform.x.x, transform.y.x, transform.origin.x])
  145. print("| %s | %s | %s" % [transform.x.y, transform.y.y, transform.origin.y])
  146. # Prints:
  147. # | X | Y | Origin
  148. # | 1 | 0 | 0
  149. # | 0 | 1 | 0
  150. This is identical to creating :ref:`Transform2D<class_Transform2D_constructor_Transform2D>` without any parameters. This constant can be used to make your code clearer, and for consistency with C#.
  151. .. _class_Transform2D_constant_FLIP_X:
  152. .. rst-class:: classref-constant
  153. **FLIP_X** = ``Transform2D(-1, 0, 0, 1, 0, 0)`` :ref:`🔗<class_Transform2D_constant_FLIP_X>`
  154. When any transform is multiplied by :ref:`FLIP_X<class_Transform2D_constant_FLIP_X>`, it negates all components of the :ref:`x<class_Transform2D_property_x>` axis (the X column).
  155. When :ref:`FLIP_X<class_Transform2D_constant_FLIP_X>` is multiplied by any basis, it negates the :ref:`Vector2.x<class_Vector2_property_x>` component of all axes (the X row).
  156. .. _class_Transform2D_constant_FLIP_Y:
  157. .. rst-class:: classref-constant
  158. **FLIP_Y** = ``Transform2D(1, 0, 0, -1, 0, 0)`` :ref:`🔗<class_Transform2D_constant_FLIP_Y>`
  159. When any transform is multiplied by :ref:`FLIP_Y<class_Transform2D_constant_FLIP_Y>`, it negates all components of the :ref:`y<class_Transform2D_property_y>` axis (the Y column).
  160. When :ref:`FLIP_Y<class_Transform2D_constant_FLIP_Y>` is multiplied by any basis, it negates the :ref:`Vector2.y<class_Vector2_property_y>` component of all axes (the Y row).
  161. .. rst-class:: classref-section-separator
  162. ----
  163. .. rst-class:: classref-descriptions-group
  164. Property Descriptions
  165. ---------------------
  166. .. _class_Transform2D_property_origin:
  167. .. rst-class:: classref-property
  168. :ref:`Vector2<class_Vector2>` **origin** = ``Vector2(0, 0)`` :ref:`🔗<class_Transform2D_property_origin>`
  169. The translation offset of this transform, and the column ``2`` of the matrix. In 2D space, this can be seen as the position.
  170. .. rst-class:: classref-item-separator
  171. ----
  172. .. _class_Transform2D_property_x:
  173. .. rst-class:: classref-property
  174. :ref:`Vector2<class_Vector2>` **x** = ``Vector2(1, 0)`` :ref:`🔗<class_Transform2D_property_x>`
  175. The transform basis's X axis, and the column ``0`` of the matrix. Combined with :ref:`y<class_Transform2D_property_y>`, this represents the transform's rotation, scale, and skew.
  176. On the identity transform, this vector points right (:ref:`Vector2.RIGHT<class_Vector2_constant_RIGHT>`).
  177. .. rst-class:: classref-item-separator
  178. ----
  179. .. _class_Transform2D_property_y:
  180. .. rst-class:: classref-property
  181. :ref:`Vector2<class_Vector2>` **y** = ``Vector2(0, 1)`` :ref:`🔗<class_Transform2D_property_y>`
  182. The transform basis's Y axis, and the column ``1`` of the matrix. Combined with :ref:`x<class_Transform2D_property_x>`, this represents the transform's rotation, scale, and skew.
  183. On the identity transform, this vector points up (:ref:`Vector2.UP<class_Vector2_constant_UP>`).
  184. .. rst-class:: classref-section-separator
  185. ----
  186. .. rst-class:: classref-descriptions-group
  187. Constructor Descriptions
  188. ------------------------
  189. .. _class_Transform2D_constructor_Transform2D:
  190. .. rst-class:: classref-constructor
  191. :ref:`Transform2D<class_Transform2D>` **Transform2D**\ (\ ) :ref:`🔗<class_Transform2D_constructor_Transform2D>`
  192. Constructs a **Transform2D** identical to :ref:`IDENTITY<class_Transform2D_constant_IDENTITY>`.
  193. .. rst-class:: classref-item-separator
  194. ----
  195. .. rst-class:: classref-constructor
  196. :ref:`Transform2D<class_Transform2D>` **Transform2D**\ (\ from\: :ref:`Transform2D<class_Transform2D>`\ )
  197. Constructs a **Transform2D** as a copy of the given **Transform2D**.
  198. .. rst-class:: classref-item-separator
  199. ----
  200. .. rst-class:: classref-constructor
  201. :ref:`Transform2D<class_Transform2D>` **Transform2D**\ (\ rotation\: :ref:`float<class_float>`, position\: :ref:`Vector2<class_Vector2>`\ )
  202. Constructs a **Transform2D** from a given angle (in radians) and position.
  203. .. rst-class:: classref-item-separator
  204. ----
  205. .. rst-class:: classref-constructor
  206. :ref:`Transform2D<class_Transform2D>` **Transform2D**\ (\ rotation\: :ref:`float<class_float>`, scale\: :ref:`Vector2<class_Vector2>`, skew\: :ref:`float<class_float>`, position\: :ref:`Vector2<class_Vector2>`\ )
  207. Constructs a **Transform2D** from a given angle (in radians), scale, skew (in radians), and position.
  208. .. rst-class:: classref-item-separator
  209. ----
  210. .. rst-class:: classref-constructor
  211. :ref:`Transform2D<class_Transform2D>` **Transform2D**\ (\ x_axis\: :ref:`Vector2<class_Vector2>`, y_axis\: :ref:`Vector2<class_Vector2>`, origin\: :ref:`Vector2<class_Vector2>`\ )
  212. Constructs a **Transform2D** from 3 :ref:`Vector2<class_Vector2>` values representing :ref:`x<class_Transform2D_property_x>`, :ref:`y<class_Transform2D_property_y>`, and the :ref:`origin<class_Transform2D_property_origin>` (the three matrix columns).
  213. .. rst-class:: classref-section-separator
  214. ----
  215. .. rst-class:: classref-descriptions-group
  216. Method Descriptions
  217. -------------------
  218. .. _class_Transform2D_method_affine_inverse:
  219. .. rst-class:: classref-method
  220. :ref:`Transform2D<class_Transform2D>` **affine_inverse**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_affine_inverse>`
  221. Returns the inverted version of this transform. Unlike :ref:`inverse<class_Transform2D_method_inverse>`, this method works with almost any basis, including non-uniform ones, but is slower. See also :ref:`inverse<class_Transform2D_method_inverse>`.
  222. \ **Note:** For this method to return correctly, the transform's basis needs to have a determinant that is not exactly ``0`` (see :ref:`determinant<class_Transform2D_method_determinant>`).
  223. .. rst-class:: classref-item-separator
  224. ----
  225. .. _class_Transform2D_method_basis_xform:
  226. .. rst-class:: classref-method
  227. :ref:`Vector2<class_Vector2>` **basis_xform**\ (\ v\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Transform2D_method_basis_xform>`
  228. Returns a copy of the ``v`` vector, transformed (multiplied) by the transform basis's matrix. Unlike the multiplication operator (``*``), this method ignores the :ref:`origin<class_Transform2D_property_origin>`.
  229. .. rst-class:: classref-item-separator
  230. ----
  231. .. _class_Transform2D_method_basis_xform_inv:
  232. .. rst-class:: classref-method
  233. :ref:`Vector2<class_Vector2>` **basis_xform_inv**\ (\ v\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Transform2D_method_basis_xform_inv>`
  234. Returns a copy of the ``v`` vector, transformed (multiplied) by the inverse transform basis's matrix (see :ref:`inverse<class_Transform2D_method_inverse>`). This method ignores the :ref:`origin<class_Transform2D_property_origin>`.
  235. \ **Note:** This method assumes that this transform's basis is *orthonormal* (see :ref:`orthonormalized<class_Transform2D_method_orthonormalized>`). If the basis is not orthonormal, ``transform.affine_inverse().basis_xform(vector)`` should be used instead (see :ref:`affine_inverse<class_Transform2D_method_affine_inverse>`).
  236. .. rst-class:: classref-item-separator
  237. ----
  238. .. _class_Transform2D_method_determinant:
  239. .. rst-class:: classref-method
  240. :ref:`float<class_float>` **determinant**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_determinant>`
  241. Returns the `determinant <https://en.wikipedia.org/wiki/Determinant>`__ of this transform basis's matrix. For advanced math, this number can be used to determine a few attributes:
  242. - If the determinant is exactly ``0``, the basis is not invertible (see :ref:`inverse<class_Transform2D_method_inverse>`).
  243. - If the determinant is a negative number, the basis represents a negative scale.
  244. \ **Note:** If the basis's scale is the same for every axis, its determinant is always that scale by the power of 2.
  245. .. rst-class:: classref-item-separator
  246. ----
  247. .. _class_Transform2D_method_get_origin:
  248. .. rst-class:: classref-method
  249. :ref:`Vector2<class_Vector2>` **get_origin**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_get_origin>`
  250. Returns this transform's translation. Equivalent to :ref:`origin<class_Transform2D_property_origin>`.
  251. .. rst-class:: classref-item-separator
  252. ----
  253. .. _class_Transform2D_method_get_rotation:
  254. .. rst-class:: classref-method
  255. :ref:`float<class_float>` **get_rotation**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_get_rotation>`
  256. Returns this transform's rotation (in radians). This is equivalent to :ref:`x<class_Transform2D_property_x>`'s angle (see :ref:`Vector2.angle<class_Vector2_method_angle>`).
  257. .. rst-class:: classref-item-separator
  258. ----
  259. .. _class_Transform2D_method_get_scale:
  260. .. rst-class:: classref-method
  261. :ref:`Vector2<class_Vector2>` **get_scale**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_get_scale>`
  262. Returns the length of both :ref:`x<class_Transform2D_property_x>` and :ref:`y<class_Transform2D_property_y>`, as a :ref:`Vector2<class_Vector2>`. If this transform's basis is not skewed, this value is the scaling factor. It is not affected by rotation.
  263. .. tabs::
  264. .. code-tab:: gdscript
  265. var my_transform = Transform2D(
  266. Vector2(2, 0),
  267. Vector2(0, 4),
  268. Vector2(0, 0)
  269. )
  270. # Rotating the Transform2D in any way preserves its scale.
  271. my_transform = my_transform.rotated(TAU / 2)
  272. print(my_transform.get_scale()) # Prints (2, 4).
  273. .. code-tab:: csharp
  274. var myTransform = new Transform2D(
  275. Vector3(2.0f, 0.0f),
  276. Vector3(0.0f, 4.0f),
  277. Vector3(0.0f, 0.0f)
  278. );
  279. // Rotating the Transform2D in any way preserves its scale.
  280. myTransform = myTransform.Rotated(Mathf.Tau / 2.0f);
  281. GD.Print(myTransform.GetScale()); // Prints (2, 4, 8).
  282. \ **Note:** If the value returned by :ref:`determinant<class_Transform2D_method_determinant>` is negative, the scale is also negative.
  283. .. rst-class:: classref-item-separator
  284. ----
  285. .. _class_Transform2D_method_get_skew:
  286. .. rst-class:: classref-method
  287. :ref:`float<class_float>` **get_skew**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_get_skew>`
  288. Returns this transform's skew (in radians).
  289. .. rst-class:: classref-item-separator
  290. ----
  291. .. _class_Transform2D_method_interpolate_with:
  292. .. rst-class:: classref-method
  293. :ref:`Transform2D<class_Transform2D>` **interpolate_with**\ (\ xform\: :ref:`Transform2D<class_Transform2D>`, weight\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Transform2D_method_interpolate_with>`
  294. Returns the result of the linear interpolation between this transform and ``xform`` by the given ``weight``.
  295. The ``weight`` should be between ``0.0`` and ``1.0`` (inclusive). Values outside this range are allowed and can be used to perform *extrapolation* instead.
  296. .. rst-class:: classref-item-separator
  297. ----
  298. .. _class_Transform2D_method_inverse:
  299. .. rst-class:: classref-method
  300. :ref:`Transform2D<class_Transform2D>` **inverse**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_inverse>`
  301. Returns the `inverted version of this transform <https://en.wikipedia.org/wiki/Invertible_matrix>`__.
  302. \ **Note:** For this method to return correctly, the transform's basis needs to be *orthonormal* (see :ref:`orthonormalized<class_Transform2D_method_orthonormalized>`). That means, the basis should only represent a rotation. If it does not, use :ref:`affine_inverse<class_Transform2D_method_affine_inverse>` instead.
  303. .. rst-class:: classref-item-separator
  304. ----
  305. .. _class_Transform2D_method_is_conformal:
  306. .. rst-class:: classref-method
  307. :ref:`bool<class_bool>` **is_conformal**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_is_conformal>`
  308. Returns ``true`` if this transform's 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.
  309. .. rst-class:: classref-item-separator
  310. ----
  311. .. _class_Transform2D_method_is_equal_approx:
  312. .. rst-class:: classref-method
  313. :ref:`bool<class_bool>` **is_equal_approx**\ (\ xform\: :ref:`Transform2D<class_Transform2D>`\ ) |const| :ref:`🔗<class_Transform2D_method_is_equal_approx>`
  314. Returns ``true`` if this transform and ``xform`` are approximately equal, by running :ref:`@GlobalScope.is_equal_approx<class_@GlobalScope_method_is_equal_approx>` on each component.
  315. .. rst-class:: classref-item-separator
  316. ----
  317. .. _class_Transform2D_method_is_finite:
  318. .. rst-class:: classref-method
  319. :ref:`bool<class_bool>` **is_finite**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_is_finite>`
  320. Returns ``true`` if this transform is finite, by calling :ref:`@GlobalScope.is_finite<class_@GlobalScope_method_is_finite>` on each component.
  321. .. rst-class:: classref-item-separator
  322. ----
  323. .. _class_Transform2D_method_looking_at:
  324. .. rst-class:: classref-method
  325. :ref:`Transform2D<class_Transform2D>` **looking_at**\ (\ target\: :ref:`Vector2<class_Vector2>` = Vector2(0, 0)\ ) |const| :ref:`🔗<class_Transform2D_method_looking_at>`
  326. Returns a copy of the transform rotated such that the rotated X-axis points towards the ``target`` position, in global space.
  327. .. rst-class:: classref-item-separator
  328. ----
  329. .. _class_Transform2D_method_orthonormalized:
  330. .. rst-class:: classref-method
  331. :ref:`Transform2D<class_Transform2D>` **orthonormalized**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_orthonormalized>`
  332. Returns a copy of this transform with its basis orthonormalized. An orthonormal basis is both *orthogonal* (the axes are perpendicular to each other) and *normalized* (the axes have a length of ``1``), which also means it can only represent rotation.
  333. .. rst-class:: classref-item-separator
  334. ----
  335. .. _class_Transform2D_method_rotated:
  336. .. rst-class:: classref-method
  337. :ref:`Transform2D<class_Transform2D>` **rotated**\ (\ angle\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Transform2D_method_rotated>`
  338. Returns a copy of the transform rotated by the given ``angle`` (in radians).
  339. This method is an optimized version of multiplying the given transform ``X`` with a corresponding rotation transform ``R`` from the left, i.e., ``R * X``.
  340. This can be seen as transforming with respect to the global/parent frame.
  341. .. rst-class:: classref-item-separator
  342. ----
  343. .. _class_Transform2D_method_rotated_local:
  344. .. rst-class:: classref-method
  345. :ref:`Transform2D<class_Transform2D>` **rotated_local**\ (\ angle\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Transform2D_method_rotated_local>`
  346. Returns a copy of the transform rotated by the given ``angle`` (in radians).
  347. This method is an optimized version of multiplying the given transform ``X`` with a corresponding rotation transform ``R`` from the right, i.e., ``X * R``.
  348. This can be seen as transforming with respect to the local frame.
  349. .. rst-class:: classref-item-separator
  350. ----
  351. .. _class_Transform2D_method_scaled:
  352. .. rst-class:: classref-method
  353. :ref:`Transform2D<class_Transform2D>` **scaled**\ (\ scale\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Transform2D_method_scaled>`
  354. Returns a copy of the transform scaled by the given ``scale`` factor.
  355. This method is an optimized version of multiplying the given transform ``X`` with a corresponding scaling transform ``S`` from the left, i.e., ``S * X``.
  356. This can be seen as transforming with respect to the global/parent frame.
  357. .. rst-class:: classref-item-separator
  358. ----
  359. .. _class_Transform2D_method_scaled_local:
  360. .. rst-class:: classref-method
  361. :ref:`Transform2D<class_Transform2D>` **scaled_local**\ (\ scale\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Transform2D_method_scaled_local>`
  362. Returns a copy of the transform scaled by the given ``scale`` factor.
  363. This method is an optimized version of multiplying the given transform ``X`` with a corresponding scaling transform ``S`` from the right, i.e., ``X * S``.
  364. This can be seen as transforming with respect to the local frame.
  365. .. rst-class:: classref-item-separator
  366. ----
  367. .. _class_Transform2D_method_translated:
  368. .. rst-class:: classref-method
  369. :ref:`Transform2D<class_Transform2D>` **translated**\ (\ offset\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Transform2D_method_translated>`
  370. Returns a copy of the transform translated by the given ``offset``.
  371. This method is an optimized version of multiplying the given transform ``X`` with a corresponding translation transform ``T`` from the left, i.e., ``T * X``.
  372. This can be seen as transforming with respect to the global/parent frame.
  373. .. rst-class:: classref-item-separator
  374. ----
  375. .. _class_Transform2D_method_translated_local:
  376. .. rst-class:: classref-method
  377. :ref:`Transform2D<class_Transform2D>` **translated_local**\ (\ offset\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Transform2D_method_translated_local>`
  378. Returns a copy of the transform translated by the given ``offset``.
  379. This method is an optimized version of multiplying the given transform ``X`` with a corresponding translation transform ``T`` from the right, i.e., ``X * T``.
  380. This can be seen as transforming with respect to the local frame.
  381. .. rst-class:: classref-section-separator
  382. ----
  383. .. rst-class:: classref-descriptions-group
  384. Operator Descriptions
  385. ---------------------
  386. .. _class_Transform2D_operator_neq_Transform2D:
  387. .. rst-class:: classref-operator
  388. :ref:`bool<class_bool>` **operator !=**\ (\ right\: :ref:`Transform2D<class_Transform2D>`\ ) :ref:`🔗<class_Transform2D_operator_neq_Transform2D>`
  389. Returns ``true`` if the components of both transforms are not equal.
  390. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Transform2D_method_is_equal_approx>` instead, which is more reliable.
  391. .. rst-class:: classref-item-separator
  392. ----
  393. .. _class_Transform2D_operator_mul_PackedVector2Array:
  394. .. rst-class:: classref-operator
  395. :ref:`PackedVector2Array<class_PackedVector2Array>` **operator ***\ (\ right\: :ref:`PackedVector2Array<class_PackedVector2Array>`\ ) :ref:`🔗<class_Transform2D_operator_mul_PackedVector2Array>`
  396. Transforms (multiplies) every :ref:`Vector2<class_Vector2>` element of the given :ref:`PackedVector2Array<class_PackedVector2Array>` by this transformation matrix.
  397. On larger arrays, this operation is much faster than transforming each :ref:`Vector2<class_Vector2>` individually.
  398. .. rst-class:: classref-item-separator
  399. ----
  400. .. _class_Transform2D_operator_mul_Rect2:
  401. .. rst-class:: classref-operator
  402. :ref:`Rect2<class_Rect2>` **operator ***\ (\ right\: :ref:`Rect2<class_Rect2>`\ ) :ref:`🔗<class_Transform2D_operator_mul_Rect2>`
  403. Transforms (multiplies) the :ref:`Rect2<class_Rect2>` by this transformation matrix.
  404. .. rst-class:: classref-item-separator
  405. ----
  406. .. _class_Transform2D_operator_mul_Transform2D:
  407. .. rst-class:: classref-operator
  408. :ref:`Transform2D<class_Transform2D>` **operator ***\ (\ right\: :ref:`Transform2D<class_Transform2D>`\ ) :ref:`🔗<class_Transform2D_operator_mul_Transform2D>`
  409. Transforms (multiplies) this transform by the ``right`` transform.
  410. This is the operation performed between parent and child :ref:`CanvasItem<class_CanvasItem>` nodes.
  411. \ **Note:** If you need to only modify one attribute of this transform, consider using one of the following methods, instead:
  412. - For translation, see :ref:`translated<class_Transform2D_method_translated>` or :ref:`translated_local<class_Transform2D_method_translated_local>`.
  413. - For rotation, see :ref:`rotated<class_Transform2D_method_rotated>` or :ref:`rotated_local<class_Transform2D_method_rotated_local>`.
  414. - For scale, see :ref:`scaled<class_Transform2D_method_scaled>` or :ref:`scaled_local<class_Transform2D_method_scaled_local>`.
  415. .. rst-class:: classref-item-separator
  416. ----
  417. .. _class_Transform2D_operator_mul_Vector2:
  418. .. rst-class:: classref-operator
  419. :ref:`Vector2<class_Vector2>` **operator ***\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_Transform2D_operator_mul_Vector2>`
  420. Transforms (multiplies) the :ref:`Vector2<class_Vector2>` by this transformation matrix.
  421. .. rst-class:: classref-item-separator
  422. ----
  423. .. _class_Transform2D_operator_mul_float:
  424. .. rst-class:: classref-operator
  425. :ref:`Transform2D<class_Transform2D>` **operator ***\ (\ right\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Transform2D_operator_mul_float>`
  426. Multiplies all components of the **Transform2D** by the given :ref:`float<class_float>`, including the :ref:`origin<class_Transform2D_property_origin>`. This affects the transform's scale uniformly.
  427. .. rst-class:: classref-item-separator
  428. ----
  429. .. _class_Transform2D_operator_mul_int:
  430. .. rst-class:: classref-operator
  431. :ref:`Transform2D<class_Transform2D>` **operator ***\ (\ right\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Transform2D_operator_mul_int>`
  432. Multiplies all components of the **Transform2D** by the given :ref:`int<class_int>`, including the :ref:`origin<class_Transform2D_property_origin>`. This affects the transform's scale uniformly.
  433. .. rst-class:: classref-item-separator
  434. ----
  435. .. _class_Transform2D_operator_div_float:
  436. .. rst-class:: classref-operator
  437. :ref:`Transform2D<class_Transform2D>` **operator /**\ (\ right\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Transform2D_operator_div_float>`
  438. Divides all components of the **Transform2D** by the given :ref:`float<class_float>`, including the :ref:`origin<class_Transform2D_property_origin>`. This affects the transform's scale uniformly.
  439. .. rst-class:: classref-item-separator
  440. ----
  441. .. _class_Transform2D_operator_div_int:
  442. .. rst-class:: classref-operator
  443. :ref:`Transform2D<class_Transform2D>` **operator /**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Transform2D_operator_div_int>`
  444. Divides all components of the **Transform2D** by the given :ref:`int<class_int>`, including the :ref:`origin<class_Transform2D_property_origin>`. This affects the transform's scale uniformly.
  445. .. rst-class:: classref-item-separator
  446. ----
  447. .. _class_Transform2D_operator_eq_Transform2D:
  448. .. rst-class:: classref-operator
  449. :ref:`bool<class_bool>` **operator ==**\ (\ right\: :ref:`Transform2D<class_Transform2D>`\ ) :ref:`🔗<class_Transform2D_operator_eq_Transform2D>`
  450. Returns ``true`` if the components of both transforms are exactly equal.
  451. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Transform2D_method_is_equal_approx>` instead, which is more reliable.
  452. .. rst-class:: classref-item-separator
  453. ----
  454. .. _class_Transform2D_operator_idx_int:
  455. .. rst-class:: classref-operator
  456. :ref:`Vector2<class_Vector2>` **operator []**\ (\ index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Transform2D_operator_idx_int>`
  457. Accesses each axis (column) of this transform by their index. Index ``0`` is the same as :ref:`x<class_Transform2D_property_x>`, index ``1`` is the same as :ref:`y<class_Transform2D_property_y>`, and index ``2`` is the same as :ref:`origin<class_Transform2D_property_origin>`.
  458. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  459. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  460. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  461. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  462. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  463. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  464. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  465. .. |void| replace:: :abbr:`void (No return value.)`