This is very off topic but anyway:

// Template for a quaternion object with common operations for performing 3D transformations.

// Note that when I say quaternion, I mean unit quaternion. Currently only useful for rotations.

// Designed to be used as quaternion or quaternion. Because of some specific

// function calls, won’t work with other types.

template class quaternion {

public:

// Convenient rename.

typedef quaternion qt;

// Constructors & destructor.

quaternion();

explicit quaternion(const qt& q);

explicit quaternion(const T& rot, const T& x, const T& y, const T& z);

explicit quaternion(const T m[]);

explicit quaternion(const T& roll, const T& pitch, const T& yaw);

~quaternion();

// Common operations on a quaternion.

qt& operator=(const qt& q);

const qt conjugate() const;

void normalize();

const qt inverse() const;

void matrix(T m[]) const;

void axisAngle(T v[]) const;

const T norm() const;

const T modulus() const;

qt& operator*=(const qt& rhs);

// operator T*() const;

// Indices for accessing the quaternion.

enum index { w=0, x, y, z };

// Constant accessor for the values held in a quaternion.

inline const T& operator[](const unsigned short int i) const { return _q[i]; };

private:

// Mutator for the values held in a quaternion.

// Don’t need it public.

inline T& operator[](const unsigned short int i) { return _q[i]; };

// Internal storage for a quaternion.

T* _q;

};

// Convenient rename.

template

typedef quaternion qt;

// Constructor for the quaternion class. Allocates memory and assigns default values.

template

quaternion::quaternion() : _q(new T[4])

{

_q[w] = 1.0f;

_q[x] = 0.0f;

_q[y] = 0.0f;

_q[z] = 0.0f;

}

// etc…

Then you use them like this:

// …

quaternion q1();

// Do some stuff with it …

quaternion q2();

// Do some stuff with it …

quaternion q3();

// Do some stuff with it (although this class is designed for floats and doubles only).

They’re extremely useful, one of the most powerful features of C++. There’s also a very tricky use for them called template metaprogramming. You need a good compiler (VC++ isn’t one - good IDE but poor compiler) and you can do some very cool maths, etc. Do a search for template metaprogramming or buy “Game Programming Gems”. Be warned, you should know how to use regular templates first and have a strong knowledge of recursion principles.

Hope that helps.