Skip to content

Class: Matrix4D

Matrix4D is the representation of a 4x4 matrix. Used for transformations and applying transforms to shapes/objects. Used mainly in the rendering pipeline, as GLSL works best with 4x4 matrices. Inspired by the glMatrix library: https://github.com/toji/gl-matrix

Hierarchy

Implements

Table of contents

Constructors

Properties

Methods

Constructors

constructor

+ new Matrix4D(): Matrix4D

Returns: Matrix4D

Inherited from: Pooled

Properties

data

data: Float32Array


objectInPool

objectInPool: boolean= false

objectInPool is true if an object is made available in the object pool. If it is false it is not currently available in the object pool. This is used to avoid adding the same object to the same object pool multiple times if there are successive calls to free the the same object.

Implementation of: IPoolable.objectInPool

Inherited from: Pooled.objectInPool


pools

Protected Static pools: Map<string, [number, IPoolable[]]>

pools is the global, static mapping of string keys to object pools. An object pool contains two pieces of data, the maximum size of the pool (first value), and the objects that make up the pool as an array (second value).

Inherited from: Pooled.pools

Methods

Blank

Blank(): Matrix4D

Returns: Matrix4D


Free

Free(): void

Free releases an object or it's constituent parts back into any available object pools.

Returns: void

Implementation of: IPoolable


GetFloat32Array

GetFloat32Array(): Float32Array

GetFloat32Array converts the matrix to a WebGL/glMatrix compatible Float32Array

Returns: Float32Array

The array representation of the matrix


Ortho

Ortho(left: number, right: number, bottom: number, top: number, near: number, far: number): Matrix4D

Sets the matrix to be an orthogonal projection matrix. This is an in-place transformation.

Parameters:

Name Type Description
left number Left bound
right number Right bound
bottom number Bottom bound
top number Top bound
near number Near bound
far number Far bound

Returns: Matrix4D


Recycle

Recycle(): IPoolable

Returns: IPoolable


Rotate

Rotate(angle: number): Matrix4D

Rotate applies a radians rotation along the z axis to the matrix (clockwise). This is an in-place transformation.

Parameters:

Name Type Description
angle number The angle in radians to rotate the matrix by

Returns: Matrix4D


RotateDeg

RotateDeg(angle: number): Matrix4D

RotateDeg applies a degrees rotation along the z axis to the matrix (clockwise). This is an in-place transformation.

Parameters:

Name Type Description
angle number The angle in degrees to rotate the matrix by

Returns: Matrix4D


Scale

Scale(scale: Vector): Matrix4D

Scale applies a scaling vector to the matrix. The Z part of the vector is assumed to be 0. This is an in-place transformation.

Parameters:

Name Type Description
scale Vector The vector scaling to apply to the matrix

Returns: Matrix4D


Set

Set(values: Matrix4DValues): Matrix4D

Parameters:

Name Type
values Matrix4DValues

Returns: Matrix4D


Translate

Translate(translation: Vector): Matrix4D

Translate applies a vector translation to the matrix. The Z part of the vector is assumed to be 0. This is an in-place transformation.

Parameters:

Name Type Description
translation Vector The vector transformation to apply to the matrix

Returns: Matrix4D


Free

StaticFree(obj: Matrix4D): void

Free the provided Matrix4D.

Parameters:

Name Type
obj Matrix4D

Returns: void


Init

StaticInit(size: number): void

Initialize the Matrix4D pool to the size provided.

Parameters:

Name Type
size number

Returns: void


New

StaticNew(): Matrix4D

Create a new Matrix4D, using pooling if available.

Returns: Matrix4D


free

Protected Staticfree(poolKey: string, obj: IPoolable): void

free is used to mark a provided object as free in the pool provided. This method can be called multiple times with the same object, it will only add one entry to the pool.

Parameters:

Name Type Description
poolKey string The key of the pool to add the object to.
obj IPoolable The object to add to the pool.

Returns: void

Inherited from: Pooled


init

Protected Staticinit(poolKey: string, emptyGenerator: () => IPoolable, size: number): void

init is used to initialize an object pool to a certain size. This method takes a key of the pool to initialize, an 'empty generator' which is a function that should return an empty/blank instance of the object being pooled which can be overwritten at a later point, and the maximum size of the pool (which it will be initialized to at the start using the empty generator).

Parameters:

Name Type
poolKey string
emptyGenerator () => IPoolable
size number

Returns: void

Inherited from: Pooled


new

Protected Staticnew(poolKey: *string*, type: (...args: *any*) => T, ...args: any): T

new is used to request a new object from the pool specified, if the pool is unavailable or empty it will use the type to provision a new object through a constructor. This is a generic method, it includes a cast to the generic type provided - this cast can fail if the objects returned from the pool are not the type expected.

Type parameters:

Name Type
T IPoolable

Parameters:

Name Type Description
poolKey string The key of the pool to retrieve from.
type (...args: any) => T The fallback constructor to use if the pool is not initialized/empty.
...args any The args to use when creating/recycling the object.

Returns: T

Inherited from: Pooled