class_transform2d.rst 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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/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 down (:ref:`Vector2.DOWN<class_Vector2_constant_DOWN>`).
  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 down (:ref:`Vector2.DOWN<class_Vector2_constant_DOWN>`).
  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. \ **Note:** In C#, this constructs a **Transform2D** with all of its components set to :ref:`Vector2.ZERO<class_Vector2_constant_ZERO>`.
  194. .. rst-class:: classref-item-separator
  195. ----
  196. .. rst-class:: classref-constructor
  197. :ref:`Transform2D<class_Transform2D>` **Transform2D**\ (\ from\: :ref:`Transform2D<class_Transform2D>`\ )
  198. Constructs a **Transform2D** as a copy of the given **Transform2D**.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. rst-class:: classref-constructor
  202. :ref:`Transform2D<class_Transform2D>` **Transform2D**\ (\ rotation\: :ref:`float<class_float>`, position\: :ref:`Vector2<class_Vector2>`\ )
  203. Constructs a **Transform2D** from a given angle (in radians) and position.
  204. .. rst-class:: classref-item-separator
  205. ----
  206. .. rst-class:: classref-constructor
  207. :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>`\ )
  208. Constructs a **Transform2D** from a given angle (in radians), scale, skew (in radians), and position.
  209. .. rst-class:: classref-item-separator
  210. ----
  211. .. rst-class:: classref-constructor
  212. :ref:`Transform2D<class_Transform2D>` **Transform2D**\ (\ x_axis\: :ref:`Vector2<class_Vector2>`, y_axis\: :ref:`Vector2<class_Vector2>`, origin\: :ref:`Vector2<class_Vector2>`\ )
  213. 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).
  214. .. rst-class:: classref-section-separator
  215. ----
  216. .. rst-class:: classref-descriptions-group
  217. Method Descriptions
  218. -------------------
  219. .. _class_Transform2D_method_affine_inverse:
  220. .. rst-class:: classref-method
  221. :ref:`Transform2D<class_Transform2D>` **affine_inverse**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_affine_inverse>`
  222. 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>`.
  223. \ **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>`).
  224. .. rst-class:: classref-item-separator
  225. ----
  226. .. _class_Transform2D_method_basis_xform:
  227. .. rst-class:: classref-method
  228. :ref:`Vector2<class_Vector2>` **basis_xform**\ (\ v\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Transform2D_method_basis_xform>`
  229. 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>`.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_Transform2D_method_basis_xform_inv:
  233. .. rst-class:: classref-method
  234. :ref:`Vector2<class_Vector2>` **basis_xform_inv**\ (\ v\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Transform2D_method_basis_xform_inv>`
  235. 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>`.
  236. \ **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>`).
  237. .. rst-class:: classref-item-separator
  238. ----
  239. .. _class_Transform2D_method_determinant:
  240. .. rst-class:: classref-method
  241. :ref:`float<class_float>` **determinant**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_determinant>`
  242. 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:
  243. - If the determinant is exactly ``0``, the basis is not invertible (see :ref:`inverse<class_Transform2D_method_inverse>`).
  244. - If the determinant is a negative number, the basis represents a negative scale.
  245. \ **Note:** If the basis's scale is the same for every axis, its determinant is always that scale by the power of 2.
  246. .. rst-class:: classref-item-separator
  247. ----
  248. .. _class_Transform2D_method_get_origin:
  249. .. rst-class:: classref-method
  250. :ref:`Vector2<class_Vector2>` **get_origin**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_get_origin>`
  251. Returns this transform's translation. Equivalent to :ref:`origin<class_Transform2D_property_origin>`.
  252. .. rst-class:: classref-item-separator
  253. ----
  254. .. _class_Transform2D_method_get_rotation:
  255. .. rst-class:: classref-method
  256. :ref:`float<class_float>` **get_rotation**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_get_rotation>`
  257. 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>`).
  258. .. rst-class:: classref-item-separator
  259. ----
  260. .. _class_Transform2D_method_get_scale:
  261. .. rst-class:: classref-method
  262. :ref:`Vector2<class_Vector2>` **get_scale**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_get_scale>`
  263. 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.
  264. .. tabs::
  265. .. code-tab:: gdscript
  266. var my_transform = Transform2D(
  267. Vector2(2, 0),
  268. Vector2(0, 4),
  269. Vector2(0, 0)
  270. )
  271. # Rotating the Transform2D in any way preserves its scale.
  272. my_transform = my_transform.rotated(TAU / 2)
  273. print(my_transform.get_scale()) # Prints (2, 4).
  274. .. code-tab:: csharp
  275. var myTransform = new Transform2D(
  276. Vector3(2.0f, 0.0f),
  277. Vector3(0.0f, 4.0f),
  278. Vector3(0.0f, 0.0f)
  279. );
  280. // Rotating the Transform2D in any way preserves its scale.
  281. myTransform = myTransform.Rotated(Mathf.Tau / 2.0f);
  282. GD.Print(myTransform.GetScale()); // Prints (2, 4, 8).
  283. \ **Note:** If the value returned by :ref:`determinant<class_Transform2D_method_determinant>` is negative, the scale is also negative.
  284. .. rst-class:: classref-item-separator
  285. ----
  286. .. _class_Transform2D_method_get_skew:
  287. .. rst-class:: classref-method
  288. :ref:`float<class_float>` **get_skew**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_get_skew>`
  289. Returns this transform's skew (in radians).
  290. .. rst-class:: classref-item-separator
  291. ----
  292. .. _class_Transform2D_method_interpolate_with:
  293. .. rst-class:: classref-method
  294. :ref:`Transform2D<class_Transform2D>` **interpolate_with**\ (\ xform\: :ref:`Transform2D<class_Transform2D>`, weight\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Transform2D_method_interpolate_with>`
  295. Returns the result of the linear interpolation between this transform and ``xform`` by the given ``weight``.
  296. 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.
  297. .. rst-class:: classref-item-separator
  298. ----
  299. .. _class_Transform2D_method_inverse:
  300. .. rst-class:: classref-method
  301. :ref:`Transform2D<class_Transform2D>` **inverse**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_inverse>`
  302. Returns the `inverted version of this transform <https://en.wikipedia.org/wiki/Invertible_matrix>`__.
  303. \ **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.
  304. .. rst-class:: classref-item-separator
  305. ----
  306. .. _class_Transform2D_method_is_conformal:
  307. .. rst-class:: classref-method
  308. :ref:`bool<class_bool>` **is_conformal**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_is_conformal>`
  309. 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.
  310. .. rst-class:: classref-item-separator
  311. ----
  312. .. _class_Transform2D_method_is_equal_approx:
  313. .. rst-class:: classref-method
  314. :ref:`bool<class_bool>` **is_equal_approx**\ (\ xform\: :ref:`Transform2D<class_Transform2D>`\ ) |const| :ref:`🔗<class_Transform2D_method_is_equal_approx>`
  315. 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.
  316. .. rst-class:: classref-item-separator
  317. ----
  318. .. _class_Transform2D_method_is_finite:
  319. .. rst-class:: classref-method
  320. :ref:`bool<class_bool>` **is_finite**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_is_finite>`
  321. Returns ``true`` if this transform is finite, by calling :ref:`@GlobalScope.is_finite<class_@GlobalScope_method_is_finite>` on each component.
  322. .. rst-class:: classref-item-separator
  323. ----
  324. .. _class_Transform2D_method_looking_at:
  325. .. rst-class:: classref-method
  326. :ref:`Transform2D<class_Transform2D>` **looking_at**\ (\ target\: :ref:`Vector2<class_Vector2>` = Vector2(0, 0)\ ) |const| :ref:`🔗<class_Transform2D_method_looking_at>`
  327. Returns a copy of the transform rotated such that the rotated X-axis points towards the ``target`` position, in global space.
  328. .. rst-class:: classref-item-separator
  329. ----
  330. .. _class_Transform2D_method_orthonormalized:
  331. .. rst-class:: classref-method
  332. :ref:`Transform2D<class_Transform2D>` **orthonormalized**\ (\ ) |const| :ref:`🔗<class_Transform2D_method_orthonormalized>`
  333. 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.
  334. .. rst-class:: classref-item-separator
  335. ----
  336. .. _class_Transform2D_method_rotated:
  337. .. rst-class:: classref-method
  338. :ref:`Transform2D<class_Transform2D>` **rotated**\ (\ angle\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Transform2D_method_rotated>`
  339. Returns a copy of the transform rotated by the given ``angle`` (in radians).
  340. 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``.
  341. This can be seen as transforming with respect to the global/parent frame.
  342. .. rst-class:: classref-item-separator
  343. ----
  344. .. _class_Transform2D_method_rotated_local:
  345. .. rst-class:: classref-method
  346. :ref:`Transform2D<class_Transform2D>` **rotated_local**\ (\ angle\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Transform2D_method_rotated_local>`
  347. Returns a copy of the transform rotated by the given ``angle`` (in radians).
  348. 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``.
  349. This can be seen as transforming with respect to the local frame.
  350. .. rst-class:: classref-item-separator
  351. ----
  352. .. _class_Transform2D_method_scaled:
  353. .. rst-class:: classref-method
  354. :ref:`Transform2D<class_Transform2D>` **scaled**\ (\ scale\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Transform2D_method_scaled>`
  355. Returns a copy of the transform scaled by the given ``scale`` factor.
  356. 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``.
  357. This can be seen as transforming with respect to the global/parent frame.
  358. .. rst-class:: classref-item-separator
  359. ----
  360. .. _class_Transform2D_method_scaled_local:
  361. .. rst-class:: classref-method
  362. :ref:`Transform2D<class_Transform2D>` **scaled_local**\ (\ scale\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Transform2D_method_scaled_local>`
  363. Returns a copy of the transform scaled by the given ``scale`` factor.
  364. 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``.
  365. This can be seen as transforming with respect to the local frame.
  366. .. rst-class:: classref-item-separator
  367. ----
  368. .. _class_Transform2D_method_translated:
  369. .. rst-class:: classref-method
  370. :ref:`Transform2D<class_Transform2D>` **translated**\ (\ offset\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Transform2D_method_translated>`
  371. Returns a copy of the transform translated by the given ``offset``.
  372. 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``.
  373. This can be seen as transforming with respect to the global/parent frame.
  374. .. rst-class:: classref-item-separator
  375. ----
  376. .. _class_Transform2D_method_translated_local:
  377. .. rst-class:: classref-method
  378. :ref:`Transform2D<class_Transform2D>` **translated_local**\ (\ offset\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Transform2D_method_translated_local>`
  379. Returns a copy of the transform translated by the given ``offset``.
  380. 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``.
  381. This can be seen as transforming with respect to the local frame.
  382. .. rst-class:: classref-section-separator
  383. ----
  384. .. rst-class:: classref-descriptions-group
  385. Operator Descriptions
  386. ---------------------
  387. .. _class_Transform2D_operator_neq_Transform2D:
  388. .. rst-class:: classref-operator
  389. :ref:`bool<class_bool>` **operator !=**\ (\ right\: :ref:`Transform2D<class_Transform2D>`\ ) :ref:`🔗<class_Transform2D_operator_neq_Transform2D>`
  390. Returns ``true`` if the components of both transforms are not equal.
  391. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Transform2D_method_is_equal_approx>` instead, which is more reliable.
  392. .. rst-class:: classref-item-separator
  393. ----
  394. .. _class_Transform2D_operator_mul_PackedVector2Array:
  395. .. rst-class:: classref-operator
  396. :ref:`PackedVector2Array<class_PackedVector2Array>` **operator ***\ (\ right\: :ref:`PackedVector2Array<class_PackedVector2Array>`\ ) :ref:`🔗<class_Transform2D_operator_mul_PackedVector2Array>`
  397. Transforms (multiplies) every :ref:`Vector2<class_Vector2>` element of the given :ref:`PackedVector2Array<class_PackedVector2Array>` by this transformation matrix.
  398. On larger arrays, this operation is much faster than transforming each :ref:`Vector2<class_Vector2>` individually.
  399. .. rst-class:: classref-item-separator
  400. ----
  401. .. _class_Transform2D_operator_mul_Rect2:
  402. .. rst-class:: classref-operator
  403. :ref:`Rect2<class_Rect2>` **operator ***\ (\ right\: :ref:`Rect2<class_Rect2>`\ ) :ref:`🔗<class_Transform2D_operator_mul_Rect2>`
  404. Transforms (multiplies) the :ref:`Rect2<class_Rect2>` by this transformation matrix.
  405. .. rst-class:: classref-item-separator
  406. ----
  407. .. _class_Transform2D_operator_mul_Transform2D:
  408. .. rst-class:: classref-operator
  409. :ref:`Transform2D<class_Transform2D>` **operator ***\ (\ right\: :ref:`Transform2D<class_Transform2D>`\ ) :ref:`🔗<class_Transform2D_operator_mul_Transform2D>`
  410. Transforms (multiplies) this transform by the ``right`` transform.
  411. This is the operation performed between parent and child :ref:`CanvasItem<class_CanvasItem>` nodes.
  412. \ **Note:** If you need to only modify one attribute of this transform, consider using one of the following methods, instead:
  413. - For translation, see :ref:`translated<class_Transform2D_method_translated>` or :ref:`translated_local<class_Transform2D_method_translated_local>`.
  414. - For rotation, see :ref:`rotated<class_Transform2D_method_rotated>` or :ref:`rotated_local<class_Transform2D_method_rotated_local>`.
  415. - For scale, see :ref:`scaled<class_Transform2D_method_scaled>` or :ref:`scaled_local<class_Transform2D_method_scaled_local>`.
  416. .. rst-class:: classref-item-separator
  417. ----
  418. .. _class_Transform2D_operator_mul_Vector2:
  419. .. rst-class:: classref-operator
  420. :ref:`Vector2<class_Vector2>` **operator ***\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_Transform2D_operator_mul_Vector2>`
  421. Transforms (multiplies) the :ref:`Vector2<class_Vector2>` by this transformation matrix.
  422. .. rst-class:: classref-item-separator
  423. ----
  424. .. _class_Transform2D_operator_mul_float:
  425. .. rst-class:: classref-operator
  426. :ref:`Transform2D<class_Transform2D>` **operator ***\ (\ right\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Transform2D_operator_mul_float>`
  427. 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.
  428. .. rst-class:: classref-item-separator
  429. ----
  430. .. _class_Transform2D_operator_mul_int:
  431. .. rst-class:: classref-operator
  432. :ref:`Transform2D<class_Transform2D>` **operator ***\ (\ right\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Transform2D_operator_mul_int>`
  433. 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.
  434. .. rst-class:: classref-item-separator
  435. ----
  436. .. _class_Transform2D_operator_div_float:
  437. .. rst-class:: classref-operator
  438. :ref:`Transform2D<class_Transform2D>` **operator /**\ (\ right\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Transform2D_operator_div_float>`
  439. 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.
  440. .. rst-class:: classref-item-separator
  441. ----
  442. .. _class_Transform2D_operator_div_int:
  443. .. rst-class:: classref-operator
  444. :ref:`Transform2D<class_Transform2D>` **operator /**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Transform2D_operator_div_int>`
  445. 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.
  446. .. rst-class:: classref-item-separator
  447. ----
  448. .. _class_Transform2D_operator_eq_Transform2D:
  449. .. rst-class:: classref-operator
  450. :ref:`bool<class_bool>` **operator ==**\ (\ right\: :ref:`Transform2D<class_Transform2D>`\ ) :ref:`🔗<class_Transform2D_operator_eq_Transform2D>`
  451. Returns ``true`` if the components of both transforms are exactly equal.
  452. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Transform2D_method_is_equal_approx>` instead, which is more reliable.
  453. .. rst-class:: classref-item-separator
  454. ----
  455. .. _class_Transform2D_operator_idx_int:
  456. .. rst-class:: classref-operator
  457. :ref:`Vector2<class_Vector2>` **operator []**\ (\ index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Transform2D_operator_idx_int>`
  458. 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>`.
  459. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  460. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  461. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  462. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  463. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  464. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  465. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  466. .. |void| replace:: :abbr:`void (No return value.)`