class_transform3d.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 Transform3D.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Transform3D:
  6. Transform3D
  7. ===========
  8. 3D transformation (3×4 matrix).
  9. Description
  10. -----------
  11. 3×4 matrix (3 rows, 4 columns) used for 3D linear transformations. It can represent transformations such as translation, rotation, or scaling. It consists of a :ref:`basis<class_Transform3D_property_basis>` (first 3 columns) and a :ref:`Vector3<class_Vector3>` for the :ref:`origin<class_Transform3D_property_origin>` (last column).
  12. For more information, read the "Matrices and transforms" documentation article.
  13. Tutorials
  14. ---------
  15. - :doc:`Math documentation index <../tutorials/math/index>`
  16. - :doc:`Matrices and transforms <../tutorials/math/matrices_and_transforms>`
  17. - :doc:`Using 3D transforms <../tutorials/3d/using_transforms>`
  18. - `Matrix Transform Demo <https://godotengine.org/asset-library/asset/584>`__
  19. - `3D Platformer Demo <https://godotengine.org/asset-library/asset/125>`__
  20. - `2.5D Demo <https://godotengine.org/asset-library/asset/583>`__
  21. Properties
  22. ----------
  23. +-------------------------------+--------------------------------------------------+--------------------------------------+
  24. | :ref:`Basis<class_Basis>` | :ref:`basis<class_Transform3D_property_basis>` | ``Basis(1, 0, 0, 0, 1, 0, 0, 0, 1)`` |
  25. +-------------------------------+--------------------------------------------------+--------------------------------------+
  26. | :ref:`Vector3<class_Vector3>` | :ref:`origin<class_Transform3D_property_origin>` | ``Vector3(0, 0, 0)`` |
  27. +-------------------------------+--------------------------------------------------+--------------------------------------+
  28. Constructors
  29. ------------
  30. +---------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Transform3D<class_Transform3D>` | :ref:`Transform3D<class_Transform3D_constructor_Transform3D>` **(** **)** |
  32. +---------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Transform3D<class_Transform3D>` | :ref:`Transform3D<class_Transform3D_constructor_Transform3D>` **(** :ref:`Transform3D<class_Transform3D>` from **)** |
  34. +---------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Transform3D<class_Transform3D>` | :ref:`Transform3D<class_Transform3D_constructor_Transform3D>` **(** :ref:`Basis<class_Basis>` basis, :ref:`Vector3<class_Vector3>` origin **)** |
  36. +---------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Transform3D<class_Transform3D>` | :ref:`Transform3D<class_Transform3D_constructor_Transform3D>` **(** :ref:`Vector3<class_Vector3>` x_axis, :ref:`Vector3<class_Vector3>` y_axis, :ref:`Vector3<class_Vector3>` z_axis, :ref:`Vector3<class_Vector3>` origin **)** |
  38. +---------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. Methods
  40. -------
  41. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Transform3D<class_Transform3D>` | :ref:`affine_inverse<class_Transform3D_method_affine_inverse>` **(** **)** |const| |
  43. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`Transform3D<class_Transform3D>` | :ref:`interpolate_with<class_Transform3D_method_interpolate_with>` **(** :ref:`Transform3D<class_Transform3D>` xform, :ref:`float<class_float>` weight **)** |const| |
  45. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Transform3D<class_Transform3D>` | :ref:`inverse<class_Transform3D_method_inverse>` **(** **)** |const| |
  47. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Transform3D_method_is_equal_approx>` **(** :ref:`Transform3D<class_Transform3D>` xform **)** |const| |
  49. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Transform3D<class_Transform3D>` | :ref:`looking_at<class_Transform3D_method_looking_at>` **(** :ref:`Vector3<class_Vector3>` target, :ref:`Vector3<class_Vector3>` up=Vector3(0, 1, 0) **)** |const| |
  51. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Transform3D<class_Transform3D>` | :ref:`orthonormalized<class_Transform3D_method_orthonormalized>` **(** **)** |const| |
  53. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Transform3D<class_Transform3D>` | :ref:`rotated<class_Transform3D_method_rotated>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` phi **)** |const| |
  55. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Transform3D<class_Transform3D>` | :ref:`scaled<class_Transform3D_method_scaled>` **(** :ref:`Vector3<class_Vector3>` scale **)** |const| |
  57. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`Transform3D<class_Transform3D>` | :ref:`sphere_interpolate_with<class_Transform3D_method_sphere_interpolate_with>` **(** :ref:`Transform3D<class_Transform3D>` xform, :ref:`float<class_float>` weight **)** |const| |
  59. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Transform3D<class_Transform3D>` | :ref:`translated<class_Transform3D_method_translated>` **(** :ref:`Vector3<class_Vector3>` offset **)** |const| |
  61. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. Operators
  63. ---------
  64. +-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Transform3D_operator_neq_bool>` **(** **)** |
  66. +-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Transform3D_operator_neq_bool>` **(** :ref:`Transform3D<class_Transform3D>` right **)** |
  68. +-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`AABB<class_AABB>` | :ref:`operator *<class_Transform3D_operator_mul_AABB>` **(** :ref:`AABB<class_AABB>` right **)** |
  70. +-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`PackedVector3Array<class_PackedVector3Array>` | :ref:`operator *<class_Transform3D_operator_mul_PackedVector3Array>` **(** :ref:`PackedVector3Array<class_PackedVector3Array>` right **)** |
  72. +-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Transform3D<class_Transform3D>` | :ref:`operator *<class_Transform3D_operator_mul_Transform3D>` **(** :ref:`Transform3D<class_Transform3D>` right **)** |
  74. +-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`Vector3<class_Vector3>` | :ref:`operator *<class_Transform3D_operator_mul_Vector3>` **(** :ref:`Vector3<class_Vector3>` right **)** |
  76. +-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`Transform3D<class_Transform3D>` | :ref:`operator *<class_Transform3D_operator_mul_Transform3D>` **(** :ref:`float<class_float>` right **)** |
  78. +-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`Transform3D<class_Transform3D>` | :ref:`operator *<class_Transform3D_operator_mul_Transform3D>` **(** :ref:`int<class_int>` right **)** |
  80. +-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Transform3D_operator_eq_bool>` **(** **)** |
  82. +-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Transform3D_operator_eq_bool>` **(** :ref:`Transform3D<class_Transform3D>` right **)** |
  84. +-----------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
  85. Constants
  86. ---------
  87. .. _class_Transform3D_constant_IDENTITY:
  88. .. _class_Transform3D_constant_FLIP_X:
  89. .. _class_Transform3D_constant_FLIP_Y:
  90. .. _class_Transform3D_constant_FLIP_Z:
  91. - **IDENTITY** = **Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)** --- ``Transform3D`` with no translation, rotation or scaling applied. When applied to other data structures, :ref:`IDENTITY<class_Transform3D_constant_IDENTITY>` performs no transformation.
  92. - **FLIP_X** = **Transform3D(-1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)** --- ``Transform3D`` with mirroring applied perpendicular to the YZ plane.
  93. - **FLIP_Y** = **Transform3D(1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0)** --- ``Transform3D`` with mirroring applied perpendicular to the XZ plane.
  94. - **FLIP_Z** = **Transform3D(1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0)** --- ``Transform3D`` with mirroring applied perpendicular to the XY plane.
  95. Property Descriptions
  96. ---------------------
  97. .. _class_Transform3D_property_basis:
  98. - :ref:`Basis<class_Basis>` **basis**
  99. +-----------+--------------------------------------+
  100. | *Default* | ``Basis(1, 0, 0, 0, 1, 0, 0, 0, 1)`` |
  101. +-----------+--------------------------------------+
  102. 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.
  103. ----
  104. .. _class_Transform3D_property_origin:
  105. - :ref:`Vector3<class_Vector3>` **origin**
  106. +-----------+----------------------+
  107. | *Default* | ``Vector3(0, 0, 0)`` |
  108. +-----------+----------------------+
  109. The translation offset of the transform (column 3, the fourth column). Equivalent to array index ``3``.
  110. Constructor Descriptions
  111. ------------------------
  112. .. _class_Transform3D_constructor_Transform3D:
  113. - :ref:`Transform3D<class_Transform3D>` **Transform3D** **(** **)**
  114. Constructs a default-initialized ``Transform3D`` set to :ref:`IDENTITY<class_Transform3D_constant_IDENTITY>`.
  115. ----
  116. - :ref:`Transform3D<class_Transform3D>` **Transform3D** **(** :ref:`Transform3D<class_Transform3D>` from **)**
  117. Constructs a ``Transform3D`` as a copy of the given ``Transform3D``.
  118. ----
  119. - :ref:`Transform3D<class_Transform3D>` **Transform3D** **(** :ref:`Basis<class_Basis>` basis, :ref:`Vector3<class_Vector3>` origin **)**
  120. Constructs a Transform3D from a :ref:`Basis<class_Basis>` and :ref:`Vector3<class_Vector3>`.
  121. ----
  122. - :ref:`Transform3D<class_Transform3D>` **Transform3D** **(** :ref:`Vector3<class_Vector3>` x_axis, :ref:`Vector3<class_Vector3>` y_axis, :ref:`Vector3<class_Vector3>` z_axis, :ref:`Vector3<class_Vector3>` origin **)**
  123. Constructs a Transform3D from four :ref:`Vector3<class_Vector3>` values (matrix columns). Each axis corresponds to local basis vectors (some of which may be scaled).
  124. Method Descriptions
  125. -------------------
  126. .. _class_Transform3D_method_affine_inverse:
  127. - :ref:`Transform3D<class_Transform3D>` **affine_inverse** **(** **)** |const|
  128. Returns the inverse of the transform, under the assumption that the transformation is composed of rotation, scaling and translation.
  129. ----
  130. .. _class_Transform3D_method_interpolate_with:
  131. - :ref:`Transform3D<class_Transform3D>` **interpolate_with** **(** :ref:`Transform3D<class_Transform3D>` xform, :ref:`float<class_float>` weight **)** |const|
  132. Returns a transform interpolated between this transform and another by a given ``weight`` (on the range of 0.0 to 1.0).
  133. ----
  134. .. _class_Transform3D_method_inverse:
  135. - :ref:`Transform3D<class_Transform3D>` **inverse** **(** **)** |const|
  136. 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_Transform3D_method_affine_inverse>` for transforms with scaling).
  137. ----
  138. .. _class_Transform3D_method_is_equal_approx:
  139. - :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Transform3D<class_Transform3D>` xform **)** |const|
  140. Returns ``true`` if this transform and ``transform`` are approximately equal, by calling ``is_equal_approx`` on each component.
  141. ----
  142. .. _class_Transform3D_method_looking_at:
  143. - :ref:`Transform3D<class_Transform3D>` **looking_at** **(** :ref:`Vector3<class_Vector3>` target, :ref:`Vector3<class_Vector3>` up=Vector3(0, 1, 0) **)** |const|
  144. Returns a copy of the transform rotated such that the forward axis (-Z) points towards the ``target`` position.
  145. The up axis (+Y) points as close to the ``up`` vector as possible while staying perpendicular to the forward axis. The resulting transform is orthonormalized. The existing rotation, scale, and skew information from the original transform is discarded. The ``target`` and ``up`` vectors cannot be zero, cannot be parallel to each other, and are defined in global/parent space.
  146. ----
  147. .. _class_Transform3D_method_orthonormalized:
  148. - :ref:`Transform3D<class_Transform3D>` **orthonormalized** **(** **)** |const|
  149. Returns the transform with the basis orthogonal (90 degrees), and normalized axis vectors (scale of 1 or -1).
  150. ----
  151. .. _class_Transform3D_method_rotated:
  152. - :ref:`Transform3D<class_Transform3D>` **rotated** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` phi **)** |const|
  153. Rotates the transform around the given axis by the given angle (in radians), using matrix multiplication. The axis must be a normalized vector.
  154. ----
  155. .. _class_Transform3D_method_scaled:
  156. - :ref:`Transform3D<class_Transform3D>` **scaled** **(** :ref:`Vector3<class_Vector3>` scale **)** |const|
  157. Scales basis and origin of the transform by the given scale factor, using matrix multiplication.
  158. ----
  159. .. _class_Transform3D_method_sphere_interpolate_with:
  160. - :ref:`Transform3D<class_Transform3D>` **sphere_interpolate_with** **(** :ref:`Transform3D<class_Transform3D>` xform, :ref:`float<class_float>` weight **)** |const|
  161. Returns a transform spherically interpolated between this transform and another by a given ``weight`` (on the range of 0.0 to 1.0).
  162. ----
  163. .. _class_Transform3D_method_translated:
  164. - :ref:`Transform3D<class_Transform3D>` **translated** **(** :ref:`Vector3<class_Vector3>` offset **)** |const|
  165. Translates the transform by the given offset, relative to the transform's basis vectors.
  166. Unlike :ref:`rotated<class_Transform3D_method_rotated>` and :ref:`scaled<class_Transform3D_method_scaled>`, this does not use matrix multiplication.
  167. Operator Descriptions
  168. ---------------------
  169. .. _class_Transform3D_operator_neq_bool:
  170. - :ref:`bool<class_bool>` **operator !=** **(** **)**
  171. ----
  172. - :ref:`bool<class_bool>` **operator !=** **(** :ref:`Transform3D<class_Transform3D>` right **)**
  173. Returns ``true`` if the transforms are not equal.
  174. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Transform3D_method_is_equal_approx>` instead, which is more reliable.
  175. ----
  176. .. _class_Transform3D_operator_mul_AABB:
  177. - :ref:`AABB<class_AABB>` **operator *** **(** :ref:`AABB<class_AABB>` right **)**
  178. Transforms (multiplies) the :ref:`AABB<class_AABB>` by the given ``Transform3D`` matrix.
  179. ----
  180. - :ref:`PackedVector3Array<class_PackedVector3Array>` **operator *** **(** :ref:`PackedVector3Array<class_PackedVector3Array>` right **)**
  181. Transforms (multiplies) each element of the :ref:`Vector3<class_Vector3>` array by the given ``Transform3D`` matrix.
  182. ----
  183. - :ref:`Transform3D<class_Transform3D>` **operator *** **(** :ref:`Transform3D<class_Transform3D>` right **)**
  184. Composes these two transformation matrices by multiplying them together. This has the effect of transforming the second transform (the child) by the first transform (the parent).
  185. ----
  186. - :ref:`Vector3<class_Vector3>` **operator *** **(** :ref:`Vector3<class_Vector3>` right **)**
  187. Transforms (multiplies) the :ref:`Vector3<class_Vector3>` by the given ``Transform3D`` matrix.
  188. ----
  189. - :ref:`Transform3D<class_Transform3D>` **operator *** **(** :ref:`float<class_float>` right **)**
  190. This operator multiplies all components of the ``Transform3D``, including the origin vector, which scales it uniformly.
  191. ----
  192. - :ref:`Transform3D<class_Transform3D>` **operator *** **(** :ref:`int<class_int>` right **)**
  193. This operator multiplies all components of the ``Transform3D``, including the origin vector, which scales it uniformly.
  194. ----
  195. .. _class_Transform3D_operator_eq_bool:
  196. - :ref:`bool<class_bool>` **operator ==** **(** **)**
  197. ----
  198. - :ref:`bool<class_bool>` **operator ==** **(** :ref:`Transform3D<class_Transform3D>` right **)**
  199. Returns ``true`` if the transforms are exactly equal.
  200. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Transform3D_method_is_equal_approx>` instead, which is more reliable.
  201. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  202. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  203. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  204. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  205. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  206. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`