class_transform2d.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Transform2D.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Transform2D:
  6. Transform2D
  7. ===========
  8. 2D transformation (2×3 matrix).
  9. Description
  10. -----------
  11. 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>`.
  12. For more information, read the "Matrices and transforms" documentation article.
  13. Tutorials
  14. ---------
  15. - :doc:`../tutorials/math/index`
  16. - :doc:`../tutorials/math/matrices_and_transforms`
  17. - `Matrix Transform Demo <https://godotengine.org/asset-library/asset/584>`__
  18. - `2.5D Demo <https://godotengine.org/asset-library/asset/583>`__
  19. Properties
  20. ----------
  21. +-------------------------------+--------------------------------------------------+---------------------+
  22. | :ref:`Vector2<class_Vector2>` | :ref:`origin<class_Transform2D_property_origin>` | ``Vector2( 0, 0 )`` |
  23. +-------------------------------+--------------------------------------------------+---------------------+
  24. | :ref:`Vector2<class_Vector2>` | :ref:`x<class_Transform2D_property_x>` | ``Vector2( 1, 0 )`` |
  25. +-------------------------------+--------------------------------------------------+---------------------+
  26. | :ref:`Vector2<class_Vector2>` | :ref:`y<class_Transform2D_property_y>` | ``Vector2( 0, 1 )`` |
  27. +-------------------------------+--------------------------------------------------+---------------------+
  28. Methods
  29. -------
  30. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Transform2D<class_Transform2D>` | :ref:`Transform2D<class_Transform2D_method_Transform2D>` **(** :ref:`Transform<class_Transform>` from **)** |
  32. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :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 **)** |
  34. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Transform2D<class_Transform2D>` | :ref:`Transform2D<class_Transform2D_method_Transform2D>` **(** :ref:`float<class_float>` rotation, :ref:`Vector2<class_Vector2>` position **)** |
  36. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Transform2D<class_Transform2D>` | :ref:`affine_inverse<class_Transform2D_method_affine_inverse>` **(** **)** |
  38. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Vector2<class_Vector2>` | :ref:`basis_xform<class_Transform2D_method_basis_xform>` **(** :ref:`Vector2<class_Vector2>` v **)** |
  40. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Vector2<class_Vector2>` | :ref:`basis_xform_inv<class_Transform2D_method_basis_xform_inv>` **(** :ref:`Vector2<class_Vector2>` v **)** |
  42. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Vector2<class_Vector2>` | :ref:`get_origin<class_Transform2D_method_get_origin>` **(** **)** |
  44. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`float<class_float>` | :ref:`get_rotation<class_Transform2D_method_get_rotation>` **(** **)** |
  46. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Vector2<class_Vector2>` | :ref:`get_scale<class_Transform2D_method_get_scale>` **(** **)** |
  48. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Transform2D<class_Transform2D>` | :ref:`interpolate_with<class_Transform2D_method_interpolate_with>` **(** :ref:`Transform2D<class_Transform2D>` transform, :ref:`float<class_float>` weight **)** |
  50. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Transform2D<class_Transform2D>` | :ref:`inverse<class_Transform2D_method_inverse>` **(** **)** |
  52. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Transform2D_method_is_equal_approx>` **(** :ref:`Transform2D<class_Transform2D>` transform **)** |
  54. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Transform2D<class_Transform2D>` | :ref:`orthonormalized<class_Transform2D_method_orthonormalized>` **(** **)** |
  56. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`Transform2D<class_Transform2D>` | :ref:`rotated<class_Transform2D_method_rotated>` **(** :ref:`float<class_float>` phi **)** |
  58. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`Transform2D<class_Transform2D>` | :ref:`scaled<class_Transform2D_method_scaled>` **(** :ref:`Vector2<class_Vector2>` scale **)** |
  60. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Transform2D<class_Transform2D>` | :ref:`translated<class_Transform2D_method_translated>` **(** :ref:`Vector2<class_Vector2>` offset **)** |
  62. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Variant<class_Variant>` | :ref:`xform<class_Transform2D_method_xform>` **(** :ref:`Variant<class_Variant>` v **)** |
  64. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Variant<class_Variant>` | :ref:`xform_inv<class_Transform2D_method_xform_inv>` **(** :ref:`Variant<class_Variant>` v **)** |
  66. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. Constants
  68. ---------
  69. .. _class_Transform2D_constant_IDENTITY:
  70. .. _class_Transform2D_constant_FLIP_X:
  71. .. _class_Transform2D_constant_FLIP_Y:
  72. - **IDENTITY** = **Transform2D( 1, 0, 0, 1, 0, 0 )** --- 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.
  73. - **FLIP_X** = **Transform2D( -1, 0, 0, 1, 0, 0 )** --- The ``Transform2D`` that will flip something along the X axis.
  74. - **FLIP_Y** = **Transform2D( 1, 0, 0, -1, 0, 0 )** --- The ``Transform2D`` that will flip something along the Y axis.
  75. Property Descriptions
  76. ---------------------
  77. .. _class_Transform2D_property_origin:
  78. - :ref:`Vector2<class_Vector2>` **origin**
  79. +-----------+---------------------+
  80. | *Default* | ``Vector2( 0, 0 )`` |
  81. +-----------+---------------------+
  82. The origin vector (column 2, the third column). Equivalent to array index ``2``. The origin vector represents translation.
  83. ----
  84. .. _class_Transform2D_property_x:
  85. - :ref:`Vector2<class_Vector2>` **x**
  86. +-----------+---------------------+
  87. | *Default* | ``Vector2( 1, 0 )`` |
  88. +-----------+---------------------+
  89. The basis matrix's X vector (column 0). Equivalent to array index ``0``.
  90. ----
  91. .. _class_Transform2D_property_y:
  92. - :ref:`Vector2<class_Vector2>` **y**
  93. +-----------+---------------------+
  94. | *Default* | ``Vector2( 0, 1 )`` |
  95. +-----------+---------------------+
  96. The basis matrix's Y vector (column 1). Equivalent to array index ``1``.
  97. Method Descriptions
  98. -------------------
  99. .. _class_Transform2D_method_Transform2D:
  100. - :ref:`Transform2D<class_Transform2D>` **Transform2D** **(** :ref:`Transform<class_Transform>` from **)**
  101. Constructs the transform from a 3D :ref:`Transform<class_Transform>`.
  102. ----
  103. - :ref:`Transform2D<class_Transform2D>` **Transform2D** **(** :ref:`Vector2<class_Vector2>` x_axis, :ref:`Vector2<class_Vector2>` y_axis, :ref:`Vector2<class_Vector2>` origin **)**
  104. 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).
  105. ----
  106. - :ref:`Transform2D<class_Transform2D>` **Transform2D** **(** :ref:`float<class_float>` rotation, :ref:`Vector2<class_Vector2>` position **)**
  107. Constructs the transform from a given angle (in radians) and position.
  108. ----
  109. .. _class_Transform2D_method_affine_inverse:
  110. - :ref:`Transform2D<class_Transform2D>` **affine_inverse** **(** **)**
  111. Returns the inverse of the transform, under the assumption that the transformation is composed of rotation, scaling and translation.
  112. ----
  113. .. _class_Transform2D_method_basis_xform:
  114. - :ref:`Vector2<class_Vector2>` **basis_xform** **(** :ref:`Vector2<class_Vector2>` v **)**
  115. Returns a vector transformed (multiplied) by the basis matrix.
  116. This method does not account for translation (the origin vector).
  117. ----
  118. .. _class_Transform2D_method_basis_xform_inv:
  119. - :ref:`Vector2<class_Vector2>` **basis_xform_inv** **(** :ref:`Vector2<class_Vector2>` v **)**
  120. Returns a vector transformed (multiplied) by the inverse basis matrix.
  121. This method does not account for translation (the origin vector).
  122. ----
  123. .. _class_Transform2D_method_get_origin:
  124. - :ref:`Vector2<class_Vector2>` **get_origin** **(** **)**
  125. Returns the transform's origin (translation).
  126. ----
  127. .. _class_Transform2D_method_get_rotation:
  128. - :ref:`float<class_float>` **get_rotation** **(** **)**
  129. Returns the transform's rotation (in radians).
  130. ----
  131. .. _class_Transform2D_method_get_scale:
  132. - :ref:`Vector2<class_Vector2>` **get_scale** **(** **)**
  133. Returns the scale.
  134. ----
  135. .. _class_Transform2D_method_interpolate_with:
  136. - :ref:`Transform2D<class_Transform2D>` **interpolate_with** **(** :ref:`Transform2D<class_Transform2D>` transform, :ref:`float<class_float>` weight **)**
  137. Returns a transform interpolated between this transform and another by a given ``weight`` (on the range of 0.0 to 1.0).
  138. ----
  139. .. _class_Transform2D_method_inverse:
  140. - :ref:`Transform2D<class_Transform2D>` **inverse** **(** **)**
  141. 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).
  142. ----
  143. .. _class_Transform2D_method_is_equal_approx:
  144. - :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Transform2D<class_Transform2D>` transform **)**
  145. Returns ``true`` if this transform and ``transform`` are approximately equal, by calling ``is_equal_approx`` on each component.
  146. ----
  147. .. _class_Transform2D_method_orthonormalized:
  148. - :ref:`Transform2D<class_Transform2D>` **orthonormalized** **(** **)**
  149. Returns the transform with the basis orthogonal (90 degrees), and normalized axis vectors (scale of 1 or -1).
  150. ----
  151. .. _class_Transform2D_method_rotated:
  152. - :ref:`Transform2D<class_Transform2D>` **rotated** **(** :ref:`float<class_float>` phi **)**
  153. Rotates the transform by the given angle (in radians), using matrix multiplication.
  154. ----
  155. .. _class_Transform2D_method_scaled:
  156. - :ref:`Transform2D<class_Transform2D>` **scaled** **(** :ref:`Vector2<class_Vector2>` scale **)**
  157. Scales the transform by the given scale factor, using matrix multiplication.
  158. ----
  159. .. _class_Transform2D_method_translated:
  160. - :ref:`Transform2D<class_Transform2D>` **translated** **(** :ref:`Vector2<class_Vector2>` offset **)**
  161. Translates the transform by the given offset, relative to the transform's basis vectors.
  162. Unlike :ref:`rotated<class_Transform2D_method_rotated>` and :ref:`scaled<class_Transform2D_method_scaled>`, this does not use matrix multiplication.
  163. ----
  164. .. _class_Transform2D_method_xform:
  165. - :ref:`Variant<class_Variant>` **xform** **(** :ref:`Variant<class_Variant>` v **)**
  166. Transforms the given :ref:`Vector2<class_Vector2>`, :ref:`Rect2<class_Rect2>`, or :ref:`PoolVector2Array<class_PoolVector2Array>` by this transform.
  167. ----
  168. .. _class_Transform2D_method_xform_inv:
  169. - :ref:`Variant<class_Variant>` **xform_inv** **(** :ref:`Variant<class_Variant>` v **)**
  170. 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.
  171. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  172. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  173. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`