TMat3



This template represents 3x3 matrix. It uses row major order of data.

You can find more information in comments below.

template<class TYPE>
union TMat3
{
    struct
    {
        TYPE _11, _12, _13; // First row
        TYPE _21, _22, _23; // Second row
        TYPE _31, _32, _33; // Third row
    };
    TVec3<TYPE> Rows[3]; // Rows as vectors
    TYPE Data[9]; // Elements as array
    TMatrix<TYPE, 3, 3> M; // As TMatrix

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

    // Create with specified elements
    TMat3(
        const TYPE m11, const TYPE m12, const TYPE m13,
        const TYPE m21, const TYPE m22, const TYPE m23,
        const TYPE m31, const TYPE m32, const TYPE m33);

    // Create with specified rows
    TMat3(const TVec3<TYPE> &row1, const TVec3<TYPE> &row2, const TVec3<TYPE> &row3);

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

    // Create from TMatrix
    TMat3(const TMatrix<TYPE, 3, 3> &m);

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

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

Additionally following operators exists.

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