QVM: Quaternions, Vectors, Matrices

mat

#include <boost/qvm/mat.hpp>

namespace boost
{
    namespace qvm
    {
        template <class T,int Rows,int Cols>
        struct mat
        {
            T a[Rows][Cols];
        
            template <class R>
            operator R() const
                {
                R r;
                assign(r,*this);
                return r;
                }
        };
        
        template <class Matrix>
        struct mat_traits;
        
        template <class T,int Rows,int Cols>
        struct mat_traits< mat<T,Rows,Cols> >
        {
            typedef T scalar_type;
            static int const rows=Rows;
            static int const cols=Cols;
        
            template <int Row,int Col> static scalar_type read_element( mat<T,Rows,Cols> const & x ) { return x.a[Row][Col]; }
            template <int Row,int Col> static scalar_type & write_element( mat<T,Rows,Cols> & x ) { return x.a[Row][Col]; }
        
            static scalar_type read_element_idx( int row, int col, mat<T,Rows,Cols> const & x ) { return x.a[row][col]; }
            static scalar_type & write_element_idx( int row, int col, mat<T,Rows,Cols> & x ) { return x.a[row][col]; }
        };
    }
}

This is a simple matrix type. It converts to any other matrix type of compatible size.

The partial specialization of the mat_traits template makes the mat template compatible with the generic operations defined by Boost QVM.


See also: boost/qvm/mat.hpp