class_transform2d.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Transform2D.xml.
  6. .. _class_Transform2D:
  7. Transform2D
  8. ===========
  9. 2D transformation (2×3 matrix).
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. 2×3 matrix (2 rows, 3 columns) used for 2D linear transformations. It can represent transformations such as translation, rotation, or scaling. It consists of three :ref:`Vector2<class_Vector2>` values: :ref:`x<class_Transform2D_property_x>`, :ref:`y<class_Transform2D_property_y>`, and the :ref:`origin<class_Transform2D_property_origin>`.
  14. For more information, read the "Matrices and transforms" documentation article.
  15. .. rst-class:: classref-introduction-group
  16. Tutorials
  17. ---------
  18. - :doc:`Math tutorial index <../tutorials/math/index>`
  19. - :doc:`Matrices and transforms <../tutorials/math/matrices_and_transforms>`
  20. - `Matrix Transform Demo <https://godotengine.org/asset-library/asset/584>`__
  21. - `2.5D Demo <https://godotengine.org/asset-library/asset/583>`__
  22. .. rst-class:: classref-reftable-group
  23. Properties
  24. ----------
  25. .. table::
  26. :widths: auto
  27. +-------------------------------+--------------------------------------------------+---------------------+
  28. | :ref:`Vector2<class_Vector2>` | :ref:`origin<class_Transform2D_property_origin>` | ``Vector2( 0, 0 )`` |
  29. +-------------------------------+--------------------------------------------------+---------------------+
  30. | :ref:`Vector2<class_Vector2>` | :ref:`x<class_Transform2D_property_x>` | ``Vector2( 1, 0 )`` |
  31. +-------------------------------+--------------------------------------------------+---------------------+
  32. | :ref:`Vector2<class_Vector2>` | :ref:`y<class_Transform2D_property_y>` | ``Vector2( 0, 1 )`` |
  33. +-------------------------------+--------------------------------------------------+---------------------+
  34. .. rst-class:: classref-reftable-group
  35. Methods
  36. -------
  37. .. table::
  38. :widths: auto
  39. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Transform2D<class_Transform2D>` | :ref:`Transform2D<class_Transform2D_method_Transform2D>` **(** :ref:`Transform<class_Transform>` from **)** |
  41. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Transform2D<class_Transform2D>` | :ref:`Transform2D<class_Transform2D_method_Transform2D>` **(** :ref:`Vector2<class_Vector2>` x_axis, :ref:`Vector2<class_Vector2>` y_axis, :ref:`Vector2<class_Vector2>` origin **)** |
  43. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`Transform2D<class_Transform2D>` | :ref:`Transform2D<class_Transform2D_method_Transform2D>` **(** :ref:`float<class_float>` rotation, :ref:`Vector2<class_Vector2>` position **)** |
  45. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Transform2D<class_Transform2D>` | :ref:`affine_inverse<class_Transform2D_method_affine_inverse>` **(** **)** |
  47. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`Vector2<class_Vector2>` | :ref:`basis_xform<class_Transform2D_method_basis_xform>` **(** :ref:`Vector2<class_Vector2>` v **)** |
  49. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Vector2<class_Vector2>` | :ref:`basis_xform_inv<class_Transform2D_method_basis_xform_inv>` **(** :ref:`Vector2<class_Vector2>` v **)** |
  51. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`float<class_float>` | :ref:`determinant<class_Transform2D_method_determinant>` **(** **)** |
  53. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Vector2<class_Vector2>` | :ref:`get_origin<class_Transform2D_method_get_origin>` **(** **)** |
  55. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`float<class_float>` | :ref:`get_rotation<class_Transform2D_method_get_rotation>` **(** **)** |
  57. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`Vector2<class_Vector2>` | :ref:`get_scale<class_Transform2D_method_get_scale>` **(** **)** |
  59. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Transform2D<class_Transform2D>` | :ref:`interpolate_with<class_Transform2D_method_interpolate_with>` **(** :ref:`Transform2D<class_Transform2D>` transform, :ref:`float<class_float>` weight **)** |
  61. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Transform2D<class_Transform2D>` | :ref:`inverse<class_Transform2D_method_inverse>` **(** **)** |
  63. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Transform2D_method_is_equal_approx>` **(** :ref:`Transform2D<class_Transform2D>` transform **)** |
  65. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`Transform2D<class_Transform2D>` | :ref:`orthonormalized<class_Transform2D_method_orthonormalized>` **(** **)** |
  67. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`Transform2D<class_Transform2D>` | :ref:`rotated<class_Transform2D_method_rotated>` **(** :ref:`float<class_float>` angle **)** |
  69. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Transform2D<class_Transform2D>` | :ref:`scaled<class_Transform2D_method_scaled>` **(** :ref:`Vector2<class_Vector2>` scale **)** |
  71. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`Transform2D<class_Transform2D>` | :ref:`translated<class_Transform2D_method_translated>` **(** :ref:`Vector2<class_Vector2>` offset **)** |
  73. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`Variant<class_Variant>` | :ref:`xform<class_Transform2D_method_xform>` **(** :ref:`Variant<class_Variant>` v **)** |
  75. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`Variant<class_Variant>` | :ref:`xform_inv<class_Transform2D_method_xform_inv>` **(** :ref:`Variant<class_Variant>` v **)** |
  77. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. .. rst-class:: classref-section-separator
  79. ----
  80. .. rst-class:: classref-descriptions-group
  81. Constants
  82. ---------
  83. .. _class_Transform2D_constant_IDENTITY:
  84. .. rst-class:: classref-constant
  85. **IDENTITY** = ``Transform2D( 1, 0, 0, 1, 0, 0 )``
  86. The identity **Transform2D** with no translation, rotation or scaling applied. When applied to other data structures, :ref:`IDENTITY<class_Transform2D_constant_IDENTITY>` performs no transformation.
  87. .. _class_Transform2D_constant_FLIP_X:
  88. .. rst-class:: classref-constant
  89. **FLIP_X** = ``Transform2D( -1, 0, 0, 1, 0, 0 )``
  90. The **Transform2D** that will flip something along the X axis.
  91. .. _class_Transform2D_constant_FLIP_Y:
  92. .. rst-class:: classref-constant
  93. **FLIP_Y** = ``Transform2D( 1, 0, 0, -1, 0, 0 )``
  94. The **Transform2D** that will flip something along the Y axis.
  95. .. rst-class:: classref-section-separator
  96. ----
  97. .. rst-class:: classref-descriptions-group
  98. Property Descriptions
  99. ---------------------
  100. .. _class_Transform2D_property_origin:
  101. .. rst-class:: classref-property
  102. :ref:`Vector2<class_Vector2>` **origin** = ``Vector2( 0, 0 )``
  103. The origin vector (column 2, the third column). Equivalent to array index ``2``. The origin vector represents translation.
  104. .. rst-class:: classref-item-separator
  105. ----
  106. .. _class_Transform2D_property_x:
  107. .. rst-class:: classref-property
  108. :ref:`Vector2<class_Vector2>` **x** = ``Vector2( 1, 0 )``
  109. The basis matrix's X vector (column 0). Equivalent to array index ``0``.
  110. .. rst-class:: classref-item-separator
  111. ----
  112. .. _class_Transform2D_property_y:
  113. .. rst-class:: classref-property
  114. :ref:`Vector2<class_Vector2>` **y** = ``Vector2( 0, 1 )``
  115. The basis matrix's Y vector (column 1). Equivalent to array index ``1``.
  116. .. rst-class:: classref-section-separator
  117. ----
  118. .. rst-class:: classref-descriptions-group
  119. Method Descriptions
  120. -------------------
  121. .. _class_Transform2D_method_Transform2D:
  122. .. rst-class:: classref-method
  123. :ref:`Transform2D<class_Transform2D>` **Transform2D** **(** :ref:`Transform<class_Transform>` from **)**
  124. Constructs the transform from a 3D :ref:`Transform<class_Transform>`.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. rst-class:: classref-method
  128. :ref:`Transform2D<class_Transform2D>` **Transform2D** **(** :ref:`Vector2<class_Vector2>` x_axis, :ref:`Vector2<class_Vector2>` y_axis, :ref:`Vector2<class_Vector2>` origin **)**
  129. Constructs the transform 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 column vectors).
  130. .. rst-class:: classref-item-separator
  131. ----
  132. .. rst-class:: classref-method
  133. :ref:`Transform2D<class_Transform2D>` **Transform2D** **(** :ref:`float<class_float>` rotation, :ref:`Vector2<class_Vector2>` position **)**
  134. Constructs the transform from a given angle (in radians) and position.
  135. .. rst-class:: classref-item-separator
  136. ----
  137. .. _class_Transform2D_method_affine_inverse:
  138. .. rst-class:: classref-method
  139. :ref:`Transform2D<class_Transform2D>` **affine_inverse** **(** **)**
  140. Returns the inverse of the transform, under the assumption that the transformation is composed of rotation, scaling and translation.
  141. .. rst-class:: classref-item-separator
  142. ----
  143. .. _class_Transform2D_method_basis_xform:
  144. .. rst-class:: classref-method
  145. :ref:`Vector2<class_Vector2>` **basis_xform** **(** :ref:`Vector2<class_Vector2>` v **)**
  146. Returns a vector transformed (multiplied) by the basis matrix.
  147. This method does not account for translation (the origin vector).
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. _class_Transform2D_method_basis_xform_inv:
  151. .. rst-class:: classref-method
  152. :ref:`Vector2<class_Vector2>` **basis_xform_inv** **(** :ref:`Vector2<class_Vector2>` v **)**
  153. Returns a vector transformed (multiplied) by the inverse basis matrix.
  154. This method does not account for translation (the origin vector).
  155. .. rst-class:: classref-item-separator
  156. ----
  157. .. _class_Transform2D_method_determinant:
  158. .. rst-class:: classref-method
  159. :ref:`float<class_float>` **determinant** **(** **)**
  160. Returns the determinant of the basis matrix. If the basis is uniformly scaled, then its determinant equals the square of the scale factor.
  161. A negative determinant means the basis was flipped, so one part of the scale is negative. A zero determinant means the basis isn't invertible, and is usually considered invalid.
  162. .. rst-class:: classref-item-separator
  163. ----
  164. .. _class_Transform2D_method_get_origin:
  165. .. rst-class:: classref-method
  166. :ref:`Vector2<class_Vector2>` **get_origin** **(** **)**
  167. Returns the transform's origin (translation).
  168. .. rst-class:: classref-item-separator
  169. ----
  170. .. _class_Transform2D_method_get_rotation:
  171. .. rst-class:: classref-method
  172. :ref:`float<class_float>` **get_rotation** **(** **)**
  173. Returns the transform's rotation (in radians).
  174. .. rst-class:: classref-item-separator
  175. ----
  176. .. _class_Transform2D_method_get_scale:
  177. .. rst-class:: classref-method
  178. :ref:`Vector2<class_Vector2>` **get_scale** **(** **)**
  179. Returns the scale.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_Transform2D_method_interpolate_with:
  183. .. rst-class:: classref-method
  184. :ref:`Transform2D<class_Transform2D>` **interpolate_with** **(** :ref:`Transform2D<class_Transform2D>` transform, :ref:`float<class_float>` weight **)**
  185. Returns a transform interpolated between this transform and another by a given ``weight`` (on the range of 0.0 to 1.0).
  186. .. rst-class:: classref-item-separator
  187. ----
  188. .. _class_Transform2D_method_inverse:
  189. .. rst-class:: classref-method
  190. :ref:`Transform2D<class_Transform2D>` **inverse** **(** **)**
  191. Returns the inverse of the transform, under the assumption that the transformation is composed of rotation and translation (no scaling, use :ref:`affine_inverse<class_Transform2D_method_affine_inverse>` for transforms with scaling).
  192. .. rst-class:: classref-item-separator
  193. ----
  194. .. _class_Transform2D_method_is_equal_approx:
  195. .. rst-class:: classref-method
  196. :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Transform2D<class_Transform2D>` transform **)**
  197. Returns ``true`` if this transform and ``transform`` are approximately equal, by calling ``is_equal_approx`` on each component.
  198. .. rst-class:: classref-item-separator
  199. ----
  200. .. _class_Transform2D_method_orthonormalized:
  201. .. rst-class:: classref-method
  202. :ref:`Transform2D<class_Transform2D>` **orthonormalized** **(** **)**
  203. Returns the transform with the basis orthogonal (90 degrees), and normalized axis vectors (scale of 1 or -1).
  204. .. rst-class:: classref-item-separator
  205. ----
  206. .. _class_Transform2D_method_rotated:
  207. .. rst-class:: classref-method
  208. :ref:`Transform2D<class_Transform2D>` **rotated** **(** :ref:`float<class_float>` angle **)**
  209. Returns a copy of the transform rotated by the given ``angle`` (in radians), using matrix multiplication.
  210. .. rst-class:: classref-item-separator
  211. ----
  212. .. _class_Transform2D_method_scaled:
  213. .. rst-class:: classref-method
  214. :ref:`Transform2D<class_Transform2D>` **scaled** **(** :ref:`Vector2<class_Vector2>` scale **)**
  215. Returns a copy of the transform scaled by the given ``scale`` factor, using matrix multiplication.
  216. \ **Note:** Negative X scales in 2D are not decomposable from the transformation matrix. Due to the way scale is represented with transformation matrices in Godot, negative scales on the X axis will be changed to negative scales on the Y axis and a rotation of 180 degrees when decomposed.
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_Transform2D_method_translated:
  220. .. rst-class:: classref-method
  221. :ref:`Transform2D<class_Transform2D>` **translated** **(** :ref:`Vector2<class_Vector2>` offset **)**
  222. Returns a copy of the transform translated by the given ``offset``, relative to the transform's basis vectors.
  223. Unlike :ref:`rotated<class_Transform2D_method_rotated>` and :ref:`scaled<class_Transform2D_method_scaled>`, this does not use matrix multiplication.
  224. .. rst-class:: classref-item-separator
  225. ----
  226. .. _class_Transform2D_method_xform:
  227. .. rst-class:: classref-method
  228. :ref:`Variant<class_Variant>` **xform** **(** :ref:`Variant<class_Variant>` v **)**
  229. Transforms the given :ref:`Vector2<class_Vector2>`, :ref:`Rect2<class_Rect2>`, or :ref:`PoolVector2Array<class_PoolVector2Array>` by this transform.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_Transform2D_method_xform_inv:
  233. .. rst-class:: classref-method
  234. :ref:`Variant<class_Variant>` **xform_inv** **(** :ref:`Variant<class_Variant>` v **)**
  235. Inverse-transforms the given :ref:`Vector2<class_Vector2>`, :ref:`Rect2<class_Rect2>`, or :ref:`PoolVector2Array<class_PoolVector2Array>` by this transform, under the assumption that the transformation is composed of rotation and translation (no scaling). Equivalent to calling ``inverse().xform(v)`` on this transform. For affine transformations (e.g. with scaling) see :ref:`affine_inverse<class_Transform2D_method_affine_inverse>` method.
  236. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  237. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  238. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  239. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`