Boost QVM

Quaternion, Vector and Matrix Types

Boost QVM does define generic yet simple quaternion, vector and matrix types, however it has been designed to work with user-defined quaternions, vectors and matrices.

A user-defined 3D vector type float3 can be introduced to Boost QVM as follows:

#include <boost/qvm/v_traits.hpp>

struct float3 { float a[3]; };

namespace boost
{
    namespace qvm
    {
        template <>
        struct v_traits<float3>
        {
            static int const dim=3;
            typedef float scalar_type;

            template <int I> static inline scalar_type & w( float3 & v ) { return v.a[I]; }
            template <int I> static inline scalar_type r( float3 const & v ) { return v.a[I]; }

            static inline scalar_type & iw( int i, float3 & v ) { return v.a[i]; }
            static inline scalar_type ir( int i, float3 const & v ) { return v.a[i]; }
        };
    }
}

After a similar specialization of the m_traits template for a user-defined 3x3 matrix type float33, a full range of vector and matrix operations defined in Boost QVM headers become available automatically:

float3 v;
v%X = 0;
v%Y = 0;
v%Z = 7;
float vmag = mag(v);
float33 m = rotx_m<3>(3.14159f);
float3 vrot = m * v;

User-defined quaternion types are similarly introduced to Boost QVM by specializing the q_traits template.


Tutorial: Quaternion, Vector and Matrix Types | C Arrays | Views | Swizzling | Interoperability | Back to Boost QVM