Matrix4
A 4x4 matrix. Any arguments to Matrix4
methods can be plain JavaScript arrays or other math.gl
objects.
Usage
import {Matrix4} from `math.gl`;
Copy a matrix to a Matrix4
so that it can be manipulated (and mutated) with Matrix4
methods:
const IDENTITY = [1, 0, ..., 1];
const m = new Matrix4(IDENTITY).translate([1, 0, 0]);
Create a perspective projection matrix
const projectionMatrix = new Matrix4().perspective({fov, aspect, near, far});
Create an orthograhic projection matrix
Invert a matrix
const inverse = matrix.invert();
Transform a vector as a point (including translations)
const transform = new Matrix4();
const vector2 = transform.transformPoint([0, 0]);
const vector3 = transform.transformPoint([0, 1, 2]);
const vector4 = transform.transformPoint([0, 1, 2, 1]);
Transform a vector as a direction (NOT including translations)
const transform = new Matrix4();
const vector2 = transform.transformDirection([0, 0]);
const vector3 = transform.transformDirection([0, 1, 2]);
const vector4 = transform.transformDirection([0, 1, 2, 1]);
Inheritance
class Matrix4 extends
Matrix
extends
MathArray
extends
Array
`
Many basic methods are inherited:
matrix4.clone()
matrix4.copy(array)
matrix4.set(...args)
matrix4.fromArray(array, offset = 0)
matrix4.toString()
matrix4.toArray(array = [], offset = 0)
matrix4.equals(array)
matrix4.exactEquals(array)
matrix4.validate(array = this)
matrix4.check(array = this)
matrix4.normalize()
Since Matrix4
is a subclass of the built in JavaScript Array
it can be used directly as a parameter to any function expecting an Array
.
Methods
constructor()
Creates an empty Matrix4
new Matrix4()