Phaser API Documentation

  Version: 
Filter

A four-dimensional matrix.

Adapted from gl-matrix by toji and vecmath by mattdesl

Constructor:

new Matrix4([m])

Parameters:

name type arguments description
m Phaser.Math.Matrix4 <optional>

Optional Matrix4 to copy values from.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 15)

Members

val: Float32Array
Focus
Focus

Description:

The matrix values.

Type:
Float32Array
Since: 3.0.0
Source: src/math/Matrix4.js (Line 35)
Focus
Focus

Methods

adjoint()
Focus
Focus

Description:

Calculate the adjoint, or adjugate, of this Matrix.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 418)
Focus
Focus
clone()
Focus
Focus

Description:

Make a clone of this Matrix4.

Returns:
Description:

A clone of this Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 56)
Focus
Focus
copy(src)
Focus
Focus

Description:

Copy the values of a given Matrix into this Matrix.

Parameters:

name type description
src Phaser.Math.Matrix4

The Matrix to copy the values from.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 133)
Focus
Focus
determinant()
Focus
Focus

Description:

Calculate the determinant of this Matrix.

Returns:
Description:

The determinant of this Matrix.

Type:
  • number
Since: 3.0.0
Source: src/math/Matrix4.js (Line 470)
Focus
Focus
fromArray(a)
Focus
Focus

Description:

Set the values of this Matrix from the given array.

Parameters:

name type description
a Array.<number>

The array to copy the values from. Must have at least 16 elements.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 150)
Focus
Focus
fromQuat(q)
Focus
Focus

Description:

Set the values of this Matrix from the given Quaternion.

Parameters:

name type description
q Phaser.Math.Quaternion

The Quaternion to set the values of this Matrix from.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 1105)
Focus
Focus
fromRotationTranslation(q, v)
Focus
Focus

Description:

Set the values of this Matrix from the given rotation Quaternion and translation Vector.

Parameters:

name type description
q Phaser.Math.Quaternion

The Quaternion to set rotation from.

v Phaser.Math.Vector3

The Vector to set translation from.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 1047)
Focus
Focus
fromRotationXYTranslation(rotation, position, translateFirst)
Focus
Focus

Description:

Takes the rotation and position vectors and builds this Matrix4 from them.

Parameters:

name type description
rotation Phaser.Math.Vector3

The rotation vector.

position Phaser.Math.Vector3

The position vector.

translateFirst boolean

Should the operation translate then rotate (true), or rotate then translate? (false)

Returns:
Description:

This Matrix4.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 1670)
Focus
Focus
frustum(left, right, bottom, top, near, far)
Focus
Focus

Description:

Generate a frustum matrix with the given bounds.

Parameters:

name type description
left number

The left bound of the frustum.

right number

The right bound of the frustum.

bottom number

The bottom bound of the frustum.

top number

The top bound of the frustum.

near number

The near bound of the frustum.

far number

The far bound of the frustum.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 1161)
Focus
Focus
getInverse(m)
Focus
Focus

Description:

Copies the given Matrix4 into this Matrix and then inverses it.

Parameters:

name type description
m Phaser.Math.Matrix4

The Matrix4 to invert into this Matrix4.

Returns:
Description:

This Matrix4.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 324)
Focus
Focus
getMaxScaleOnAxis()
Focus
Focus

Description:

Returns the maximum axis scale from this Matrix4.

Returns:
Description:

The maximum axis scale.

Type:
  • number
Since: 3.50.0
Source: src/math/Matrix4.js (Line 1741)
Focus
Focus
identity()
Focus
Focus

Description:

Reset this Matrix to an identity (default) matrix.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 276)
Focus
Focus
invert()
Focus
Focus

Description:

Invert this Matrix.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 341)
Focus
Focus
lookAt(eye, center, up)
Focus
Focus

Description:

Generate a look-at matrix with the given eye position, focal point, and up axis.

Parameters:

name type description
eye Phaser.Math.Vector3

Position of the viewer

center Phaser.Math.Vector3

Point the viewer is looking at

up Phaser.Math.Vector3

vec3 pointing up.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 1393)
Focus
Focus
lookAtRH(eye, target, up)
Focus
Focus

Description:

Generate a right-handed look-at matrix with the given eye position, target and up axis.

Parameters:

name type description
eye Phaser.Math.Vector3

Position of the viewer.

target Phaser.Math.Vector3

Point the viewer is looking at.

up Phaser.Math.Vector3

vec3 pointing up.

Returns:
Description:

This Matrix4.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 1333)
Focus
Focus
makeRotationAxis(axis, angle)
Focus
Focus

Description:

Derive a rotation matrix around the given axis.

Parameters:

name type description
axis Phaser.Math.Vector3 | Phaser.Math.Vector4

The rotation axis.

angle number

The rotation angle in radians.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 814)
Focus
Focus
multiply(src)
Focus
Focus

Description:

Multiply this Matrix by the given Matrix.

Parameters:

name type description
src Phaser.Math.Matrix4

The Matrix to multiply this Matrix by.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 519)
Focus
Focus
multiplyLocal(src)
Focus
Focus

Description:

Multiply the values of this Matrix4 by those given in the src argument.

Parameters:

name type description
src Phaser.Math.Matrix4

The source Matrix4 that this Matrix4 is multiplied by.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 599)
Focus
Focus
multiplyMatrices(a, b)
Focus
Focus

Description:

Multiplies the two given Matrix4 objects and stores the results in this Matrix.

Parameters:

name type description
a Phaser.Math.Matrix4

The first Matrix4 to multiply.

b Phaser.Math.Matrix4

The second Matrix4 to multiply.

Returns:
Description:

This Matrix4.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 654)
Focus
Focus
multiplyToMat4(src, out)
Focus
Focus

Description:

Multiplies this Matrix4 by the given src Matrix4 and stores the results in the out Matrix4.

Parameters:

name type description
src Phaser.Math.Matrix4

The Matrix4 to multiply with this one.

out Phaser.Math.Matrix4

The receiving Matrix.

Returns:
Description:

This out Matrix4.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 1597)
Focus
Focus
ortho(left, right, bottom, top, near, far)
Focus
Focus

Description:

Generate an orthogonal projection matrix with the given bounds.

Parameters:

name type description
left number

The left bound of the frustum.

right number

The right bound of the frustum.

bottom number

The bottom bound of the frustum.

top number

The top bound of the frustum.

near number

The near bound of the frustum.

far number

The far bound of the frustum.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 1284)
Focus
Focus
perspective(fovy, aspect, near, far)
Focus
Focus

Description:

Generate a perspective projection matrix with the given bounds.

Parameters:

name type description
fovy number

Vertical field of view in radians

aspect number

Aspect ratio. Typically viewport width /height.

near number

Near bound of the frustum.

far number

Far bound of the frustum.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 1205)
Focus
Focus
perspectiveLH(width, height, near, far)
Focus
Focus

Description:

Generate a perspective projection matrix with the given bounds.

Parameters:

name type description
width number

The width of the frustum.

height number

The height of the frustum.

near number

Near bound of the frustum.

far number

Far bound of the frustum.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 1246)
Focus
Focus
premultiply(m)
Focus
Focus

Description:

Multiplies the given Matrix4 object with this Matrix.

This is the same as calling multiplyMatrices(m, this).

Parameters:

name type description
m Phaser.Math.Matrix4

The Matrix4 to multiply with this one.

Returns:
Description:

This Matrix4.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 637)
Focus
Focus
rotate(rad, axis)
Focus
Focus

Description:

Apply a rotation transformation to this Matrix.

Parameters:

name type description
rad number

The angle in radians to rotate by.

axis Phaser.Math.Vector3

The axis to rotate upon.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 846)
Focus
Focus
rotateX(rad)
Focus
Focus

Description:

Rotate this matrix on its X axis.

Parameters:

name type description
rad number

The angle in radians to rotate by.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 930)
Focus
Focus
rotateY(rad)
Focus
Focus

Description:

Rotate this matrix on its Y axis.

Parameters:

name type description
rad number

The angle to rotate by, in radians.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 969)
Focus
Focus
rotateZ(rad)
Focus
Focus

Description:

Rotate this matrix on its Z axis.

Parameters:

name type description
rad number

The angle to rotate by, in radians.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 1008)
Focus
Focus
scale(v)
Focus
Focus

Description:

Apply a scale transformation to this Matrix.

Uses the x, y and z components of the given Vector to scale the Matrix.

Parameters:

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

The Vector to scale this Matrix with.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 763)
Focus
Focus
scaleXYZ(x, y, z)
Focus
Focus

Description:

Apply a scale transformation to this Matrix.

Parameters:

name type description
x number

The x component.

y number

The y component.

z number

The z component.

Returns:
Description:

This Matrix4.

Since: 3.16.0
Source: src/math/Matrix4.js (Line 780)
Focus
Focus
scaling(x, y, z)
Focus
Focus

Description:

Set the scaling values of this Matrix.

Parameters:

name type description
x number

The x scaling value.

y number

The y scaling value.

z number

The z scaling value.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 250)
Focus
Focus
set(src)
Focus
Focus

Description:

This method is an alias for Matrix4.copy.

Parameters:

name type description
src Phaser.Math.Matrix4

The Matrix to set the values of this Matrix's from.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 69)
Focus
Focus
setValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33)
Focus
Focus

Description:

Sets all values of this Matrix4.

Parameters:

name type description
m00 number

The m00 value.

m01 number

The m01 value.

m02 number

The m02 value.

m03 number

The m03 value.

m10 number

The m10 value.

m11 number

The m11 value.

m12 number

The m12 value.

m13 number

The m13 value.

m20 number

The m20 value.

m21 number

The m21 value.

m22 number

The m22 value.

m23 number

The m23 value.

m30 number

The m30 value.

m31 number

The m31 value.

m32 number

The m32 value.

m33 number

The m33 value.

Returns:
Description:

This Matrix4 instance.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 84)
Focus
Focus
setWorldMatrix(rotation, position, scale, [viewMatrix], [projectionMatrix])
Focus
Focus

Description:

Generate a world matrix from the given rotation, position, scale, view matrix and projection matrix.

Parameters:

name type arguments description
rotation Phaser.Math.Vector3

The rotation of the world matrix.

position Phaser.Math.Vector3

The position of the world matrix.

scale Phaser.Math.Vector3

The scale of the world matrix.

viewMatrix Phaser.Math.Matrix4 <optional>

The view matrix.

projectionMatrix Phaser.Math.Matrix4 <optional>

The projection matrix.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 1560)
Focus
Focus
transform(position, scale, rotation)
Focus
Focus

Description:

Generates a transform matrix based on the given position, scale and rotation.

Parameters:

name type description
position Phaser.Math.Vector3

The position vector.

scale Phaser.Math.Vector3

The scale vector.

rotation Phaser.Math.Quaternion

The rotation quaternion.

Returns:
Description:

This Matrix4.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 180)
Focus
Focus
translate(v)
Focus
Focus

Description:

Translate this Matrix using the given Vector.

Parameters:

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

The Vector to translate this Matrix with.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 724)
Focus
Focus
translateXYZ(x, y, z)
Focus
Focus

Description:

Translate this Matrix using the given values.

Parameters:

name type description
x number

The x component.

y number

The y component.

z number

The z component.

Returns:
Description:

This Matrix4.

Since: 3.16.0
Source: src/math/Matrix4.js (Line 739)
Focus
Focus
transpose()
Focus
Focus

Description:

Transpose this Matrix.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 289)
Focus
Focus
xyz(x, y, z)
Focus
Focus

Description:

Set the x, y and z values of this Matrix.

Parameters:

name type description
x number

The x value.

y number

The y value.

z number

The z value.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 225)
Focus
Focus
yawPitchRoll(yaw, pitch, roll)
Focus
Focus

Description:

Set the values of this matrix from the given yaw, pitch and roll values.

Parameters:

name type description
yaw number

The yaw value.

pitch number

The pitch value.

roll number

The roll value.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 1499)
Focus
Focus
zero()
Focus
Focus

Description:

Reset this Matrix.

Sets all values to 0.

Returns:
Description:

This Matrix4.

Since: 3.0.0
Source: src/math/Matrix4.js (Line 165)
Focus
Focus