Example of use

Following is a brief example of how the CML might be used in an application (in this case using the OpenGL API):

//////////////////////////////////////////////////////////////////////////
// typedef a 3D CML vector with element type float                      //
//////////////////////////////////////////////////////////////////////////

typedef cml::vector3f vector3;

//////////////////////////////////////////////////////////////////////////
// typedef a 4x4 column-major CML matrix with element type float,       //
// configured for use with column vectors:                              //
//////////////////////////////////////////////////////////////////////////

typedef cml::matrix44f_c matrix;

//////////////////////////////////////////////////////////////////////////
// Set up a 'look at' matrix and submit it to OpenGL:                   //
//////////////////////////////////////////////////////////////////////////

vector3 eye, target, up;
eye.set(10,10,10);      // Set 'eye' to (10,10,10)
target.zero();          // Set 'target' to (0,0,0)
up.cardinal(1);         // Set 'up' to (0,1,0), the cardinal Y axis

matrix view;
cml::matrix_look_at_RH(view, eye, target, up);

glMatrixMode(GL_MODELVIEW);
glLoadMatrixf( view.data() ); // data() returns pointer to matrix elements

//////////////////////////////////////////////////////////////////////////
// Set up an axially-aligned billboard aligned to the global y axis     //
//////////////////////////////////////////////////////////////////////////

vector3 pos(5,0,5);
vector3 axis(0,1,0);
matrix billboard;
cml::matrix_aim_at_axial(
    billboard,            // matrix in which to build the transform
    pos,                  // the position of the billboard
    eye,                  // the position to aim at (i.e. the camera)
    axis                  // the axis to align to
);
glMultMatrixf( billboard.data() );

//////////////////////////////////////////////////////////////////////////
// Draw the billboard                                                   //
//////////////////////////////////////////////////////////////////////////

vector3 v1(-1,0,0),
        v2( 1,0,0),
        v3( 1,2,0),
        v4(-1,2,0);

glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_LINE_LOOP);
glVertex3fv( v1.data() );
glVertex3fv( v2.data() );
glVertex3fv( v3.data() );
glVertex3fv( v4.data() );
glEnd();