Class: Quaternion

Phaser.Math. Quaternion

A quaternion.


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

Parameters:
Name Type Argument 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


onChangeCallback :function

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)

w :number

The w component of this Quaternion.

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

x :number

The x component of this Quaternion.

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

y :number

The y component of this Quaternion.

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

z :number

The z component of this Quaternion.

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

Methods


add(v)

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.

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

This Quaternion.

Type
Phaser.Math.Quaternion

calculateW()

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

Sets the w component.

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

This Quaternion.

Type
Phaser.Math.Quaternion

conjugate()

Convert this Quaternion into its conjugate.

Sets the x, y and z components.

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

This Quaternion.

Type
Phaser.Math.Quaternion

copy(src)

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.

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

This Quaternion.

Type
Phaser.Math.Quaternion

dot(v)

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.

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

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

Type
number

fromMat3(mat)

Convert the given Matrix into this Quaternion.

Parameters:
Name Type Description
mat Phaser.Math.Matrix3

The Matrix to convert from.

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

This Quaternion.

Type
Phaser.Math.Quaternion

identity()

Reset this Matrix to an identity (default) Quaternion.

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

This Quaternion.

Type
Phaser.Math.Quaternion

invert()

Invert this Quaternion.

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

This Quaternion.

Type
Phaser.Math.Quaternion

length()

Calculate the length of this Quaternion.

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

The length of this Quaternion.

Type
number

lengthSq()

Calculate the length of this Quaternion squared.

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

The length of this Quaternion, squared.

Type
number

lerp(v [, t])

Linearly interpolate this Quaternion towards the given Quaternion or Vector.

Parameters:
Name Type Argument Default Description
v Phaser.Math.Quaternion | Phaser.Math.Vector4

The Quaternion or Vector to interpolate towards.

t number <optional>
0

The percentage of interpolation.

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

This Quaternion.

Type
Phaser.Math.Quaternion

multiply(b)

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.

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

This Quaternion.

Type
Phaser.Math.Quaternion

normalize()

Normalize this Quaternion.

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

This Quaternion.

Type
Phaser.Math.Quaternion

rotateX(rad)

Rotate this Quaternion on the X axis.

Parameters:
Name Type Description
rad number

The rotation angle in radians.

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

This Quaternion.

Type
Phaser.Math.Quaternion

rotateY(rad)

Rotate this Quaternion on the Y axis.

Parameters:
Name Type Description
rad number

The rotation angle in radians.

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

This Quaternion.

Type
Phaser.Math.Quaternion

rotateZ(rad)

Rotate this Quaternion on the Z axis.

Parameters:
Name Type Description
rad number

The rotation angle in radians.

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

This Quaternion.

Type
Phaser.Math.Quaternion

rotationTo(a, b)

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.

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

This Quaternion.

Type
Phaser.Math.Quaternion

scale(scale)

Scale this Quaternion by the given value.

Parameters:
Name Type Description
scale number

The value to scale this Quaternion by.

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

This Quaternion.

Type
Phaser.Math.Quaternion

set( [x] [, y] [, z] [, w] [, update])

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

Parameters:
Name Type Argument 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?

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

This Quaternion.

Type
Phaser.Math.Quaternion

setAxes(view, right, up)

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.

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

This Quaternion.

Type
Phaser.Math.Quaternion

setAxisAngle(axis, rad)

Set the axis angle of this Quaternion.

Parameters:
Name Type Description
axis Phaser.Math.Vector3

The axis.

rad number

The angle in radians.

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

This Quaternion.

Type
Phaser.Math.Quaternion

setFromEuler(euler [, update])

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

Parameters:
Name Type Argument Default Description
euler Phaser.Math.Euler

The Euler to convert from.

update boolean <optional>
true

Run the onChangeCallback?

Since: 3.50.0
Source: src/math/Quaternion.js (Line 784)
Returns:

This Quaternion.

Type
Phaser.Math.Quaternion

setFromRotationMatrix(mat4)

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.

Since: 3.50.0
Source: src/math/Quaternion.js (Line 893)
Returns:

This Quaternion.

Type
Phaser.Math.Quaternion

slerp(b, t)

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.

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

This Quaternion.

Type
Phaser.Math.Quaternion

subtract(v)

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.

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

This Quaternion.

Type
Phaser.Math.Quaternion