GCubeSDK
©2026 FenixFox®Studios

Quaternion

Class representing a quaternion (x, y, z, w).
Quaternions are used to represent 3D rotations without suffering from gimbal lock. This class mirrors three.js Quaternion closely where applicable.

Methods

Quaternion()

Default constructor - creates identity quaternion (0, 0, 0, 1)

Quaternion(f32 x, f32 y, f32 z, f32 w)

Value constructor for quaternion components

x X component of quaternion 0.0f
y Y component of quaternion 0.0f
z Z component of quaternion 0.0f
w W component of quaternion 1.0f

Quaternion& set(f32 x, f32 y, f32 z, f32 w)

Sets the quaternion components

x X component value
y Y component value
z Z component value
w W component value

Quaternion clone() const

Creates a copy of this quaternion

Quaternion& copy(const Quaternion& q)

Copies values from another quaternion

q Source quaternion

Quaternion& setFromEuler(const Euler& euler)

Sets quaternion from Euler angles

euler Euler angles to convert from

Quaternion& setFromAxisAngle(const Vector3& axis, f32 angle)

Sets quaternion from axis-angle representation

axis Normalized rotation axis
angle Rotation angle in radians

Quaternion& setFromRotationMatrix(const Mtx& m)

Sets quaternion from rotation matrix

m 3x3 rotation matrix (upper part of 3x4)

Quaternion& setFromUnitVectors(const Vector3& vFrom, const Vector3& vTo)

Sets quaternion to rotate from one vector to another

vFrom First normalized direction vector
vTo Second normalized direction vector

Quaternion& identity()

Sets quaternion to identity (no rotation)

Quaternion& invert()

Inverts this quaternion (assumes unit length)

Quaternion& conjugate()

Returns conjugate of this quaternion

f32 dot(const Quaternion& v) const

Calculates dot product with another quaternion

v Quaternion to dot with

f32 lengthSq() const

Calculates squared length of quaternion

f32 length() const

Calculates length of quaternion

Quaternion& normalize()

Normalizes quaternion to unit length

Quaternion& multiply(const Quaternion& q)

Multiplies this quaternion by another

q Quaternion to multiply by

Quaternion& premultiply(const Quaternion& q)

Pre-multiplies this quaternion by another

q Quaternion to pre-multiply by

Quaternion& multiplyQuaternions(const Quaternion& a, const Quaternion& b)

Multiplies two quaternions and stores result in this

a First quaternion
b Second quaternion

Quaternion& slerp(const Quaternion& qb, f32 t)

Spherical linear interpolation toward target quaternion

qb Target quaternion
t Interpolation factor (0-1)

Quaternion& slerpQuaternions(const Quaternion& qa, const Quaternion& qb, f32 t)

Sets this quaternion to slerp between two quaternions

qa Source quaternion
qb Target quaternion
t Interpolation factor (0-1)

f32 angleTo(const Quaternion& q) const

Returns angle between this and target quaternion

q Target quaternion

Quaternion& rotateTowards(const Quaternion& q, f32 step)

Rotates toward target quaternion by given step

q Target quaternion
step Angular step in radians

bool equals(const Quaternion& q) const

Checks if this quaternion equals another

q Quaternion to compare with

Quaternion& fromArray(const f32* array, u32 offset)

Sets quaternion from array of floats

array Array of float values
offset Starting offset in array 0

f32* toArray(f32* array, u32 offset) const

Writes quaternion components to array

array Target array (nullptr for static temp) nullptr
offset Starting offset in array 0

Quaternion& fromBufferAttribute(const class BufferAttribute& attribute, u32 index)

Sets quaternion from GPU buffer attribute

attribute Buffer attribute to read from
index Vertex index in buffer

Quaternion& random()

Sets quaternion to random normalized rotation

Properties

isQuaternion bool Read-only tag
w f32 W component of quaternion
x f32 X component of quaternion
y f32 Y component of quaternion
z f32 Z component of quaternion