|
@@ -2,8 +2,8 @@
|
|
|
|
|
|
.. DO NOT EDIT THIS FILE!!!
|
|
|
.. Generated automatically from Godot engine sources.
|
|
|
-.. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
|
|
|
-.. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Basis.xml.
|
|
|
+.. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py.
|
|
|
+.. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/Basis.xml.
|
|
|
|
|
|
.. _class_Basis:
|
|
|
|
|
@@ -17,13 +17,17 @@ A 3×3 matrix for representing 3D rotation and scale.
|
|
|
Description
|
|
|
-----------
|
|
|
|
|
|
-A 3×3 matrix used for representing 3D rotation and scale. Usually used as an orthogonal basis for a :ref:`Transform3D<class_Transform3D>`.
|
|
|
+The **Basis** built-in :ref:`Variant<class_Variant>` type is a 3x3 `matrix <https://en.wikipedia.org/wiki/Matrix_(mathematics)>`__ used to represent 3D rotation, scale, and shear. It is frequently used within a :ref:`Transform3D<class_Transform3D>`.
|
|
|
|
|
|
-Contains 3 vector fields X, Y and Z as its columns, which are typically interpreted as the local basis vectors of a transformation. For such use, it is composed of a scaling and a rotation matrix, in that order (M = R.S).
|
|
|
+A **Basis** is composed by 3 axis vectors, each representing a column of the matrix: :ref:`x<class_Basis_property_x>`, :ref:`y<class_Basis_property_y>`, and :ref:`z<class_Basis_property_z>`. The length of each axis (:ref:`Vector3.length<class_Vector3_method_length>`) influences the basis's scale, while the direction of all axes influence the rotation. Usually, these axes are perpendicular to one another. However, when you rotate any axis individually, the basis becomes sheared. Applying a sheared basis to a 3D model will make the model appear distorted.
|
|
|
|
|
|
-Basis can also be accessed as an array of 3D vectors. These vectors are usually orthogonal to each other, but are not necessarily normalized (due to scaling).
|
|
|
+A **Basis** is **orthogonal** if its axes are perpendicular to each other. A basis is **normalized** if the length of every axis is ``1``. A basis is **uniform** if all axes share the same length (see :ref:`get_scale<class_Basis_method_get_scale>`). A basis is **orthonormal** if it is both orthogonal and normalized, which allows it to only represent rotations. A basis is **conformal** if it is both orthogonal and uniform, which ensures it is not distorted.
|
|
|
|
|
|
-For more information, read the "Matrices and transforms" documentation article.
|
|
|
+For a general introduction, see the :doc:`Matrices and transforms <../tutorials/math/matrices_and_transforms>` tutorial.
|
|
|
+
|
|
|
+\ **Note:** Godot uses a `right-handed coordinate system <https://en.wikipedia.org/wiki/Right-hand_rule>`__, which is a common standard. For directions, the convention for built-in types like :ref:`Camera3D<class_Camera3D>` is for -Z to point forward (+X is right, +Y is up, and +Z is back). Other objects may use different direction conventions. For more information, see the `Importing 3D Scenes <../tutorials/assets_pipeline/importing_scenes.html#d-asset-direction-conventions>`__ tutorial.
|
|
|
+
|
|
|
+\ **Note:** The basis matrices are exposed as `column-major <https://www.mindcontrol.org/~hplus/graphics/matrix-layout.html>`__ order, which is the same as OpenGL. However, they are stored internally in row-major order, which is the same as DirectX.
|
|
|
|
|
|
.. note::
|
|
|
|
|
@@ -171,7 +175,26 @@ Constants
|
|
|
|
|
|
**IDENTITY** = ``Basis(1, 0, 0, 0, 1, 0, 0, 0, 1)``
|
|
|
|
|
|
-The identity basis, with no rotation or scaling applied.
|
|
|
+The identity basis. This is a basis with no rotation, no shear, and its scale being ``1``. This means that:
|
|
|
+
|
|
|
+- The :ref:`x<class_Basis_property_x>` points right (:ref:`Vector3.RIGHT<class_Vector3_constant_RIGHT>`);
|
|
|
+
|
|
|
+- The :ref:`y<class_Basis_property_y>` points up (:ref:`Vector3.UP<class_Vector3_constant_UP>`);
|
|
|
+
|
|
|
+- The :ref:`z<class_Basis_property_z>` points back (:ref:`Vector3.BACK<class_Vector3_constant_BACK>`).
|
|
|
+
|
|
|
+::
|
|
|
+
|
|
|
+ var basis := Basis.IDENTITY
|
|
|
+ print("| X | Y | Z")
|
|
|
+ print("| %s | %s | %s" % [basis.x.x, basis.y.x, basis.z.x])
|
|
|
+ print("| %s | %s | %s" % [basis.x.y, basis.y.y, basis.z.y])
|
|
|
+ print("| %s | %s | %s" % [basis.x.z, basis.y.z, basis.z.z])
|
|
|
+ # Prints:
|
|
|
+ # | X | Y | Z
|
|
|
+ # | 1 | 0 | 0
|
|
|
+ # | 0 | 1 | 0
|
|
|
+ # | 0 | 0 | 1
|
|
|
|
|
|
This is identical to creating :ref:`Basis<class_Basis_constructor_Basis>` without any parameters. This constant can be used to make your code clearer, and for consistency with C#.
|
|
|
|
|
@@ -181,7 +204,9 @@ This is identical to creating :ref:`Basis<class_Basis_constructor_Basis>` withou
|
|
|
|
|
|
**FLIP_X** = ``Basis(-1, 0, 0, 0, 1, 0, 0, 0, 1)``
|
|
|
|
|
|
-The basis that will flip something along the X axis when used in a transformation.
|
|
|
+When any basis is multiplied by :ref:`FLIP_X<class_Basis_constant_FLIP_X>`, it negates all components of the :ref:`x<class_Basis_property_x>` axis (the X column).
|
|
|
+
|
|
|
+When :ref:`FLIP_X<class_Basis_constant_FLIP_X>` is multiplied by any basis, it negates the :ref:`Vector3.x<class_Vector3_property_x>` component of all axes (the X row).
|
|
|
|
|
|
.. _class_Basis_constant_FLIP_Y:
|
|
|
|
|
@@ -189,7 +214,9 @@ The basis that will flip something along the X axis when used in a transformatio
|
|
|
|
|
|
**FLIP_Y** = ``Basis(1, 0, 0, 0, -1, 0, 0, 0, 1)``
|
|
|
|
|
|
-The basis that will flip something along the Y axis when used in a transformation.
|
|
|
+When any basis is multiplied by :ref:`FLIP_Y<class_Basis_constant_FLIP_Y>`, it negates all components of the :ref:`y<class_Basis_property_y>` axis (the Y column).
|
|
|
+
|
|
|
+When :ref:`FLIP_Y<class_Basis_constant_FLIP_Y>` is multiplied by any basis, it negates the :ref:`Vector3.y<class_Vector3_property_y>` component of all axes (the Y row).
|
|
|
|
|
|
.. _class_Basis_constant_FLIP_Z:
|
|
|
|
|
@@ -197,7 +224,9 @@ The basis that will flip something along the Y axis when used in a transformatio
|
|
|
|
|
|
**FLIP_Z** = ``Basis(1, 0, 0, 0, 1, 0, 0, 0, -1)``
|
|
|
|
|
|
-The basis that will flip something along the Z axis when used in a transformation.
|
|
|
+When any basis is multiplied by :ref:`FLIP_Z<class_Basis_constant_FLIP_Z>`, it negates all components of the :ref:`z<class_Basis_property_z>` axis (the Z column).
|
|
|
+
|
|
|
+When :ref:`FLIP_Z<class_Basis_constant_FLIP_Z>` is multiplied by any basis, it negates the :ref:`Vector3.z<class_Vector3_property_z>` component of all axes (the Z row).
|
|
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
|
@@ -214,7 +243,9 @@ Property Descriptions
|
|
|
|
|
|
:ref:`Vector3<class_Vector3>` **x** = ``Vector3(1, 0, 0)``
|
|
|
|
|
|
-The basis matrix's X vector (column 0). Equivalent to array index ``0``.
|
|
|
+The basis's X axis, and the column ``0`` of the matrix.
|
|
|
+
|
|
|
+On the identity basis, this vector points right (:ref:`Vector3.RIGHT<class_Vector3_constant_RIGHT>`).
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -226,7 +257,9 @@ The basis matrix's X vector (column 0). Equivalent to array index ``0``.
|
|
|
|
|
|
:ref:`Vector3<class_Vector3>` **y** = ``Vector3(0, 1, 0)``
|
|
|
|
|
|
-The basis matrix's Y vector (column 1). Equivalent to array index ``1``.
|
|
|
+The basis's Y axis, and the column ``1`` of the matrix.
|
|
|
+
|
|
|
+On the identity basis, this vector points up (:ref:`Vector3.UP<class_Vector3_constant_UP>`).
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -238,7 +271,9 @@ The basis matrix's Y vector (column 1). Equivalent to array index ``1``.
|
|
|
|
|
|
:ref:`Vector3<class_Vector3>` **z** = ``Vector3(0, 0, 1)``
|
|
|
|
|
|
-The basis matrix's Z vector (column 2). Equivalent to array index ``2``.
|
|
|
+The basis's Z axis, and the column ``2`` of the matrix.
|
|
|
+
|
|
|
+On the identity basis, this vector points back (:ref:`Vector3.BACK<class_Vector3_constant_BACK>`).
|
|
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
|
@@ -255,7 +290,7 @@ Constructor Descriptions
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **Basis** **(** **)**
|
|
|
|
|
|
-Constructs a default-initialized **Basis** set to :ref:`IDENTITY<class_Basis_constant_IDENTITY>`.
|
|
|
+Constructs a **Basis** identical to the :ref:`IDENTITY<class_Basis_constant_IDENTITY>`.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -275,7 +310,9 @@ Constructs a **Basis** as a copy of the given **Basis**.
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **Basis** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)**
|
|
|
|
|
|
-Constructs a pure rotation basis matrix, rotated around the given ``axis`` by ``angle`` (in radians). The axis must be a normalized vector.
|
|
|
+Constructs a **Basis** that only represents rotation, rotated around the ``axis`` by the given ``angle``, in radians. The axis must be a normalized vector.
|
|
|
+
|
|
|
+\ **Note:** This is the same as using :ref:`rotated<class_Basis_method_rotated>` on the :ref:`IDENTITY<class_Basis_constant_IDENTITY>` basis. With more than one angle consider using :ref:`from_euler<class_Basis_method_from_euler>`, instead.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -285,7 +322,9 @@ Constructs a pure rotation basis matrix, rotated around the given ``axis`` by ``
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **Basis** **(** :ref:`Quaternion<class_Quaternion>` from **)**
|
|
|
|
|
|
-Constructs a pure rotation basis matrix from the given quaternion.
|
|
|
+Constructs a **Basis** that only represents rotation from the given :ref:`Quaternion<class_Quaternion>`.
|
|
|
+
|
|
|
+\ **Note:** Quaternions *only* store rotation, not scale. Because of this, conversions from **Basis** to :ref:`Quaternion<class_Quaternion>` cannot always be reversed.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -295,7 +334,7 @@ Constructs a pure rotation basis matrix from the given quaternion.
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **Basis** **(** :ref:`Vector3<class_Vector3>` x_axis, :ref:`Vector3<class_Vector3>` y_axis, :ref:`Vector3<class_Vector3>` z_axis **)**
|
|
|
|
|
|
-Constructs a basis matrix from 3 axis vectors (matrix columns).
|
|
|
+Constructs a **Basis** from 3 axis vectors. These are the columns of the basis matrix.
|
|
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
|
@@ -312,9 +351,13 @@ Method Descriptions
|
|
|
|
|
|
:ref:`float<class_float>` **determinant** **(** **)** |const|
|
|
|
|
|
|
-Returns the determinant of the basis matrix. If the basis is uniformly scaled, its determinant is the square of the scale.
|
|
|
+Returns the `determinant <https://en.wikipedia.org/wiki/Determinant>`__ of this basis's matrix. For advanced math, this number can be used to determine a few attributes:
|
|
|
+
|
|
|
+- If the determinant is exactly ``0``, the basis is not invertible (see :ref:`inverse<class_Basis_method_inverse>`).
|
|
|
+
|
|
|
+- If the determinant is a negative number, the basis represents a negative scale.
|
|
|
|
|
|
-A negative determinant means the basis has a negative scale. A zero determinant means the basis isn't invertible, and is usually considered invalid.
|
|
|
+\ **Note:** If the basis's scale is the same for every axis, its determinant is always that scale by the power of 2.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -326,7 +369,34 @@ A negative determinant means the basis has a negative scale. A zero determinant
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **from_euler** **(** :ref:`Vector3<class_Vector3>` euler, :ref:`int<class_int>` order=2 **)** |static|
|
|
|
|
|
|
-Constructs a pure rotation Basis matrix from Euler angles in the specified Euler rotation order. By default, use YXZ order (most common). See the :ref:`EulerOrder<enum_@GlobalScope_EulerOrder>` enum for possible values.
|
|
|
+Constructs a new **Basis** that only represents rotation from the given :ref:`Vector3<class_Vector3>` of `Euler angles <https://en.wikipedia.org/wiki/Euler_angles>`__, in radians.
|
|
|
+
|
|
|
+- The :ref:`Vector3.x<class_Vector3_property_x>` should contain the angle around the :ref:`x<class_Basis_property_x>` axis (pitch).
|
|
|
+
|
|
|
+- The :ref:`Vector3.y<class_Vector3_property_y>` should contain the angle around the :ref:`y<class_Basis_property_y>` axis (yaw).
|
|
|
+
|
|
|
+- The :ref:`Vector3.z<class_Vector3_property_z>` should contain the angle around the :ref:`z<class_Basis_property_z>` axis (roll).
|
|
|
+
|
|
|
+
|
|
|
+.. tabs::
|
|
|
+
|
|
|
+ .. code-tab:: gdscript
|
|
|
+
|
|
|
+ # Creates a Basis whose z axis points down.
|
|
|
+ var my_basis = Basis.from_euler(Vector3(TAU / 4, 0, 0))
|
|
|
+
|
|
|
+ print(my_basis.z) # Prints (0, -1, 0).
|
|
|
+
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ // Creates a Basis whose z axis points down.
|
|
|
+ var myBasis = Basis.FromEuler(new Vector3(Mathf.Tau / 4.0f, 0.0f, 0.0f));
|
|
|
+
|
|
|
+ GD.Print(myBasis.Z); // Prints (0, -1, 0).
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+The order of each consecutive rotation can be changed with ``order`` (see :ref:`EulerOrder<enum_@GlobalScope_EulerOrder>` constants). By default, the YXZ convention is used (:ref:`@GlobalScope.EULER_ORDER_YXZ<class_@GlobalScope_constant_EULER_ORDER_YXZ>`): the basis rotates first around the Y axis (yaw), then X (pitch), and lastly Z (roll). When using the opposite method :ref:`get_euler<class_Basis_method_get_euler>`, this order is reversed.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -338,7 +408,30 @@ Constructs a pure rotation Basis matrix from Euler angles in the specified Euler
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **from_scale** **(** :ref:`Vector3<class_Vector3>` scale **)** |static|
|
|
|
|
|
|
-Constructs a pure scale basis matrix with no rotation or shearing. The scale values are set as the diagonal of the matrix, and the other parts of the matrix are zero.
|
|
|
+Constructs a new **Basis** that only represents scale, with no rotation or shear, from the given ``scale`` vector.
|
|
|
+
|
|
|
+
|
|
|
+.. tabs::
|
|
|
+
|
|
|
+ .. code-tab:: gdscript
|
|
|
+
|
|
|
+ var my_basis = Basis.from_scale(Vector3(2, 4, 8))
|
|
|
+
|
|
|
+ print(my_basis.x) # Prints (2, 0, 0).
|
|
|
+ print(my_basis.y) # Prints (0, 4, 0).
|
|
|
+ print(my_basis.z) # Prints (0, 0, 8).
|
|
|
+
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ var myBasis = Basis.FromScale(new Vector3(2.0f, 4.0f, 8.0f));
|
|
|
+
|
|
|
+ GD.Print(myBasis.X); // Prints (2, 0, 0).
|
|
|
+ GD.Print(myBasis.Y); // Prints (0, 4, 0).
|
|
|
+ GD.Print(myBasis.Z); // Prints (0, 0, 8).
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+\ **Note:** In linear algebra, the matrix of this basis is also known as a `diagonal matrix <https://en.wikipedia.org/wiki/Diagonal_matrix>`__.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -350,9 +443,19 @@ Constructs a pure scale basis matrix with no rotation or shearing. The scale val
|
|
|
|
|
|
:ref:`Vector3<class_Vector3>` **get_euler** **(** :ref:`int<class_int>` order=2 **)** |const|
|
|
|
|
|
|
-Returns the basis's rotation in the form of Euler angles. The Euler order depends on the ``order`` parameter, by default it uses the YXZ convention: when decomposing, first Z, then X, and Y last. The returned vector contains the rotation angles in the format (X angle, Y angle, Z angle).
|
|
|
+Returns this basis's rotation as a :ref:`Vector3<class_Vector3>` of `Euler angles <https://en.wikipedia.org/wiki/Euler_angles>`__, in radians.
|
|
|
+
|
|
|
+- The :ref:`Vector3.x<class_Vector3_property_x>` contains the angle around the :ref:`x<class_Basis_property_x>` axis (pitch);
|
|
|
|
|
|
-Consider using the :ref:`get_rotation_quaternion<class_Basis_method_get_rotation_quaternion>` method instead, which returns a :ref:`Quaternion<class_Quaternion>` quaternion instead of Euler angles.
|
|
|
+- The :ref:`Vector3.y<class_Vector3_property_y>` contains the angle around the :ref:`y<class_Basis_property_y>` axis (yaw);
|
|
|
+
|
|
|
+- The :ref:`Vector3.z<class_Vector3_property_z>` contains the angle around the :ref:`z<class_Basis_property_z>` axis (roll).
|
|
|
+
|
|
|
+The order of each consecutive rotation can be changed with ``order`` (see :ref:`EulerOrder<enum_@GlobalScope_EulerOrder>` constants). By default, the YXZ convention is used (:ref:`@GlobalScope.EULER_ORDER_YXZ<class_@GlobalScope_constant_EULER_ORDER_YXZ>`): Z (roll) is calculated first, then X (pitch), and lastly Y (yaw). When using the opposite method :ref:`from_euler<class_Basis_method_from_euler>`, this order is reversed.
|
|
|
+
|
|
|
+\ **Note:** Euler angles are much more intuitive but are not suitable for 3D math. Because of this, consider using the :ref:`get_rotation_quaternion<class_Basis_method_get_rotation_quaternion>` method instead, which returns a :ref:`Quaternion<class_Quaternion>`.
|
|
|
+
|
|
|
+\ **Note:** In the Inspector dock, a basis's rotation is often displayed in Euler angles (in degrees), as is the case with the :ref:`Node3D.rotation<class_Node3D_property_rotation>` property.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -364,7 +467,9 @@ Consider using the :ref:`get_rotation_quaternion<class_Basis_method_get_rotation
|
|
|
|
|
|
:ref:`Quaternion<class_Quaternion>` **get_rotation_quaternion** **(** **)** |const|
|
|
|
|
|
|
-Returns the basis's rotation in the form of a quaternion. See :ref:`get_euler<class_Basis_method_get_euler>` if you need Euler angles, but keep in mind quaternions should generally be preferred to Euler angles.
|
|
|
+Returns this basis's rotation as a :ref:`Quaternion<class_Quaternion>`.
|
|
|
+
|
|
|
+\ **Note:** Quatenions are much more suitable for 3D math but are less intuitive. For user interfaces, consider using the :ref:`get_euler<class_Basis_method_get_euler>` method, which returns Euler angles.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -376,7 +481,40 @@ Returns the basis's rotation in the form of a quaternion. See :ref:`get_euler<cl
|
|
|
|
|
|
:ref:`Vector3<class_Vector3>` **get_scale** **(** **)** |const|
|
|
|
|
|
|
-Assuming that the matrix is the combination of a rotation and scaling, return the absolute value of scaling factors along each axis.
|
|
|
+Returns the length of each axis of this basis, as a :ref:`Vector3<class_Vector3>`. If the basis is not sheared, this is the scaling factor. It is not affected by rotation.
|
|
|
+
|
|
|
+
|
|
|
+.. tabs::
|
|
|
+
|
|
|
+ .. code-tab:: gdscript
|
|
|
+
|
|
|
+ var my_basis = Basis(
|
|
|
+ Vector3(2, 0, 0),
|
|
|
+ Vector3(0, 4, 0),
|
|
|
+ Vector3(0, 0, 8)
|
|
|
+ )
|
|
|
+ # Rotating the Basis in any way preserves its scale.
|
|
|
+ my_basis = my_basis.rotated(Vector3.UP, TAU / 2)
|
|
|
+ my_basis = my_basis.rotated(Vector3.RIGHT, TAU / 4)
|
|
|
+
|
|
|
+ print(my_basis.get_scale()) # Prints (2, 4, 8).
|
|
|
+
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ var myBasis = new Basis(
|
|
|
+ Vector3(2.0f, 0.0f, 0.0f),
|
|
|
+ Vector3(0.0f, 4.0f, 0.0f),
|
|
|
+ Vector3(0.0f, 0.0f, 8.0f)
|
|
|
+ );
|
|
|
+ // Rotating the Basis in any way preserves its scale.
|
|
|
+ myBasis = myBasis.Rotated(Vector3.Up, Mathf.Tau / 2.0f);
|
|
|
+ myBasis = myBasis.Rotated(Vector3.Right, Mathf.Tau / 4.0f);
|
|
|
+
|
|
|
+ GD.Print(myBasis.Scale); // Prints (2, 4, 8).
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+\ **Note:** If the value returned by :ref:`determinant<class_Basis_method_determinant>` is negative, the scale is also negative.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -388,7 +526,7 @@ Assuming that the matrix is the combination of a rotation and scaling, return th
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **inverse** **(** **)** |const|
|
|
|
|
|
|
-Returns the inverse of the matrix.
|
|
|
+Returns the `inverse of this basis's matrix <https://en.wikipedia.org/wiki/Invertible_matrix>`__.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -400,7 +538,7 @@ Returns the inverse of the matrix.
|
|
|
|
|
|
:ref:`bool<class_bool>` **is_conformal** **(** **)** |const|
|
|
|
|
|
|
-Returns ``true`` if the basis is conformal, meaning it preserves angles and distance ratios, and may only be composed of rotation and uniform scale. Returns ``false`` if the basis has non-uniform scale or shear/skew. This can be used to validate if the basis is non-distorted, which is important for physics and other use cases.
|
|
|
+Returns ``true`` if this basis is conformal. A conformal basis is both *orthogonal* (the axes are perpendicular to each other) and *uniform* (the axes share the same length). This method can be especially useful during physics calculations.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -436,11 +574,11 @@ Returns ``true`` if this basis is finite, by calling :ref:`@GlobalScope.is_finit
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **looking_at** **(** :ref:`Vector3<class_Vector3>` target, :ref:`Vector3<class_Vector3>` up=Vector3(0, 1, 0), :ref:`bool<class_bool>` use_model_front=false **)** |static|
|
|
|
|
|
|
-Creates a Basis with a rotation such that the forward axis (-Z) points towards the ``target`` position.
|
|
|
+Creates a new **Basis** with a rotation such that the forward axis (-Z) points towards the ``target`` position.
|
|
|
|
|
|
-The up axis (+Y) points as close to the ``up`` vector as possible while staying perpendicular to the forward axis. The resulting Basis is orthonormalized. The ``target`` and ``up`` vectors cannot be zero, and cannot be parallel to each other.
|
|
|
+By default, the -Z axis (camera forward) is treated as forward (implies +X is right). If ``use_model_front`` is ``true``, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the ``target`` position.
|
|
|
|
|
|
-If ``use_model_front`` is ``true``, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the ``target`` position. By default, the -Z axis (camera forward) is treated as forward (implies +X is right).
|
|
|
+The up axis (+Y) points as close to the ``up`` vector as possible while staying perpendicular to the forward axis. The returned basis is orthonormalized (see :ref:`orthonormalized<class_Basis_method_orthonormalized>`). The ``target`` and ``up`` vectors cannot be :ref:`Vector3.ZERO<class_Vector3_constant_ZERO>`, and cannot be parallel to each other.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -452,7 +590,33 @@ If ``use_model_front`` is ``true``, the +Z axis (asset front) is treated as forw
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **orthonormalized** **(** **)** |const|
|
|
|
|
|
|
-Returns the orthonormalized version of the matrix (useful to call from time to time to avoid rounding error for orthogonal matrices). This performs a Gram-Schmidt orthonormalization on the basis of the matrix.
|
|
|
+Returns the orthonormalized version of this basis. An orthonormal basis is both *orthogonal* (the axes are perpendicular to each other) and *normalized* (the axes have a length of ``1``), which also means it can only represent rotation.
|
|
|
+
|
|
|
+It is often useful to call this method to avoid rounding errors on a rotating basis:
|
|
|
+
|
|
|
+
|
|
|
+.. tabs::
|
|
|
+
|
|
|
+ .. code-tab:: gdscript
|
|
|
+
|
|
|
+ # Rotate this Node3D every frame.
|
|
|
+ func _process(delta):
|
|
|
+ basis = basis.rotated(Vector3.UP, TAU * delta)
|
|
|
+ basis = basis.rotated(Vector3.RIGHT, TAU * delta)
|
|
|
+
|
|
|
+ basis = basis.orthonormalized()
|
|
|
+
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ // Rotate this Node3D every frame.
|
|
|
+ public override void _Process(double delta)
|
|
|
+ {
|
|
|
+ Basis = Basis.Rotated(Vector3.Up, Mathf.Tau * (float)delta)
|
|
|
+ .Rotated(Vector3.Right, Mathf.Tau * (float)delta)
|
|
|
+ .Orthonormalized();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -464,7 +628,32 @@ Returns the orthonormalized version of the matrix (useful to call from time to t
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **rotated** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |const|
|
|
|
|
|
|
-Introduce an additional rotation around the given axis by ``angle`` (in radians). The axis must be a normalized vector.
|
|
|
+Returns this basis rotated around the given ``axis`` by ``angle`` (in radians). The ``axis`` must be a normalized vector (see :ref:`Vector3.normalized<class_Vector3_method_normalized>`).
|
|
|
+
|
|
|
+Positive values rotate this basis clockwise around the axis, while negative values rotate it counterclockwise.
|
|
|
+
|
|
|
+
|
|
|
+.. tabs::
|
|
|
+
|
|
|
+ .. code-tab:: gdscript
|
|
|
+
|
|
|
+ var my_basis = Basis.IDENTITY
|
|
|
+ var angle = TAU / 2
|
|
|
+
|
|
|
+ my_basis = my_basis.rotated(Vector3.UP, angle) # Rotate around the up axis (yaw).
|
|
|
+ my_basis = my_basis.rotated(Vector3.RIGHT, angle) # Rotate around the right axis (pitch).
|
|
|
+ my_basis = my_basis.rotated(Vector3.BACK, angle) # Rotate around the back axis (roll).
|
|
|
+
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ var myBasis = Basis.Identity;
|
|
|
+ var angle = Mathf.Tau / 2.0f;
|
|
|
+
|
|
|
+ myBasis = myBasis.Rotated(Vector3.Up, angle); // Rotate around the up axis (yaw).
|
|
|
+ myBasis = myBasis.Rotated(Vector3.Right, angle); // Rotate around the right axis (pitch).
|
|
|
+ myBasis = myBasis.Rotated(Vector3.Back, angle); // Rotate around the back axis (roll).
|
|
|
+
|
|
|
+
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -476,7 +665,40 @@ Introduce an additional rotation around the given axis by ``angle`` (in radians)
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **scaled** **(** :ref:`Vector3<class_Vector3>` scale **)** |const|
|
|
|
|
|
|
-Introduce an additional scaling specified by the given 3D scaling factor.
|
|
|
+Returns this basis with each axis's components scaled by the given ``scale``'s components.
|
|
|
+
|
|
|
+The basis matrix's rows are multiplied by ``scale``'s components. This operation is a global scale (relative to the parent).
|
|
|
+
|
|
|
+
|
|
|
+.. tabs::
|
|
|
+
|
|
|
+ .. code-tab:: gdscript
|
|
|
+
|
|
|
+ var my_basis = Basis(
|
|
|
+ Vector3(1, 1, 1),
|
|
|
+ Vector3(2, 2, 2),
|
|
|
+ Vector3(3, 3, 3)
|
|
|
+ )
|
|
|
+ my_basis = my_basis.scaled(Vector3(0, 2, -2))
|
|
|
+
|
|
|
+ print(my_basis.x) # Prints (0, 2, -2).
|
|
|
+ print(my_basis.y) # Prints (0, 4, -4).
|
|
|
+ print(my_basis.z) # Prints (0, 6, -6).
|
|
|
+
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ var myBasis = new Basis(
|
|
|
+ new Vector3(1.0f, 1.0f, 1.0f),
|
|
|
+ new Vector3(2.0f, 2.0f, 2.0f),
|
|
|
+ new Vector3(3.0f, 3.0f, 3.0f)
|
|
|
+ );
|
|
|
+ myBasis = myBasis.Scaled(new Vector3(0.0f, 2.0f, -2.0f));
|
|
|
+
|
|
|
+ GD.Print(myBasis.X); // Prints (0, 2, -2).
|
|
|
+ GD.Print(myBasis.Y); // Prints (0, 4, -4).
|
|
|
+ GD.Print(myBasis.Z); // Prints (0, 6, -6).
|
|
|
+
|
|
|
+
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -488,7 +710,20 @@ Introduce an additional scaling specified by the given 3D scaling factor.
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **slerp** **(** :ref:`Basis<class_Basis>` to, :ref:`float<class_float>` weight **)** |const|
|
|
|
|
|
|
-Assuming that the matrix is a proper rotation matrix, slerp performs a spherical-linear interpolation with another rotation matrix.
|
|
|
+Performs a spherical-linear interpolation with the ``to`` basis, given a ``weight``. Both this basis and ``to`` should represent a rotation.
|
|
|
+
|
|
|
+\ **Example:** Smoothly rotate a :ref:`Node3D<class_Node3D>` to the target basis over time, with a :ref:`Tween<class_Tween>`.
|
|
|
+
|
|
|
+::
|
|
|
+
|
|
|
+ var start_basis = Basis.IDENTITY
|
|
|
+ var target_basis = Basis.IDENTITY.rotated(Vector3.UP, TAU / 2)
|
|
|
+
|
|
|
+ func _ready():
|
|
|
+ create_tween().tween_method(interpolate, 0.0, 1.0, 5.0).set_trans(Tween.TRANS_EXPO)
|
|
|
+
|
|
|
+ func interpolate(weight):
|
|
|
+ basis = start_basis.slerp(target_basis, weight)
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -500,7 +735,9 @@ Assuming that the matrix is a proper rotation matrix, slerp performs a spherical
|
|
|
|
|
|
:ref:`float<class_float>` **tdotx** **(** :ref:`Vector3<class_Vector3>` with **)** |const|
|
|
|
|
|
|
-Transposed dot product with the X axis of the matrix.
|
|
|
+Returns the transposed dot product between ``with`` and the :ref:`x<class_Basis_property_x>` axis (see :ref:`transposed<class_Basis_method_transposed>`).
|
|
|
+
|
|
|
+This is equivalent to ``basis.x.dot(vector)``.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -512,7 +749,9 @@ Transposed dot product with the X axis of the matrix.
|
|
|
|
|
|
:ref:`float<class_float>` **tdoty** **(** :ref:`Vector3<class_Vector3>` with **)** |const|
|
|
|
|
|
|
-Transposed dot product with the Y axis of the matrix.
|
|
|
+Returns the transposed dot product between ``with`` and the :ref:`y<class_Basis_property_y>` axis (see :ref:`transposed<class_Basis_method_transposed>`).
|
|
|
+
|
|
|
+This is equivalent to ``basis.y.dot(vector)``.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -524,7 +763,9 @@ Transposed dot product with the Y axis of the matrix.
|
|
|
|
|
|
:ref:`float<class_float>` **tdotz** **(** :ref:`Vector3<class_Vector3>` with **)** |const|
|
|
|
|
|
|
-Transposed dot product with the Z axis of the matrix.
|
|
|
+Returns the transposed dot product between ``with`` and the :ref:`z<class_Basis_property_z>` axis (see :ref:`transposed<class_Basis_method_transposed>`).
|
|
|
+
|
|
|
+This is equivalent to ``basis.z.dot(vector)``.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -536,7 +777,38 @@ Transposed dot product with the Z axis of the matrix.
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **transposed** **(** **)** |const|
|
|
|
|
|
|
-Returns the transposed version of the matrix.
|
|
|
+Returns the transposed version of this basis. This turns the basis matrix's columns into rows, and its rows into columns.
|
|
|
+
|
|
|
+
|
|
|
+.. tabs::
|
|
|
+
|
|
|
+ .. code-tab:: gdscript
|
|
|
+
|
|
|
+ var my_basis = Basis(
|
|
|
+ Vector3(1, 2, 3),
|
|
|
+ Vector3(4, 5, 6),
|
|
|
+ Vector3(7, 8, 9)
|
|
|
+ )
|
|
|
+ my_basis = my_basis.transposed()
|
|
|
+
|
|
|
+ print(my_basis.x) # Prints (1, 4, 7).
|
|
|
+ print(my_basis.y) # Prints (2, 5, 8).
|
|
|
+ print(my_basis.z) # Prints (3, 6, 9).
|
|
|
+
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ var myBasis = new Basis(
|
|
|
+ new Vector3(1.0f, 2.0f, 3.0f),
|
|
|
+ new Vector3(4.0f, 5.0f, 6.0f),
|
|
|
+ new Vector3(7.0f, 8.0f, 9.0f)
|
|
|
+ );
|
|
|
+ myBasis = myBasis.Transposed();
|
|
|
+
|
|
|
+ GD.Print(myBasis.X); // Prints (1, 4, 7).
|
|
|
+ GD.Print(myBasis.Y); // Prints (2, 5, 8).
|
|
|
+ GD.Print(myBasis.Z); // Prints (3, 6, 9).
|
|
|
+
|
|
|
+
|
|
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
|
@@ -553,7 +825,7 @@ Operator Descriptions
|
|
|
|
|
|
:ref:`bool<class_bool>` **operator !=** **(** :ref:`Basis<class_Basis>` right **)**
|
|
|
|
|
|
-Returns ``true`` if the **Basis** matrices are not equal.
|
|
|
+Returns ``true`` if the components of both **Basis** matrices are not equal.
|
|
|
|
|
|
\ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Basis_method_is_equal_approx>` instead, which is more reliable.
|
|
|
|
|
@@ -567,7 +839,9 @@ Returns ``true`` if the **Basis** matrices are not equal.
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **operator *** **(** :ref:`Basis<class_Basis>` right **)**
|
|
|
|
|
|
-Composes these two basis matrices by multiplying them together. This has the effect of transforming the second basis (the child) by the first basis (the parent).
|
|
|
+Transforms (multiplies) the ``right`` basis by this basis.
|
|
|
+
|
|
|
+This is the operation performed between parent and child :ref:`Node3D<class_Node3D>`\ s.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -579,7 +853,22 @@ Composes these two basis matrices by multiplying them together. This has the eff
|
|
|
|
|
|
:ref:`Vector3<class_Vector3>` **operator *** **(** :ref:`Vector3<class_Vector3>` right **)**
|
|
|
|
|
|
-Transforms (multiplies) the :ref:`Vector3<class_Vector3>` by the given **Basis** matrix.
|
|
|
+Transforms (multiplies) the ``right`` vector by this basis, returning a :ref:`Vector3<class_Vector3>`.
|
|
|
+
|
|
|
+
|
|
|
+.. tabs::
|
|
|
+
|
|
|
+ .. code-tab:: gdscript
|
|
|
+
|
|
|
+ var my_basis = Basis(Vector3(1, 1, 1), Vector3(1, 1, 1), Vector3(0, 2, 5))
|
|
|
+ print(my_basis * Vector3(1, 2, 3)) # Prints (7, 3, 16)
|
|
|
+
|
|
|
+ .. code-tab:: csharp
|
|
|
+
|
|
|
+ var myBasis = new Basis(new Vector3(1, 1, 1), new Vector3(1, 1, 1), new Vector3(0, 2, 5));
|
|
|
+ GD.Print(my_basis * new Vector3(1, 2, 3)); // Prints (7, 3, 16)
|
|
|
+
|
|
|
+
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -591,7 +880,7 @@ Transforms (multiplies) the :ref:`Vector3<class_Vector3>` by the given **Basis**
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **operator *** **(** :ref:`float<class_float>` right **)**
|
|
|
|
|
|
-This operator multiplies all components of the **Basis**, which scales it uniformly.
|
|
|
+Multiplies all components of the **Basis** by the given :ref:`float<class_float>`. This affects the basis's scale uniformly, resizing all 3 axes by the ``right`` value.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -603,7 +892,7 @@ This operator multiplies all components of the **Basis**, which scales it unifor
|
|
|
|
|
|
:ref:`Basis<class_Basis>` **operator *** **(** :ref:`int<class_int>` right **)**
|
|
|
|
|
|
-This operator multiplies all components of the **Basis**, which scales it uniformly.
|
|
|
+Multiplies all components of the **Basis** by the given :ref:`int<class_int>`. This affects the basis's scale uniformly, resizing all 3 axes by the ``right`` value.
|
|
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
|
@@ -615,7 +904,7 @@ This operator multiplies all components of the **Basis**, which scales it unifor
|
|
|
|
|
|
:ref:`bool<class_bool>` **operator ==** **(** :ref:`Basis<class_Basis>` right **)**
|
|
|
|
|
|
-Returns ``true`` if the **Basis** matrices are exactly equal.
|
|
|
+Returns ``true`` if the components of both **Basis** matrices are exactly equal.
|
|
|
|
|
|
\ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Basis_method_is_equal_approx>` instead, which is more reliable.
|
|
|
|
|
@@ -629,7 +918,9 @@ Returns ``true`` if the **Basis** matrices are exactly equal.
|
|
|
|
|
|
:ref:`Vector3<class_Vector3>` **operator []** **(** :ref:`int<class_int>` index **)**
|
|
|
|
|
|
-Access basis components using their index. ``b[0]`` is equivalent to ``b.x``, ``b[1]`` is equivalent to ``b.y``, and ``b[2]`` is equivalent to ``b.z``.
|
|
|
+Accesses each axis (column) of this basis by their index. Index ``0`` is the same as :ref:`x<class_Basis_property_x>`, index ``1`` is the same as :ref:`y<class_Basis_property_y>`, and index ``2`` is the same as :ref:`z<class_Basis_property_z>`.
|
|
|
+
|
|
|
+\ **Note:** In C++, this operator accesses the rows of the basis matrix, *not* the columns. For the same behavior as scripting languages, use the ``set_column`` and ``get_column`` methods.
|
|
|
|
|
|
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
|
|
|
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
|