Class: Matrix4

Phaser.Math. Matrix4

A four-dimensional matrix.

Adapted from gl-matrix by toji and vecmath by mattdesl


new Matrix4( [m])

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

The matrix values.

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

Methods


adjoint()

Calculate the adjoint, or adjugate, of this Matrix.

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

This Matrix4.

Type
Phaser.Math.Matrix4

clone()

Make a clone of this Matrix4.

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

A clone of this Matrix4.

Type
Phaser.Math.Matrix4

copy(src)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

determinant()

Calculate the determinant of this Matrix.

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

The determinant of this Matrix.

Type
number

fromArray(a)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

fromQuat(q)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

fromRotationTranslation(q, v)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

fromRotationXYTranslation(rotation, position, translateFirst)

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)

Since: 3.50.0
Source: src/math/Matrix4.js (Line 1670)
Returns:

This Matrix4.

Type
Phaser.Math.Matrix4

frustum(left, right, bottom, top, near, far)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

getInverse(m)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

getMaxScaleOnAxis()

Returns the maximum axis scale from this Matrix4.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 1741)
Returns:

The maximum axis scale.

Type
number

identity()

Reset this Matrix to an identity (default) matrix.

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

This Matrix4.

Type
Phaser.Math.Matrix4

invert()

Invert this Matrix.

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

This Matrix4.

Type
Phaser.Math.Matrix4

lookAt(eye, center, up)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

lookAtRH(eye, target, up)

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.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 1333)
Returns:

This Matrix4.

Type
Phaser.Math.Matrix4

makeRotationAxis(axis, angle)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

multiply(src)

Multiply this Matrix by the given Matrix.

Parameters:
Name Type Description
src Phaser.Math.Matrix4

The Matrix to multiply this Matrix by.

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

This Matrix4.

Type
Phaser.Math.Matrix4

multiplyLocal(src)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

multiplyMatrices(a, b)

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.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 654)
Returns:

This Matrix4.

Type
Phaser.Math.Matrix4

multiplyToMat4(src, out)

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.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 1597)
Returns:

This out Matrix4.

Type
Phaser.Math.Matrix4

ortho(left, right, bottom, top, near, far)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

perspective(fovy, aspect, near, far)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

perspectiveLH(width, height, near, far)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

premultiply(m)

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.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 637)
Returns:

This Matrix4.

Type
Phaser.Math.Matrix4

rotate(rad, axis)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

rotateX(rad)

Rotate this matrix on its X axis.

Parameters:
Name Type Description
rad number

The angle in radians to rotate by.

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

This Matrix4.

Type
Phaser.Math.Matrix4

rotateY(rad)

Rotate this matrix on its Y axis.

Parameters:
Name Type Description
rad number

The angle to rotate by, in radians.

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

This Matrix4.

Type
Phaser.Math.Matrix4

rotateZ(rad)

Rotate this matrix on its Z axis.

Parameters:
Name Type Description
rad number

The angle to rotate by, in radians.

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

This Matrix4.

Type
Phaser.Math.Matrix4

scale(v)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

scaleXYZ(x, y, z)

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.

Since: 3.16.0
Source: src/math/Matrix4.js (Line 780)
Returns:

This Matrix4.

Type
Phaser.Math.Matrix4

scaling(x, y, z)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

set(src)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

setValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33)

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.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 84)
Returns:

This Matrix4 instance.

Type
Phaser.Math.Matrix4

setWorldMatrix(rotation, position, scale [, viewMatrix] [, projectionMatrix])

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

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

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

This Matrix4.

Type
Phaser.Math.Matrix4

transform(position, scale, rotation)

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.

Since: 3.50.0
Source: src/math/Matrix4.js (Line 180)
Returns:

This Matrix4.

Type
Phaser.Math.Matrix4

translate(v)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

translateXYZ(x, y, z)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

transpose()

Transpose this Matrix.

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

This Matrix4.

Type
Phaser.Math.Matrix4

xyz(x, y, z)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

yawPitchRoll(yaw, pitch, roll)

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.

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

This Matrix4.

Type
Phaser.Math.Matrix4

zero()

Reset this Matrix.

Sets all values to 0.

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

This Matrix4.

Type
Phaser.Math.Matrix4