Mirror Engine
V7
How To
Mirror Engine Logo

Mirror Engine API


Mirror Engine API / Mat3

Class: Mat3

A 3x3 matrix.

Constructors

new Mat3()

new Mat3(): Mat3

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

Returns

Mat3

Properties

data

data: Float32Array<ArrayBufferLike>

Matrix elements in the form of a flat array.


IDENTITY

readonly static IDENTITY: Mat3;

A constant matrix set to the identity.


ZERO

readonly static ZERO: Mat3;

A constant matrix with all elements set to 0.

Methods

clone()

clone(): Mat3

Creates a duplicate of the specified matrix.

Returns

Mat3

A duplicate matrix.

Example

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

copy()

copy(rhs: Mat3): Mat3

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

Parameters

rhs

Mat3

A 3x3 matrix to be copied.

Returns

Mat3

Self for chaining.

Example

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

equals()

equals(rhs: Mat3): boolean

Reports whether two matrices are equal.

Parameters

rhs

Mat3

The other matrix.

Returns

boolean

True if the matrices are equal and false otherwise.

Example

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

getX()

getX(x?: Vec3): Vec3

Extracts the x-axis from the specified matrix.

Parameters

x?

Vec3 = ...

The vector to receive the x axis of the matrix.

Returns

Vec3

The x-axis of the specified matrix.


getY()

getY(y?: Vec3): Vec3

Extracts the y-axis from the specified matrix.

Parameters

y?

Vec3 = ...

The vector to receive the y axis of the matrix.

Returns

Vec3

The y-axis of the specified matrix.


getZ()

getZ(z?: Vec3): Vec3

Extracts the z-axis from the specified matrix.

Parameters

z?

Vec3 = ...

The vector to receive the z axis of the matrix.

Returns

Vec3

The z-axis of the specified matrix.


isIdentity()

isIdentity(): boolean

Reports whether the specified matrix is the identity matrix.

Returns

boolean

True if the matrix is identity and false otherwise.

Example

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

set()

set(src: number[]): Mat3

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

Parameters

src

number[]

An array[9] to be copied.

Returns

Mat3

Self for chaining.

Example

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

setFromMat4()

setFromMat4(m: Mat4): Mat3

Converts the specified 4x4 matrix to a Mat3.

Parameters

m

Mat4

The 4x4 matrix to convert.

Returns

Mat3

Self for chaining.


setFromQuat()

setFromQuat(r: Quat): Mat3

Sets this matrix to the given quaternion rotation.

Parameters

r

Quat

A quaternion rotation.

Returns

Mat3

Self for chaining.

Example

const r = new Quat(1, 2, 3, 4).normalize()

const m = new Mat4()
m.setFromQuat(r)

setIdentity()

setIdentity(): Mat3

Sets the matrix to the identity matrix.

Returns

Mat3

Self for chaining.

Example

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

toString()

toString(): string

Converts the matrix to string form.

Returns

string

The matrix in string form.

Example

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

transformVector()

transformVector(vec: Vec3, res?: Vec3): Vec3

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

Parameters

vec

Vec3

The 3-dimensional vector to be transformed.

res?

Vec3 = ...

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

Returns

Vec3

The input vector v transformed by the current instance.


transpose()

transpose(src?: Mat3): Mat3

Generates the transpose of the specified 3x3 matrix.

Parameters

src?

Mat3 = ...

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

Returns

Mat3

Self for chaining.

Example

const m = new Mat3()

// Transpose in place
m.transpose()
Mirror Engine Logo