webgl-2d-math

Various 2d math functions.

Methods

(static) multiply(a, b) → {module:webgl-2d-math.Matrix3}

Takes two Matrix3s, a and b, and computes the product in the order
that pre-composes b with a. In other words, the matrix returned will

Parameters:
Name Type Description
a module:webgl-2d-math.Matrix3

A matrix.

b module:webgl-2d-math.Matrix3

A matrix.

Returns:
Type:
module:webgl-2d-math.Matrix3

the result.

(static) project(the, width, height) → {module:webgl-2d-math.Matrix3}

Multiplies by a 2D projection matrix

Parameters:
Name Type Description
the module:webgl-2d-math.Matrix3

matrix to be multiplied

width number

width in pixels

height number

height in pixels

Returns:
Type:
module:webgl-2d-math.Matrix3

the result

(static) projection(width, height) → {module:webgl-2d-math.Matrix3}

Creates a 2D projection matrix

Parameters:
Name Type Description
width number

width in pixels

height number

height in pixels

Returns:
Type:
module:webgl-2d-math.Matrix3

a projection matrix that converts from pixels to clipspace with Y = 0 at the top.

(static) rotate(the, angleInRadians) → {module:webgl-2d-math.Matrix3}

Multiplies by a 2D rotation matrix

Parameters:
Name Type Description
the module:webgl-2d-math.Matrix3

matrix to be multiplied

angleInRadians number

amount to rotate in radians

Returns:
Type:
module:webgl-2d-math.Matrix3

the result

(static) rotation(angleInRadians) → {module:webgl-2d-math.Matrix3}

Creates a 2D rotation matrix

Parameters:
Name Type Description
angleInRadians number

amount to rotate in radians

Returns:
Type:
module:webgl-2d-math.Matrix3

a rotation matrix that rotates by angleInRadians

(static) scale(the, sx, sy) → {module:webgl-2d-math.Matrix3}

Multiplies by a 2D scaling matrix

Parameters:
Name Type Description
the module:webgl-2d-math.Matrix3

matrix to be multiplied

sx number

amount to scale in x

sy number

amount to scale in y

Returns:
Type:
module:webgl-2d-math.Matrix3

the result

(static) scaling(sx, sy) → {module:webgl-2d-math.Matrix3}

Creates a 2D scaling matrix

Parameters:
Name Type Description
sx number

amount to scale in x

sy number

amount to scale in y

Returns:
Type:
module:webgl-2d-math.Matrix3

a scale matrix that scales by sx and sy.

(static) translate(the, tx, ty) → {module:webgl-2d-math.Matrix3}

Multiplies by a 2D translation matrix

Parameters:
Name Type Description
the module:webgl-2d-math.Matrix3

matrix to be multiplied

tx number

amount to translate in x

ty number

amount to translate in y

Returns:
Type:
module:webgl-2d-math.Matrix3

the result

(static) translation(tx, ty) → {module:webgl-2d-math.Matrix3}

Creates a 2D translation matrix

Parameters:
Name Type Description
tx number

amount to translate in x

ty number

amount to translate in y

Returns:
Type:
module:webgl-2d-math.Matrix3

a translation matrix that translates by tx and ty.

Type Definitions

Matrix3

An array or typed array with 9 values.

Type:
  • Array.<number> | TypedArray