Class: Matrix4

caph.math. Matrix4

new Matrix4(matrix)

A class which provides 4x4 matrix.

Parameters:
Name Type Argument Description
matrix Array <optional>

An array of 16 integer. If not passed, sets identity matrix.

Since:
  • 2.0.0
Example
var matrix = new caph.math.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 100, 0, 1]);
 matrix.translate(100, 0, 0).multiply(caph.math.Matrix4.rotateZ(90));

Methods

clone() → {caph.math.Matrix4}

Creates a copy of this matrix.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
var matrix = new caph.math.Matrix4().clone();

get() → {Array}

Gets the current matrix.

Since:
  • 2.0.0
Returns:
Type
Array
Example
var array = new caph.math.Matrix4().get();

identity() → {caph.math.Matrix4}

Sets the identity matrix to the current matrix.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
var identity = new caph.math.Matrix4().identity(); // equivalent to new caph.math.Matrix4().

multiply(m2) → {caph.math.Matrix4}

Multiplies the current matrix by the given matrix. This is different from the normal matrix multiply. This is optimized for CSS transform matrix calculation. If want to multiply normally, use multiplyMatrix instead.

Parameters:
Name Type Description
m2 Array | caph.math.Matrix4

A matrix to multiply.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
new caph.math.Matrix4().multiply([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 100, 0, 1]).multiply(caph.math.Matrix4.rotateZ(90));

multiplyMatrix(m2) → {caph.math.Matrix4}

Multiplies the current matrix by the given matrix.

Parameters:
Name Type Description
m2 Array | caph.math.Matrix4

A matrix to multiply.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
new caph.math.Matrix4().multiplyMatrix([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 100, 0, 1]).multiply(caph.math.Matrix4.rotateZ(90));

rotateAxis(x, y, z, degree) → {caph.math.Matrix4}

Sets the axis rotation matrix to the current matrix.

Parameters:
Name Type Description
x Number

A value of x-axis.

y Number

A value of y-axis.

z Number

A value of z-axis.

degree Number

A degree to rotate.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
new caph.math.Matrix4().rotateAxis(1, 0, 0, 90);

rotateX(degree) → {caph.math.Matrix4}

Sets the x-axis rotation matrix to the current matrix.

Parameters:
Name Type Description
degree Number

A degree of x-axis.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
new caph.math.Matrix4().rotateX(90);

rotateXYZ(x, y, z) → {caph.math.Matrix4}

Sets the rotation matrix to the current matrix.

Parameters:
Name Type Description
x Number

A degree of x-axis.

y Number

A degree of y-axis.

z Number

A degree of z-axis.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
new caph.math.Matrix4().rotateXYZ(90, 0, 0);

rotateY(degree) → {caph.math.Matrix4}

Sets the y-axis rotation matrix to the current matrix.

Parameters:
Name Type Description
degree Number

A degree of y-axis.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
new caph.math.Matrix4().rotateY(90);

rotateZ(degree) → {caph.math.Matrix4}

Sets the z-axis rotation matrix to the current matrix.

Parameters:
Name Type Description
degree Number

A degree of z-axis.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
new caph.math.Matrix4().rotateZ(90);

scale(x, y, z) → {caph.math.Matrix4}

Sets the scale matrix to the current matrix.

Parameters:
Name Type Description
x Number

A value of x scale.

y Number

A value of y scale.

z Number

A value of z scale.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
new caph.math.Matrix4().scale(1.5, 0, 0);

set(matrix) → {caph.math.Matrix4}

Sets the given argument to the current matrix.

Parameters:
Name Type Description
matrix Array

An array of 16 integer.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
new caph.math.Matrix4().set([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 100, 0, 1]);

skewXY(x, y) → {caph.math.Matrix4}

Sets the skew matrix along the X and Y axis to the current matrix.

Parameters:
Name Type Description
x Number

A value of x-axis.

y Number

A value of y-axis.

Returns:
Type
caph.math.Matrix4
Example
new caph.math.Matrix4().skewXY(30, 0);
 

translate(x, y, z) → {caph.math.Matrix4}

Sets the translation matrix to the current matrix.

Parameters:
Name Type Description
x Number

A x-coordinate.

y Number

A y-coordinate.

z Number

A z-coordinate.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
new caph.math.Matrix4().translate(100, 0, 0);

transpose() → {caph.math.Matrix4}

Transpose current matrix

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
var transposedMatrix = new caph.math.Matrix4().transpose();

<static> multiply(m1, m2) → {caph.math.Matrix4}

Returns a multiplied matrix (m1 x m2). This is different from the normal matrix multiply. This is optimized for CSS transform matrix calculation. If want to multiply normally, use multiplyMatrix instead.

Parameters:
Name Type Description
m1 Array | caph.math.Matrix4

A matrix to multiply.

m2 Array | caph.math.Matrix4

A matrix to multiply.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
var matrix = caph.math.Matrix4.multiply(caph.math.Matrix4.translate(100, 0, 0), caph.math.Matrix4.rotateZ(90));

<static> multiplyMatrix(m1, m2) → {caph.math.Matrix4}

Returns a multiplied matrix (m1 x m2).

Parameters:
Name Type Description
m1 Array | caph.math.Matrix4

A matrix to multiply.

m2 Array | caph.math.Matrix4

A matrix to multiply.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
var matrix = caph.math.Matrix4.multiplyMatrix(caph.math.Matrix4.translate(100, 0, 0), caph.math.Matrix4.rotateZ(90));

<static> rotateAxis(x, y, z, degree) → {caph.math.Matrix4}

Returns a axis rotation matrix.

Parameters:
Name Type Description
x Number

A value of x-axis.

y Number

A value of y-axis.

z Number

A value of z-axis.

degree Number

A degree to rotate.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
var rotateAxis = caph.math.Matrix4.rotateAxis(1, 0, 0, 90);
 

<static> rotateX(degree) → {caph.math.Matrix4}

Returns a x-axis rotation matrix.

Parameters:
Name Type Description
degree Number

A degree of x-axis.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
var rotateX = caph.math.Matrix4.rotateX(45);

<static> rotateXYZ(x, y, z) → {caph.math.Matrix4}

Returns a rotation matrix.

Parameters:
Name Type Description
x Number

A degree of x-axis.

y Number

A degree of y-axis.

z Number

A degree of z-axis.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
var rotate = caph.math.Matrix4.rotateXYZ(45, 45, 0);

<static> rotateY(degree) → {caph.math.Matrix4}

Returns a y-axis rotation matrix.

Parameters:
Name Type Description
degree Number

A degree of y-axis.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
var rotateY = caph.math.Matrix4.rotateY(45);

<static> rotateZ(degree) → {caph.math.Matrix4}

Returns a z-axis rotation matrix.

Parameters:
Name Type Description
degree Number

A degree of z-axis.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
var rotateZ = caph.math.Matrix4.rotateZ(45);

<static> scale(x, y, z) → {caph.math.Matrix4}

Returns a scale matrix.

Parameters:
Name Type Description
x Number

A value of x scale.

y Number

A value of y scale.

z Number

A value of z scale.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
var scale = caph.math.Matrix4.scale(2, 2, 0);

<static> skewXY(x, y) → {caph.math.Matrix4}

Returns a skew matrix along the X and Y axis.

Parameters:
Name Type Description
x Number

A value of x-axis.

y Number

A value of y-axis.

Returns:
Type
caph.math.Matrix4
Example
var skewXY = caph.math.Matrix4.skewXY(30, 0);

<static> translate(x, y, z) → {caph.math.Matrix4}

Returns a translation matrix.

Parameters:
Name Type Description
x Number

A x-coordinate.

y Number

A y-coordinate.

z Number

A z-coordinate.

Since:
  • 2.0.0
Returns:
Type
caph.math.Matrix4
Example
var translate = caph.math.Matrix4.translate(100, 0, 0);