A unit quaternion used for representing 3D rotations. Quaternions need to be normalized to be used for rotation.

It is similar to godot.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.

Static variables

@:native("Identity")staticread onlyIDENTITY:Quat

The identity quaternion, representing no rotation. Equivalent to an identity godot.Basis matrix. If a vector is transformed by an identity quaternion, it will not change.

Value: Equivalent to new Quat(0, 0, 0, 1).

Static methods

@:op(A + B)staticinlineop_Addition(left:Quat, right:Quat):Quat

Operator overload for godot.Quat + godot.Quat.

@:op(A / B)staticinlineop_Division(left:Quat, right:Float):Quat

Operator overload for godot.Quat / ((global::System.Single)(Float)).

@:op(A == B)staticinlineop_Equality(left:Quat, right:Quat):Bool

Operator overload for godot.Quat == godot.Quat.

@:op(A != B)staticinlineop_Inequality(left:Quat, right:Quat):Bool

Operator overload for godot.Quat != godot.Quat.

@:op(A * B)staticinlineop_Multiply(left:Quat, right:Quat):Quat

@:op(A * B)staticinlineop_Multiply(left:Float, right:Quat):Quat

@:op(A * B)staticinlineop_Multiply(left:Quat, right:Float):Quat

@:op(A * B)staticinlineop_Multiply(left:Vector3, right:Quat):Quat

@:op(A * B)staticinlineop_Multiply(left:Quat, right:Vector3):Quat

Operator overload for godot.Quat * godot.Quat.

@:op(A - B)staticinlineop_Subtraction(left:Quat, right:Quat):Quat

Operator overload for godot.Quat - godot.Quat.

@:op(-A)staticinlineop_UnaryNegation(left:Quat):Quat

Operator overload for -godot.Quat.

Constructor

@:native("new")new(x:Single, y:Single, z:Single, w:Single)

@:native("new")new(axis:Vector3, angle:Single)

@:native("new")new(eulerYXZ:Vector3)

@:native("new")new(basis:Basis)

@:native("new")new(q:Quat)

Constructs a godot.Quat defined by the given values.

Parameters:

x

X component of the quaternion (imaginary i axis part).

y

Y component of the quaternion (imaginary j axis part).

z

Z component of the quaternion (imaginary k axis part).

w

W component of the quaternion (real part).

Variables

@:native("Length")read onlylength:Single

Returns the length (magnitude) of the quaternion.

See also:

@:native("LengthSquared")read onlylengthSquared:Single

Returns the squared length (squared magnitude) of the quaternion. This method runs faster than godot.Quat.length, so prefer it if you need to compare quaternions or need the squared length for some formula.

Value: Equivalent to Dot(this).

@:native("w")w:Single

W component of the quaternion (real part). Quaternion components should usually not be manipulated directly.

@:native("x")x:Single

X component of the quaternion (imaginary i axis part). Quaternion components should usually not be manipulated directly.

@:native("y")y:Single

Y component of the quaternion (imaginary j axis part). Quaternion components should usually not be manipulated directly.

@:native("z")z:Single

Z component of the quaternion (imaginary k axis part). Quaternion components should usually not be manipulated directly.

Methods

@:native("AngleTo")angleTo(to:Quat):Single

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 godot.Mathf.isZeroApprox will not work reliably.

Parameters:

to

The other quaternion.

Returns:

The angle between the quaternions.

@:native("CubicSlerp")cubicSlerp(b:Quat, preA:Quat, postB:Quat, weight:Single):Quat

Performs a cubic spherical interpolation between quaternions preA, this quaternion, b, and postB, by the given amount weight.

Parameters:

b

The destination quaternion.

preA

A quaternion before this quaternion.

postB

A quaternion after b.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns:

The interpolated quaternion.

@:native("Dot")dot(b:Quat):Single

Returns the dot product of two quaternions.

Parameters:

b

The other quaternion.

Returns:

The dot product.

@:native("GetEuler")getEuler():Vector3

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).

Returns:

The Euler angle representation of this quaternion.

@:native("Inverse")inverse():Quat

Returns the inverse of the quaternion.

Returns:

The inverse quaternion.

@:native("IsEqualApprox")isEqualApprox(other:Quat):Bool

Returns true if this quaternion and other are approximately equal, by running godot.Mathf.isEqualApprox on each component.

Parameters:

other

The other quaternion to compare.

Returns:

Whether or not the quaternions are approximately equal.

@:native("IsNormalized")isNormalized():Bool

Returns whether the quaternion is normalized or not.

Returns:

A bool for whether the quaternion is normalized or not.

@:native("Normalized")normalized():Quat

Returns a copy of the quaternion, normalized to unit length.

Returns:

The normalized quaternion.

@:native("Set")set(x:Single, y:Single, z:Single, w:Single):Void

@:native("Set")Set(q:Quat):Void

@:native("SetAxisAngle")setAxisAngle(axis:Vector3, angle:Single):Void

@:native("SetEuler")setEuler(eulerYXZ:Vector3):Void

@:native("Slerp")slerp(to:Quat, weight:Single):Quat

Returns the result of the spherical linear interpolation between this quaternion and to by amount weight.

Note: Both quaternions must be normalized.

Parameters:

to

The destination quaternion for interpolation. Must be normalized.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns:

The resulting quaternion of the interpolation.

@:native("Slerpni")slerpni(to:Quat, weight:Single):Quat

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.

Parameters:

to

The destination quaternion for interpolation. Must be normalized.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns:

The resulting quaternion of the interpolation.

@:native("ToString")toString():String

@:native("ToString")ToString(format:String):String

Converts this godot.Quat to a string.

Returns:

A string representation of this quaternion.

@:native("Xform")xform(v:Vector3):Vector3

Returns a vector transformed (multiplied) by this quaternion.

Parameters:

v

A vector to transform.

Returns:

The transformed vector.