API Reference

Class List

Mat3

A 3x3 matrix.

Summary

Static Properties

IDENTITY

A constant matrix set to the identity.[read only]

ZERO

A constant matrix with all elements set to 0.[read only]

Properties

data

Matrix elements in the form of a flat array.

Methods

clone

Creates a duplicate of the specified matrix.

copy

Copies the contents of a source 3x3 matrix to a destination 3x3 matrix.

equals

Reports whether two matrices are equal.

isIdentity

Reports whether the specified matrix is the identity matrix.

set

Copies the contents of a source array[9] to a destination 3x3 matrix.

setFromMat4

Converts the specified 4x4 matrix to a Mat3.

setIdentity

Sets the matrix to the identity matrix.

toString

Converts the matrix to string form.

transformVector

Transforms a 3-dimensional vector by a 3x3 matrix.

transpose

Generates the transpose of the specified 3x3 matrix.

Details

Static Properties

IDENTITY

A constant matrix set to the identity.

[read only]
ZERO

A constant matrix with all elements set to 0.

[read only]

Constructor

Mat3()

Create a new Mat3 instance. It is initialized to the identity matrix.

Properties

Float32Arraydata

Matrix elements in the form of a flat array.

Methods

clone()

Creates a duplicate of the specified matrix.

const src = new pc.Mat3().translate(10, 20, 30);
const dst = src.clone();
console.log("The two matrices are " + (src.equals(dst) ? "equal" : "different"));

Returns

this

A duplicate matrix.

copy(rhs)

Copies the contents of a source 3x3 matrix to a destination 3x3 matrix.

const src = new pc.Mat3().translate(10, 20, 30);
const dst = new pc.Mat3();
dst.copy(src);
console.log("The two matrices are " + (src.equals(dst) ? "equal" : "different"));

Parameters

rhsMat3

A 3x3 matrix to be copied.

Returns

Mat3

Self for chaining.

equals(rhs)

Reports whether two matrices are equal.

const a = new pc.Mat3().translate(10, 20, 30);
const b = new pc.Mat3();
console.log("The two matrices are " + (a.equals(b) ? "equal" : "different"));

Parameters

rhsMat3

The other matrix.

Returns

boolean

True if the matrices are equal and false otherwise.

isIdentity()

Reports whether the specified matrix is the identity matrix.

const m = new pc.Mat3();
console.log("The matrix is " + (m.isIdentity() ? "identity" : "not identity"));

Returns

boolean

True if the matrix is identity and false otherwise.

set(src)

Copies the contents of a source array[9] to a destination 3x3 matrix.

const dst = new pc.Mat3();
dst.set([0, 1, 2, 3, 4, 5, 6, 7, 8]);

Parameters

srcnumber[]

An array[9] to be copied.

Returns

Mat3

Self for chaining.

setFromMat4(m)

Converts the specified 4x4 matrix to a Mat3.

Parameters

mMat4

The 4x4 matrix to convert.

Returns

Mat3

Self for chaining.

setIdentity()

Sets the matrix to the identity matrix.

m.setIdentity();
console.log("The matrix is " + (m.isIdentity() ? "identity" : "not identity"));

Returns

Mat3

Self for chaining.

toString()

Converts the matrix to string form.

const m = new pc.Mat3();
// Outputs [1, 0, 0, 0, 1, 0, 0, 0, 1]
console.log(m.toString());

Returns

string

The matrix in string form.

transformVector(vec, [res])

Transforms a 3-dimensional vector by a 3x3 matrix.

Parameters

vecVec3

The 3-dimensional vector to be transformed.

resVec3

An optional 3-dimensional vector to receive the result of the transformation.

Returns

Vec3

The input vector v transformed by the current instance.

transpose([src])

Generates the transpose of the specified 3x3 matrix.

const m = new pc.Mat3();

// Transpose in place
m.transpose();

Parameters

srcMat3

The matrix to transpose. If not set, the matrix is transposed in-place.

Returns

Mat3

Self for chaining.