TMat4



This template represents 4x4 matrix. It uses row major order of data.

You can find more information in comments below.

template<class TYPE>
union TMat4
{
    struct
    {
        TYPE _11, _12, _13, _14; // First row
        TYPE _21, _22, _23, _24; // Second row
        TYPE _31, _32, _33, _34; // Third row
        TYPE _41, _42, _43, _44; // Fourth row
    };
    TVec4<TYPE> Rows[4]; // Rows as vectors
    TYPE Data[16]; // Elements as array
    TMatrix<TYPE, 4, 4> M; // As TMatrix

    TMat4() = default;
    TMat4(const TMat4 &other) = default;
    TMat4(TMat4 &&other) = default;

    // Create with specified elements
    TMat4(
        const TYPE m11, const TYPE m12, const TYPE m13, const TYPE m14,
        const TYPE m21, const TYPE m22, const TYPE m23, const TYPE m24,
        const TYPE m31, const TYPE m32, const TYPE m33, const TYPE m34,
        const TYPE m41, const TYPE m42, const TYPE m43, const TYPE m44);

    // Create with specified rows
    TMat4(const TVec4<TYPE> &row1, const TVec4<TYPE> &row2, const TVec4<TYPE> &row3, const TVec4<TYPE> &row4);

    // Create diagonal matrix
    TMat4(const TYPE diagonal, const TYPE other);

    // Create from TMatrix
    TMat4(const TMatrix<TYPE, 4, 4> &m);

    // Create from rotation quaternion
    TMat4(const TQuaternion<TYPE> &q);

    TMat4 &operator=(const TMat4 &other) = default;
    TMat4 &operator=(TMat4 &&other) = default;

    TVec4<TYPE> operator[](const size_t row) const; // Return specified row. Used when matrix is a constant
    TVec4<TYPE> &operator[](const size_t row); // Return specified row
};

Additionally following operators exists.

template<class TYPE>
bool operator==(const TMat4<TYPE> &a, const TMat4<TYPE> &b); // Check whether matrices are equal. Can be used for non-float data types only
template<class TYPE>
bool operator!=(const TMat4<TYPE> &a, const TMat4<TYPE> &b); // Check whether matrices aren't equal. Can be used for non-float data types only
template<class TYPE>
TMat4<TYPE> operator+(const TMat4<TYPE> &m, const TYPE val); // Add matrix and scalar
template<class TYPE>
TMat4<TYPE> operator-(const TMat4<TYPE> &m, const TYPE val); // Subtruct matrix and scalar
template<class TYPE>
TMat4<TYPE> operator*(const TMat4<TYPE> &m, const TYPE val); // Multiply matrix and scalar
template<class TYPE>
TMat4<TYPE> operator/(const TMat4<TYPE> &m, const TYPE val); // Divide matrix and scalar
template<class TYPE>
TMat4<TYPE> operator+(const TYPE val, const TMat4<TYPE> &m); // Add scalar and matrix
template<class TYPE>
TMat4<TYPE> operator-(const TYPE val, const TMat4<TYPE> &m); // Subtruct scalar and matrix
template<class TYPE>
TMat4<TYPE> operator*(const TYPE val, const TMat4<TYPE> &m); // Multiply scalar and matrix
template<class TYPE>
TMat4<TYPE> operator/(const TYPE val, const TMat4<TYPE> &m); // Divide scalar and matrix
template<class TYPE>
TMat4<TYPE> &operator+=(TMat4<TYPE> &m, const TYPE val); // Add scalar to matrix
template<class TYPE>
TMat4<TYPE> &operator-=(TMat4<TYPE> &m, const TYPE val); // Subtract scalar from matrix
template<class TYPE>
TMat4<TYPE> &operator*=(TMat4<TYPE> &m, const TYPE val); // Multiply matrix by scalar
template<class TYPE>
TMat4<TYPE> &operator/=(TMat4<TYPE> &m, const TYPE val); // Divide matrix by scalar
template<class TYPE>
TVec3<TYPE> operator*(const TVec3<TYPE> &v, const TMat4<TYPE> &m); // Multiply vector and matrix
template<class TYPE>
TVec3<TYPE> &operator*=(TVec3<TYPE> &v, const TMat4<TYPE> &m); // Multiply vector by matrix
template<class TYPE>
TVec3<TYPE> operator*(const TMat4<TYPE> &m, const TVec3<TYPE> &v); // Multiply matrix and vector
template<class TYPE>
TVec4<TYPE> operator*(const TVec4<TYPE> &v, const TMat4<TYPE> &m); // Multiply vector and matrix
template<class TYPE>
TVec4 &operator*=(TVec4<TYPE> &v, const TMat4<TYPE> &m); // Multiply vector by matrix
template<class TYPE>
TVec4<TYPE> operator*(const TMat4<TYPE> &m, const TVec4<TYPE> &v); // Multiply matrix and vector
template<class TYPE>
TQuaternion<TYPE> operator*(const TQuaternion<TYPE> &q, const TMat4<TYPE> &m); // Multiply quaternion and matrix
template<class TYPE>
TQuaternion<TYPE> &operator*=(TQuaternion<TYPE> &q, const TMat4<TYPE> &m); // Multiply quaternion by matrix
template<class TYPE>
TQuaternion<TYPE> operator*(const TMat4<TYPE> &m, const TQuaternion<TYPE> &q); // Multiply matrix and quaternion
template<class TYPE>
TMat4<TYPE> operator*(const TMat4<TYPE> &a, const TMat4<TYPE> &b); // Multiply matrices
template<class TYPE>
TMat4<TYPE> &operator*=(TMat4<TYPE> &a, const TMat4<TYPE> &b); // Multiply matrix by matrix

Also there are some functions which can be used with TMat2 template. Here they are.

Namespace: ntl
Include: NTL/Core/Mat4.h