class_transform.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 Transform.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Transform:
  6. Transform
  7. =========
  8. 3D transformation (3×4 matrix).
  9. Description
  10. -----------
  11. Represents one or many transformations in 3D space such as translation, rotation, or scaling. It consists of a :ref:`basis<class_Transform_property_basis>` and an :ref:`origin<class_Transform_property_origin>`. It is similar to a 3×4 matrix.
  12. Tutorials
  13. ---------
  14. - :doc:`../tutorials/math/index`
  15. - :doc:`../tutorials/3d/using_transforms`
  16. Properties
  17. ----------
  18. +-------------------------------+------------------------------------------------+----------------------------------------+
  19. | :ref:`Basis<class_Basis>` | :ref:`basis<class_Transform_property_basis>` | ``Basis( 1, 0, 0, 0, 1, 0, 0, 0, 1 )`` |
  20. +-------------------------------+------------------------------------------------+----------------------------------------+
  21. | :ref:`Vector3<class_Vector3>` | :ref:`origin<class_Transform_property_origin>` | ``Vector3( 0, 0, 0 )`` |
  22. +-------------------------------+------------------------------------------------+----------------------------------------+
  23. Methods
  24. -------
  25. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`Transform<class_Transform>` | :ref:`Transform<class_Transform_method_Transform>` **(** :ref:`Vector3<class_Vector3>` x_axis, :ref:`Vector3<class_Vector3>` y_axis, :ref:`Vector3<class_Vector3>` z_axis, :ref:`Vector3<class_Vector3>` origin **)** |
  27. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`Transform<class_Transform>` | :ref:`Transform<class_Transform_method_Transform>` **(** :ref:`Basis<class_Basis>` basis, :ref:`Vector3<class_Vector3>` origin **)** |
  29. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Transform<class_Transform>` | :ref:`Transform<class_Transform_method_Transform>` **(** :ref:`Transform2D<class_Transform2D>` from **)** |
  31. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Transform<class_Transform>` | :ref:`Transform<class_Transform_method_Transform>` **(** :ref:`Quat<class_Quat>` from **)** |
  33. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`Transform<class_Transform>` | :ref:`Transform<class_Transform_method_Transform>` **(** :ref:`Basis<class_Basis>` from **)** |
  35. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`Transform<class_Transform>` | :ref:`affine_inverse<class_Transform_method_affine_inverse>` **(** **)** |
  37. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Transform<class_Transform>` | :ref:`interpolate_with<class_Transform_method_interpolate_with>` **(** :ref:`Transform<class_Transform>` transform, :ref:`float<class_float>` weight **)** |
  39. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Transform<class_Transform>` | :ref:`inverse<class_Transform_method_inverse>` **(** **)** |
  41. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Transform_method_is_equal_approx>` **(** :ref:`Transform<class_Transform>` transform **)** |
  43. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`Transform<class_Transform>` | :ref:`looking_at<class_Transform_method_looking_at>` **(** :ref:`Vector3<class_Vector3>` target, :ref:`Vector3<class_Vector3>` up **)** |
  45. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Transform<class_Transform>` | :ref:`orthonormalized<class_Transform_method_orthonormalized>` **(** **)** |
  47. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`Transform<class_Transform>` | :ref:`rotated<class_Transform_method_rotated>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` phi **)** |
  49. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Transform<class_Transform>` | :ref:`scaled<class_Transform_method_scaled>` **(** :ref:`Vector3<class_Vector3>` scale **)** |
  51. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Transform<class_Transform>` | :ref:`translated<class_Transform_method_translated>` **(** :ref:`Vector3<class_Vector3>` offset **)** |
  53. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Variant<class_Variant>` | :ref:`xform<class_Transform_method_xform>` **(** :ref:`Variant<class_Variant>` v **)** |
  55. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Variant<class_Variant>` | :ref:`xform_inv<class_Transform_method_xform_inv>` **(** :ref:`Variant<class_Variant>` v **)** |
  57. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. Constants
  59. ---------
  60. .. _class_Transform_constant_IDENTITY:
  61. .. _class_Transform_constant_FLIP_X:
  62. .. _class_Transform_constant_FLIP_Y:
  63. .. _class_Transform_constant_FLIP_Z:
  64. - **IDENTITY** = **Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )** --- ``Transform`` with no translation, rotation or scaling applied. When applied to other data structures, :ref:`IDENTITY<class_Transform_constant_IDENTITY>` performs no transformation.
  65. - **FLIP_X** = **Transform( -1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )** --- ``Transform`` with mirroring applied perpendicular to the YZ plane.
  66. - **FLIP_Y** = **Transform( 1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0 )** --- ``Transform`` with mirroring applied perpendicular to the XZ plane.
  67. - **FLIP_Z** = **Transform( 1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0 )** --- ``Transform`` with mirroring applied perpendicular to the XY plane.
  68. Property Descriptions
  69. ---------------------
  70. .. _class_Transform_property_basis:
  71. - :ref:`Basis<class_Basis>` **basis**
  72. +-----------+----------------------------------------+
  73. | *Default* | ``Basis( 1, 0, 0, 0, 1, 0, 0, 0, 1 )`` |
  74. +-----------+----------------------------------------+
  75. The basis is a matrix containing 3 :ref:`Vector3<class_Vector3>` as its columns: X axis, Y axis, and Z axis. These vectors can be interpreted as the basis vectors of local coordinate system traveling with the object.
  76. ----
  77. .. _class_Transform_property_origin:
  78. - :ref:`Vector3<class_Vector3>` **origin**
  79. +-----------+------------------------+
  80. | *Default* | ``Vector3( 0, 0, 0 )`` |
  81. +-----------+------------------------+
  82. The translation offset of the transform.
  83. Method Descriptions
  84. -------------------
  85. .. _class_Transform_method_Transform:
  86. - :ref:`Transform<class_Transform>` **Transform** **(** :ref:`Vector3<class_Vector3>` x_axis, :ref:`Vector3<class_Vector3>` y_axis, :ref:`Vector3<class_Vector3>` z_axis, :ref:`Vector3<class_Vector3>` origin **)**
  87. Constructs the Transform from four :ref:`Vector3<class_Vector3>`. Each axis corresponds to local basis vectors (some of which may be scaled).
  88. ----
  89. - :ref:`Transform<class_Transform>` **Transform** **(** :ref:`Basis<class_Basis>` basis, :ref:`Vector3<class_Vector3>` origin **)**
  90. Constructs the Transform from a :ref:`Basis<class_Basis>` and :ref:`Vector3<class_Vector3>`.
  91. ----
  92. - :ref:`Transform<class_Transform>` **Transform** **(** :ref:`Transform2D<class_Transform2D>` from **)**
  93. Constructs the Transform from a :ref:`Transform2D<class_Transform2D>`.
  94. ----
  95. - :ref:`Transform<class_Transform>` **Transform** **(** :ref:`Quat<class_Quat>` from **)**
  96. Constructs the Transform from a :ref:`Quat<class_Quat>`. The origin will be Vector3(0, 0, 0).
  97. ----
  98. - :ref:`Transform<class_Transform>` **Transform** **(** :ref:`Basis<class_Basis>` from **)**
  99. Constructs the Transform from a :ref:`Basis<class_Basis>`. The origin will be Vector3(0, 0, 0).
  100. ----
  101. .. _class_Transform_method_affine_inverse:
  102. - :ref:`Transform<class_Transform>` **affine_inverse** **(** **)**
  103. Returns the inverse of the transform, under the assumption that the transformation is composed of rotation, scaling and translation.
  104. ----
  105. .. _class_Transform_method_interpolate_with:
  106. - :ref:`Transform<class_Transform>` **interpolate_with** **(** :ref:`Transform<class_Transform>` transform, :ref:`float<class_float>` weight **)**
  107. Interpolates the transform to other Transform by weight amount (0-1).
  108. ----
  109. .. _class_Transform_method_inverse:
  110. - :ref:`Transform<class_Transform>` **inverse** **(** **)**
  111. 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).
  112. ----
  113. .. _class_Transform_method_is_equal_approx:
  114. - :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Transform<class_Transform>` transform **)**
  115. Returns ``true`` if this transform and ``transform`` are approximately equal, by calling ``is_equal_approx`` on each component.
  116. ----
  117. .. _class_Transform_method_looking_at:
  118. - :ref:`Transform<class_Transform>` **looking_at** **(** :ref:`Vector3<class_Vector3>` target, :ref:`Vector3<class_Vector3>` up **)**
  119. Returns a copy of the transform rotated such that its -Z axis points towards the ``target`` position.
  120. The transform will first be rotated around the given ``up`` vector, and then fully aligned to the target by a further rotation around an axis perpendicular to both the ``target`` and ``up`` vectors.
  121. Operations take place in global space.
  122. ----
  123. .. _class_Transform_method_orthonormalized:
  124. - :ref:`Transform<class_Transform>` **orthonormalized** **(** **)**
  125. Returns the transform with the basis orthogonal (90 degrees), and normalized axis vectors.
  126. ----
  127. .. _class_Transform_method_rotated:
  128. - :ref:`Transform<class_Transform>` **rotated** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` phi **)**
  129. Rotates the transform around the given axis by the given angle (in radians), using matrix multiplication. The axis must be a normalized vector.
  130. ----
  131. .. _class_Transform_method_scaled:
  132. - :ref:`Transform<class_Transform>` **scaled** **(** :ref:`Vector3<class_Vector3>` scale **)**
  133. Scales the transform by the given scale factor, using matrix multiplication.
  134. ----
  135. .. _class_Transform_method_translated:
  136. - :ref:`Transform<class_Transform>` **translated** **(** :ref:`Vector3<class_Vector3>` offset **)**
  137. Translates the transform by the given offset, relative to the transform's basis vectors.
  138. Unlike :ref:`rotated<class_Transform_method_rotated>` and :ref:`scaled<class_Transform_method_scaled>`, this does not use matrix multiplication.
  139. ----
  140. .. _class_Transform_method_xform:
  141. - :ref:`Variant<class_Variant>` **xform** **(** :ref:`Variant<class_Variant>` v **)**
  142. Transforms the given :ref:`Vector3<class_Vector3>`, :ref:`Plane<class_Plane>`, :ref:`AABB<class_AABB>`, or :ref:`PackedVector3Array<class_PackedVector3Array>` by this transform.
  143. ----
  144. .. _class_Transform_method_xform_inv:
  145. - :ref:`Variant<class_Variant>` **xform_inv** **(** :ref:`Variant<class_Variant>` v **)**
  146. Inverse-transforms the given :ref:`Vector3<class_Vector3>`, :ref:`Plane<class_Plane>`, :ref:`AABB<class_AABB>`, or :ref:`PackedVector3Array<class_PackedVector3Array>` by this transform.