URL: https://graphicscomputing.fr/cgp/reference/mat4/
Description: 4x4 matrix of floats (affine and projective transforms).

# mat4

C++ type: `matrix_stack<float,4,4>`.
4x4 matrix of floats (affine and projective transforms).

Fields:

- `numarray_stack<numarray_stack<float,4>,4> data` - Coefficients stored row by row as 4 rows of 4 floats, contiguous in memory.

Functions taking it:

- `std::string type_str(mat4 const&)` - Type name as a string: "mat4".
- `float det(mat4 const& m)` - Determinant of a 4x4 matrix, by cofactor expansion along the last row.
- `mat4 inverse(mat4 const& m)` - Matrix inverse.
- `vec3 camera_ray_direction(mat4 const& camera_frame, mat4 const& perspective_inverse, vec2 const& screen_position)` - Unit world-space direction of the ray through a screen position given in normalized device coordinates [-1,1]^2, from the camera frame and the inverse projection matrix.
- `void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, mat4 const& m, bool expected = true)` - Send a mat4 uniform (row-major, transposed on upload) to the shader; warns if the uniform is not found and expected is true.

Functions returning it:

- `mat4 tensor_product(vec4 const& a, vec4 const& b)` - Outer product a * transpose(b), as a 4x4 matrix.
- `mat4 projection_perspective(float fov, float aspect, float z_near, float z_far)` - OpenGL perspective projection matrix from a vertical field of view in radians, an aspect ratio (width/height) and the near and far distances.
- `mat4 projection_perspective_inverse(float fov, float aspect, float z_near, float z_far)` - Inverse of the perspective projection matrix of projection_perspective, computed in closed form.
- `mat4 projection_orthographic(float left, float right, float bottom, float top, float z_near, float z_far)` - OpenGL orthographic projection matrix mapping the box [left,right] x [bottom,top] x [-z_near,-z_far] to the unit cube.
- `mat4 projection_orthographic_inverse(float left, float right, float bottom, float top, float z_near, float z_far)` - Inverse of the orthographic projection matrix of projection_orthographic, computed in closed form.

Operators:

- `mat4 operator*(mat4 const& a, mat4 const& b)` - Matrix product of two 4x4 matrices.
- `mat4 operator*(float s, mat4 const& M)` - 4x4 matrix scaled by a scalar.
- `mat4& operator*=(mat4& a, mat4 const& b)` - Replaces a by the matrix product a*b.
- `mat4& operator*=(mat4& M, float s)` - Multiplies each coefficient of a 4x4 matrix by a scalar in place.
- `mat4& operator+=(mat4& a, mat4 const& b)` - Adds a 4x4 matrix coefficient-wise in place.
- `mat4 operator*(affine const& T1, mat4 const& T2)` - Product of the 4x4 matrix of the affine transform with a mat4.
- `mat4 operator*(mat4 const& T1, affine const& T2)` - Product of a mat4 with the 4x4 matrix of the affine transform.
- `mat4 operator*(affine const& T1, mat3 const& T2)` - Product of the 4x4 matrix of the affine transform with a mat3 extended to a mat4.
- `mat4 operator*(mat3 const& T1, affine const& T2)` - Product of a mat3 extended to a mat4 with the 4x4 matrix of the affine transform.
- `mat4 operator*(affine_rt const& T1, mat4 const& T2)` - Product of the 4x4 matrix of the rigid transform with a mat4.
- `mat4 operator*(mat4 const& T1, affine_rt const& T2)` - Product of a mat4 with the 4x4 matrix of the rigid transform.
- `mat4 operator*(affine_rt const& T1, mat3 const& T2)` - Product of the 4x4 matrix of the rigid transform with a mat3 extended to a mat4.
- `mat4 operator*(mat3 const& T1, affine_rt const& T2)` - Product of a mat3 extended to a mat4 with the 4x4 matrix of the rigid transform.
- `mat4 operator*(affine_rts const& T1, mat4 const& T2)` - Product of the 4x4 matrix of the transform with a mat4.
- `mat4 operator*(mat4 const& T1, affine_rts const& T2)` - Product of a mat4 with the 4x4 matrix of the transform.
- `mat4 operator*(affine_rts const& T1, mat3 const& T2)` - Product of the 4x4 matrix of the transform with a mat3 extended to a mat4.
- `mat4 operator*(mat3 const& T1, affine_rts const& T2)` - Product of a mat3 extended to a mat4 with the 4x4 matrix of the transform.
- `mat4 operator*(rotation_transform const& r, mat4 const& M)` - Product of the rotation, as a 4x4 matrix, with a mat4.
