123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- :github_url: hide
- .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
- .. DO NOT EDIT THIS FILE, but the Quat.xml source instead.
- .. The source is found in doc/classes or modules/<name>/doc_classes.
- .. _class_Quat:
- Quat
- ====
- Quaternion.
- Description
- -----------
- A unit quaternion used for representing 3D rotations. Quaternions need to be normalized to be used for rotation.
- It is similar to Basis, which implements matrix representation of rotations, and can be parametrized using both an axis-angle pair or Euler angles. Basis stores rotation, scale, and shearing, while Quat only stores rotation.
- Due to its compactness and the way it is stored in memory, certain operations (obtaining axis-angle and performing SLERP, in particular) are more efficient and robust against floating-point errors.
- Tutorials
- ---------
- - `#interpolating-with-quaternions <../tutorials/3d/using_transforms.html#interpolating-with-quaternions>`_ in :doc:`../tutorials/3d/using_transforms`
- - `Third Person Shooter Demo <https://godotengine.org/asset-library/asset/678>`__
- Properties
- ----------
- +---------------------------+---------------------------------+---------+
- | :ref:`float<class_float>` | :ref:`w<class_Quat_property_w>` | ``1.0`` |
- +---------------------------+---------------------------------+---------+
- | :ref:`float<class_float>` | :ref:`x<class_Quat_property_x>` | ``0.0`` |
- +---------------------------+---------------------------------+---------+
- | :ref:`float<class_float>` | :ref:`y<class_Quat_property_y>` | ``0.0`` |
- +---------------------------+---------------------------------+---------+
- | :ref:`float<class_float>` | :ref:`z<class_Quat_property_z>` | ``0.0`` |
- +---------------------------+---------------------------------+---------+
- Methods
- -------
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Quat<class_Quat>` | :ref:`Quat<class_Quat_method_Quat>` **(** :ref:`Basis<class_Basis>` from **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Quat<class_Quat>` | :ref:`Quat<class_Quat_method_Quat>` **(** :ref:`Vector3<class_Vector3>` euler **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Quat<class_Quat>` | :ref:`Quat<class_Quat_method_Quat>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Quat<class_Quat>` | :ref:`Quat<class_Quat_method_Quat>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y, :ref:`float<class_float>` z, :ref:`float<class_float>` w **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`angle_to<class_Quat_method_angle_to>` **(** :ref:`Quat<class_Quat>` to **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Quat<class_Quat>` | :ref:`cubic_slerp<class_Quat_method_cubic_slerp>` **(** :ref:`Quat<class_Quat>` b, :ref:`Quat<class_Quat>` pre_a, :ref:`Quat<class_Quat>` post_b, :ref:`float<class_float>` weight **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`dot<class_Quat_method_dot>` **(** :ref:`Quat<class_Quat>` b **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector3<class_Vector3>` | :ref:`get_euler<class_Quat_method_get_euler>` **(** **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Quat<class_Quat>` | :ref:`inverse<class_Quat_method_inverse>` **(** **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Quat_method_is_equal_approx>` **(** :ref:`Quat<class_Quat>` quat **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`is_normalized<class_Quat_method_is_normalized>` **(** **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`length<class_Quat_method_length>` **(** **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`length_squared<class_Quat_method_length_squared>` **(** **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Quat<class_Quat>` | :ref:`normalized<class_Quat_method_normalized>` **(** **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_axis_angle<class_Quat_method_set_axis_angle>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_euler<class_Quat_method_set_euler>` **(** :ref:`Vector3<class_Vector3>` euler **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Quat<class_Quat>` | :ref:`slerp<class_Quat_method_slerp>` **(** :ref:`Quat<class_Quat>` to, :ref:`float<class_float>` weight **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Quat<class_Quat>` | :ref:`slerpni<class_Quat_method_slerpni>` **(** :ref:`Quat<class_Quat>` to, :ref:`float<class_float>` weight **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector3<class_Vector3>` | :ref:`xform<class_Quat_method_xform>` **(** :ref:`Vector3<class_Vector3>` v **)** |
- +-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- Constants
- ---------
- .. _class_Quat_constant_IDENTITY:
- - **IDENTITY** = **Quat( 0, 0, 0, 1 )** --- The identity quaternion, representing no rotation. Equivalent to an identity :ref:`Basis<class_Basis>` matrix. If a vector is transformed by an identity quaternion, it will not change.
- Property Descriptions
- ---------------------
- .. _class_Quat_property_w:
- - :ref:`float<class_float>` **w**
- +-----------+---------+
- | *Default* | ``1.0`` |
- +-----------+---------+
- W component of the quaternion (real part).
- Quaternion components should usually not be manipulated directly.
- ----
- .. _class_Quat_property_x:
- - :ref:`float<class_float>` **x**
- +-----------+---------+
- | *Default* | ``0.0`` |
- +-----------+---------+
- X component of the quaternion (imaginary ``i`` axis part).
- Quaternion components should usually not be manipulated directly.
- ----
- .. _class_Quat_property_y:
- - :ref:`float<class_float>` **y**
- +-----------+---------+
- | *Default* | ``0.0`` |
- +-----------+---------+
- Y component of the quaternion (imaginary ``j`` axis part).
- Quaternion components should usually not be manipulated directly.
- ----
- .. _class_Quat_property_z:
- - :ref:`float<class_float>` **z**
- +-----------+---------+
- | *Default* | ``0.0`` |
- +-----------+---------+
- Z component of the quaternion (imaginary ``k`` axis part).
- Quaternion components should usually not be manipulated directly.
- Method Descriptions
- -------------------
- .. _class_Quat_method_Quat:
- - :ref:`Quat<class_Quat>` **Quat** **(** :ref:`Basis<class_Basis>` from **)**
- Constructs a quaternion from the given :ref:`Basis<class_Basis>`.
- ----
- - :ref:`Quat<class_Quat>` **Quat** **(** :ref:`Vector3<class_Vector3>` euler **)**
- Constructs a quaternion that will perform a rotation specified by Euler angles (in the YXZ convention: when decomposing, first Z, then X, and Y last), given in the vector format as (X angle, Y angle, Z angle).
- ----
- - :ref:`Quat<class_Quat>` **Quat** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)**
- Constructs a quaternion that will rotate around the given axis by the specified angle. The axis must be a normalized vector.
- ----
- - :ref:`Quat<class_Quat>` **Quat** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y, :ref:`float<class_float>` z, :ref:`float<class_float>` w **)**
- Constructs a quaternion defined by the given values.
- ----
- .. _class_Quat_method_angle_to:
- - :ref:`float<class_float>` **angle_to** **(** :ref:`Quat<class_Quat>` to **)**
- Returns the angle between this quaternion and ``to``. This is the magnitude of the angle you would need to rotate by to get from one to the other.
- **Note:** This method has an abnormally high amount of floating-point error, so methods such as :ref:`@GDScript.is_zero_approx<class_@GDScript_method_is_zero_approx>` will not work reliably.
- ----
- .. _class_Quat_method_cubic_slerp:
- - :ref:`Quat<class_Quat>` **cubic_slerp** **(** :ref:`Quat<class_Quat>` b, :ref:`Quat<class_Quat>` pre_a, :ref:`Quat<class_Quat>` post_b, :ref:`float<class_float>` weight **)**
- Performs a cubic spherical interpolation between quaternions ``pre_a``, this vector, ``b``, and ``post_b``, by the given amount ``weight``.
- ----
- .. _class_Quat_method_dot:
- - :ref:`float<class_float>` **dot** **(** :ref:`Quat<class_Quat>` b **)**
- Returns the dot product of two quaternions.
- ----
- .. _class_Quat_method_get_euler:
- - :ref:`Vector3<class_Vector3>` **get_euler** **(** **)**
- Returns Euler angles (in the YXZ convention: when decomposing, first Z, then X, and Y last) corresponding to the rotation represented by the unit quaternion. Returned vector contains the rotation angles in the format (X angle, Y angle, Z angle).
- ----
- .. _class_Quat_method_inverse:
- - :ref:`Quat<class_Quat>` **inverse** **(** **)**
- Returns the inverse of the quaternion.
- ----
- .. _class_Quat_method_is_equal_approx:
- - :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Quat<class_Quat>` quat **)**
- Returns ``true`` if this quaternion and ``quat`` are approximately equal, by running :ref:`@GDScript.is_equal_approx<class_@GDScript_method_is_equal_approx>` on each component.
- ----
- .. _class_Quat_method_is_normalized:
- - :ref:`bool<class_bool>` **is_normalized** **(** **)**
- Returns whether the quaternion is normalized or not.
- ----
- .. _class_Quat_method_length:
- - :ref:`float<class_float>` **length** **(** **)**
- Returns the length of the quaternion.
- ----
- .. _class_Quat_method_length_squared:
- - :ref:`float<class_float>` **length_squared** **(** **)**
- Returns the length of the quaternion, squared.
- ----
- .. _class_Quat_method_normalized:
- - :ref:`Quat<class_Quat>` **normalized** **(** **)**
- Returns a copy of the quaternion, normalized to unit length.
- ----
- .. _class_Quat_method_set_axis_angle:
- - void **set_axis_angle** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)**
- Sets the quaternion to a rotation which rotates around axis by the specified angle, in radians. The axis must be a normalized vector.
- ----
- .. _class_Quat_method_set_euler:
- - void **set_euler** **(** :ref:`Vector3<class_Vector3>` euler **)**
- Sets the quaternion to a rotation specified by Euler angles (in the YXZ convention: when decomposing, first Z, then X, and Y last), given in the vector format as (X angle, Y angle, Z angle).
- ----
- .. _class_Quat_method_slerp:
- - :ref:`Quat<class_Quat>` **slerp** **(** :ref:`Quat<class_Quat>` to, :ref:`float<class_float>` weight **)**
- Returns the result of the spherical linear interpolation between this quaternion and ``to`` by amount ``weight``.
- **Note:** Both quaternions must be normalized.
- ----
- .. _class_Quat_method_slerpni:
- - :ref:`Quat<class_Quat>` **slerpni** **(** :ref:`Quat<class_Quat>` to, :ref:`float<class_float>` weight **)**
- Returns the result of the spherical linear interpolation between this quaternion and ``to`` by amount ``weight``, but without checking if the rotation path is not bigger than 90 degrees.
- ----
- .. _class_Quat_method_xform:
- - :ref:`Vector3<class_Vector3>` **xform** **(** :ref:`Vector3<class_Vector3>` v **)**
- Returns a vector transformed (multiplied) by this quaternion.
- .. |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.)`
- .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
|