mat4

Header file: include/mat4.h

mat4 is a column-major matrix with 4 columns and 4 rows.

\(mat4 = \begin{bmatrix} x.x & y.x & z.x & w.x \\ x.y & y.y & z.y & w.y \\ x.z & y.z & z.z & w.z \\ x.w & y.w & z.w & w.w \end{bmatrix}\)

Class variables

Type

Name

Description

nml::vec4

x

The first column of the mat4.

nml::vec4

y

The second column of the mat4.

nml::vec4

z

The third column of the mat4.

nml::vec4

w

The fourth column of the mat4.

Class functions

Constructors

Name

Description

mat4()

Construct a ([0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]) matrix.

mat4(float _value)

Construct a ([_value, _value, _value, _value], [_value, _value, _value, _value], [_value, _value, _value, _value], [_value, _value, _value, _value]) matrix.

mat4(float _xx, float _xy, float _xz, float _xw, float _yx, float _yy, float _yz, float _yw, float _zx, float _zy, float _zz, float _zw, float _wx, float _wy, float _wz, float _ww)

Construct a ([_xx, _xy, _xz, _xw], [_yx, _yy, _yz, _yw], [_zx, _zy, _zz, _zw], [_wx, _wy, _wz, _ww]) matrix.

mat4(float _xx, float _xy, float _xz, float _xw, float _yx, float _yy, float _yz, float _yw, float _zx, float _zy, float _zz, float _zw, const nml::vec4& _w)

Construct a ([_xx, _xy, _xz, _xw], [_yx, _yy, _yz, _yw], [_zx, _zy, _zz, _zw], [_w.x, _w.y, _w.z, _w.w]) matrix.

mat4(float _xx, float _xy, float _xz, float _xw, float _yx, float _yy, float _yz, float _yw, const nml::vec4& _z, float _wx, float _wy, float _wz, float _ww)

Construct a ([_xx, _xy, _xz, _xw], [_yx, _yy, _yz, _yw], [_z.x, _z.y, _z.z, _z.w], [_wx, _wy, _wz, _ww]) matrix.

mat4(float _xx, float _xy, float _xz, float _xw, const nml::vec4& _y, float _zx, float _zy, float _zz, float _zw, float _wx, float _wy, float _wz, float _ww)

Construct a ([_xx, _xy, _xz, _xw], [_y.x, _y.y, _y.z, _y.w], [_zx, _zy, _zz, _zw], [_wx, _wy, _wz, _ww]) matrix.

mat4(const nml::vec4& _x, float _yx, float _yy, float _yz, float _yw, float _zx, float _zy, float _zz, float _zw, float _wx, float _wy, float _wz, float _ww)

Construct a ([_x.x, _x.y, _x.z, _x.w], [_yx, _yy, _yz, _yw], [_zx, _zy, _zz, _zw], [_wx, _wy, _wz, _ww]) matrix.

mat4(float _xx, float _xy, float _xz, float _xw, float _yx, float _yy, float _yz, float _yw, const nml::vec4& _z, const nml::vec4& _w)

Construct a ([_xx, _xy, _xz, _xw], [_yx, _yy, _yz, _yw], [_z.x, _z.y, _z.z, _z.w], [_w.x, _w.y, _w.z, _w.w]) matrix.

mat4(float _xx, float _xy, float _xz, float _xw, const nml::vec4& _y, float _zx, float _zy, float _zz, float _zw, const nml::vec4& _w)

Construct a ([_xx, _xy, _xz, _xw], [_y.x, _y.y, _y.z, _y.w], [_zx, _zy, _zz, _zw], [_w.x, _w.y, _w.z, _w.w]) matrix.

mat4(const nml::vec4& _x, float _yx, float _yy, float _yz, float _yw, float _zx, float _zy, float _zz, float _zw, const nml::vec4& _w)

Construct a ([_x.x, _x.y, _x.z, _x.w], [_yx, _yy, _yz, _yw], [_zx, _zy, _zz, _zw], [_w.x, _w.y, _w.z, _w.w]) matrix.

mat4(float _xx, float _xy, float _xz, float _xw, const nml::vec4& _y, const nml::vec4& _z, float _wx, float _wy, float _wz, float _ww)

Construct a ([_xx, _xy, _xz, _xw], [_y.x, _y.y, _y.z, _y.w], [_z.x, _z.y, _z.z, _z.w], [_wx, _wy, _wz, _ww]) matrix.

mat4(const nml::vec4& _x, float _yx, float _yy, float _yz, float _yw, const nml::vec4& _z, float _wx, float _wy, float _wz, float _ww)

Construct a ([_x.x, _x.y, _x.z, _x.w], [_yx, _yy, _yz, _yw], [_z.x, _z.y, _z.z, _z.w], [_wx, _wy, _wz, _ww]) matrix.

mat4(const nml::vec4& _x, const nml::vec4& _y, float _zx, float _zy, float _zz, float _zw, float _wx, float _wy, float _wz, float _ww)

Construct a ([_x.x, _x.y, _x.z, _x.w], [_y.x, _y.y, _y.z, _y.w], [_zx, _zy, _zz, _zw], [_wx, _wy, _wz, _ww]) matrix.

mat4(float _xx, float _xy, float _xz, float _xw, const nml::vec4& _y, const nml::vec4& _z, const nml::vec4& _w)

Construct a ([_xx, _xy, _xz, _xw], [_y.x, _y.y, _y.z, _y.w], [_z.x, _z.y, _z.z, _z.w], [_w.x, _w.y, _w.z, _w.w]) matrix.

mat4(const nml::vec4& _x, float _yx, float _yy, float _yz, float _yw, const nml::vec4& _z, const nml::vec4& _w)

Construct a ([_x.x, _x.y, _x.z, _x.w], [_yx, _yy, _yz, _yw], [_z.x, _z.y, _z.z, _z.w], [_w.x, _w.y, _w.z, _w.w]) matrix.

mat4(const nml::vec4& _x, const nml::vec4& _y, float _zx, float _zy, float _zz, float _zw, const nml::vec4& _w)

Construct a ([_x.x, _x.y, _x.z, _x.w], [_y.x, _y.y, _y.z, _y.w], [_zx, _zy, _zz, _zw], [_w.x, _w.y, _w.z, _w.w]) matrix.

mat4(const nml::vec4& _x, const nml::vec4& _y, const nml::vec4& _z, float _wx, float _wy, float _wz, float _ww)

Construct a ([_x.x, _x.y, _x.z, _x.w], [_y.x, _y.y, _y.z, _y.w], [_z.x, _z.y, _z.z, _z.w], [_wx, _wy, _wz, _ww]) matrix.

mat4(const nml::vec4& _x, const nml::vec4& _y, const nml::vec4& _z, const nml::vec4& _w)

Construct a ([_x.x, _x.y, _x.z, _x.w], [_y.x, _y.y, _y.z, _y.w], [_z.x, _z.y, _z.z, _z.w], [_w.x, _w.y, _w.z, _w.w]) matrix.

mat4(const float* _ptr)

Construct a matrix from a pointer.

Operators

Name

Description

nml::mat4& operator+=(const nml::mat4& other)

Add a mat4 to the current mat4.

nml::mat4& operator-=(const nml::mat4& other)

Substract a mat4 from the current mat4.

nml::mat4& operator*=(const nml::mat4& other)

Multiply the current mat4 by a mat4.

nml::mat4& operator*=(const float other)

Multiply the current mat4 by a scalar.

nml::mat4& operator/=(const float other)

Divide the current mat4 by a scalar.

nml::vec4& operator[](size_t index)

Return a reference to x if index is 0, a reference to y if index is 1, a reference to z if index is 2 or a reference to w if index is 3 else, throw an exception.

const nml::vec4& operator[](size_t index) const

Return a const reference to x if index is 0, a const reference to y if index is 1, a const reference to z if index is 2 or a const reference to w if index is 3 else, throw an exception.

Functions

Name

Description

float det() const

Return the determinant of the matrix.

float* data()

Return a pointer to the matrix’s elements.

Static Functions

Name

Description

nml::mat4 nml::mat4::identity()

Return a ([1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]) identity matrix.

Namespace functions

Operators

Name

Description

nml::mat4 operator+(nml::mat4 lhs, const nml::mat4& rhs)

Return a mat4 that is the sum between two mat4.

nml::mat4 operator-(nml::mat4 lhs, const nml::mat4& rhs)

Return a mat4 that is the difference between two mat4.

nml::mat4 operator*(nml::mat4 lhs, const nml::mat4& rhs)

Return a mat4 that is the product between two mat4.

nml::vec4 operator*(nml::mat4 lhs, const nml::vec4& rhs)

Return a vec4 that is the product between a mat4 and a vec4.

nml::mat4 operator*(nml::mat4 lhs, const float rhs)

Return a mat4 that is the product between a mat4 and a scalar.

nml::mat4 operator*(float lhs, const nml::mat4& rhs)

Return a mat4 that is the product between a scalar and a mat4.

nml::mat4 operator/(nml::mat4 lhs, const float rhs)

Return a mat4 that is the quotient between a mat4 and a scalar.

bool operator==(const nml::mat4& lhs, const nml::mat4& rhs)

Return true if the two mat4 are identical, else, return false.

bool operator!=(const nml::mat4& lhs, const nml::mat4& rhs)

Return true if the two mat4 are different, else, return false.

Functions

Name

Description

nml::mat4 transpose(const nml::mat4& mat)

Return a mat4 where the columns of mat are the rows and the rows of mat are the columns.

nml::mat4 inverse(const nml::mat4& mat)

Return the inverse of a mat4.

nml::mat4 translate(const nml::vec3& translation)

Return a 3D translation matrix according to the translation vector.

nml::mat4 rotate(const float angle, const nml::vec3& axis)

Return a 3D rotation matrix according to the angle (in radians) and the axis.

nml::mat4 scale(const nml::vec3& scaling)

Return a 3D scaling matrix according to the scaling factors.

nml::mat4 lookAtLH(const nml::vec3& from, const nml::vec3& to, const nml::vec3& up)

Return a left-hand look at view matrix.

nml::mat4 lookAtRH(const nml::vec3& from, const nml::vec3& to, const nml::vec3& up)

Return a right-hand look at view matrix.

nml::mat4 orthoLH(const float left, const float right, const float bottom, const float top, const float near, const float far)

Return a left-hand orthographic projection matrix.

nml::mat4 orthoRH(const float left, const float right, const float bottom, const float top, const float near, const float far)

Return a right-hand orthographic projection matrix.

nml::mat4 perspectiveLH(const float fovY, const float aspectRatio, const float near, const float far)

Return a left-hand perspective projection matrix.

nml::mat4 perspectiveRH(const float fovY, const float aspectRatio, const float near, const float far)

Return a right-hand perspective projection matrix.

void nml::decomposeTransform(const nml::mat4& transform, nml::vec3& translation, nml::quat& rotation, nml::vec3& scale)

Decompose a transform matrix into a translation vector, a rotation quaternion and a scale vector.

nml::mat4 quatToRotationMatrix(const quat& qua)

Return a 3D rotation matrix from a quaternion.

std::string nml::to_string(const nml::mat4& mat)

Return a mat4 as a string under the format “[[x.x, x.y, x.z, x.w], [y.x, y.y, y.z, y.w], [z.x, z.y, z.z, z.w], [w.x, w.y, w.z, w.w]]”.