Creates a new Matrix4, defaulting to the identity matrix
Optionalelements: TypedFixedArray<16>
Optional column-major Float32Array of 16 floats, used as is rather than
copied. Its byte offset must be a multiple of 8, or this throws, since
Matrix4#elements64 views the same memory.
AdvancedarrayThe array Matrix4#toArray writes into when given no out; null until its first call
The sixteen values, column by column: the translation sits at indices 12, 13 and 14
Advancedelements64A Float64Array over the same memory as Matrix4#elements, for copying the matrix as
eight 64-bit moves instead of sixteen 32-bit ones
Each entry is two of the matrix's floats read as one 64-bit number, which means
nothing on its own. Use it only to copy into another Float64Array view of float data.
StaticIDENTITYA read-only identity matrix
This is a shared instance; do not mutate it. Use Matrix4.shared when you need a writable temporary.
StaticsharedA shared Matrix4, reset to identity on every access, for a one-off calculation
This matrix is shared and temporary. Do not store references to it.
Pixi-style alias for Matrix4#multiply: this = this * m
The matrix the result was written to
Alias for Matrix4#multiplyMatrices: this matrix becomes a * b
The matrix the result was written to
Composes this matrix from a translation, rotation and scale
A point is scaled first, then rotated, then moved: the order a Container3D builds its Container3D#localTransform in.
Translation component
Rotation component
Scale component
Optional target; defaults to writing into this matrix
The matrix the result was written to
Copies the elements of m into this matrix
Matrix to copy from
This matrix
Splits this matrix into a translation, rotation and scale
A mirroring matrix (negative determinant) comes back with a negative X scale, so the rotation stays a rotation. A sheared matrix has no exact split; the result only approximates it.
Receives the translation component
Receives the rotation component
Receives the scale component
Matrix that receives a copy of this one first; decomposing changes no matrix
out, which is this matrix when omitted
Checks whether all 16 elements of this matrix match m exactly, with no tolerance
Matrix to compare against
True when every element matches
Writes the three basis vectors of this matrix into xAxis, yAxis and zAxis
They are the first three columns: the matrix's own axes, scale included.
The matrix the basis was read from
Writes the negated Z column (forward direction, length 1) into out
That is the way a Camera3D or a light faces. Other Container3Ds, such as meshes, face +Z, so for them this points backwards.
Point that receives the direction
The given output point
Writes the translation column into out
Point that receives the translation
The given output point
Writes the X column (right direction, length 1) into out
Point that receives the direction
The given output point
Sets this matrix to m with each axis scaled to unit length and the translation cleared
That removes only the scale: a mirroring matrix (negative determinant) gives a mirrored result, and shear stays.
The matrix the result was written to
Writes the per-axis scale (column magnitudes) into out
The lengths are never negative, so a mirrored axis reads as a positive scale; Matrix4#decompose reports the mirror.
Point that receives the scale
The given output point
Writes the Y column (up direction, length 1) into out
Point that receives the direction
The given output point
Sets this matrix to the inverse of m
When m can't be inverted (its determinant is 0), the result is the identity and a warning is
logged.
The matrix the result was written to
Computes the largest of the three axis scales: the length of the longest of the first three columns
Scaling a bounding radius by it covers rotation and per-axis scale. Under shear, as when a non-uniformly scaled parent holds a rotated child, the matrix can stretch some other direction further; Matrix4#getMaxSingularValueSq measures that.
The largest axis scale
Largest singular value of the upper-left 3x3, squared: the square of the most this matrix stretches any direction
A bounding radius scaled by its square root covers the transformed shape even under shear, where Matrix4#getMaxScaleOnAxis can fall short; without shear, it's the square of that. It comes back squared so a comparison against squared distances skips a square root.
Sets this matrix's rotation so its -Z axis points from eye toward target, with its +Y axis
as close to up as it can be
That turns a camera at eye to face target. Only the rotation part is written; the
translation and bottom row stay (copied into out first when it is another matrix). Set the
position and invert the result to get the camera's view matrix. When up lies along the view
direction, the direction is nudged slightly so the result is still a rotation.
Viewer position
Point to look toward
Up direction
Optional target; defaults to writing into this matrix
The matrix the result was written to
Sets this matrix using the three basis vectors as its columns, with no translation
Unit-length axes at right angles to each other make a rotation when zAxis is xAxis cross
yAxis, and a mirror when it points the other way.
X basis vector
Y basis vector
Z basis vector
This matrix
Sets this matrix to an orthographic projection of the box between the given planes, for a camera looking down -Z
top comes before bottom in the arguments. Clip-space depth runs from -1 at near to 1 at
far, as with Matrix4#makePerspective.
Left clip plane
Right clip plane
Top clip plane
Bottom clip plane
Near clip distance
Far clip distance
This matrix
Sets this matrix to a perspective projection from a vertical field-of-view (radians), for a camera looking down -Z
Clip-space depth runs from -1 at near to 1 at far, as WebGL expects, and
Camera3D#projection is built the same way. On WebGPU, whose depth runs from 0 to 1, the
renderer remaps the copy it draws with, but a matrix you bind yourself, the camera's included,
needs the same remap. fovy is in radians, unlike Camera3D#fov, which is in degrees.
Vertical field-of-view in radians
Viewport width / height
Near clip distance
Optionalfar: number
Far clip distance; leave it out or pass Infinity for no far plane
This matrix
Sets this matrix to a rotation of angle radians around axis
Positive angles turn counter-clockwise as seen from the tip of axis, like the single-axis
methods.
Unit-length rotation axis
Rotation angle in radians
This matrix
Sets this matrix to a rotation derived from XYZ Euler angles in rotation (radians)
The matrix is Rx * Ry * Rz, the convention Container3D#rotation and
Quaternion#setFromEuler use, so the same angles give the same orientation.
Euler angles in radians
This matrix
Sets this matrix to a rotation derived from the quaternion q
Rotation quaternion
This matrix
Sets this matrix to a shear, where each factor adds that multiple of a point's coordinate on its axis to the point's other two coordinates
With y = 0.2, a point 1 unit up moves 0.2 along both x and z. To shear one axis only, write
the matrix with Matrix4#set.
How much a point's x adds to its y and z
How much a point's y adds to its x and z
How much a point's z adds to its x and y
This matrix
Advanced
Multiplies every element of this matrix by the scalar s
Scalar to multiply by
Optional target; defaults to writing into this matrix
The matrix the result was written to
Pixi-style alias for Matrix4#premultiply: this = m * this
The matrix the result was written to
Scales this matrix along its own axes by (v.x, v.y, v.z)
Multiplies the first three columns, which is the same as multiplying by Matrix4#makeScale on the right: the scale applies to a point first.
Per-axis scale factors
Optional target; defaults to writing into this matrix
The matrix the result was written to
Sets the 16 elements from arguments given row by row, as the matrix is written on paper
Row 1, column 1
Row 1, column 2
Row 1, column 3
Row 1, column 4
Row 2, column 1
Row 2, column 2
Row 2, column 3
Row 2, column 4
Row 3, column 1
Row 3, column 2
Row 3, column 3
Row 3, column 4
Row 4, column 1
Row 4, column 2
Row 4, column 3
Row 4, column 4
This matrix
Writes (v.x, v.y, v.z) into the translation column of this matrix, leaving the rest intact
Position to write
Optional target; defaults to writing into this matrix
The matrix the result was written to
Writes this matrix's elements into a Float32Array
Without out, writes into and returns Matrix4#array.
Optionaltranspose: boolean
true writes row-major instead of column-major
Optionalout: Float32Array<ArrayBufferLike>
Optional destination array
The populated array
Advanced
Formats this matrix as a readable row-by-row string
The string representation
Transposes this matrix
Optional target; defaults to writing into this matrix
The matrix the result was written to
StaticmultiplyAdvanced
Multiplies two affine matrices held in flat arrays, out = a * b, skipping the bottom row
Reads only the top three rows of a and b and writes 0, 0, 0, 1 as the bottom row, so it
does 36 multiplies where a full 4x4 product does 64. out may be the same array as a or b.
Buffer receiving the product
Index of the product's first element in out
Buffer holding the left operand
Index of the left operand's first element in a
Buffer holding the right operand
Index of the right operand's first element in b
StaticmultiplyAdvanced
Multiplies two affine matrices, out = a * b, and writes the result as three rows of four
The rows land as [m00 m01 m02 m03][m10 m11 m12 m13][m20 m21 m22 m23], translation last in
each, so a shader can read them as three vec4s and transform a point with three dot products.
The bottom rows of a and b are never read.
Destination, 12 floats per entry.
Float offset of the destination entry.
Left operand, 16 floats per entry (column-major).
Float offset of the left entry.
Right operand, 16 floats per entry (column-major).
Float offset of the right entry.
A 4x4 matrix for 3D transforms and projections
Matrix4#elements holds the sixteen values column by column, the order shaders use, and a
Matrix4can be the value of amat4x4<f32>uniform as it is. Points are columns, so ina * bthe matrixbapplies to a point first:projection * view * worldtakes a point on a model to clip space.Methods that change the matrix do so in place, or write into an
outmatrix when you pass one and leave this matrix as it is.Example
See
Vector3#applyMatrix4 For applying this matrix to a point