Index: trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrMatrix4x4f.h
===================================================================
--- trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrMatrix4x4f.h	(revision 2841)
+++ trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrMatrix4x4f.h	(revision 2842)
@@ -11,4 +11,9 @@
 {
 public:
+    vrMatrix4x4f()
+    {
+        makeIdentity();
+    }
+
     /**
      * @brief make a identity matrix
Index: trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrQuaternion.h
===================================================================
--- trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrQuaternion.h	(revision 2841)
+++ trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrQuaternion.h	(revision 2842)
@@ -17,9 +17,33 @@
 public:
     vrQuaternion();
+
     explicit vrQuaternion(const vrRotation& rot);
+
     vrQuaternion(float x, float y = 0, float z = 0, float w = 0);
 
     void set(float x1, float y1, float z1, float w1);
+
     const vrQuaternion& set(const vrRotation& rot);
+
+    vrQuaternion conjugate() const
+    {
+        vrQuaternion result;
+        result.w = w;
+        result.x = -x;
+        result.y = -y;
+        result.z = -z;
+        return result;
+    }
+
+    vrQuaternion reciprocal() const
+    {
+        double denom =  w*w + x*x + y*y + z*z;
+        vrQuaternion result = conjugate();
+        result.x /= denom;
+        result.y /= denom;
+        result.z /= denom;
+        result.w /= denom;
+        return result;
+    }
 
     void slerp(const vrRotation &a,const vrRotation &b, const float t);
@@ -28,4 +52,14 @@
 
     const vrQuaternion& normalize();
+
+    vrQuaternion operator*(const vrQuaternion& q2) const
+    {
+        vrQuaternion result;
+        result.w = (w * q2.w) - (x * q2.x) - (y * q2.y) - (z * q2.z);
+        result.x = (w * q2.x) + (x * q2.w) + (y * q2.z) - (z * q2.y);
+        result.y = (w * q2.y) + (y * q2.w) + (z * q2.x) - (x * q2.z);
+        result.z = (w * q2.z) + (z * q2.w) + (x * q2.y) - (y * q2.x);
+        return result;
+    }
 
     friend bool operator==(const vrQuaternion& q1, const vrQuaternion& q2);
Index: trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrRotation.h
===================================================================
--- trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrRotation.h	(revision 2841)
+++ trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrRotation.h	(revision 2842)
@@ -8,4 +8,7 @@
 class vrQuaternion;
 
+/**
+ * Represents an axis/angle rotation
+ */
 class vrRotation
 {
@@ -28,11 +31,13 @@
     float getAngle() const;
 
+    vrQuaternion getQuaternion() const;
+
     void set(float x, float y, float z, float angle);
-    void set(const vrVector3f &vec1, const vrVector3f &vec2);
+    void set(const vrVector3f& vec1, const vrVector3f& vec2);
     void set(const vrQuaternion& quat);
     void set(const vrRotation& rot);
     void setAxis(float x, float y, float z);
     void setAngle(float angle);
-	
+
     friend bool operator!=(const vrRotation& rot1, const vrRotation& rot2);
     friend bool operator==(const vrRotation& rot1, const vrRotation& rot2);
Index: trunk/packages/vizservers/nanovis/vrmath/vrMatrix4x4f.cpp
===================================================================
--- trunk/packages/vizservers/nanovis/vrmath/vrMatrix4x4f.cpp	(revision 2841)
+++ trunk/packages/vizservers/nanovis/vrmath/vrMatrix4x4f.cpp	(revision 2842)
@@ -7,6 +7,6 @@
 {
     _data[1] = _data[2] = _data[3] = _data[4] =
-	_data[6] = _data[7] = _data[8] = _data[9] =
-	_data[11] = _data[12] = _data[13] = _data[14] = 0.0f;
+        _data[6] = _data[7] = _data[8] = _data[9] =
+        _data[11] = _data[12] = _data[13] = _data[14] = 0.0f;
     _data[0] = _data[5] = _data[10] = _data[15] = 1.0f;
 }
@@ -15,6 +15,6 @@
 {
     _data[1] = _data[2] = _data[3] = _data[4] =
-	_data[6] = _data[7] = _data[8] = _data[9] =
-	_data[11] = 0.0f;
+        _data[6] = _data[7] = _data[8] = _data[9] =
+        _data[11] = 0.0f;
     _data[0] = _data[5] = _data[10] = _data[15] = 1.0f;
     _data[12] = translation.x;
@@ -26,6 +26,6 @@
 {
     _data[1] = _data[2] = _data[3] = _data[4] =
-	_data[6] = _data[7] = _data[8] = _data[9] =
-	_data[11] = 0.0f;
+        _data[6] = _data[7] = _data[8] = _data[9] =
+        _data[11] = 0.0f;
     _data[0] = _data[5] = _data[10] = _data[15] = 1.0f;
     _data[12] = x;
@@ -36,5 +36,8 @@
 void vrMatrix4x4f::makeRotation(const vrRotation& rotation)
 {
-    if (rotation.getX() == 0.0f && rotation.getY() == 0.0f && rotation.getZ() == 0.0f) {
+    if (rotation.getAngle() == 0.0f || 
+        (rotation.getX() == 0.0f &&
+         rotation.getY() == 0.0f &&
+         rotation.getZ() == 0.0f)) {
         makeIdentity();
         return;
@@ -42,5 +45,5 @@
 
     float xAxis = rotation.getX(), yAxis = rotation.getY(), zAxis = rotation.getZ();
-    float invLen = 1.0f / sqrt( xAxis * xAxis + yAxis * yAxis + zAxis * zAxis);
+    float invLen = 1.0f / sqrt(xAxis * xAxis + yAxis * yAxis + zAxis * zAxis);
     float cosine = cos(rotation.getAngle());
     float sine = sin(rotation.getAngle());
@@ -70,10 +73,13 @@
 void vrMatrix4x4f::makeRotation(float xAxis, float yAxis, float zAxis, float angle)
 {
-    if (xAxis == 0.0f && yAxis == 0.0f && zAxis == 0.0f) {
+    if (angle == 0.0f ||
+        (xAxis == 0.0f &&
+         yAxis == 0.0f &&
+         zAxis == 0.0f)) {
         makeIdentity();
         return;
     }
 
-    float invLen = 1.0f / sqrt( xAxis * xAxis + yAxis * yAxis + zAxis * zAxis);
+    float invLen = 1.0f / sqrt(xAxis * xAxis + yAxis * yAxis + zAxis * zAxis);
     float cosine = cos(angle);
     float sine = sin(angle);
@@ -101,10 +107,9 @@
 }
 
-
 void vrMatrix4x4f::makeScale(const vrVector3f& scale)
 {
     _data[1] = _data[2] = _data[3] = _data[4] =
-	_data[6] = _data[7] = _data[8] = _data[9] =
-	_data[11] = 0.0f;
+        _data[6] = _data[7] = _data[8] = _data[9] =
+        _data[11] = 0.0f;
 
     _data[0] = scale.x;
@@ -119,5 +124,5 @@
 {
     float mat[16];
-    float* mat1 = (float*) m1._data;
+    float *mat1 = (float *)m1._data;
 
     // 1 row
@@ -169,6 +174,6 @@
 {
     float mat[16];
-    float* mat1 = (float*) m1._data;
-    float* mat2 = (float*) m2._data;
+    float *mat1 = (float *)m1._data;
+    float *mat2 = (float *)m2._data;
 
     // 1 row
@@ -218,6 +223,6 @@
 void vrMatrix4x4f::multiplyFast(const vrMatrix4x4f& m1, const vrMatrix4x4f& m2)
 {
-    float* mat1 = (float*) m1._data;
-    float* mat2 = (float*) m2._data;
+    float *mat1 = (float *)m1._data;
+    float *mat2 = (float *)m2._data;
 
     // 1 row
@@ -284,5 +289,4 @@
 
 void vrMatrix4x4f::invert()
-
 {
     float det =
@@ -432,9 +436,7 @@
 }
 
-
-
 void vrMatrix4x4f::invert(const vrMatrix4x4f& mat)
 {
-    float* data = (float*) mat._data;
+    float *data = (float *)mat._data;
 
     float det =
@@ -586,5 +588,5 @@
 void vrMatrix4x4f::invertFast(const vrMatrix4x4f& mat)
 {
-    float* srcData = (float*) mat._data;
+    float *srcData = (float *)mat._data;
 
     float det =
@@ -810,5 +812,5 @@
 {
     for (int i = 0; i < 16; ++i) {
-        _data[i] = (float) m[i];
+        _data[i] = (float)m[i];
     }
 }
Index: trunk/packages/vizservers/nanovis/vrmath/vrRotation.cpp
===================================================================
--- trunk/packages/vizservers/nanovis/vrmath/vrRotation.cpp	(revision 2841)
+++ trunk/packages/vizservers/nanovis/vrmath/vrRotation.cpp	(revision 2842)
@@ -1,3 +1,5 @@
 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+#include <math.h>
+
 #include <vrmath/vrRotation.h>
 #include <vrmath/vrVector3f.h>
@@ -17,5 +19,5 @@
     cross.cross(vec1, vec2);
 
-    float ang = atan2( cross.length(), vec1.dot(vec2) );
+    float ang = atan2(cross.length(), vec1.dot(vec2));
 
     cross.normalize();
@@ -33,5 +35,9 @@
     angle = acos(quat.w) * 2.0f;
     float scale = sqrt(1 - quat.w * quat.w);
-    if (scale < 0.001) {
+    if (angle < 1.0e-6f) {
+        x = 1;
+        y = 0;
+        z = 0;
+    } else if (scale < 1.0e-6f) {
         x = quat.x;
         y = quat.y;
@@ -42,10 +48,16 @@
         z = quat.z / scale;
     }
-    /*
-    // http://gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation#Quaternion_to_axis-angle
-    float scale = sqrt(quat.x * quat.x + quat.y * quat.y + quat.z * quat.z);
-    x = quat.x / scale;
-    y = quat.y / scale;
-    z = quat.z / scale;
-    */
 }
+
+vrQuaternion vrRotation::getQuaternion() const
+{
+    vrQuaternion result;
+
+    result.w = cos(angle / 2.0);
+    double sinHalfAngle = sin(angle / 2.0);
+    result.x = x * sinHalfAngle;
+    result.y = y * sinHalfAngle;
+    result.z = z * sinHalfAngle;
+
+    return result;
+}
