Matrix elements in the form of a flat array.
Static
Readonly
IDENTITYA constant matrix set to the identity.
Static
Readonly
ZEROA constant matrix with all elements set to 0.
Copies the contents of a source 4x4 matrix to a destination 4x4 matrix.
A 4x4 matrix to be copied.
Self for chaining.
const src = new pc.Mat4().setFromEulerAngles(10, 20, 30);
const dst = new pc.Mat4();
dst.copy(src);
console.log("The two matrices are " + (src.equals(dst) ? "equal" : "different"));
Reports whether two matrices are equal.
The other matrix.
True if the matrices are equal and false otherwise.
const a = new pc.Mat4().setFromEulerAngles(10, 20, 30);
const b = new pc.Mat4();
console.log("The two matrices are " + (a.equals(b) ? "equal" : "different"));
Extracts the Euler angles equivalent to the rotational portion of the specified matrix. The returned Euler angles are in XYZ order an in degrees.
Optional
eulers: Vec3 = ...A 3-d vector to receive the Euler angles.
A 3-d vector containing the Euler angles.
// Create a 4x4 rotation matrix of 45 degrees around the y-axis
const m = new pc.Mat4().setFromAxisAngle(pc.Vec3.UP, 45);
const eulers = m.getEulerAngles();
Extracts the translational component from the specified 4x4 matrix.
Optional
t: Vec3 = ...The vector to receive the translation of the matrix.
The translation of the specified 4x4 matrix.
// Create a 4x4 matrix
const m = new pc.Mat4();
// Query the translation component
const t = new pc.Vec3();
m.getTranslation(t);
Extracts the x-axis from the specified 4x4 matrix.
Optional
x: Vec3 = ...The vector to receive the x axis of the matrix.
The x-axis of the specified 4x4 matrix.
// Create a 4x4 matrix
const m = new pc.Mat4();
// Query the x-axis component
const x = new pc.Vec3();
m.getX(x);
Extracts the y-axis from the specified 4x4 matrix.
Optional
y: Vec3 = ...The vector to receive the y axis of the matrix.
The y-axis of the specified 4x4 matrix.
// Create a 4x4 matrix
const m = new pc.Mat4();
// Query the y-axis component
const y = new pc.Vec3();
m.getY(y);
Extracts the z-axis from the specified 4x4 matrix.
Optional
z: Vec3 = ...The vector to receive the z axis of the matrix.
The z-axis of the specified 4x4 matrix.
// Create a 4x4 matrix
const m = new pc.Mat4();
// Query the z-axis component
const z = new pc.Vec3();
m.getZ(z);
Sets the matrix to the inverse of a source matrix.
Optional
src: Mat4 = ...The matrix to invert. If not set, the matrix is inverted in-place.
Self for chaining.
// Create a 4x4 rotation matrix of 180 degrees around the y-axis
const rot = new pc.Mat4().setFromAxisAngle(pc.Vec3.UP, 180);
// Invert in place
rot.invert();
Multiplies the current instance by the specified 4x4 matrix.
The 4x4 matrix used as the second multiplicand of the operation.
Self for chaining.
const a = new pc.Mat4().setFromEulerAngles(10, 20, 30);
const b = new pc.Mat4().setFromAxisAngle(pc.Vec3.UP, 180);
// a = a * b
a.mul(b);
console.log("The result of the multiplication is: " + a.toString());
Multiplies the specified 4x4 matrices together and stores the result in the current instance.
Self for chaining.
const a = new pc.Mat4().setFromEulerAngles(10, 20, 30);
const b = new pc.Mat4().setFromAxisAngle(pc.Vec3.UP, 180);
const r = new pc.Mat4();
// r = a * b
r.mul2(a, b);
console.log("The result of the multiplication is: " + r.toString());
Multiplies the specified 4x4 matrices together and stores the result in the current instance. This function assumes the matrices are affine transformation matrices, where the upper left 3x3 elements are a rotation matrix, and the bottom left 3 elements are translation. The rightmost column is assumed to be [0, 0, 0, 1]. The parameters are not verified to be in the expected format. This function is faster than general Mat4#mul2.
Self for chaining.
Sets the specified matrix to a rotation matrix equivalent to a rotation around an axis. The axis must be normalized (unit length) and the angle must be specified in degrees.
The normalized axis vector around which to rotate.
The angle of rotation in degrees.
Self for chaining.
// Create a 4x4 rotation matrix
const rm = new pc.Mat4().setFromAxisAngle(pc.Vec3.UP, 90);
Sets the specified matrix to a rotation matrix defined by Euler angles. The Euler angles are specified in XYZ order and in degrees.
Angle to rotate around X axis in degrees.
Angle to rotate around Y axis in degrees.
Angle to rotate around Z axis in degrees.
Self for chaining.
const m = new pc.Mat4();
m.setFromEulerAngles(45, 90, 180);
Sets the specified matrix to a viewing matrix derived from an eye point, a target point and an up vector. The matrix maps the target point to the negative z-axis and the eye point to the origin, so that when you use a typical projection matrix, the center of the scene maps to the center of the viewport. Similarly, the direction described by the up vector projected onto the viewing plane is mapped to the positive y-axis so that it points upward in the viewport. The up vector must not be parallel to the line of sight from the eye to the reference point.
Self for chaining.
const position = new pc.Vec3(10, 10, 10);
const target = new pc.Vec3(0, 0, 0);
const up = new pc.Vec3(0, 1, 0);
const m = new pc.Mat4().setLookAt(position, target, up);
Sets the specified matrix to an orthographic projection matrix. The function's parameters define the shape of a cuboid-shaped frustum.
The x-coordinate for the left edge of the camera's projection plane in eye space.
The x-coordinate for the right edge of the camera's projection plane in eye space.
The y-coordinate for the bottom edge of the camera's projection plane in eye space.
The y-coordinate for the top edge of the camera's projection plane in eye space.
The near clip plane in eye coordinates.
The far clip plane in eye coordinates.
Self for chaining.
// Create a 4x4 orthographic projection matrix
const ortho = pc.Mat4().ortho(-2, 2, -2, 2, 1, 1000);
Sets the specified matrix to a perspective projection matrix. The function's parameters define the shape of a frustum.
The frustum's field of view in degrees. The fovIsHorizontal parameter controls whether this is a vertical or horizontal field of view. By default, it's a vertical field of view.
The aspect ratio of the frustum's projection plane (width / height).
The near clip plane in eye coordinates.
The far clip plane in eye coordinates.
Optional
fovIsHorizontal: booleanSet to true to treat the fov as horizontal (x-axis) and false for vertical (y-axis). Defaults to false.
Self for chaining.
// Create a 4x4 perspective projection matrix
const persp = pc.Mat4().setPerspective(45, 16 / 9, 1, 1000);
Transforms a 3-dimensional point by a 4x4 matrix.
The input point v transformed by the current instance.
// Create a 3-dimensional point
const v = new pc.Vec3(1, 2, 3);
// Create a 4x4 rotation matrix
const m = new pc.Mat4().setFromEulerAngles(10, 20, 30);
const tv = m.transformPoint(v);
Transforms a 4-dimensional vector by a 4x4 matrix.
The input vector v transformed by the current instance.
// Create an input 4-dimensional vector
const v = new pc.Vec4(1, 2, 3, 4);
// Create an output 4-dimensional vector
const result = new pc.Vec4();
// Create a 4x4 rotation matrix
const m = new pc.Mat4().setFromEulerAngles(10, 20, 30);
m.transformVec4(v, result);
Transforms a 3-dimensional vector by a 4x4 matrix.
The input vector v transformed by the current instance.
// Create a 3-dimensional vector
const v = new pc.Vec3(1, 2, 3);
// Create a 4x4 rotation matrix
const m = new pc.Mat4().setFromEulerAngles(10, 20, 30);
const tv = m.transformVector(v);
A 4x4 matrix.