LittleJS 1.30.0

Math3D

Matrix4

4x4 transform matrix for moving, rotating and scaling points in 3D

  • Static builders like Matrix4.translation return a new matrix
  • Methods on a matrix change it in place and return it, so calls can chain
  • a.multiply(b) means b happens first, then a
  • Stored the way WebGL wants it, so it can be sent to a shader as is

Constructor

new Matrix4(m)math3d.js:303

Create a matrix, identity by default

m Float32Array|Array<number> optional

16 column major values

const m = buildMatrix(vec3(0, 1, 0), vec3(0, PI/2, 0)); // rotate then move up
const p = m.transformPoint(vec3(1, 0, 0));

Members

Methods

Members

m : Float32Arraymath3d.js:310

The 16 column major values

Methods

Returns a new matrix that is a copy of this

determinant() → numbermath3d.js:531

Returns the determinant of the rotation and scale part: negative when the matrix mirrors, 0 when it flattens a shape and has no inverse

getRotation() → Vector3math3d.js:550

Returns the rotation part of this matrix as vec3(pitch, yaw, roll), the angles Matrix4.rotation builds it from

  • The scale is divided out first, so it works on a full transform
  • A matrix with shear, from a scaled parent with a turned child, has no exact answer and gets the nearest
getScale() → Vector3math3d.js:539

Returns the scale part of this matrix, the length of each axis; a mirroring matrix shows as a negative x

getTranslation() → Vector3math3d.js:526

Returns the translation part of this matrix

identity() → Matrix4staticmath3d.js:320

Returns a new identity matrix

Flip this matrix so it undoes itself, returns this and does nothing if it cannot be inverted

lookAt(eye, target, up) → Matrix4staticmath3d.js:406

Returns the transform of something at eye turned to face target

  • Invert it to get a view matrix for a camera there
eye Vector3
target Vector3
up Vector3 optional
multiply(matrix) → Matrix4math3d.js:427

Multiply this matrix by another and return this, the other happens first

matrix Matrix4
orthographic(left, right, bottom, top, near, far) → Matrix4staticmath3d.js:384

Returns a new orthographic projection, camera looks down -Z

left number

Edge of the visible box

right number

Edge of the visible box

bottom number

Edge of the visible box

top number

Edge of the visible box

near number

Closest visible distance

far number

Furthest visible distance, Infinity is not allowed here

perspective(fov, aspect, near, far) → Matrix4staticmath3d.js:361

Returns a new perspective projection, camera looks down -Z

fov number

Vertical field of view in radians

aspect number

Width divided by height

near number

Closest visible distance

far number

Furthest visible distance, Infinity is allowed

rotate(euler) → Matrix4math3d.js:445

Append a rotation, returns self

euler Vector3

vec3(pitch, yaw, roll) in radians

rotation(euler, matrix) → Matrix4staticmath3d.js:337

Returns a rotation matrix, rolled first, then pitched, then yawed

euler Vector3

vec3(pitch, yaw, roll) in radians

matrix Matrix4 optional

Written into instead of a new one, for a loop that builds many

Append a scale, returns self

v Vector3
scaling(v) → Matrix4staticmath3d.js:347

Returns a new scale matrix

v Vector3
toString() → stringmath3d.js:567

Returns a string representation of this matrix for debugging

transformDirection(v) → Vector3math3d.js:515

Transform a direction, rotation and scale only

v Vector3
transformPoint(v) → Vector3math3d.js:503

Transform a point, translation included

v Vector3
translate(v) → Matrix4math3d.js:440

Append a translation, returns self

v Vector3
translation(v) → Matrix4staticmath3d.js:325

Returns a new translation matrix

v Vector3
transpose() → Matrix4math3d.js:454

Transpose this matrix in place, returns self