# Mat4

class `cee.``Mat4`()

  An immutable 4x4 matrix

  Matrices are stored internally as a one dimensional array for performance reasons.

  The mapping of matrix elements to indices of this internal array is as follows:

      | m00  m01  m02  m03 |     | 0  4   8  12 |
      | m10  m11  m12  m13 |     | 1  5   9  13 |
      | m20  m21  m22  m23 |     | 2  6  10  14 |
      | m30  m31  m32  m33 |     | 3  7  11  15 |

  This is consistent with the way matrices are represented in WebGL. To exemplify, translation values are stored in elements 12,13,14; see figure below

      | 1  0  0 Tx |
      | 0  1  0 Ty |
      | 0  0  1 Tz |
      | 0  0  0  1 |

  From the OpenGL red book (page 68) v’ = M*v

      | X'|   | 1  0  0 Tx |   | X |
      | Y'|   | 0  1  0 Ty |   | Y |
      | Z'| = | 0  0  1 Tz | * | Z |
      | 1 |   | 0  0  0  1 |   | 1 |

  Note that this class is immutable.

Constructors

- `constructor`

Methods

- `equals`
- `getAsArray`
- `getInverse`
- `getRowCol`
- `isIdentity`
- `fromArray`
- `fromCoordSystemAxes`
- `fromElements`
- `fromRotation`
- `fromScaling`
- `fromTranslation`
- `multiply`
- `translatePostMultiply`
- `translatePreMultiply`

## Constructors

`Mat4.``constructor`()

  Creates the matrix. Default is an identity matrix.

  Return type: | Mat4

## Methods

### equals

`Mat4.``equals`(other)

  Arguments: | other (`Mat4`) – None

  Returns true if the matrices are equal

  Return type: | boolean

### getAsArray

`Mat4.``getAsArray`()

  Returns a reference to the internal array storing the matrix values.

  The array will be ordered as follows:

      | m00  m01  m02  m03 |     | 0  4   8  12 |
      | m10  m11  m12  m13 |     | 1  5   9  13 |
      | m20  m21  m22  m23 |     | 2  6  10  14 |
      | m30  m31  m32  m33 |     | 3  7  11  15 |

  Return type: | ArrayLike <number>

### getInverse

`Mat4.``getInverse`()

  Returns this inverse of this matrix.

  If this matrix is not invertible, returns a zero matrix.

  Return type: | Mat4

### getRowCol

`Mat4.``getRowCol`(row, col)

  Arguments: | row (`number`) – None col (`number`) – None

  Returns the value at the given row and column

  Return type: | number

### isIdentity

`Mat4.``isIdentity`()

  Returns true if the matrix is an identity matrix

  Return type: | boolean

### static fromArray

`Mat4.``fromArray`(array)

  Arguments: | array (`ArrayLike`) – None

  Returns a matrix initialized with the values in the passed array

  The array must be ordered as follows:

      | m00  m01  m02  m03 |     | 0  4   8  12 |
      | m10  m11  m12  m13 |     | 1  5   9  13 |
      | m20  m21  m22  m23 |     | 2  6  10  14 |
      | m30  m31  m32  m33 |     | 3  7  11  15 |

  Return type: | Mat4

### static fromCoordSystemAxes

`Mat4.``fromCoordSystemAxes`(xAxis, yAxis, zAxis)

  Arguments: | xAxis (`Vec3Like`) – Orientation of x axis yAxis (`Vec3Like`) – Orientation of y axis zAxis (`Vec3Like`) – Orientation of z axis

  Returns a rotation matrix that will align the global X, Y and Z axes with the specified axes.

  Note that at least one axis must be specified and all specified axes must be normalized. If two or three axes are specified, they must be orthogonal to each other.

  Return type: | Mat4

### static fromElements

`Mat4.``fromElements`(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33)

  Arguments: | m00 (`number`) – None m01 (`number`) – None m02 (`number`) – None m03 (`number`) – None m10 (`number`) – None m11 (`number`) – None m12 (`number`) – None m13 (`number`) – None m20 (`number`) – None m21 (`number`) – None m22 (`number`) – None m23 (`number`) – None m30 (`number`) – None m31 (`number`) – None m32 (`number`) – None m33 (`number`) – None

  Returns a transformation matrix containing the given element values

      | m00  m01  m02  m03 |
      | m10  m11  m12  m13 |
      | m20  m21  m22  m23 |
      | m30  m31  m32  m33 |

  Return type: | Mat4

### static fromRotation

`Mat4.``fromRotation`(axis, angle)

  Arguments: | axis (`Vec3Like`) – None angle (`number`) – None

  Returns a transformation matrix containing only rotation, specified as a rotation around the given axis

  Return type: | Mat4

### static fromScaling

`Mat4.``fromScaling`(scale)

  Arguments: | scale (`Vec3Like`) – None

  Returns a transformation matrix containing only the given scaling

      | Sx 0  0  0 |
      | 0  Sy 0  0 |
      | 0  0  Sz 0 |
      | 0  0  0  1 |

  Return type: | Mat4

### static fromTranslation

`Mat4.``fromTranslation`(trans)

  Arguments: | trans (`Vec3Like`) – None

  Returns a transformation matrix containing only the given translation

  Will set m03 to x, m13 to y, and m23 to z, resulting in the following matrix

      | 1  0  0 Tx |
      | 0  1  0 Ty |
      | 0  0  1 Tz |
      | 0  0  0  1 |

  Return type: | Mat4

### static multiply

`Mat4.``multiply`(matrices)

  Arguments: | matrices (`[Mat4]`) – None

  Multiplies given matrices.

  Return type: | Mat4

### static translatePostMultiply

`Mat4.``translatePostMultiply`(M, tv)

  Arguments: | M (`Mat4`) – None tv (`Vec3Like`) – None

  Adds translation to the given matrix M by post-multiplying it with a matrix containing the given translation tv.

  This has the effect of performing the multiplication M’ = M x T

  Return type: | Mat4

### static translatePreMultiply

`Mat4.``translatePreMultiply`(M, tv)

  Arguments: | M (`Mat4`) – None tv (`Vec3Like`) – None

  Adds translation to the given matrix M by pre-multiplying it with a matrix containing the given translation tv.

  This has the effect of performing the multiplication M’ = T x M

  Return type: | Mat4

Conversation saved
HOOPSY BETA

### Hello! I'm HOOPSY

Your Docs generative AI assistant. Ask me anything about HOOPS Envision for Web or choose a sample question below to start a conversation:

What is HOOPS Envision for Web?
What are the latest release notes for HOOPS Envision for Web?
How do I start evaluating HOOPS Envision for Web?
How do I write my first sample application?
How can I get assistance?

HOOPSY may store conversations according to OpenAI's policy. Responses may not always be accurate.

HOOPSY is thinking...