TMat3


This object has been removed in release 10.0.0. Use NTL objects instead.

Template class for working with 3x3 matrices. If you use matrix for transforming vector pay attention on the fact that the matrix is designed to be used for such a purpose in the way that vector should be multiplied to the matrix. If you try to multiply, for example rotate, matrix to a vector, you will get wrong transformation. The matrix give you access to the entire elements data by returning pointer to it via data() method. This can be used, for example, for direct data uploading into your shader program without any temporary storages(in you shader program you, as well, should multiply vector on matrix and not vise versa) and without transposing.

You can find more information in comments below.

template<class TYPE>
    class TMat3
    {
    public:
        // Indices 
        static const size_t _11{ 0 }, _21{ 1 }, _31{ 2 };
        static const size_t _12{ 3 }, _22{ 4 }, _32{ 5 };
        static const size_t _13{ 6 }, _23{ 7 }, _33{ 8 };
    
        TMat3();
        TMat3(const TYPE diagonal); // Create diaginal matrix with all diagonal elements equal to the specified value 
        TMat3(const TYPE _11, const TYPE _22, const TYPE _33); // Create diaginal matrix with diagonal elements equal to the specified values 
        TMat3(const TVec3<TYPE> &row1, const TVec3<TYPE> &row2, const TVec3<TYPE> &row3); // Create with specified rows 
        TMat3(const TMat3 &other);
        TMat3(TMat3 &&other);
        ~TMat3();
    
        const TYPE &operator[](const size_t index) const; // Return constant reference to the element with specified index 
        TYPE &operator[](const size_t index); // Return reference to the element with specified index 
        bool operator==(const TMat3 &other) const; // Strict comparison for equality 
        bool operator!=(const TMat3 &other) const; // Strict comparison for inequality 
        TMat3 &operator=(const TMat3 &other);
        TMat3 &operator=(TMat3 &&other);
    
        TMat3 operator+(const TYPE value) const; // Add scalar value to all elements and return new matrix 
        TMat3 operator-(const TYPE value) const; // Subtract scalar value from all elements and return new matrix 
        TMat3 operator*(const TYPE value) const; // Multiply scalar value to all elements and return new matrix 
        TMat3 operator/(const TYPE value) const; // Divide all elements on scalar value and return new matrix 
        TMat3 &operator+=(const TYPE value); // Add scalar value to all elements of this matrix 
        TMat3 &operator-=(const TYPE value); // Subtract scalar value from all elements of this matrix 
        TMat3 &operator*=(const TYPE value); // Multiply scalar value to all elements of this matrix 
        TMat3 &operator/=(const TYPE value); // Divide all elements on scalar value of this matrix 
    
        TMat3 operator+(const TMat3 &other) const; // Add elements of another matrix to corresponding elements of this matrix and return new matrix 
        TMat3 operator-(const TMat3 &other) const; // Subtract elements of another matrix from corresponding elements of this matrix and return new matrix 
        TMat3 operator*(const TMat3 &other) const; // Multiply elements of another matrix on corresponding elements of this matrix and return new matrix 
        TMat3 operator/(const TMat3 &other) const; // Divide elements of this matrix on corresponding elements of another matrix and return new matrix 
        TMat3 operator^(const TMat3 &other) const; // Multiply matrices 
        TMat3 &operator+=(const TMat3 &other); // Add elements of another matrix to corresponding elements of this matrix 
        TMat3 &operator-=(const TMat3 &other); // Subtract elements of another matrix from corresponding elements of this matrix 
        TMat3 &operator*=(const TMat3 &other); // Multiply elements of another matrix on corresponding elements of this matrix 
        TMat3 &operator/=(const TMat3 &other); // Divide elements of this matrix on corresponding elements of another matrix 
        TMat3 &operator^=(const TMat3 &other); // Multiply matrices and store result in this one 
    
        const TYPE *data() const; // Return pointer to elements array 
        TYPE get(const size_t column, const size_t row) const; // Get specified element 
        void set(const size_t column, const size_t row, const TYPE value); // Set specified element 
        bool is_equal(const TMat3 &other, const TYPE tolerance) const; // Soft comparison for equality with another matrix 
        bool is_not_equal(const TMat3 &other, const TYPE tolerance) const; // Soft comparison for inequality with another matrix 
        TMat2<TYPE> minor(const size_t column, const size_t row) const; // Return minor 
        TYPE determinant() const; // Calculate determinant 
        void transpose(); // Transpose this matrix 
        TMat3 transposed() const; // Return matrix transposed to this one 
        void inverse(); // Inverse this matrix 
        TMat3 inversed() const; // Return matrix inversed to this one 
        void identity(); // Make this matrix identity 
        void diagonal(const TYPE value); // Make this matrix diagonal with all diagonal elements equal to specified value 
        void diagonal(const TYPE _11, const TYPE _22, const TYPE _33); // Make this matrix diagonal with diagonal elements equal to specified values 
        void scale(const TYPE x, const TYPE y, const TYPE z); // Make scaling matrix 
        void rotate_x(const TYPE angle); // Make rotation around X-axis matrix 
        void rotate_y(const TYPE angle); // Make rotation around Y-axis matrix 
        void rotate_z(const TYPE angle); // Make rotation around Z-axis matrix 
        void rotate(const TYPE angle_z, const TYPE angle_y, const TYPE angle_x); // Make rotation matrix with spaceified rotation angles around axes 
        void rotate(const TYPE angle, const TVec3<TYPE> &v); // Make rotation matrix around specified vector/axes 
    };

Additionally following operators exists and can be used for arithmetic operations with scalar value and 3x3 matrices and 3D vectors. So as a final result you may use the 3x3 matrix template with scalar/3D vector values in both directions(scalar * matrix and matrix * scalar). Pay attention on the -, /, and ^ operators. The result of operation like scalar - matrix will be different from the result of operation like matrix - scalar.

template<class TYPE> TMat3<TYPE> operator+(const TYPE value, const TMat3<TYPE> &m);
    template<class TYPE> TMat3<TYPE> operator-(const TYPE value, const TMat3<TYPE> &m);
    template<class TYPE> TMat3<TYPE> operator*(const TYPE value, const TMat3<TYPE> &m);
    template<class TYPE> TMat3<TYPE> operator/(const TYPE value, const TMat3<TYPE> &m);
    template<class TYPE> TVec3<TYPE> operator^(const TVec3<TYPE> &v, const TMat3<TYPE> &m);
    template<class TYPE> TVec3<TYPE> &operator^=(TVec3<TYPE> &v, const TMat3<TYPE> &m);
    template<class TYPE> TVec3<TYPE> operator^(const TMat3<TYPE> &m, const TVec3<TYPE> &v);
Namespace: nitisa::math
Include: Nitisa/Modules/Math/Matrix.h