class-description NEWS COMMUNITY STORE TUTORIALS SIGN UP LOGIN LOGOUT ROKOJORI NEWSLETTER SIGN UP LOGIN LOGOUT NEWS COMMUNITY STORE TUTORIALS TOGGLE FULLSCREEN VOLLBILD AN/AUS Quaternion
A unit quaternion used for representing 3D rotations.

The Quaternion built-in Variant type is a 4D data structure that represents rotation in the form of a Hamilton convention quaternion. Compared to the Basis type which can store both rotation and scale, quaternions can only store rotation.

A Quaternion is composed by 4 floating-point components: w, x, y, and 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 get_angle(), get_axis(), and slerp() are faster than their Basis counterparts.

For a great introduction to quaternions, see this video by 3Blue1Brown. You do not need to know the math behind quaternions, as Godot provides several helper methods that handle it for you. These include slerp() and spherical_cubic_interpolate(), as well as the * operator.

Quaternion Quaternion<>():Quaternion

Constructs a Quaternion identical to IDENTITY.

Note: In C#, this constructs a Quaternion with all of its components set to 0.0.

Quaternion Quaternion<>( Quaternion from=, from:Quaternion=, ):Quaternion

Constructs a Quaternion as a copy of the given Quaternion.

Quaternion Quaternion<>( Vector3 arc_from=, arc_from:Vector3=, Vector3 arc_to=, arc_to:Vector3=, ):Quaternion

Constructs a Quaternion representing the shortest arc between arc_from and arc_to. These can be imagined as two points intersecting a sphere's surface, with a radius of 1.0.

Quaternion Quaternion<>( Vector3 axis=, axis:Vector3=, float angle=, angle:float=, ):Quaternion

Constructs a Quaternion representing rotation around the axis by the given angle, in radians. The axis must be a normalized vector.

Quaternion Quaternion<>( Basis from=, from:Basis=, ):Quaternion

Constructs a Quaternion from the given rotation Basis.

This constructor is faster than Basis.get_rotation_quaternion(), but the given basis must be orthonormalized (see Basis.orthonormalized()). Otherwise, the constructor fails and returns IDENTITY.

Quaternion Quaternion<>( float x=, x:float=, float y=, y:float=, float z=, z:float=, float w=, w:float=, ):Quaternion

Constructs a Quaternion defined by the given values.

Note: Only normalized quaternions represent rotation; if these values are not normalized, the new Quaternion will not be a valid rotation.

bool operator !=<>( Quaternion right=, right:Quaternion=, ):bool

Returns true if the components of both quaternions are not exactly equal.

Note: Due to floating-point precision errors, consider using is_equal_approx() instead, which is more reliable.

Quaternion operator *<>( Quaternion right=, right:Quaternion=, ):Quaternion

Composes (multiplies) two quaternions. This rotates the right quaternion (the child) by this quaternion (the parent).

Vector3 operator *<>( Vector3 right=, right:Vector3=, ):Vector3

Rotates (multiplies) the right vector by this quaternion, returning a Vector3.

Quaternion operator *<>( float right=, right:float=, ):Quaternion

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.

Quaternion operator *<>( int right=, right:int=, ):Quaternion

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.

Quaternion operator +<>( Quaternion right=, right:Quaternion=, ):Quaternion

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.

Quaternion operator -<>( Quaternion right=, right:Quaternion=, ):Quaternion

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.

Quaternion operator /<>( float right=, right:float=, ):Quaternion

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.

Quaternion operator /<>( int right=, right:int=, ):Quaternion

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.

bool operator ==<>( Quaternion right=, right:Quaternion=, ):bool

Returns true if the components of both quaternions are exactly equal.

Note: Due to floating-point precision errors, consider using is_equal_approx() instead, which is more reliable.

float operator []<>( int index=, index:int=, ):float

Accesses each component of this quaternion by their index.

Index 0 is the same as x, index 1 is the same as y, index 2 is the same as z, and index 3 is the same as w.

Quaternion operator unary+<>():Quaternion

Returns the same value as if the + was not there. Unary + does nothing, but sometimes it can make your code more readable.

Quaternion operator unary-<>():Quaternion

Returns the negative value of the Quaternion. This is the same as multiplying all components by -1. This operation results in a quaternion that represents the same rotation.

float w<>():float

W component of the quaternion. This is the "real" part.

Note: Quaternion components should usually not be manipulated directly.

float x<>():float

X component of the quaternion. This is the value along the "imaginary" i axis.

Note: Quaternion components should usually not be manipulated directly.

float y<>():float

Y component of the quaternion. This is the value along the "imaginary" j axis.

Note: Quaternion components should usually not be manipulated directly.

float z<>():float

Z component of the quaternion. This is the value along the "imaginary" k axis.

Note: Quaternion components should usually not be manipulated directly.

float angle_to<>( Quaternion to=, to:Quaternion=, ):float

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: The magnitude of the floating-point error for this method is abnormally high, so methods such as is_zero_approx will not work reliably.

float dot<>( Quaternion with=, with:Quaternion=, ):float

Returns the dot product between this quaternion and with.

This is equivalent to (quat.x * with.x) + (quat.y * with.y) + (quat.z * with.z) + (quat.w * with.w).

Quaternion exp<>():Quaternion

Returns the exponential of this quaternion. The rotation axis of the result is the normalized rotation axis of this quaternion, the angle of the result is the length of the vector part of this quaternion.

Quaternion from_euler<>( Vector3 euler=, euler:Vector3=, ):Quaternion

Constructs a new Quaternion from the given Vector3 of Euler angles, in radians. This method always uses the YXZ convention (@GlobalScope.EULER_ORDER_YXZ).

float get_angle<>():float

Returns the angle of the rotation represented by this quaternion.

Note: The quaternion must be normalized.

Vector3 get_axis<>():Vector3

Returns the rotation axis of the rotation represented by this quaternion.

Vector3 get_euler<>( int order=2, order:int=2, ):Vector3

Returns this quaternion's rotation as a Vector3 of Euler angles, in radians.

The order of each consecutive rotation can be changed with order (see EulerOrder constants). By default, the YXZ convention is used (@GlobalScope.EULER_ORDER_YXZ): Z (roll) is calculated first, then X (pitch), and lastly Y (yaw). When using the opposite method from_euler(), this order is reversed.

Quaternion inverse<>():Quaternion

Returns the inverse version of this quaternion, inverting the sign of every component except w.

bool is_equal_approx<>( Quaternion to=, to:Quaternion=, ):bool

Returns true if this quaternion and to are approximately equal, by calling @GlobalScope.is_equal_approx() on each component.

bool is_finite<>():bool

Returns true if this quaternion is finite, by calling @GlobalScope.is_finite() on each component.

bool is_normalized<>():bool

Returns true if this quaternion is normalized. See also normalized().

float length<>():float

Returns this quaternion's length, also called magnitude.

float length_squared<>():float

Returns this quaternion's length, squared.

Note: This method is faster than length(), so prefer it if you only need to compare quaternion lengths.

Quaternion log<>():Quaternion

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 (x, y, and z). The returned quaternion's real part (w) is always 0.0.

Quaternion normalized<>():Quaternion

Returns a copy of this quaternion, normalized so that its length is 1.0. See also is_normalized().

Quaternion slerp<>( Quaternion to=, to:Quaternion=, float weight=, weight:float=, ):Quaternion

Performs a spherical-linear interpolation with the to quaternion, given a weight and returns the result. Both this quaternion and to must be normalized.

Quaternion slerpni<>( Quaternion to=, to:Quaternion=, float weight=, weight:float=, ):Quaternion

Performs a spherical-linear interpolation with the to quaternion, given a weight and returns the result. Unlike slerp(), this method does not check if the rotation path is smaller than 90 degrees. Both this quaternion and to must be normalized.

Quaternion spherical_cubic_interpolate<>( Quaternion b=, b:Quaternion=, Quaternion pre_a=, pre_a:Quaternion=, Quaternion post_b=, post_b:Quaternion=, float weight=, weight:float=, ):Quaternion

Performs a spherical cubic interpolation between quaternions pre_a, this vector, b, and post_b, by the given amount weight.

Quaternion spherical_cubic_interpolate_in_time<>( Quaternion b=, b:Quaternion=, Quaternion pre_a=, pre_a:Quaternion=, Quaternion post_b=, post_b:Quaternion=, float weight=, weight:float=, float b_t=, b_t:float=, float pre_a_t=, pre_a_t:float=, float post_b_t=, post_b_t:float=, ):Quaternion

Performs a spherical cubic interpolation between quaternions pre_a, this vector, b, and post_b, by the given amount weight.

It can perform smoother interpolation than spherical_cubic_interpolate() by the time values.




All social media brands are registrated trademarks and belong to their respective owners.





CONTACT IMPRINT TERMS OF USE PRIVACY © ROKOROJI ® 2021 rokojori.com
CONTACT IMPRINT TERMS OF USE PRIVACY © ROKOROJI ® 2021 rokojori.com
We are using cookies on this site. Read more... Wir benutzen Cookies auf dieser Seite. Mehr lesen...