Matrix4
A 4x4 transformation matrix. Arguments to set() and the constructor are in row-major order; elements is stored in column-major order.
Constructor
const m = new Matrix4() // identity
const m = new Matrix4(n11, n12, n13, n14, ..., n44) // row-major
Properties
elements— Column-majorArray<number>(length 16)isMatrix4— Type flag (true)
Methods
Setting
set(n11..n44)— Set elements (row-major)identity()— Reset to identitycopy(m),clone()copyPosition(m)— Copy only translation componentsetFromMatrix3(m)— Set upper 3x3 from Matrix3setPosition(x, y, z)orsetPosition(vector3)— Set translationfromArray(array, offset?)— Set from column-major array
Arithmetic
multiply(m)— Post-multiplypremultiply(m)— Pre-multiplymultiplyMatrices(a, b)— Multiply two matrices, store resultmultiplyScalar(s)— Scale all elements
Operations
determinant()— Compute determinantinvert()— Invert in-place (zero matrix if det=0)transpose()— Transpose in-placescale(v)— Scale columns by Vector3
Decomposition
extractBasis(xAxis, yAxis, zAxis)— Extract basis vectorsmakeBasis(xAxis, yAxis, zAxis)— Set from basis vectorsextractRotation(m)— Extract rotation (removes scale)compose(position, quaternion, scale)— Build from TRSdecompose(position, quaternion, scale)— Break into TRSgetMaxScaleOnAxis()— Largest axis scale
Factory Methods
makeTranslation(x, y, z)ormakeTranslation(vector3)makeRotationX(theta),makeRotationY(theta),makeRotationZ(theta)makeRotationAxis(axis, angle)— Rotation around arbitrary axismakeRotationFromEuler(euler),makeRotationFromQuaternion(q)makeScale(x, y, z)makeShear(xy, xz, yx, yz, zx, zy)lookAt(eye, target, up)— Look-at rotation
Projection
makePerspective(left, right, top, bottom, near, far, coordinateSystem?, reversedDepth?)makeOrthographic(left, right, top, bottom, near, far, coordinateSystem?, reversedDepth?)
Other
equals(matrix)— Equality testtoArray(array?, offset?)— Write to column-major array