.. role:: ts-api-decorator

####
Mat4
####

.. js:module:: cee
   :noindex:

.. container:: ts-api-section

   .. js:class:: 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:


      .. code-block::


           | 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


      .. code-block::


           | 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


      .. code-block::


           | 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.



.. container:: api-index-section

   .. rubric:: Constructors

   .. rst-class:: api-index-list-item api-kind-constructor api-parent-kind-class

   * :js:meth:`~cee.Mat4.constructor`



.. container:: api-index-section

   .. rubric:: Methods

   .. rst-class:: api-index-list-item api-kind-method api-parent-kind-class

   * :js:meth:`~cee.Mat4.equals`
   * :js:meth:`~cee.Mat4.getAsArray`
   * :js:meth:`~cee.Mat4.getInverse`
   * :js:meth:`~cee.Mat4.getRowCol`
   * :js:meth:`~cee.Mat4.isIdentity`
   * :js:meth:`~cee.Mat4.fromArray`
   * :js:meth:`~cee.Mat4.fromCoordSystemAxes`
   * :js:meth:`~cee.Mat4.fromElements`
   * :js:meth:`~cee.Mat4.fromRotation`
   * :js:meth:`~cee.Mat4.fromScaling`
   * :js:meth:`~cee.Mat4.fromTranslation`
   * :js:meth:`~cee.Mat4.multiply`
   * :js:meth:`~cee.Mat4.translatePostMultiply`
   * :js:meth:`~cee.Mat4.translatePreMultiply`





------------

Constructors
============

.. container:: ts-api-section

   .. js:function:: Mat4.constructor()



      Creates the matrix. Default is an identity matrix.


      :rtype: Mat4



Methods
=======

.. rst-class:: ts-api-section

equals
------

.. js:method:: Mat4.equals( other)

   :param other: None
   :type other: Mat4


   Returns true if the matrices are equal


   :rtype: boolean

.. rst-class:: ts-api-section

getAsArray
----------

.. js:method:: Mat4.getAsArray()



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

   The array will be ordered as follows:


   .. code-block::


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



   :rtype: ArrayLike <number>

.. rst-class:: ts-api-section

getInverse
----------

.. js:method:: Mat4.getInverse()



   Returns this inverse of this matrix.

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


   :rtype: Mat4

.. rst-class:: ts-api-section

getRowCol
---------

.. js:method:: Mat4.getRowCol( row, col)

   :param row: None
   :type row: number
   :param col: None
   :type col: number


   Returns the value at the given row and column


   :rtype: number

.. rst-class:: ts-api-section

isIdentity
----------

.. js:method:: Mat4.isIdentity()



   Returns true if the matrix is an identity matrix


   :rtype: boolean

.. rst-class:: ts-api-section

:ts-api-decorator:`static` fromArray
------------------------------------

.. js:method:: Mat4.fromArray( array)

   :param array: None
   :type array: ArrayLike <number>


   Returns a matrix initialized with the values in the passed array

   The array must be ordered as follows:


   .. code-block::


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



   :rtype: Mat4

.. rst-class:: ts-api-section

:ts-api-decorator:`static` fromCoordSystemAxes
----------------------------------------------

.. js:method:: Mat4.fromCoordSystemAxes( xAxis, yAxis, zAxis)

   :param xAxis: Orientation of x axis
   :type xAxis: Vec3Like
   :param yAxis: Orientation of y axis
   :type yAxis: Vec3Like
   :param zAxis: Orientation of z axis
   :type zAxis: Vec3Like


   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.


   :rtype: Mat4

.. rst-class:: ts-api-section

:ts-api-decorator:`static` fromElements
---------------------------------------

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

   :param m00: None
   :type m00: number
   :param m01: None
   :type m01: number
   :param m02: None
   :type m02: number
   :param m03: None
   :type m03: number
   :param m10: None
   :type m10: number
   :param m11: None
   :type m11: number
   :param m12: None
   :type m12: number
   :param m13: None
   :type m13: number
   :param m20: None
   :type m20: number
   :param m21: None
   :type m21: number
   :param m22: None
   :type m22: number
   :param m23: None
   :type m23: number
   :param m30: None
   :type m30: number
   :param m31: None
   :type m31: number
   :param m32: None
   :type m32: number
   :param m33: None
   :type m33: number


   Returns a transformation matrix containing the given element values


   .. code-block::


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



   :rtype: Mat4

.. rst-class:: ts-api-section

:ts-api-decorator:`static` fromRotation
---------------------------------------

.. js:method:: Mat4.fromRotation( axis, angle)

   :param axis: None
   :type axis: Vec3Like
   :param angle: None
   :type angle: number


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


   :rtype: Mat4

.. rst-class:: ts-api-section

:ts-api-decorator:`static` fromScaling
--------------------------------------

.. js:method:: Mat4.fromScaling( scale)

   :param scale: None
   :type scale: Vec3Like


   Returns a transformation matrix containing only the given scaling


   .. code-block::


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



   :rtype: Mat4

.. rst-class:: ts-api-section

:ts-api-decorator:`static` fromTranslation
------------------------------------------

.. js:method:: Mat4.fromTranslation( trans)

   :param trans: None
   :type trans: Vec3Like


   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


   .. code-block::


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



   :rtype: Mat4

.. rst-class:: ts-api-section

:ts-api-decorator:`static` multiply
-----------------------------------

.. js:method:: Mat4.multiply( matrices)

   :param matrices: None
   :type matrices: [Mat4]


   Multiplies given matrices.


   :rtype: Mat4

.. rst-class:: ts-api-section

:ts-api-decorator:`static` translatePostMultiply
------------------------------------------------

.. js:method:: Mat4.translatePostMultiply( M, tv)

   :param M: None
   :type M: Mat4
   :param tv: None
   :type tv: Vec3Like


   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


   :rtype: Mat4

.. rst-class:: ts-api-section

:ts-api-decorator:`static` translatePreMultiply
-----------------------------------------------

.. js:method:: Mat4.translatePreMultiply( M, tv)

   :param M: None
   :type M: Mat4
   :param tv: None
   :type tv: Vec3Like


   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


   :rtype: Mat4

