class_transform2d.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.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 (3×2 matrix).
  9. Description
  10. -----------
  11. Represents one or many transformations in 2D space such as translation, rotation, or scaling. It consists of two :ref:`x<class_Transform2D_property_x>` and :ref:`y<class_Transform2D_property_y>` :ref:`Vector2<class_Vector2>`\ s and an :ref:`origin<class_Transform2D_property_origin>`. It is similar to a 3×2 matrix.
  12. Properties
  13. ----------
  14. +-------------------------------+--------------------------------------------------+---------------------+
  15. | :ref:`Vector2<class_Vector2>` | :ref:`origin<class_Transform2D_property_origin>` | ``Vector2( 0, 0 )`` |
  16. +-------------------------------+--------------------------------------------------+---------------------+
  17. | :ref:`Vector2<class_Vector2>` | :ref:`x<class_Transform2D_property_x>` | ``Vector2( 1, 0 )`` |
  18. +-------------------------------+--------------------------------------------------+---------------------+
  19. | :ref:`Vector2<class_Vector2>` | :ref:`y<class_Transform2D_property_y>` | ``Vector2( 0, 1 )`` |
  20. +-------------------------------+--------------------------------------------------+---------------------+
  21. Methods
  22. -------
  23. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`Transform2D<class_Transform2D>` | :ref:`Transform2D<class_Transform2D_method_Transform2D>` **(** :ref:`Transform<class_Transform>` from **)** |
  25. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :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 **)** |
  27. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`Transform2D<class_Transform2D>` | :ref:`Transform2D<class_Transform2D_method_Transform2D>` **(** :ref:`float<class_float>` rotation, :ref:`Vector2<class_Vector2>` position **)** |
  29. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Transform2D<class_Transform2D>` | :ref:`affine_inverse<class_Transform2D_method_affine_inverse>` **(** **)** |
  31. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Vector2<class_Vector2>` | :ref:`basis_xform<class_Transform2D_method_basis_xform>` **(** :ref:`Vector2<class_Vector2>` v **)** |
  33. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`Vector2<class_Vector2>` | :ref:`basis_xform_inv<class_Transform2D_method_basis_xform_inv>` **(** :ref:`Vector2<class_Vector2>` v **)** |
  35. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`Vector2<class_Vector2>` | :ref:`get_origin<class_Transform2D_method_get_origin>` **(** **)** |
  37. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`float<class_float>` | :ref:`get_rotation<class_Transform2D_method_get_rotation>` **(** **)** |
  39. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Vector2<class_Vector2>` | :ref:`get_scale<class_Transform2D_method_get_scale>` **(** **)** |
  41. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Transform2D<class_Transform2D>` | :ref:`interpolate_with<class_Transform2D_method_interpolate_with>` **(** :ref:`Transform2D<class_Transform2D>` transform, :ref:`float<class_float>` weight **)** |
  43. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`Transform2D<class_Transform2D>` | :ref:`inverse<class_Transform2D_method_inverse>` **(** **)** |
  45. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Transform2D_method_is_equal_approx>` **(** :ref:`Transform2D<class_Transform2D>` transform **)** |
  47. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`Transform2D<class_Transform2D>` | :ref:`orthonormalized<class_Transform2D_method_orthonormalized>` **(** **)** |
  49. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Transform2D<class_Transform2D>` | :ref:`rotated<class_Transform2D_method_rotated>` **(** :ref:`float<class_float>` phi **)** |
  51. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Transform2D<class_Transform2D>` | :ref:`scaled<class_Transform2D_method_scaled>` **(** :ref:`Vector2<class_Vector2>` scale **)** |
  53. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Transform2D<class_Transform2D>` | :ref:`translated<class_Transform2D_method_translated>` **(** :ref:`Vector2<class_Vector2>` offset **)** |
  55. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Variant<class_Variant>` | :ref:`xform<class_Transform2D_method_xform>` **(** :ref:`Variant<class_Variant>` v **)** |
  57. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`Variant<class_Variant>` | :ref:`xform_inv<class_Transform2D_method_xform_inv>` **(** :ref:`Variant<class_Variant>` v **)** |
  59. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. Constants
  61. ---------
  62. .. _class_Transform2D_constant_IDENTITY:
  63. .. _class_Transform2D_constant_FLIP_X:
  64. .. _class_Transform2D_constant_FLIP_Y:
  65. - **IDENTITY** = **Transform2D( 1, 0, 0, 1, 0, 0 )** --- ``Transform2D`` with no translation, rotation or scaling applied. When applied to other data structures, :ref:`IDENTITY<class_Transform2D_constant_IDENTITY>` performs no transformation.
  66. - **FLIP_X** = **Transform2D( -1, 0, 0, 1, 0, 0 )** --- ``Transform2D`` with mirroring applied parallel to the X axis.
  67. - **FLIP_Y** = **Transform2D( 1, 0, 0, -1, 0, 0 )** --- ``Transform2D`` with mirroring applied parallel to the Y axis.
  68. Property Descriptions
  69. ---------------------
  70. .. _class_Transform2D_property_origin:
  71. - :ref:`Vector2<class_Vector2>` **origin**
  72. +-----------+---------------------+
  73. | *Default* | ``Vector2( 0, 0 )`` |
  74. +-----------+---------------------+
  75. The transform's translation offset.
  76. ----
  77. .. _class_Transform2D_property_x:
  78. - :ref:`Vector2<class_Vector2>` **x**
  79. +-----------+---------------------+
  80. | *Default* | ``Vector2( 1, 0 )`` |
  81. +-----------+---------------------+
  82. The X axis of 2×2 basis matrix containing 2 :ref:`Vector2<class_Vector2>`\ s as its columns: X axis and Y axis. These vectors can be interpreted as the basis vectors of local coordinate system traveling with the object.
  83. ----
  84. .. _class_Transform2D_property_y:
  85. - :ref:`Vector2<class_Vector2>` **y**
  86. +-----------+---------------------+
  87. | *Default* | ``Vector2( 0, 1 )`` |
  88. +-----------+---------------------+
  89. The Y axis of 2×2 basis matrix containing 2 :ref:`Vector2<class_Vector2>`\ s as its columns: X axis and Y axis. These vectors can be interpreted as the basis vectors of local coordinate system traveling with the object.
  90. Method Descriptions
  91. -------------------
  92. .. _class_Transform2D_method_Transform2D:
  93. - :ref:`Transform2D<class_Transform2D>` **Transform2D** **(** :ref:`Transform<class_Transform>` from **)**
  94. Constructs the transform from a 3D :ref:`Transform<class_Transform>`.
  95. ----
  96. - :ref:`Transform2D<class_Transform2D>` **Transform2D** **(** :ref:`Vector2<class_Vector2>` x_axis, :ref:`Vector2<class_Vector2>` y_axis, :ref:`Vector2<class_Vector2>` origin **)**
  97. Constructs the transform from 3 :ref:`Vector2<class_Vector2>`\ s representing x, y, and origin.
  98. ----
  99. - :ref:`Transform2D<class_Transform2D>` **Transform2D** **(** :ref:`float<class_float>` rotation, :ref:`Vector2<class_Vector2>` position **)**
  100. Constructs the transform from a given angle (in radians) and position.
  101. ----
  102. .. _class_Transform2D_method_affine_inverse:
  103. - :ref:`Transform2D<class_Transform2D>` **affine_inverse** **(** **)**
  104. Returns the inverse of the matrix.
  105. ----
  106. .. _class_Transform2D_method_basis_xform:
  107. - :ref:`Vector2<class_Vector2>` **basis_xform** **(** :ref:`Vector2<class_Vector2>` v **)**
  108. Transforms the given vector by this transform's basis (no translation).
  109. ----
  110. .. _class_Transform2D_method_basis_xform_inv:
  111. - :ref:`Vector2<class_Vector2>` **basis_xform_inv** **(** :ref:`Vector2<class_Vector2>` v **)**
  112. Inverse-transforms the given vector by this transform's basis (no translation).
  113. ----
  114. .. _class_Transform2D_method_get_origin:
  115. - :ref:`Vector2<class_Vector2>` **get_origin** **(** **)**
  116. Returns the transform's origin (translation).
  117. ----
  118. .. _class_Transform2D_method_get_rotation:
  119. - :ref:`float<class_float>` **get_rotation** **(** **)**
  120. Returns the transform's rotation (in radians).
  121. ----
  122. .. _class_Transform2D_method_get_scale:
  123. - :ref:`Vector2<class_Vector2>` **get_scale** **(** **)**
  124. Returns the scale.
  125. ----
  126. .. _class_Transform2D_method_interpolate_with:
  127. - :ref:`Transform2D<class_Transform2D>` **interpolate_with** **(** :ref:`Transform2D<class_Transform2D>` transform, :ref:`float<class_float>` weight **)**
  128. Returns a transform interpolated between this transform and another by a given weight (0-1).
  129. ----
  130. .. _class_Transform2D_method_inverse:
  131. - :ref:`Transform2D<class_Transform2D>` **inverse** **(** **)**
  132. Returns the inverse of the transform, under the assumption that the transformation is composed of rotation and translation (no scaling, use affine_inverse for transforms with scaling).
  133. ----
  134. .. _class_Transform2D_method_is_equal_approx:
  135. - :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Transform2D<class_Transform2D>` transform **)**
  136. Returns ``true`` if this transform and ``transform`` are approximately equal, by calling ``is_equal_approx`` on each component.
  137. ----
  138. .. _class_Transform2D_method_orthonormalized:
  139. - :ref:`Transform2D<class_Transform2D>` **orthonormalized** **(** **)**
  140. Returns the transform with the basis orthogonal (90 degrees), and normalized axis vectors.
  141. ----
  142. .. _class_Transform2D_method_rotated:
  143. - :ref:`Transform2D<class_Transform2D>` **rotated** **(** :ref:`float<class_float>` phi **)**
  144. Rotates the transform by the given angle (in radians), using matrix multiplication.
  145. ----
  146. .. _class_Transform2D_method_scaled:
  147. - :ref:`Transform2D<class_Transform2D>` **scaled** **(** :ref:`Vector2<class_Vector2>` scale **)**
  148. Scales the transform by the given scale factor, using matrix multiplication.
  149. ----
  150. .. _class_Transform2D_method_translated:
  151. - :ref:`Transform2D<class_Transform2D>` **translated** **(** :ref:`Vector2<class_Vector2>` offset **)**
  152. Translates the transform by the given offset, relative to the transform's basis vectors.
  153. Unlike :ref:`rotated<class_Transform2D_method_rotated>` and :ref:`scaled<class_Transform2D_method_scaled>`, this does not use matrix multiplication.
  154. ----
  155. .. _class_Transform2D_method_xform:
  156. - :ref:`Variant<class_Variant>` **xform** **(** :ref:`Variant<class_Variant>` v **)**
  157. Transforms the given :ref:`Vector2<class_Vector2>`, :ref:`Rect2<class_Rect2>`, or :ref:`PackedVector2Array<class_PackedVector2Array>` by this transform.
  158. ----
  159. .. _class_Transform2D_method_xform_inv:
  160. - :ref:`Variant<class_Variant>` **xform_inv** **(** :ref:`Variant<class_Variant>` v **)**
  161. Inverse-transforms the given :ref:`Vector2<class_Vector2>`, :ref:`Rect2<class_Rect2>`, or :ref:`PackedVector2Array<class_PackedVector2Array>` by this transform.