# Unigine::mat3 Class

This class represents a matrix of nine (3x3) float components.

## mat3()

Default constructor. Produces an identity matrix.

## mat3(const mat3 & m)

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

### Arguments

• const mat3 & m - Source matrix.

## mat3(float v)

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

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

### Arguments

• float v - Scalar value.

## mat3(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 |
M=  | m10    m11      0.0f |
| 0.0f   0.0f     1.0f |``````

### Arguments

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

## mat3(const mat4 & m)

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

### Arguments

• const mat4 & m - Source matrix (4x4).

## mat3(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).

## mat3(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     |
M=  | 2xy - 2wz        1 - 2x² - 2z²    2yz + 2wx     |
| 2xz + 2wy        2yz - 2wx        1 - 2x² - 2y² |``````

### Arguments

• const quat & q - Source quaternion.

## mat3(const float * m)

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

### Arguments

• const float * m - Pointer to the source matrix.

## mat3(const vec3 & col0, const vec3 & col1, const vec3 & col2)

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

### Arguments

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

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

## voidset(const dmat4 & m)

Sets the matrix using a given dmat4 source matrix (3x4). The matrix elements are set equal to corresponding elements of the source matrix.

### Arguments

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

## voidset(const mat4 & m)

Sets the matrix using a given mat4 source matrix (4x4). The matrix elements are set equal to corresponding elements of the source matrix.

### Arguments

• const mat4 & m - Source matrix (4x4).

## voidset(const float * m)

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

### Arguments

• const float * m - Pointer to the source matrix.

## voidset(const quat & q)

Sets 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     |
M=  | 2xy - 2wz        1 - 2x² - 2z²    2yz + 2wx     |
| 2xz + 2wy        2yz - 2wx        1 - 2x² - 2y² |``````

### Arguments

• const quat & q - Source quaternion.

## voidset(const mat3 & m)

Sets the matrix equal to the specified source matrix.

### Arguments

• const mat3 & m - Source matrix.

## 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 |
M=  | m10    m11      0.0f |
| 0.0f   0.0f     1.0f |``````

### Arguments

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

## float *get()

Returns the pointer to the matrix.

### Return value

Pointer to the matrix.

## const float *get()

Returns the constant pointer to the matrix.

### Return value

Constant pointer to the matrix.

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

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)

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

### Arguments

• float * m - Destination matrix pointer.

## vec3getBack()

Returns the 'backward' vector (positive Y) of the matrix.

### Return value

'Backward' vector of the matrix.

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

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

### Arguments

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

## vec3getColumn(int column)

Returns the specified matrix column.

### Arguments

• int column - Column.

### Return value

The vec3 vector with column values.

## voidsetDiagonal(const vec3 & v)

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

### Arguments

• const vec3 & v - Source vector.

## vec3getDiagonal()

Returns the main diagonal of the matrix.

### Return value

The vec3 vector with the elements of the main diagonal.

## vec3getDown()

Returns the 'down' vector (negative Z) of the matrix.

### Return value

'Down' vector of the matrix.

## vec3getForward()

Returns the 'forward' vector (negative Y) of the matrix.

### Return value

'Forward' vector of the matrix.

## voidsetIdentity()

Sets the matrix equal to the identity matrix.

## vec3getLeft()

Returns the 'left' vector (positive X) of the matrix.

### Return value

'Left' vector of the matrix.

## quatgetQuat()

Returns the quaternion of the matrix values.

Quaternion.

## vec3getRight()

Returns the 'right' vector (negative X) of the matrix.

### Return value

'Right' vector of the 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.

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

Sets Z rotation matrix.

### Arguments

• float angle - Rotation angle, in degrees.

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

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

### Arguments

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

## vec3getRow(int row)

Returns the specified matrix row.

### Arguments

• int row - Row.

### Return value

The vec3 vector with column values.

## voidsetScale(const vec3 & v)

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

### Arguments

• const vec3 & v - Source vector.

## voidsetSkewSymmetric(const vec3 & v)

Fills the skew-symmetric matrix using a given vec3 source vector.
Output
``````Skew-symmetric matrix:
| 0.0f   	-v.z	   v.y |
S=  | v.z       0.0f      -v.x |
| -v.y      v.x       0.0f |``````

### Arguments

• const vec3 & v - Source vector.

## vec3getUp()

Returns the 'up' vector (positive Z) of the matrix.

### Return value

'Up' vector (positive Z) 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 *.

## mat3 &operator*=(float v)

Performs scalar multiplication.

### Arguments

• float v - Scalar value.

### Return value

Resulting matrix.

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

Performs matrix multiplication.

### Arguments

• const mat3 & m - Matrix.

### Return value

Resulting matrix.

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

### Arguments

• const mat3 & m - Matrix.

### Return value

Resulting matrix.

## mat3operator-()

Performs matrix negation.

### Return value

Resulting matrix.

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

Performs matrix subtraction.

### Arguments

• const mat3 & m - mat3 matrix.

### Return value

Resulting matrix.

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

Performs matrix assignment. Destination matrix = Source matrix.

### Arguments

• const mat3 & m - Source matrix

Result.

## floatoperator[](int i)

### Arguments

• int i - Matrix item index.

Matrix item.

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

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

Sets the values of the matrix elements using three 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.
• const __m128 & v1 - 128-bit variable containing the following matrix elements: m01, m11, m21.
• const __m128 & v2 - 128-bit variable containing the following matrix elements: m02, m12, m22.

## voidsse0(const __m128 & v)

Sets the values of matrix elements m00, m10, m20 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.

## __m128sse0()

Returns the values of matrix elements m00, m10, m20 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.

## __m128sse1()

Returns the values of matrix elements m01, m11, m21 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.

## voidsse1(const __m128 & v)

Sets the values of matrix elements m01, m11, m21 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.

## __m128sse2()

Returns the values of matrix elements m02, m12, m22 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.

## voidsse2(const __m128 & v)

Sets the values of matrix elements m02, m12, m22 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.

Identity matrix.

Matrix of ones.

## mat3 ZERO

### Description

Zero matrix.
Last update: 2018-04-26