QVM: Quaternions, Vectors, Matrices

vec

#include <boost/qvm/vec.hpp>

namespace boost
{
    namespace qvm
    {
        template <class T,int Dim>
        struct vec
        {
            T a[Dim];
        
            template <class R>
            operator R() const
            {
                R r;
                assign(r,*this);
                return r;
            }
        };
        
        template <class Vector>
        struct vec_traits;
        
        template <class T,int Dim>
        struct vec_traits< vec<T,Dim> >
        {
            typedef T scalar_type;
            static int const dim=Dim;
        
            template <int I> static scalar_type read_element( vec<T,Dim> const & x ) { return x.a[I]; }
            template <int I> static scalar_type & write_element( vec<T,Dim> & x ) { return x.a[I]; }
        
            static scalar_type read_element_idx( int i, vec<T,Dim> const & x ) { return x.a[i]; }
            static scalar_type & write_element_idx( int i, vec<T,Dim> & x ) { return x.a[i]; }
        };
    }
}

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

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


See also: boost/qvm/vec.hpp