Theme:

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-major Array<number> (length 16)
  • isMatrix4 — Type flag (true)

Methods

Setting

  • set(n11..n44) — Set elements (row-major)
  • identity() — Reset to identity
  • copy(m), clone()
  • copyPosition(m) — Copy only translation component
  • setFromMatrix3(m) — Set upper 3x3 from Matrix3
  • setPosition(x, y, z) or setPosition(vector3) — Set translation
  • fromArray(array, offset?) — Set from column-major array

Arithmetic

  • multiply(m) — Post-multiply
  • premultiply(m) — Pre-multiply
  • multiplyMatrices(a, b) — Multiply two matrices, store result
  • multiplyScalar(s) — Scale all elements

Operations

  • determinant() — Compute determinant
  • invert() — Invert in-place (zero matrix if det=0)
  • transpose() — Transpose in-place
  • scale(v) — Scale columns by Vector3

Decomposition

  • extractBasis(xAxis, yAxis, zAxis) — Extract basis vectors
  • makeBasis(xAxis, yAxis, zAxis) — Set from basis vectors
  • extractRotation(m) — Extract rotation (removes scale)
  • compose(position, quaternion, scale) — Build from TRS
  • decompose(position, quaternion, scale) — Break into TRS
  • getMaxScaleOnAxis() — Largest axis scale

Factory Methods

  • makeTranslation(x, y, z) or makeTranslation(vector3)
  • makeRotationX(theta), makeRotationY(theta), makeRotationZ(theta)
  • makeRotationAxis(axis, angle) — Rotation around arbitrary axis
  • makeRotationFromEuler(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 test
  • toArray(array?, offset?) — Write to column-major array