Skip to content

@orillusion/core


Class: Quaternion ​

Defined in: src/math/Quaternion.ts:10

Quaternions are used to represent rotations.

Constructors ​

Constructor ​

new Quaternion(x?, y?, z?, w?): Quaternion

Defined in: src/math/Quaternion.ts:46

Create a new quaternion object

Parameters ​

x? ​

number = 0

The X component of a quaternion.

y? ​

number = 0

The Y component of a quaternion.

z? ​

number = 0

The Z component of a quaternion.

w? ​

number = 1

The W component of a quaternion.

Returns ​

Quaternion

Properties ​

HELP_0 ​

static HELP_0: Quaternion

Defined in: src/math/Quaternion.ts:13

Shared scratch quaternion for intermediate calculations.


HELP_1 ​

static HELP_1: Quaternion

Defined in: src/math/Quaternion.ts:15

Shared scratch quaternion for intermediate calculations.


HELP_2 ​

static HELP_2: Quaternion

Defined in: src/math/Quaternion.ts:17

Shared scratch quaternion for intermediate calculations.


_zero ​

static _zero: Quaternion

Defined in: src/math/Quaternion.ts:19

Shared identity quaternion (0, 0, 0, 1).


CALCULATION_QUATERNION ​

static CALCULATION_QUATERNION: Quaternion

Defined in: src/math/Quaternion.ts:21

Shared scratch quaternion used for rotation calculations.

Accessors ​

magnitude ​

Get Signature ​

get magnitude(): number

Defined in: src/math/Quaternion.ts:109

The magnitude (norm) of this quaternion.

Returns ​

number

Methods ​

identity() ​

static identity(): Quaternion

Defined in: src/math/Quaternion.ts:57

Identity quaternion

Returns ​

Quaternion


quaternionToMatrix() ​

static quaternionToMatrix(q, m): void

Defined in: src/math/Quaternion.ts:66

Converts quaternions to matrices

Parameters ​

q ​

Quaternion

Quaternion

m ​

any

Matrix

Returns ​

void


set() ​

set(x?, y?, z?, w?): Quaternion

Defined in: src/math/Quaternion.ts:120

Set the x, y, z, and w components of the existing quaternions.

Parameters ​

x? ​

number = 0

The X component of a quaternion.

y? ​

number = 0

The Y component of a quaternion.

z? ​

number = 0

The Z component of a quaternion.

w? ​

number = 1

The W component of a quaternion.

Returns ​

Quaternion


divide() ​

divide(v): Quaternion

Defined in: src/math/Quaternion.ts:129

Divide this quaternion by another quaternion (component-wise, new instance) or by a scalar (in place).

Parameters ​

v ​

any

Returns ​

Quaternion


multiply() ​

multiply(qa, qb): this

Defined in: src/math/Quaternion.ts:157

Multiply two quaternions

Parameters ​

qa ​

Quaternion

Quaternion 1

qb ​

Quaternion

Quaternion 2

Returns ​

this


multiplyVector() ​

multiplyVector(vector): Quaternion

Defined in: src/math/Quaternion.ts:177

Multiply this quaternion by a vector. Returns a new Quaternion.

Parameters ​

vector ​

Vector3

Returns ​

Quaternion


setFromAxisAngle() ​

setFromAxisAngle(axis, angle): this

Defined in: src/math/Quaternion.ts:194

Set the quaternion with a given rotation of the axis and Angle.

Parameters ​

axis ​

Vector3

axis

angle ​

number

angle

Returns ​

this


toAxisAngle() ​

toAxisAngle(axis): number

Defined in: src/math/Quaternion.ts:213

Turn quaternions into angles

Parameters ​

axis ​

Vector3

axis

Returns ​

number


slerp() ​

slerp(qa, qb, t): void

Defined in: src/math/Quaternion.ts:238

Spherically interpolates between two quaternions, providing an interpolation between rotations with constant angle change rate.

Parameters ​

qa ​

Quaternion

The first quaternion to interpolate.

qb ​

Quaternion

The second quaternion to interpolate.

t ​

number

The interpolation weight, a value between 0 and 1.

Returns ​

void


lerp() ​

lerp(qa, qb, t): void

Defined in: src/math/Quaternion.ts:288

Linearly interpolates between two quaternions.

Parameters ​

qa ​

Quaternion

The first quaternion to interpolate.

qb ​

Quaternion

The second quaternion to interpolate.

t ​

number

The interpolation weight, a value between 0 and 1.

Returns ​

void


setFromEuler() ​

setFromEuler(ax, ay, az): Quaternion

Defined in: src/math/Quaternion.ts:325

Fills the quaternion object with values representing the given euler rotation.

Parameters ​

ax ​

number

The angle in radians of the rotation around the ax axis.

ay ​

number

The angle in radians of the rotation around the ay axis.

az ​

number

The angle in radians of the rotation around the az axis.

Returns ​

Quaternion


setFromRotationMatrix() ​

setFromRotationMatrix(m): Quaternion

Defined in: src/math/Quaternion.ts:353

Sets the current quaternion from the rotation matrix

Parameters ​

m ​
rawData ​

FloatArray

Returns ​

Quaternion


getEulerAngles() ​

getEulerAngles(eulers?): Vector3

Defined in: src/math/Quaternion.ts:404

Get the Euler Angle

Parameters ​

eulers? ​

Vector3

Returns ​

Vector3


normalize() ​

normalize(val?): this

Defined in: src/math/Quaternion.ts:443

The normalize of the quaternion. Convert this quaternion to a normalize coefficient.

Parameters ​

val? ​

number = 1

normalize coefficient, which is 1 by default

Returns ​

this


toString() ​

toString(): string

Defined in: src/math/Quaternion.ts:457

Returns the value of a quaternion as a string

Returns ​

string


invert() ​

invert(): this

Defined in: src/math/Quaternion.ts:464

Inverts this quaternion in place. Mutates and returns this.

Returns ​

this


clone() ​

clone(): Quaternion

Defined in: src/math/Quaternion.ts:472

Clones the quaternion.

Returns ​

Quaternion

An exact duplicate of the current Quaternion.


transformVector() ​

transformVector(vector): Vector3

Defined in: src/math/Quaternion.ts:479

Rotates vector by this quaternion. Mutates and returns vector.

Parameters ​

vector ​

Vector3

Returns ​

Vector3


copy() ​

copy(q): this

Defined in: src/math/Quaternion.ts:487

Copies the data from a quaternion into this instance.

Parameters ​

q ​

Vector3 | Quaternion

The quaternion to copy from.

Returns ​

this


mul() ​

static mul(lhs, rhs, result?): Quaternion

Defined in: src/math/Quaternion.ts:500

from untiy API op

Parameters ​

lhs ​

Quaternion

rhs ​

Quaternion

result? ​

Quaternion

Returns ​

Quaternion


multiply() ​

static multiply(a, b, result?): Quaternion

Defined in: src/math/Quaternion.ts:516

Canonical static multiply — alias of Quaternion.mul.

Parameters ​

a ​

Quaternion

b ​

Quaternion

result? ​

Quaternion

Returns ​

Quaternion


invert() ​

static invert(src, result?): Quaternion

Defined in: src/math/Quaternion.ts:523

Invert a quaternion.

Parameters ​

src ​

Quaternion

result? ​

Quaternion

Returns ​

Quaternion


transformVector() ​

static transformVector(q, v, result?): Vector3

Defined in: src/math/Quaternion.ts:542

Rotate a Vector3 by a Quaternion.

Parameters ​

q ​

Quaternion

v ​

Vector3

result? ​

Vector3

Returns ​

Vector3


serialize() ​

static serialize(value): Quaternion

Defined in: src/math/Quaternion.ts:569

Returns a new Quaternion copy of the given quaternion, used for serialization.

Parameters ​

value ​

Quaternion

Returns ​

Quaternion


multiplyQuaternions() ​

multiplyQuaternions(a, b): this

Defined in: src/math/Quaternion.ts:577

Set this = a * b. Canonical alias of multiply.

Parameters ​

a ​

Quaternion

b ​

Quaternion

Returns ​

this


premultiply() ​

premultiply(q): this

Defined in: src/math/Quaternion.ts:582

Set this = q * this.

Parameters ​

q ​

Quaternion

Returns ​

this


conjugate() ​

conjugate(): this

Defined in: src/math/Quaternion.ts:587

Conjugate: negate (x, y, z). For a unit quaternion this equals the inverse.

Returns ​

this


dot() ​

dot(q): number

Defined in: src/math/Quaternion.ts:595

Dot product of this quaternion and q.

Parameters ​

q ​

Quaternion

Returns ​

number


lengthSq() ​

lengthSq(): number

Defined in: src/math/Quaternion.ts:600

Squared length (norm) of this quaternion.

Returns ​

number


length() ​

length(): number

Defined in: src/math/Quaternion.ts:605

Length (norm) of this quaternion.

Returns ​

number


equals() ​

equals(q): boolean

Defined in: src/math/Quaternion.ts:610

Returns true if every component of q exactly equals this quaternion.

Parameters ​

q ​

Quaternion

Returns ​

boolean


fromArray() ​

fromArray(array, offset?): this

Defined in: src/math/Quaternion.ts:615

Set x/y/z/w from array starting at offset. Mutates and returns this.

Parameters ​

array ​

ArrayLike<number>

offset? ​

number = 0

Returns ​

this


toArray() ​

toArray(array?, offset?): number[]

Defined in: src/math/Quaternion.ts:624

Write x/y/z/w into array starting at offset and return the array.

Parameters ​

array? ​

number[] = []

offset? ​

number = 0

Returns ​

number[]


setFromUnitVectors() ​

setFromUnitVectors(vFrom, vTo): this

Defined in: src/math/Quaternion.ts:633

Set this = the rotation that takes unit vector vFrom to unit vector vTo.

Parameters ​

vFrom ​

Vector3

vTo ​

Vector3

Returns ​

this


slerpQuaternions() ​

slerpQuaternions(qa, qb, t): this

Defined in: src/math/Quaternion.ts:658

Canonical alias of slerp (qa, qb, t form).

Parameters ​

qa ​

Quaternion

qb ​

Quaternion

t ​

number

Returns ​

this