Zia.Matrix4 Class

Represents a 4x4 matrix. The elements are stored in a Float32Array in column-major order to optimise handoff to WebGL.

Constructor

Name Description
Matrix4 Constructs a new 4x4 matrix.

Properties

Name Description
elements

The matrix elements.

Methods

Name Description
clone

Duplicates the current Matrix4 instance.

createFromAxisAngle static

Creates a matrix that can be used to rotate vectors around an arbitrary axis.

createIdentity static

Creates an identity matrix.

createOrthographicOffCenter static

Creates an orthographic projection matrix.

createRotationX static

Creates a matrix that can be used to rotate vectors around the x-axis.

createRotationY static

Creates a matrix that can be used to rotate vectors around the y-axis.

createRotationZ static

Creates a matrix that can be used to rotate vectors around the z-axis.

createScale static

Creates a scaling matrix.

createTranslation static

Creates a matrix that can be used to translate vectors.

createUniformScale static

Creates a uniform scaling matrix.

decompose

Extracts the scale, rotation, and translation components of the current Matrix4 instance. Assumes this is a transform matrix.

determinant

Calculates the determinant of the current Matrix4 instance.

getTranslation

Gets the translation component of the current transformation matrix.

invert static

Inverts a matrix. If the determinant is zero, then the matrix cannot be inverted and an exception will be thrown.

multiply static

Multiplies a matrix by another matrix.

multiplyByScalar static

Multiplies a matrix by a scalar value.

setTranslation

Sets the translation component of the current transformation matrix.

transpose static

Transposes a matrix.


Constructor

new Zia.Matrix4 (m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) constructor

Defined in Matrix4.js:59

Constructs a new 4x4 matrix. Parameters are supplied in row-major order to aid readability. If called with no parameters, all matrix elements are initialised to 0. If called with any parameters, make sure you supply all 16 values.

Parameters

Name Type Description
m11 Number optional

The value for row 0, column 0.

Defaults to 0.0.
m12 Number optional

The value for row 0, column 1.

Defaults to 0.0.
m13 Number optional

The value for row 0, column 2.

Defaults to 0.0.
m14 Number optional

The value for row 0, column 3.

Defaults to 0.0.
m21 Number optional

The value for row 1, column 0.

Defaults to 0.0.
m22 Number optional

The value for row 1, column 1.

Defaults to 0.0.
m23 Number optional

The value for row 1, column 2.

Defaults to 0.0.
m24 Number optional

The value for row 1, column 3.

Defaults to 0.0.
m31 Number optional

The value for row 2, column 0.

Defaults to 0.0.
m32 Number optional

The value for row 2, column 1.

Defaults to 0.0.
m33 Number optional

The value for row 2, column 2.

Defaults to 0.0.
m34 Number optional

The value for row 2, column 3.

Defaults to 0.0.
m41 Number optional

The value for row 3, column 0.

Defaults to 0.0.
m42 Number optional

The value for row 3, column 1.

Defaults to 0.0.
m43 Number optional

The value for row 3, column 2.

Defaults to 0.0.
m44 Number optional

The value for row 3, column 3.

Defaults to 0.0.

Properties

elements Float32Array property

Defined in Matrix4.js:81

The matrix elements.


Methods

clone (result) → Zia.Matrix4 method

Defined in Matrix4.js:785

Duplicates the current Matrix4 instance.

Parameters

Name Type Description
result Zia.Matrix4

The object in which to store the result.

Returns

Zia.Matrix4 -

The modified result parameter.

createFromAxisAngle (axis, angle, result) → Zia.Matrix4 method static

Defined in Matrix4.js:199

Creates a matrix that can be used to rotate vectors around an arbitrary axis.

Parameters

Name Type Description
axis Zia.Vector3

The axis to rotate around.

angle Number

The amount, in radians, by which to rotate around the vector.

result Zia.Matrix4

The object in which to place the calculated result.

Returns

Zia.Matrix4 -

The modified result parameter.

Example

var result = Zia.Matrix4.createFromAxisAngle(
  new Zia.Vector3(1, 0, 1).normalize(), Math.PI,
  new Zia.Matrix4());

createIdentity (result) → Zia.Matrix4 method static

Defined in Matrix4.js:390

Creates an identity matrix.

Parameters

Name Type Description
result Zia.Matrix4

The object in which to place the calculated result.

Returns

Zia.Matrix4 -

The modified result parameter.

Example

var result = Zia.Matrix4.createIdentity(new Zia.Matrix4());

createOrthographicOffCenter (left, right, bottom, top, near, far, result) → Zia.Matrix4 method static

Defined in Matrix4.js:294

Creates an orthographic projection matrix.

Parameters

Name Type Description
left Number

The minimum x value of the view volume.

right Number

The maximum x value of the view volume.

bottom Number

The minimum y value of the view volume.

top Number

The maximum y value of the view volume.

near Number

The minimum z value of the view volume.

far Number

The maximum z value of the view volume.

result Zia.Matrix4

The object in which to place the calculated result.

Returns

Zia.Matrix4 -

The modified result parameter.

Example

var result = Zia.Matrix4.createOrthographicOffCenter(
  -100, 100, -40, 40, -100, 100,
  new Zia.Matrix4());

createRotationX (angle, result) → Zia.Matrix4 method static

Defined in Matrix4.js:130

Creates a matrix that can be used to rotate vectors around the x-axis.

Parameters

Name Type Description
angle Number

The amount, in radians, by which to rotate around the x-axis.

result Zia.Matrix4

The object in which to place the calculated result.

Returns

Zia.Matrix4 -

The modified result parameter.

Example

var result = Zia.Matrix4.createRotationX(Math.PI, new Zia.Matrix4());

createRotationY (angle, result) → Zia.Matrix4 method static

Defined in Matrix4.js:152

Creates a matrix that can be used to rotate vectors around the y-axis.

Parameters

Name Type Description
angle Number

The amount, in radians, by which to rotate around the y-axis.

result Zia.Matrix4

The object in which to place the calculated result.

Returns

Zia.Matrix4 -

The modified result parameter.

Example

var result = Zia.Matrix4.createRotationY(Math.PI, new Zia.Matrix4());

createRotationZ (angle, result) → Zia.Matrix4 method static

Defined in Matrix4.js:174

Creates a matrix that can be used to rotate vectors around the z-axis.

Parameters

Name Type Description
angle Number

The amount, in radians, by which to rotate around the z-axis.

result Zia.Matrix4

The object in which to place the calculated result.

Returns

Zia.Matrix4 -

The modified result parameter.

Example

var result = Zia.Matrix4.createRotationZ(Math.PI, new Zia.Matrix4());

createScale (scale, result) → Zia.Matrix4 method static

Defined in Matrix4.js:351

Creates a scaling matrix.

Parameters

Name Type Description
scale Zia.Vector3

Amounts to scale by on the x, y and z axes.

result Zia.Matrix4

The object in which to place the calculated result.

Returns

Zia.Matrix4 -

The modified result parameter.

Example

var result = Zia.Matrix4.createScale(
  new Zia.Vector3(1.5, 1, 2),
  new Zia.Matrix4());

createTranslation (translation, result) → Zia.Matrix4 method static

Defined in Matrix4.js:110

Creates a matrix that can be used to translate vectors.

Parameters

Name Type Description
translation Zia.Vector3

Amounts to translate by on the x, y and z axes.

result Zia.Matrix4

The object in which to place the calculated result.

Returns

Zia.Matrix4 -

The modified result parameter.

Example

var result = Zia.Matrix4.createTranslation(
  new Zia.Vector3(1, 2, -5),
  new Zia.Matrix4());

createUniformScale (scale, result) → Zia.Matrix4 method static

Defined in Matrix4.js:371

Creates a uniform scaling matrix.

Parameters

Name Type Description
scale Number

Amount to scale by on all axes.

result Zia.Matrix4

The object in which to place the calculated result.

Returns

Zia.Matrix4 -

The modified result parameter.

Example

var result = Zia.Matrix4.createUniformScale(2, new Zia.Matrix4());

decompose (scale, rotation, translation) → Boolean method

Defined in Matrix4.js:800

Extracts the scale, rotation, and translation components of the current Matrix4 instance. Assumes this is a transform matrix.

Parameters

Name Type Description
scale Zia.Vector3

The scale component of the transform matrix.

rotation Zia.Quaternion

The rotation component of the transform matrix.

translation Zia.Vector3

The translation component of the transform matrix.

Returns

Boolean -

True if the matrix can be decomposed, otherwise false.

determinant () → Number method

Defined in Matrix4.js:734

Calculates the determinant of the current Matrix4 instance.

Returns

Number -

The determinant.

getTranslation () method

Defined in Matrix4.js:576

Gets the translation component of the current transformation matrix.

invert (matrix, result) → Zia.Matrix4 method static

Defined in Matrix4.js:504

Inverts a matrix. If the determinant is zero, then the matrix cannot be inverted and an exception will be thrown.

Parameters

Name Type Description
matrix Zia.Matrix4

The matrix to invert.

result Zia.Matrix4

The object in which to place the calculated result.

Returns

Zia.Matrix4 -

The modified result parameter.

Example

var result = Zia.Matrix4.invert(
  Zia.Matrix4.createUniformScale(2, new Zia.Matrix4()),
  new Zia.Matrix4());

multiply (left, right, result) → Zia.Matrix4 method static

Defined in Matrix4.js:414

Multiplies a matrix by another matrix.

Parameters

Name Type Description
left Zia.Matrix4

The first matrix.

right Zia.Matrix4

The second matrix.

result Zia.Matrix4

The object in which to place the calculated result.

Returns

Zia.Matrix4 -

The modified result parameter.

Example

var result = Zia.Matrix4.multiply(
  Zia.Matrix4.createUniformScale(2, new Zia.Matrix4()),
  Zia.Matrix4.createRotationX(Math.PI, new Zia.Matrix4(),
  new Zia.Matrix4());

multiplyByScalar (matrix, scalar, result) → Zia.Matrix4 method static

Defined in Matrix4.js:466

Multiplies a matrix by a scalar value.

Parameters

Name Type Description
matrix Zia.Matrix4

The matrix.

scalar Number

The scalar value.

result Zia.Matrix4

The object in which to place the calculated result.

Returns

Zia.Matrix4 -

The modified result parameter.

Example

var result = Zia.Matrix4.multiplyByScalar(
  Zia.Matrix4.createUniformScale(2, new Zia.Matrix4()), 0.5,
  new Zia.Matrix4());

setTranslation () method

Defined in Matrix4.js:587

Sets the translation component of the current transformation matrix.

transpose (matrix, result) → Zia.Matrix4 method static

Defined in Matrix4.js:555

Transposes a matrix.

Parameters

Name Type Description
matrix Zia.Matrix4

The matrix to transpose.

result Zia.Matrix4

The object in which to place the calculated result.

Returns

Zia.Matrix4 -

The modified result parameter.

Example

var result = Zia.Matrix4.transpose(
  Zia.Matrix4.createRotationX(Math.PI, new Zia.Matrix4()),
  new Zia.Matrix4());