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
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
staticinlineop_Division(left:Quat, right:Float):Quat
Operator overload for godot.Quat
/ ((global::System.Single)(Float
)).
staticinlineop_Inequality(left:Quat, right:Quat):Bool
Operator overload for godot.Quat
!= godot.Quat
.
staticinlineop_Multiply(left:Quat, right:Quat):Quat
staticinlineop_Multiply(left:Float, right:Quat):Quat
staticinlineop_Multiply(left:Quat, right:Float):Quat
staticinlineop_Multiply(left:Vector3, right:Quat):Quat
staticinlineop_Multiply(left:Quat, right:Vector3):Quat
Operator overload for godot.Quat
* godot.Quat
.
staticinlineop_Subtraction(left:Quat, right:Quat):Quat
Operator overload for godot.Quat
- godot.Quat
.
Constructor
new(x:Single, y:Single, z:Single, w:Single)
new(axis:Vector3, angle:Single)
new(eulerYXZ:Vector3)
new(basis:Basis)
new(q:Quat)
Constructs a godot.Quat
defined by the given values.
Parameters:
x | X component of the quaternion (imaginary |
---|---|
y | Y component of the quaternion (imaginary |
z | Z component of the quaternion (imaginary |
w | W component of the quaternion (real part). |
Variables
read onlylength:Single
Returns the length (magnitude) of the quaternion.
See also:
godot.Quat.lengthSquared
Value: Equivalent toMathf.Sqrt(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)
.
w:Single
W component of the quaternion (real part). Quaternion components should usually not be manipulated directly.
x:Single
X component of the quaternion (imaginary i
axis part).
Quaternion components should usually not be manipulated directly.
y:Single
Y component of the quaternion (imaginary j
axis part).
Quaternion components should usually not be manipulated directly.
z:Single
Z component of the quaternion (imaginary k
axis part).
Quaternion components should usually not be manipulated directly.
Methods
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.
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 |
weight | A value on the range of 0.0 to 1.0, representing the amount of interpolation. |
Returns:
The interpolated quaternion.
dot(b:Quat):Single
Returns the dot product of two quaternions.
Parameters:
b | The other quaternion. |
---|
Returns:
The dot product.
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.
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.
isNormalized():Bool
Returns whether the quaternion is normalized or not.
Returns:
A bool
for whether the quaternion is normalized or not.
normalized():Quat
Returns a copy of the quaternion, normalized to unit length.
Returns:
The normalized quaternion.
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.
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.