# Unigine::Math::mat4 Struct

This class represents a matrix of sixteen (4x4) float components.

## mat4 ( ) #

Default constructor. Produces an identity matrix.

## mat4 ( float v ) #

Constructor. Initializes the matrix using a given scalar value.
Source code (UnigineScript)
``````mat4(2.0);

/* Creates a matrix
| 2.0 	2.0 	2.0		2.0	|
| 2.0 	2.0 	2.0		2.0	|
| 2.0 	2.0 	2.0		2.0	|
| 2.0 	2.0 	2.0		2.0	|
*/``````

### Arguments

• float v - Scalar value.

## mat4 ( const mat3 & m ) #

Constructor. Initializes the matrix using a given mat3 source matrix (3x3). The matrix elements are filled using corresponding elements of the source matrix.
Output
``````Resulting matrix:
| m00  	 m01  	 m02	  0.0f |
M=  | m10    m11  	 m12      0.0f |
| m20    m21     m22      0.0f |
| 0.0f   0.0f    0.0f     1.0f |``````

### Arguments

• const mat3 & m - Source matrix (3x3).

## mat4 ( const mat4 & m ) #

Constructor. Initializes the matrix by copying a given source matrix.

### Arguments

• const mat4 & m - Source matrix.

## explicit mat4 ( const dmat4 & m ) #

Constructor. Initializes the matrix using a given dmat4 source matrix (3x4). The matrix elements are filled using corresponding elements of the source matrix.

### Arguments

• const dmat4 & m - Source matrix (3x4).

## mat4 ( const vec4 & col0, const vec4 & col1, const vec4 & col2, const vec4 & col3 ) #

Constructor. Initializes the matrix using given three vec4 vectors.
Output
``````Resulting matrix:
| col0.x  	 col1.x	  	col2.x	   col3.x |
M=  | col0.y   	 col1.y	  	col2.y     col3.y |
| col0.z   	 col1.z	  	col2.z     col3.z |
| col0.w   	 col1.w	  	col2.w     col3.w |``````

### Arguments

• const vec4 & col0 - Source vector for the first column.
• const vec4 & col1 - Source vector for the second column.
• const vec4 & col2 - Source vector for the third column.
• const vec4 & col3 - Source vector for the fourth column.

## explicit mat4 ( const quat & q ) #

Constructor. Initializes the matrix using a given source quaternion.
Output
``````For the quaternion (x, y, z, w) the corresponding rotation matrix M is defined as follows:
| 1 - 2y² - 2z²    2xy + 2wz      	2xz - 2wy     	0.0f |
M=  | 2xy - 2wz        1 - 2x² - 2z²    2yz + 2wx     	0.0f |
| 2xz + 2wy        2yz - 2wx        1 - 2x² - 2y² 	0.0f |
|  0.0f            0.0f        		0.0f 			1.0f |``````

### Arguments

• const quat & q - Source quaternion.

## mat4 ( const mat3 & m, const vec3 & v ) #

Constructor. Initializes the matrix using a given source mat3 matrix (3x3) and a vec3 vector.

### Arguments

• const mat3 & m - Source matrix (3x3).
• const vec3 & v - Source vector.

## mat4 ( const quat & q, const vec3 & v ) #

Constructor. Initializes the matrix using a given quaternion and a vec3 vector.

### Arguments

• const quat & q - Source quaternion.
• const vec3 & v - Source vector.

## explicit mat4 ( const float * m, int transpose ) #

Constructor. Initializes the matrix using a given pointer to the source matrix.

### Arguments

• const float * m - Pointer to the source matrix.
• int transpose - If transpose is 0 (by default), the matrix is specified in the column major style.

## voidset ( int row, int column, float v ) #

Sets a new value of the matrix element specified by row and column.

### Arguments

• int row - Row.
• int column - Column.
• float v - The value to be set.

## mat4 ( const mat2 & m ) #

Constructor. Initializes the matrix using a given mat2 source matrix (2x2). The matrix elements are filled using corresponding elements of the source matrix.
Output
``````Resulting matrix:
| m00  	 m01  	 0.0f	  0.0f |
M=  | m10    m11  	 0.0f     0.0f |
| 0.0f   0.0f    1.0f     0.0f |
| 0.0f   0.0f    0.0f     1.0f |``````

### Arguments

• const mat2 & m - Source matrix (2x2).

## voidset ( const float * m, int transpose ) #

Sets new matrix values using a pointer to the source matrix.

### Arguments

• const float * m - Pointer to the source matrix.
• int transpose - If transpose is 0 (by default), the matrix is specified in the column major style.

## voidset ( const mat2 & m ) #

Sets new matrix values using a given mat2 source matrix (2x2). The matrix elements are filled using corresponding elements of the source matrix.
Output
``````Resulting matrix:
| m00  	 m01  	 0.0f	  0.0f |
M=  | m10    m11  	 0.0f     0.0f |
| 0.0f   0.0f    1.0f     0.0f |
| 0.0f   0.0f    0.0f     1.0f |``````

### Arguments

• const mat2 & m - Source matrix (2x2).

## voidset ( const mat3 & m, const vec3 & v ) #

Sets new matrix values using a given source mat3 matrix (3x3) and a vec3 vector.

### Arguments

• const mat3 & m - Source matrix (3x3).
• const vec3 & v - Source vector.

## voidset ( const quat & q, const vec3 & v ) #

Sets new matrix values using a given quaternion and a vec3 vector.

### Arguments

• const quat & q - Source quaternion.
• const vec3 & v - Source vector.

## voidset ( const mat3 & m ) #

Sets new matrix values using a given mat3 source matrix (3x3). The matrix elements are filled using corresponding elements of the source matrix.
Output
``````Resulting matrix:
| m00  	 m01  	 m02	  0.0f |
M=  | m10    m11  	 m12      0.0f |
| m20    m21     m22      0.0f |
| 0.0f   0.0f    0.0f     1.0f |``````

### Arguments

• const mat3 & m - Source matrix (3x3).

## voidset ( const quat & q ) #

Sets new matrix values using a given source quaternion.

### Arguments

• const quat & q - Source quaternion.

## voidset ( const mat4 & m ) #

Sets the matrix equal to the specified source matrix.

### Arguments

• const mat4 & m - Source matrix.

## voidset ( const dmat4 & m ) #

Sets new matrix values using a given dmat4 source matrix (3x4). The matrix elements are filled using corresponding elements of the source matrix.

### Arguments

• const dmat4 & m - Source matrix (3x4).

## float &get ( int row, int column ) #

Returns the reference to the matrix element specified by given row and column.

### Arguments

• int row - Row.
• int column - Column.

### Return value

Matrix element reference.

## floatget ( int row, int column ) # const

Returns the value of the matrix element specified by given row and column.

### Arguments

• int row - Row.
• int column - Column.

### Return value

Matrix element value.

## voidget ( float * m, int transpose ) # const

Fills the destination matrix, specified by the given pointer, with matrix values.

### Arguments

• float * m - Destination matrix pointer.
• int transpose - If transpose is 0 (by default), the matrix is specified in the column major style.

## float *get ( ) #

Returns the pointer to the matrix.

### Return value

Pointer to the matrix.

## const float *get ( ) # const

Returns the constant pointer to the matrix.

### Return value

Constant pointer to the matrix.

## voidsetColumn ( int column, const vec4 & v ) #

Sets the specified column of the matrix using a given vec4 vector as a source.

### Arguments

• int column - Column.
• const vec4 & v - Source vector.

## vec4getColumn ( int column ) # const

Returns the specified matrix column.

### Arguments

• int column - Column.

### Return value

The vec4 vector with column values.

## voidsetColumn3 ( int column, const vec3 & v ) #

Sets the specified column of the matrix using a given three-component vec3 vector as a source, the last element of the column remains as is.

### Arguments

• int column - Column.
• const vec3 & v - Three-component source vector.

## vec3getColumn3 ( int column ) # const

Returns the XYZ components of the specified matrix column.

### Arguments

• int column - Column.

### Return value

The vec3 vector with the first three elements of the specified matrix column.

## voidsetDiagonal ( const vec4 & v ) #

Sets the main diagonal of the matrix using a given vec4 vector as a source.

### Arguments

• const vec4 & v - Source vector.

## vec4getDiagonal ( ) #

Returns the main diagonal of the matrix.

### Return value

The vec4 vector with the element of the main diagonal.

## voidsetIdentity ( ) #

Sets the matrix equal to the identity matrix.

## voidsetRotate ( const vec3 & axis, float angle ) #

Sets the rotation matrix for a given axis.

### Arguments

• const vec3 & axis - Rotation axis.
• float angle - Rotation angle, in degrees.

## quatgetRotate ( ) # const

Returns the quaternion, representing the rotation part of the matrix.

### Return value

Matrix rotation part.

## voidsetRotateX ( float angle ) #

Sets X rotation matrix.

### Arguments

• float angle - Rotation angle, in degrees.

## voidsetRotateY ( float angle ) #

Sets Y rotation matrix.

### Arguments

• float angle - Rotation angle, in degrees.

## voidsetRotateZ ( float angle ) #

Set Z rotation matrix.

### Arguments

• float angle - Rotation angle, in degrees.

## voidsetRow ( int row, const vec4 & v ) #

Sets the specified row of the matrix using a given vec4 vector as a source.

### Arguments

• int row - Row.
• const vec4 & v - Source vector.

## vec4getRow ( int row ) # const

Returns the specified matrix row.

### Arguments

• int row - Row.

### Return value

The vec4 vector with row values.

## voidsetRow3 ( int row, const vec3 & v ) #

Sets the specified row of the matrix using a given three-component vec3 vector as a source, the last element of the row remains as is.

### Arguments

• int row - Row.
• const vec3 & v - Three-component source vector.

## vec3getRow3 ( int row ) # const

Returns the first three elements of the specified matrix row.

### Arguments

• int row - Row.

### Return value

The vec3 vector with the first three elements of the specified matrix row.

## voidsetScale ( const vec3 & v ) #

Fills the scaling matrix using a given vec3 source vector.
Output
``````Scaling matrix:
| v.x   	0.0f  	  0.0f	    0.0f |
S=  | 0.0f      v.y  	  0.0f      0.0f |
| 0.0f      0.0f      v.z  		0.0f |
| 0.0f      0.0f      0.0f  	1.0f |``````

### Arguments

• const vec3 & v - Source vector.

## vec3getScale ( ) # const

Returns the three-component vec3 vector, representing the scaling part of the matrix.

### Return value

Three-component vector with the scaling part of the matrix.

## voidsetTranslate ( const vec3 & v ) #

Fills the translation matrix using a given vec3 source vector.
Output
``````Translation matrix:
| 1.0f   	0.0f  	  0.0f	    v.x |
T=  | 0.0f      1.0f  	  0.0f      v.y |
| 0.0f      0.0f      1.0f  	v.z |
| 0.0f      0.0f      0.0f     1.0f |``````

### Arguments

• const vec3 & v - Source vector.

## vec3getTranslate ( ) # const

Returns the three-component vec3 vector, representing the translation part of the matrix.

### Return value

Three-component vector with the translation part of the matrix.

## voidsetZero ( ) #

Sets all matrix elements equal to 0.

## const float *operator const float * ( ) #

Performs type conversion to const float *.

## const void *operator const void * ( ) #

Performs type conversion to const void *.

## float *operator float * ( ) #

Performs type conversion to float *.

## void *operator void * ( ) #

Performs type conversion to void *.

## mat4 &operator*= ( const mat4 & m ) #

Performs matrix multiplication.

### Arguments

• const mat4 & m - Matrix.

### Return value

Resulting matrix.

## mat4 &operator*= ( float v ) #

Performs scalar multiplication.

### Arguments

• float v - Scalar value.

### Return value

Resulting matrix.

## mat4 &operator*= ( vec3 v ) #

Performs vector multiplication.

### Arguments

• vec3 v - Vector.

### Return value

Resulting matrix.

## mat4 &operator*= ( vec4 v ) #

Performs vector multiplication.

### Arguments

• vec4 v - Vector.

### Return value

Resulting matrix.

## mat4 &operator*= ( dvec3 v ) #

Performs vector multiplication.

### Arguments

• dvec3 v - Vector.

### Return value

Resulting matrix.

## mat4 &operator*= ( dvec4 v ) #

Performs vector multiplication.

### Arguments

• dvec4 v - Vector.

### Return value

Resulting matrix.

## mat4 &operator+= ( const mat4 & m ) #

### Arguments

• const mat4 & m - Matrix.

### Return value

Resulting matrix.

## mat4operator- ( ) #

Performs matrix negation.

## mat4 &operator-= ( const mat4 & m ) #

Performs matrix subtraction.

### Arguments

• const mat4 & m - Matrix.

### Return value

Resulting matrix.

## mat4 &operator= ( const mat4 & m ) #

Performs matrix assignment. Destination matrix = Source matrix.

### Arguments

• const mat4 & m - Source matrix.

Result.

## float &operator[] ( int i ) #

Performs array access to the matrix item reference using given item index.

### Arguments

• int i - Matrix item index.

### Return value

Matrix item reference.

## floatoperator[] ( int i ) # const

### Arguments

• int i - Matrix item index.

Matrix item.

## voidsse ( const __m128 & v0, const __m128 & v1, const __m128 & v2, const __m128 & v3 ) #

Sets the values of the matrix elements using four given 128-bit variables as a source.
Notice
We do not recommend to use this method unless you have a clear understanding of SSE2.

### Arguments

• const __m128 & v0 - 128-bit variable containing the following matrix elements: m00, m10, m20, m30.
• const __m128 & v1 - 128-bit variable containing the following matrix elements: m01, m11, m21, m31.
• const __m128 & v2 - 128-bit variable containing the following matrix elements: m02, m12, m22, m32.
• const __m128 & v3 - 128-bit variable containing the following matrix elements: m03, m13, m23, m33.

## voidsse0 ( const __m128 & v ) #

Sets the values of matrix elements m00, m10, m20, m30 using a given 128-bit variable.
Notice
We do not recommend to use this method unless you have a clear understanding of SSE2.

### Arguments

• const __m128 & v - 128-bit variable containing the following matrix elements: m00, m10, m20, m30.

## __m128sse0 ( ) #

Returns the values of matrix elements m00, m10, m20, m30 as a 128-bit variable.
Notice
We do not recommend to use this method unless you have a clear understanding of SSE2.

### Return value

128-bit variable containing the following matrix elements: m00, m10, m20, m30.

## __m128sse1 ( ) #

Returns the values of matrix elements m01, m11, m21, m31 as a 128-bit variable.
Notice
We do not recommend to use this method unless you have a clear understanding of SSE2.

### Return value

128-bit variable containing the following matrix elements: m01, m11, m21, m31.

## voidsse1 ( const __m128 & v ) #

Sets the values of matrix elements m01, m11, m21, m31 using a given 128-bit variable.
Notice
We do not recommend to use this method unless you have a clear understanding of SSE2.

### Arguments

• const __m128 & v - 128-bit variable containing the following matrix elements: m01, m11, m21, m31.

## __m128sse2 ( ) #

Returns the values of matrix elements m02, m12, m22, m32 as a 128-bit variable.
Notice
We do not recommend to use this method unless you have a clear understanding of SSE2.

### Return value

128-bit variable containing the following matrix elements: m02, m12, m22, m32.

## voidsse2 ( const __m128 & v ) #

Sets the values of matrix elements m02, m12, m22, m32 using a given 128-bit variable.
Notice
We do not recommend to use this method unless you have a clear understanding of SSE2.

### Arguments

• const __m128 & v - 128-bit variable containing the following matrix elements: m02, m12, m22, m32.

## voidsse3 ( const __m128 & v ) #

Sets the values of matrix elements m03, m13, m23, m33 using a given 128-bit variable.
Notice
We do not recommend to use this method unless you have a clear understanding of SSE2.

### Arguments

• const __m128 & v - 128-bit variable containing the following matrix elements: m03, m13, m23, m33.

## __m128sse3 ( ) #

Returns the values of matrix elements m03, m13, m23, m33 as a 128-bit variable.
Notice
We do not recommend to use this method unless you have a clear understanding of SSE2.

### Return value

128-bit variable containing the following matrix elements: m03, m13, m23, m33.

## vec3getAxisX ( ) #

Returns the normalized vector representing the X axis.

### Return value

Vector representing the X axis.

## vec3getAxisY ( ) #

Returns the normalized vector representing the Y axis.

### Return value

Vector representing the Y axis.

## vec3getAxisZ ( ) #

Returns the normalized vector representing the Z axis.

### Return value

Vector representing the Z axis.
Last update: 2020-05-19