2017-09-12 20:42:36 +00:00
<?xml version="1.0" encoding="UTF-8" ?>
2023-03-01 00:44:37 +00:00
<class name= "Quaternion" version= "4.1" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "../class.xsd" >
2017-09-12 20:42:36 +00:00
<brief_description >
2023-04-15 14:01:19 +00:00
A unit quaternion used for representing 3D rotations.
2017-09-12 20:42:36 +00:00
</brief_description>
<description >
2024-01-14 17:50:06 +00:00
The [Quaternion] built-in [Variant] type is a 4D data structure that represents rotation in the form of a [url=https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation]Hamilton convention quaternion[/url]. Compared to the [Basis] type which can store both rotation and scale, quaternions can [i]only[/i] store rotation.
A [Quaternion] is composed by 4 floating-point components: [member w], [member x], [member y], and [member z]. These components are very compact in memory, and because of this some operations are more efficient and less likely to cause floating-point errors. Methods such as [method get_angle], [method get_axis], and [method slerp] are faster than their [Basis] counterparts.
For a great introduction to quaternions, see [url=https://www.youtube.com/watch?v=d4EgbgTm0Bg]this video by 3Blue1Brown[/url]. You do not need to know the math behind quaternions, as Godot provides several helper methods that handle it for you. These include [method slerp] and [method spherical_cubic_interpolate], as well as the [code]*[/code] operator.
[b]Note:[/b] Quaternions must be normalized before being used for rotation (see [method normalized]).
[b]Note:[/b] Similarly to [Vector2] and [Vector3], the components of a quaternion use 32-bit precision by default, unlike [float] which is always 64-bit. If double precision is needed, compile the engine with the option [code]precision=double[/code].
2017-09-12 20:42:36 +00:00
</description>
<tutorials >
2024-01-14 17:50:06 +00:00
<link title= "3Blue1Brown's video on Quaternions" > https://www.youtube.com/watch?v=d4EgbgTm0Bg</link>
<link title= "Online Quaternion Visualization" > https://quaternions.online/</link>
2021-11-15 09:43:07 +00:00
<link title= "Using 3D transforms" > $DOCS_URL/tutorials/3d/using_transforms.html#interpolating-with-quaternions</link>
2020-10-01 08:34:47 +00:00
<link title= "Third Person Shooter Demo" > https://godotengine.org/asset-library/asset/678</link>
2024-01-14 17:50:06 +00:00
<link title= "Advanced Quaternion Visualization" > https://iwatake2222.github.io/rotation_master/rotation_master.html</link>
2017-09-12 20:42:36 +00:00
</tutorials>
2021-09-21 02:49:02 +00:00
<constructors >
<constructor name= "Quaternion" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2020-11-09 16:46:03 +00:00
<description >
2024-01-14 17:50:06 +00:00
Constructs a [Quaternion] identical to the [constant IDENTITY].
2020-11-09 16:46:03 +00:00
</description>
2021-09-21 02:49:02 +00:00
</constructor>
<constructor name= "Quaternion" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "from" type= "Quaternion" />
2020-11-09 16:46:03 +00:00
<description >
2021-01-20 07:02:02 +00:00
Constructs a [Quaternion] as a copy of the given [Quaternion].
2020-11-09 16:46:03 +00:00
</description>
2021-09-21 02:49:02 +00:00
</constructor>
<constructor name= "Quaternion" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "arc_from" type= "Vector3" />
<param index= "1" name= "arc_to" type= "Vector3" />
2017-09-12 20:42:36 +00:00
<description >
2024-01-14 17:50:06 +00:00
Constructs a [Quaternion] representing the shortest arc between [param arc_from] and [param arc_to]. These can be imagined as two points intersecting a sphere's surface, with a radius of [code]1.0[/code].
2017-09-12 20:42:36 +00:00
</description>
2021-09-21 02:49:02 +00:00
</constructor>
<constructor name= "Quaternion" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "axis" type= "Vector3" />
<param index= "1" name= "angle" type= "float" />
2017-09-12 20:42:36 +00:00
<description >
2024-01-14 17:50:06 +00:00
Constructs a [Quaternion] representing rotation around the [param axis] by the given [param angle], in radians. The axis must be a normalized vector.
2017-09-12 20:42:36 +00:00
</description>
2021-09-21 02:49:02 +00:00
</constructor>
<constructor name= "Quaternion" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "from" type= "Basis" />
2017-09-12 20:42:36 +00:00
<description >
2024-01-14 17:50:06 +00:00
Constructs a [Quaternion] from the given rotation [Basis].
This constructor is faster than [method Basis.get_rotation_quaternion], but the given basis must be [i]orthonormalized[/i] (see [method Basis.orthonormalized]). Otherwise, the constructor fails and returns [constant IDENTITY].
2017-09-12 20:42:36 +00:00
</description>
2021-09-21 02:49:02 +00:00
</constructor>
<constructor name= "Quaternion" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "x" type= "float" />
<param index= "1" name= "y" type= "float" />
<param index= "2" name= "z" type= "float" />
<param index= "3" name= "w" type= "float" />
2020-11-09 16:46:03 +00:00
<description >
2024-01-14 17:50:06 +00:00
Constructs a [Quaternion] defined by the given values.
[b]Note:[/b] Only normalized quaternions represent rotation; if these values are not normalized, the new [Quaternion] will not be a valid rotation.
2020-11-09 16:46:03 +00:00
</description>
2021-09-21 02:49:02 +00:00
</constructor>
</constructors>
<methods >
2020-12-07 06:40:46 +00:00
<method name= "angle_to" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "to" type= "Quaternion" />
2020-12-07 06:40:46 +00:00
<description >
2022-08-11 17:52:19 +00:00
Returns the angle between this quaternion and [param to]. This is the magnitude of the angle you would need to rotate by to get from one to the other.
2022-09-21 06:53:05 +00:00
[b]Note:[/b] The magnitude of the floating-point error for this method is abnormally high, so methods such as [code]is_zero_approx[/code] will not work reliably.
2020-12-07 06:40:46 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "dot" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "with" type= "Quaternion" />
2017-09-12 20:42:36 +00:00
<description >
2024-01-14 17:50:06 +00:00
Returns the dot product between this quaternion and [param with].
This is equivalent to [code](quat.x * with.x) + (quat.y * with.y) + (quat.z * with.z) + (quat.w * with.w)[/code].
2017-09-12 20:42:36 +00:00
</description>
</method>
2022-03-15 16:35:25 +00:00
<method name= "exp" qualifiers= "const" >
<return type= "Quaternion" />
<description >
</description>
</method>
2022-11-01 13:11:09 +00:00
<method name= "from_euler" qualifiers= "static" >
<return type= "Quaternion" />
<param index= "0" name= "euler" type= "Vector3" />
<description >
2024-01-14 17:50:06 +00:00
Constructs a new [Quaternion] from the given [Vector3] of [url=https://en.wikipedia.org/wiki/Euler_angles]Euler angles[/url], in radians. This method always uses the YXZ convention ([constant EULER_ORDER_YXZ]).
2022-11-01 13:11:09 +00:00
</description>
</method>
2021-10-20 23:42:22 +00:00
<method name= "get_angle" qualifiers= "const" >
<return type= "float" />
<description >
</description>
</method>
<method name= "get_axis" qualifiers= "const" >
<return type= "Vector3" />
<description >
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "get_euler" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "Vector3" />
2022-10-02 02:54:19 +00:00
<param index= "0" name= "order" type= "int" default= "2" />
2018-05-12 00:14:39 +00:00
<description >
2024-01-14 17:50:06 +00:00
Returns this quaternion's rotation as a [Vector3] of [url=https://en.wikipedia.org/wiki/Euler_angles]Euler angles[/url], in radians.
The order of each consecutive rotation can be changed with [param order] (see [enum EulerOrder] constants). By default, the YXZ convention is used ([constant EULER_ORDER_YXZ]): Z (roll) is calculated first, then X (pitch), and lastly Y (yaw). When using the opposite method [method from_euler], this order is reversed.
2018-05-12 00:14:39 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "inverse" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2017-09-12 20:42:36 +00:00
<description >
2024-01-14 17:50:06 +00:00
Returns the inverse version of this quaternion, inverting the sign of every component except [member w].
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "is_equal_approx" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "to" type= "Quaternion" />
2019-11-08 07:33:48 +00:00
<description >
2022-08-11 17:52:19 +00:00
Returns [code]true[/code] if this quaternion and [param to] are approximately equal, by running [method @GlobalScope.is_equal_approx] on each component.
2019-11-08 07:33:48 +00:00
</description>
</method>
2022-08-11 08:12:27 +00:00
<method name= "is_finite" qualifiers= "const" >
<return type= "bool" />
<description >
Returns [code]true[/code] if this quaternion is finite, by calling [method @GlobalScope.is_finite] on each component.
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "is_normalized" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2017-09-12 20:42:36 +00:00
<description >
2024-01-14 17:50:06 +00:00
Returns [code]true[/code] if this quaternion is normalized. See also [method normalized].
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "length" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2017-09-12 20:42:36 +00:00
<description >
2024-01-14 17:50:06 +00:00
Returns this quaternion's length, also called magnitude.
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "length_squared" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2017-09-12 20:42:36 +00:00
<description >
2024-01-14 17:50:06 +00:00
Returns this quaternion's length, squared.
[b]Note:[/b] This method is faster than [method length], so prefer it if you only need to compare quaternion lengths.
2017-09-12 20:42:36 +00:00
</description>
</method>
2022-03-15 16:35:25 +00:00
<method name= "log" qualifiers= "const" >
<return type= "Quaternion" />
<description >
2024-01-14 17:50:06 +00:00
Returns the logarithm of this quaternion. Multiplies this quaternion's rotation axis by its rotation angle, and stores the result in the returned quaternion's vector part ([member x], [member y], and [member z]). The returned quaternion's real part ([member w]) is always [code]0.0[/code].
2022-03-15 16:35:25 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "normalized" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2017-09-12 20:42:36 +00:00
<description >
2024-01-14 17:50:06 +00:00
Returns a copy of this quaternion, normalized so that its length is [code]1.0[/code]. See also [method is_normalized].
2017-09-12 20:42:36 +00:00
</description>
2020-11-10 13:16:20 +00:00
</method>
2021-09-21 02:49:02 +00:00
<method name= "slerp" qualifiers= "const" >
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "to" type= "Quaternion" />
<param index= "1" name= "weight" type= "float" />
2021-09-17 15:22:48 +00:00
<description >
2024-01-14 17:50:06 +00:00
Performs a spherical-linear interpolation with the [param to] quaternion, given a [param weight] and returns the result. Both this quaternion and [param to] must be normalized.
2021-09-17 15:22:48 +00:00
</description>
</method>
2021-09-21 02:49:02 +00:00
<method name= "slerpni" qualifiers= "const" >
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "to" type= "Quaternion" />
<param index= "1" name= "weight" type= "float" />
2020-11-10 13:16:20 +00:00
<description >
2024-01-14 17:50:06 +00:00
Performs a spherical-linear interpolation with the [param to] quaternion, given a [param weight] and returns the result. Unlike [method slerp], this method does not check if the rotation path is smaller than 90 degrees. Both this quaternion and [param to] must be normalized.
2020-11-10 13:16:20 +00:00
</description>
</method>
2022-07-27 12:27:51 +00:00
<method name= "spherical_cubic_interpolate" qualifiers= "const" >
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "b" type= "Quaternion" />
<param index= "1" name= "pre_a" type= "Quaternion" />
<param index= "2" name= "post_b" type= "Quaternion" />
<param index= "3" name= "weight" type= "float" />
2022-07-27 12:27:51 +00:00
<description >
2022-08-11 17:52:19 +00:00
Performs a spherical cubic interpolation between quaternions [param pre_a], this vector, [param b], and [param post_b], by the given amount [param weight].
2022-07-27 12:27:51 +00:00
</description>
</method>
2022-07-28 19:55:10 +00:00
<method name= "spherical_cubic_interpolate_in_time" qualifiers= "const" >
<return type= "Quaternion" />
<param index= "0" name= "b" type= "Quaternion" />
<param index= "1" name= "pre_a" type= "Quaternion" />
<param index= "2" name= "post_b" type= "Quaternion" />
<param index= "3" name= "weight" type= "float" />
<param index= "4" name= "b_t" type= "float" />
<param index= "5" name= "pre_a_t" type= "float" />
<param index= "6" name= "post_b_t" type= "float" />
<description >
Performs a spherical cubic interpolation between quaternions [param pre_a], this vector, [param b], and [param post_b], by the given amount [param weight].
It can perform smoother interpolation than [code]spherical_cubic_interpolate()[/code] by the time values.
</description>
</method>
2021-09-21 02:49:02 +00:00
</methods>
<members >
<member name= "w" type= "float" setter= "" getter= "" default= "1.0" >
2024-01-14 17:50:06 +00:00
W component of the quaternion. This is the "real" part.
[b]Note:[/b] Quaternion components should usually not be manipulated directly.
2021-09-21 02:49:02 +00:00
</member>
<member name= "x" type= "float" setter= "" getter= "" default= "0.0" >
2024-01-14 17:50:06 +00:00
X component of the quaternion. This is the value along the "imaginary" [code]i[/code] axis.
[b]Note:[/b] Quaternion components should usually not be manipulated directly.
2021-09-21 02:49:02 +00:00
</member>
<member name= "y" type= "float" setter= "" getter= "" default= "0.0" >
2024-01-14 17:50:06 +00:00
Y component of the quaternion. This is the value along the "imaginary" [code]j[/code] axis.
[b]Note:[/b] Quaternion components should usually not be manipulated directly.
2021-09-21 02:49:02 +00:00
</member>
<member name= "z" type= "float" setter= "" getter= "" default= "0.0" >
2024-01-14 17:50:06 +00:00
Z component of the quaternion. This is the value along the "imaginary" [code]k[/code] axis.
[b]Note:[/b] Quaternion components should usually not be manipulated directly.
2021-09-21 02:49:02 +00:00
</member>
</members>
<constants >
<constant name= "IDENTITY" value= "Quaternion(0, 0, 0, 1)" >
2024-01-14 17:50:06 +00:00
The identity quaternion, representing no rotation. This has the same rotation as [constant Basis.IDENTITY].
If a [Vector3] is rotated (multiplied) by this quaternion, it does not change.
2021-09-21 02:49:02 +00:00
</constant>
</constants>
<operators >
<operator name= "operator !=" >
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Quaternion" />
2021-09-21 02:49:02 +00:00
<description >
2024-01-14 17:50:06 +00:00
Returns [code]true[/code] if the components of both quaternions are not exactly equal.
2021-11-04 15:58:20 +00:00
[b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable.
2021-09-21 02:49:02 +00:00
</description>
</operator>
<operator name= "operator *" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Quaternion" />
2020-11-10 13:16:20 +00:00
<description >
2024-01-14 17:50:06 +00:00
Composes (multiplies) two quaternions. This rotates the [param right] quaternion (the child) by this quaternion (the parent).
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator *" >
<return type= "Vector3" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Vector3" />
2021-09-21 02:49:02 +00:00
<description >
2024-01-14 17:50:06 +00:00
Rotates (multiplies) the [param right] vector by this quaternion, returning a [Vector3].
2021-09-21 02:49:02 +00:00
</description>
</operator>
<operator name= "operator *" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "float" />
2020-11-10 13:16:20 +00:00
<description >
2024-01-14 17:50:06 +00:00
Multiplies each component of the [Quaternion] by the right [float] value.
This operation is not meaningful on its own, but it can be used as a part of a larger expression.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator *" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "int" />
2020-11-10 13:16:20 +00:00
<description >
2024-01-14 17:50:06 +00:00
Multiplies each component of the [Quaternion] by the right [int] value.
This operation is not meaningful on its own, but it can be used as a part of a larger expression.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator +" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Quaternion" />
2020-11-10 13:16:20 +00:00
<description >
2024-01-14 17:50:06 +00:00
Adds each component of the left [Quaternion] to the right [Quaternion].
This operation is not meaningful on its own, but it can be used as a part of a larger expression, such as approximating an intermediate rotation between two nearby rotations.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator -" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Quaternion" />
2020-12-04 14:54:48 +00:00
<description >
2024-01-14 17:50:06 +00:00
Subtracts each component of the left [Quaternion] by the right [Quaternion].
This operation is not meaningful on its own, but it can be used as a part of a larger expression.
2020-12-04 14:54:48 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator /" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "float" />
2020-11-10 13:16:20 +00:00
<description >
2024-01-14 17:50:06 +00:00
Divides each component of the [Quaternion] by the right [float] value.
This operation is not meaningful on its own, but it can be used as a part of a larger expression.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator /" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "int" />
2020-11-10 13:16:20 +00:00
<description >
2024-01-14 17:50:06 +00:00
Divides each component of the [Quaternion] by the right [int] value.
This operation is not meaningful on its own, but it can be used as a part of a larger expression.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator ==" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Quaternion" />
2020-11-10 13:16:20 +00:00
<description >
2024-01-14 17:50:06 +00:00
Returns [code]true[/code] if the components of both quaternions are exactly equal.
2021-11-04 15:58:20 +00:00
[b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator []" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "index" type= "int" />
2020-11-10 13:16:20 +00:00
<description >
2024-01-14 17:50:06 +00:00
Accesses each component of this quaternion by their index.
Index [code]0[/code] is the same as [member x], index [code]1[/code] is the same as [member y], index [code]2[/code] is the same as [member z], and index [code]3[/code] is the same as [member w].
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator unary+" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2017-09-12 20:42:36 +00:00
<description >
2021-11-04 15:58:20 +00:00
Returns the same value as if the [code]+[/code] was not there. Unary [code]+[/code] does nothing, but sometimes it can make your code more readable.
2017-09-12 20:42:36 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator unary-" >
2021-07-30 13:28:05 +00:00
<return type= "Quaternion" />
2017-09-12 20:42:36 +00:00
<description >
2024-01-14 17:50:06 +00:00
Returns the negative value of the [Quaternion]. This is the same as multiplying all components by [code]-1[/code]. This operation results in a quaternion that represents the same rotation.
2017-09-12 20:42:36 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
</operators>
2017-09-12 20:42:36 +00:00
</class>