Skip to content

Class: Matrix3D

Matrix3D is the representation of a 3x3 matrix. Used for transformations and applying transforms to shapes/objects. Used mainly in collision detection. Inspired by the glMatrix library: https://github.com/toji/gl-matrix

Hierarchy

Implements

Table of contents

Constructors

Properties

Methods

Constructors

constructor

+ new Matrix3D(): Matrix3D

Returns: Matrix3D

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(): Matrix3D

Returns: Matrix3D


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


Recycle

Recycle(): IPoolable

Returns: IPoolable


Rotate

Rotate(angle: number): Matrix3D

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: Matrix3D


RotateDeg

RotateDeg(angle: number): Matrix3D

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: Matrix3D


Scale

Scale(scale: Vector): Matrix3D

Scale applies a scaling vector to the matrix. This is an in-place transformation.

Parameters:

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

Returns: Matrix3D


Set

Set(values: Matrix3DValues): Matrix3D

Parameters:

Name Type
values Matrix3DValues

Returns: Matrix3D


Translate

Translate(translation: Vector): Matrix3D

Translate applies a vector translation to the matrix. This is an in-place transformation.

Parameters:

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

Returns: Matrix3D


Free

StaticFree(obj: Matrix3D): void

Free the provided Matrix4D.

Parameters:

Name Type
obj Matrix3D

Returns: void


Init

StaticInit(size: number): void

Initialize the Matrix4D pool to the size provided.

Parameters:

Name Type
size number

Returns: void


New

StaticNew(): Matrix3D

Create a new Matrix4D, using pooling if available.

Returns: Matrix3D


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