Phaser API Documentation

  Version: 
Filter

A quaternion.

Constructor:

new Quaternion([x], [y], [z], [w])

Parameters:

name type arguments Default description
x number <optional> 0

The x component.

y number <optional> 0

The y component.

z number <optional> 0

The z component.

w number <optional> 1

The w component.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 27)

Members

<private> _w: number
Focus
Focus

Description:

The w component of this Quaternion.

Type:
number
Default: 0
Since: 3.50.0
Source: src/math/Quaternion.js (Line 77)
Focus
Focus
<private> _x: number
Focus
Focus

Description:

The x component of this Quaternion.

Type:
number
Default: 0
Since: 3.50.0
Source: src/math/Quaternion.js (Line 47)
Focus
Focus
<private> _y: number
Focus
Focus

Description:

The y component of this Quaternion.

Type:
number
Default: 0
Since: 3.50.0
Source: src/math/Quaternion.js (Line 57)
Focus
Focus
<private> _z: number
Focus
Focus

Description:

The z component of this Quaternion.

Type:
number
Default: 0
Since: 3.50.0
Source: src/math/Quaternion.js (Line 67)
Focus
Focus
onChangeCallback: function
Focus
Focus

Description:

This callback is invoked, if set, each time a value in this quaternion is changed. The callback is passed one argument, a reference to this quaternion.

Type:
function
Since: 3.50.0
Source: src/math/Quaternion.js (Line 87)
Focus
Focus
w: number
Focus
Focus

Description:

The w component of this Quaternion.

Type:
number
Default: 0
Since: 3.0.0
Source: src/math/Quaternion.js (Line 166)
Focus
Focus
x: number
Focus
Focus

Description:

The x component of this Quaternion.

Type:
number
Default: 0
Since: 3.0.0
Source: src/math/Quaternion.js (Line 100)
Focus
Focus
y: number
Focus
Focus

Description:

The y component of this Quaternion.

Type:
number
Default: 0
Since: 3.0.0
Source: src/math/Quaternion.js (Line 122)
Focus
Focus
z: number
Focus
Focus

Description:

The z component of this Quaternion.

Type:
number
Default: 0
Since: 3.0.0
Source: src/math/Quaternion.js (Line 144)
Focus
Focus

Methods

add(v)
Focus
Focus

Description:

Add a given Quaternion or Vector to this Quaternion. Addition is component-wise.

Parameters:

name type description
v Phaser.Math.Quaternion | Phaser.Math.Vector4

The Quaternion or Vector to add to this Quaternion.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 244)
Focus
Focus
calculateW()
Focus
Focus

Description:

Create a unit (or rotation) Quaternion from its x, y, and z components.

Sets the w component.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 763)
Focus
Focus
conjugate()
Focus
Focus

Description:

Convert this Quaternion into its conjugate.

Sets the x, y and z components.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 652)
Focus
Focus
copy(src)
Focus
Focus

Description:

Copy the components of a given Quaternion or Vector into this Quaternion.

Parameters:

name type description
src Phaser.Math.Quaternion | Phaser.Math.Vector4

The Quaternion or Vector to copy the components from.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 188)
Focus
Focus
dot(v)
Focus
Focus

Description:

Calculate the dot product of this Quaternion and the given Quaternion or Vector.

Parameters:

name type description
v Phaser.Math.Quaternion | Phaser.Math.Vector4

The Quaternion or Vector to dot product with this Quaternion.

Returns:
Description:

The dot product of this Quaternion and the given Quaternion or Vector.

Type:
  • number
Since: 3.0.0
Source: src/math/Quaternion.js (Line 377)
Focus
Focus
fromMat3(mat)
Focus
Focus

Description:

Convert the given Matrix into this Quaternion.

Parameters:

name type description
mat Phaser.Math.Matrix3

The Matrix to convert from.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 968)
Focus
Focus
identity()
Focus
Focus

Description:

Reset this Matrix to an identity (default) Quaternion.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 495)
Focus
Focus
invert()
Focus
Focus

Description:

Invert this Quaternion.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 626)
Focus
Focus
length()
Focus
Focus

Description:

Calculate the length of this Quaternion.

Returns:
Description:

The length of this Quaternion.

Type:
  • number
Since: 3.0.0
Source: src/math/Quaternion.js (Line 310)
Focus
Focus
lengthSq()
Focus
Focus

Description:

Calculate the length of this Quaternion squared.

Returns:
Description:

The length of this Quaternion, squared.

Type:
  • number
Since: 3.0.0
Source: src/math/Quaternion.js (Line 328)
Focus
Focus
lerp(v, [t])
Focus
Focus

Description:

Linearly interpolate this Quaternion towards the given Quaternion or Vector.

Parameters:

name type arguments description
v Phaser.Math.Quaternion | Phaser.Math.Vector4

The Quaternion or Vector to interpolate towards.

t number <optional>

The percentage of interpolation.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 392)
Focus
Focus
multiply(b)
Focus
Focus

Description:

Multiply this Quaternion by the given Quaternion or Vector.

Parameters:

name type description
b Phaser.Math.Quaternion | Phaser.Math.Vector4

The Quaternion or Vector to multiply this Quaternion by.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 533)
Focus
Focus
normalize()
Focus
Focus

Description:

Normalize this Quaternion.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 346)
Focus
Focus
rotateX(rad)
Focus
Focus

Description:

Rotate this Quaternion on the X axis.

Parameters:

name type description
rad number

The rotation angle in radians.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 673)
Focus
Focus
rotateY(rad)
Focus
Focus

Description:

Rotate this Quaternion on the Y axis.

Parameters:

name type description
rad number

The rotation angle in radians.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 703)
Focus
Focus
rotateZ(rad)
Focus
Focus

Description:

Rotate this Quaternion on the Z axis.

Parameters:

name type description
rad number

The rotation angle in radians.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 733)
Focus
Focus
rotationTo(a, b)
Focus
Focus

Description:

Rotates this Quaternion based on the two given vectors.

Parameters:

name type description
a Phaser.Math.Vector3

The transform rotation vector.

b Phaser.Math.Vector3

The target rotation vector.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 420)
Focus
Focus
scale(scale)
Focus
Focus

Description:

Scale this Quaternion by the given value.

Parameters:

name type description
scale number

The value to scale this Quaternion by.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 288)
Focus
Focus
set([x], [y], [z], [w], [update])
Focus
Focus

Description:

Set the components of this Quaternion and optionally call the onChangeCallback.

Parameters:

name type arguments Default description
x number | object <optional> 0

The x component, or an object containing x, y, z, and w components.

y number <optional> 0

The y component.

z number <optional> 0

The z component.

w number <optional> 0

The w component.

update boolean <optional> true

Call the onChangeCallback?

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 203)
Focus
Focus
setAxes(view, right, up)
Focus
Focus

Description:

Set the axes of this Quaternion.

Parameters:

name type description
view Phaser.Math.Vector3

The view axis.

right Phaser.Math.Vector3

The right axis.

up Phaser.Math.Vector3

The upwards axis.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 464)
Focus
Focus
setAxisAngle(axis, rad)
Focus
Focus

Description:

Set the axis angle of this Quaternion.

Parameters:

name type description
axis Phaser.Math.Vector3

The axis.

rad number

The angle in radians.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 508)
Focus
Focus
setFromEuler(euler, [update])
Focus
Focus

Description:

Set this Quaternion from the given Euler, based on Euler order.

Parameters:

name type arguments Default description
euler Phaser.Math.Euler

The Euler to convert from.

update boolean <optional> true

Run the onChangeCallback?

Returns:
Description:

This Quaternion.

Since: 3.50.0
Source: src/math/Quaternion.js (Line 784)
Focus
Focus
setFromRotationMatrix(mat4)
Focus
Focus

Description:

Sets the rotation of this Quaternion from the given Matrix4.

Parameters:

name type description
mat4 Phaser.Math.Matrix4

The Matrix4 to set the rotation from.

Returns:
Description:

This Quaternion.

Since: 3.50.0
Source: src/math/Quaternion.js (Line 893)
Focus
Focus
slerp(b, t)
Focus
Focus

Description:

Smoothly linearly interpolate this Quaternion towards the given Quaternion or Vector.

Parameters:

name type description
b Phaser.Math.Quaternion | Phaser.Math.Vector4

The Quaternion or Vector to interpolate towards.

t number

The percentage of interpolation.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 563)
Focus
Focus
subtract(v)
Focus
Focus

Description:

Subtract a given Quaternion or Vector from this Quaternion. Subtraction is component-wise.

Parameters:

name type description
v Phaser.Math.Quaternion | Phaser.Math.Vector4

The Quaternion or Vector to subtract from this Quaternion.

Returns:
Description:

This Quaternion.

Since: 3.0.0
Source: src/math/Quaternion.js (Line 266)
Focus
Focus