Index: code/branches/physics/src/bullet/LinearMath/CMakeLists.txt
===================================================================
--- code/branches/physics/src/bullet/LinearMath/CMakeLists.txt	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/CMakeLists.txt	(revision 2430)
@@ -1,27 +1,4 @@
-ADD_LIBRARY(LibLinearMath
-		btAlignedObjectArray.h
-		btList.h
-		btPoolAllocator.h
-		btRandom.h
-		btVector3.h
-		btDefaultMotionState.h
-		btMatrix3x3.h
-		btQuadWord.h
-		btHashMap.h
-		btScalar.h
-		btAabbUtil2.h
-		btConvexHull.h
+SET(LinearMath_SRCS
 		btConvexHull.cpp
-		btMinMax.h
-		btQuaternion.h
-		btStackAlloc.h
-		btGeometryUtil.h
-		btMotionState.h
-		btTransform.h
-		btAlignedAllocator.h
-		btIDebugDraw.h
-		btPoint3.h
-		btQuickprof.h
-		btTransformUtil.h
 		btQuickprof.cpp
 		btGeometryUtil.cpp
@@ -29,2 +6,3 @@
 )
 
+ADD_LIBRARY(LinearMath ${LinearMath_SRCS})
Index: code/branches/physics/src/bullet/LinearMath/btAabbUtil2.h
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btAabbUtil2.h	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/btAabbUtil2.h	(revision 2430)
@@ -22,4 +22,6 @@
 #include "btMinMax.h"
 
+
+
 SIMD_FORCE_INLINE void AabbExpand (btVector3& aabbMin,
 								   btVector3& aabbMax,
@@ -31,4 +33,15 @@
 }
 
+/// conservative test for overlap between two aabbs
+SIMD_FORCE_INLINE bool TestPointAgainstAabb2(const btVector3 &aabbMin1, const btVector3 &aabbMax1,
+								const btVector3 &point)
+{
+	bool overlap = true;
+	overlap = (aabbMin1.getX() > point.getX() || aabbMax1.getX() < point.getX()) ? false : overlap;
+	overlap = (aabbMin1.getZ() > point.getZ() || aabbMax1.getZ() < point.getZ()) ? false : overlap;
+	overlap = (aabbMin1.getY() > point.getY() || aabbMax1.getY() < point.getY()) ? false : overlap;
+	return overlap;
+}
+
 
 /// conservative test for overlap between two aabbs
@@ -37,7 +50,7 @@
 {
 	bool overlap = true;
-	overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? false : overlap;
-	overlap = (aabbMin1[2] > aabbMax2[2] || aabbMax1[2] < aabbMin2[2]) ? false : overlap;
-	overlap = (aabbMin1[1] > aabbMax2[1] || aabbMax1[1] < aabbMin2[1]) ? false : overlap;
+	overlap = (aabbMin1.getX() > aabbMax2.getX() || aabbMax1.getX() < aabbMin2.getX()) ? false : overlap;
+	overlap = (aabbMin1.getZ() > aabbMax2.getZ() || aabbMax1.getZ() < aabbMin2.getZ()) ? false : overlap;
+	overlap = (aabbMin1.getY() > aabbMax2.getY() || aabbMax1.getY() < aabbMin2.getY()) ? false : overlap;
 	return overlap;
 }
@@ -72,4 +85,5 @@
 		   (p.getZ() >  halfExtent.getZ() ? 0x20 : 0x0);
 }
+
 
 
@@ -83,8 +97,8 @@
 {
 	btScalar tmax, tymin, tymax, tzmin, tzmax;
-	tmin = (bounds[raySign[0]][0] - rayFrom[0]) * rayInvDirection[0];
-	tmax = (bounds[1-raySign[0]][0] - rayFrom[0]) * rayInvDirection[0];
-	tymin = (bounds[raySign[1]][1] - rayFrom[1]) * rayInvDirection[1];
-	tymax = (bounds[1-raySign[1]][1] - rayFrom[1]) * rayInvDirection[1];
+	tmin = (bounds[raySign[0]].getX() - rayFrom.getX()) * rayInvDirection.getX();
+	tmax = (bounds[1-raySign[0]].getX() - rayFrom.getX()) * rayInvDirection.getX();
+	tymin = (bounds[raySign[1]].getY() - rayFrom.getY()) * rayInvDirection.getY();
+	tymax = (bounds[1-raySign[1]].getY() - rayFrom.getY()) * rayInvDirection.getY();
 
 	if ( (tmin > tymax) || (tymin > tmax) )
@@ -97,6 +111,6 @@
 		tmax = tymax;
 
-	tzmin = (bounds[raySign[2]][2] - rayFrom[2]) * rayInvDirection[2];
-	tzmax = (bounds[1-raySign[2]][2] - rayFrom[2]) * rayInvDirection[2];
+	tzmin = (bounds[raySign[2]].getZ() - rayFrom.getZ()) * rayInvDirection.getZ();
+	tzmax = (bounds[1-raySign[2]].getZ() - rayFrom.getZ()) * rayInvDirection.getZ();
 
 	if ( (tmin > tzmax) || (tzmin > tmax) )
@@ -197,4 +211,24 @@
 }
 
+#define USE_BANCHLESS 1
+#ifdef USE_BANCHLESS
+	//This block replaces the block below and uses no branches, and replaces the 8 bit return with a 32 bit return for improved performance (~3x on XBox 360)
+	SIMD_FORCE_INLINE unsigned testQuantizedAabbAgainstQuantizedAabb(const unsigned short int* aabbMin1,const unsigned short int* aabbMax1,const unsigned short int* aabbMin2,const unsigned short int* aabbMax2)
+	{		
+		return static_cast<unsigned int>(btSelect((unsigned)((aabbMin1[0] <= aabbMax2[0]) & (aabbMax1[0] >= aabbMin2[0])
+			& (aabbMin1[2] <= aabbMax2[2]) & (aabbMax1[2] >= aabbMin2[2])
+			& (aabbMin1[1] <= aabbMax2[1]) & (aabbMax1[1] >= aabbMin2[1])),
+			1, 0));
+	}
+#else
+	SIMD_FORCE_INLINE bool testQuantizedAabbAgainstQuantizedAabb(const unsigned short int* aabbMin1,const unsigned short int* aabbMax1,const unsigned short int* aabbMin2,const unsigned short int* aabbMax2)
+	{
+		bool overlap = true;
+		overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? false : overlap;
+		overlap = (aabbMin1[2] > aabbMax2[2] || aabbMax1[2] < aabbMin2[2]) ? false : overlap;
+		overlap = (aabbMin1[1] > aabbMax2[1] || aabbMax1[1] < aabbMin2[1]) ? false : overlap;
+		return overlap;
+	}
+#endif //USE_BANCHLESS
 
 #endif
Index: code/branches/physics/src/bullet/LinearMath/btConvexHull.cpp
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btConvexHull.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/btConvexHull.cpp	(revision 2430)
@@ -343,9 +343,9 @@
 }
 
-class Tri;
-
-
-
-class Tri : public int3
+class btHullTriangle;
+
+
+
+class btHullTriangle : public int3
 {
 public:
@@ -354,10 +354,10 @@
 	int vmax;
 	btScalar rise;
-	Tri(int a,int b,int c):int3(a,b,c),n(-1,-1,-1)
+	btHullTriangle(int a,int b,int c):int3(a,b,c),n(-1,-1,-1)
 	{
 		vmax=-1;
 		rise = btScalar(0.0);
 	}
-	~Tri()
+	~btHullTriangle()
 	{
 	}
@@ -366,5 +366,5 @@
 
 
-int &Tri::neib(int a,int b)
+int &btHullTriangle::neib(int a,int b)
 {
 	static int er=-1;
@@ -380,5 +380,5 @@
 	return er;
 }
-void HullLibrary::b2bfix(Tri* s,Tri*t)
+void HullLibrary::b2bfix(btHullTriangle* s,btHullTriangle*t)
 {
 	int i;
@@ -396,5 +396,5 @@
 }
 
-void HullLibrary::removeb2b(Tri* s,Tri*t)
+void HullLibrary::removeb2b(btHullTriangle* s,btHullTriangle*t)
 {
 	b2bfix(s,t);
@@ -404,5 +404,5 @@
 }
 
-void HullLibrary::checkit(Tri *t)
+void HullLibrary::checkit(btHullTriangle *t)
 {
 	(void)t;
@@ -428,8 +428,8 @@
 }
 
-Tri*	HullLibrary::allocateTriangle(int a,int b,int c)
-{
-	void* mem = btAlignedAlloc(sizeof(Tri),16);
-	Tri* tr = new (mem)Tri(a,b,c);
+btHullTriangle*	HullLibrary::allocateTriangle(int a,int b,int c)
+{
+	void* mem = btAlignedAlloc(sizeof(btHullTriangle),16);
+	btHullTriangle* tr = new (mem)btHullTriangle(a,b,c);
 	tr->id = m_tris.size();
 	m_tris.push_back(tr);
@@ -438,24 +438,24 @@
 }
 
-void	HullLibrary::deAllocateTriangle(Tri* tri)
+void	HullLibrary::deAllocateTriangle(btHullTriangle* tri)
 {
 	btAssert(m_tris[tri->id]==tri);
 	m_tris[tri->id]=NULL;
-	tri->~Tri();
+	tri->~btHullTriangle();
 	btAlignedFree(tri);
 }
 
 
-void HullLibrary::extrude(Tri *t0,int v)
+void HullLibrary::extrude(btHullTriangle *t0,int v)
 {
 	int3 t= *t0;
 	int n = m_tris.size();
-	Tri* ta = allocateTriangle(v,t[1],t[2]);
+	btHullTriangle* ta = allocateTriangle(v,t[1],t[2]);
 	ta->n = int3(t0->n[0],n+1,n+2);
 	m_tris[t0->n[0]]->neib(t[1],t[2]) = n+0;
-	Tri* tb = allocateTriangle(v,t[2],t[0]);
+	btHullTriangle* tb = allocateTriangle(v,t[2],t[0]);
 	tb->n = int3(t0->n[1],n+2,n+0);
 	m_tris[t0->n[1]]->neib(t[2],t[0]) = n+1;
-	Tri* tc = allocateTriangle(v,t[0],t[1]);
+	btHullTriangle* tc = allocateTriangle(v,t[0],t[1]);
 	tc->n = int3(t0->n[2],n+0,n+1);
 	m_tris[t0->n[2]]->neib(t[0],t[1]) = n+2;
@@ -470,8 +470,8 @@
 }
 
-Tri* HullLibrary::extrudable(btScalar epsilon)
+btHullTriangle* HullLibrary::extrudable(btScalar epsilon)
 {
 	int i;
-	Tri *t=NULL;
+	btHullTriangle *t=NULL;
 	for(i=0;i<m_tris.size();i++)
 	{
@@ -551,8 +551,8 @@
 
 	btVector3 center = (verts[p[0]]+verts[p[1]]+verts[p[2]]+verts[p[3]]) / btScalar(4.0);  // a valid interior point
-	Tri *t0 = allocateTriangle(p[2],p[3],p[1]); t0->n=int3(2,3,1);
-	Tri *t1 = allocateTriangle(p[3],p[2],p[0]); t1->n=int3(3,2,0);
-	Tri *t2 = allocateTriangle(p[0],p[1],p[3]); t2->n=int3(0,1,3);
-	Tri *t3 = allocateTriangle(p[1],p[0],p[2]); t3->n=int3(1,0,2);
+	btHullTriangle *t0 = allocateTriangle(p[2],p[3],p[1]); t0->n=int3(2,3,1);
+	btHullTriangle *t1 = allocateTriangle(p[3],p[2],p[0]); t1->n=int3(3,2,0);
+	btHullTriangle *t2 = allocateTriangle(p[0],p[1],p[3]); t2->n=int3(0,1,3);
+	btHullTriangle *t3 = allocateTriangle(p[1],p[0],p[2]); t3->n=int3(1,0,2);
 	isextreme[p[0]]=isextreme[p[1]]=isextreme[p[2]]=isextreme[p[3]]=1;
 	checkit(t0);checkit(t1);checkit(t2);checkit(t3);
@@ -560,5 +560,5 @@
 	for(j=0;j<m_tris.size();j++)
 	{
-		Tri *t=m_tris[j];
+		btHullTriangle *t=m_tris[j];
 		btAssert(t);
 		btAssert(t->vmax<0);
@@ -567,5 +567,5 @@
 		t->rise = dot(n,verts[t->vmax]-verts[(*t)[0]]);
 	}
-	Tri *te;
+	btHullTriangle *te;
 	vlimit-=4;
 	while(vlimit >0 && ((te=extrudable(epsilon)) != 0))
@@ -595,5 +595,5 @@
 			if(above(verts,nt,center,btScalar(0.01)*epsilon)  || cross(verts[nt[1]]-verts[nt[0]],verts[nt[2]]-verts[nt[1]]).length()< epsilon*epsilon*btScalar(0.1) )
 			{
-				Tri *nb = m_tris[m_tris[j]->n[0]];
+				btHullTriangle *nb = m_tris[m_tris[j]->n[0]];
 				btAssert(nb);btAssert(!hasvert(*nb,v));btAssert(nb->id<j);
 				extrude(nb,v);
@@ -604,5 +604,5 @@
 		while(j--)
 		{
-			Tri *t=m_tris[j];
+			btHullTriangle *t=m_tris[j];
 			if(!t) continue;
 			if(t->vmax>=0) break;
Index: code/branches/physics/src/bullet/LinearMath/btConvexHull.h
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btConvexHull.h	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/btConvexHull.h	(revision 2430)
@@ -138,11 +138,7 @@
 	ConvexH()
 	{
-		int i;
-		i=0;
 	}
 	~ConvexH()
 	{
-		int i;
-		i=0;
 	}
 	btAlignedObjectArray<btVector3> vertices;
@@ -189,5 +185,5 @@
 {
 
-	btAlignedObjectArray<class Tri*> m_tris;
+	btAlignedObjectArray<class btHullTriangle*> m_tris;
 
 public:
@@ -204,13 +200,13 @@
 	bool ComputeHull(unsigned int vcount,const btVector3 *vertices,PHullResult &result,unsigned int vlimit);
 
-	class Tri*	allocateTriangle(int a,int b,int c);
-	void	deAllocateTriangle(Tri*);
-	void b2bfix(Tri* s,Tri*t);
-
-	void removeb2b(Tri* s,Tri*t);
-
-	void checkit(Tri *t);
-
-	Tri* extrudable(btScalar epsilon);
+	class btHullTriangle*	allocateTriangle(int a,int b,int c);
+	void	deAllocateTriangle(btHullTriangle*);
+	void b2bfix(btHullTriangle* s,btHullTriangle*t);
+
+	void removeb2b(btHullTriangle* s,btHullTriangle*t);
+
+	void checkit(btHullTriangle *t);
+
+	btHullTriangle* extrudable(btScalar epsilon);
 
 	int calchull(btVector3 *verts,int verts_count, TUIntArray& tris_out, int &tris_count,int vlimit);
@@ -222,5 +218,5 @@
 	class ConvexH* ConvexHCrop(ConvexH& convex,const btPlane& slice);
 
-	void extrude(class Tri* t0,int v);
+	void extrude(class btHullTriangle* t0,int v);
 
 	ConvexH* test_cube();
Index: code/branches/physics/src/bullet/LinearMath/btMatrix3x3.h
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btMatrix3x3.h	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/btMatrix3x3.h	(revision 2430)
@@ -24,12 +24,14 @@
 
 
-///The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with btQuaternion, btTransform and btVector3.
-///Make sure to only include a pure orthogonal matrix without scaling.
+/**@brief The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with btQuaternion, btTransform and btVector3.
+ * Make sure to only include a pure orthogonal matrix without scaling. */
 class btMatrix3x3 {
 	public:
+  /** @brief No initializaion constructor */
 		btMatrix3x3 () {}
 		
 //		explicit btMatrix3x3(const btScalar *m) { setFromOpenGLSubMatrix(m); }
 		
+  /**@brief Constructor from Quaternion */
 		explicit btMatrix3x3(const btQuaternion& q) { setRotation(q); }
 		/*
@@ -40,4 +42,5 @@
 		}
 		*/
+  /** @brief Constructor with row major formatting */
 		btMatrix3x3(const btScalar& xx, const btScalar& xy, const btScalar& xz,
 				  const btScalar& yx, const btScalar& yy, const btScalar& yz,
@@ -48,5 +51,5 @@
 					 zx, zy, zz);
 		}
-		
+  /** @brief Copy constructor */
 		SIMD_FORCE_INLINE btMatrix3x3 (const btMatrix3x3& other)
 		{
@@ -55,5 +58,5 @@
 			m_el[2] = other.m_el[2];
 		}
-
+  /** @brief Assignment Operator */
 		SIMD_FORCE_INLINE btMatrix3x3& operator=(const btMatrix3x3& other)
 		{
@@ -64,4 +67,6 @@
 		}
 
+  /** @brief Get a column of the matrix as a vector 
+   *  @param i Column number 0 indexed */
 		SIMD_FORCE_INLINE btVector3 getColumn(int i) const
 		{
@@ -70,11 +75,14 @@
 		
 
-
+  /** @brief Get a row of the matrix as a vector 
+   *  @param i Row number 0 indexed */
 		SIMD_FORCE_INLINE const btVector3& getRow(int i) const
 		{
+			btFullAssert(0 <= i && i < 3);
 			return m_el[i];
 		}
 
-
+  /** @brief Get a mutable reference to a row of the matrix as a vector 
+   *  @param i Row number 0 indexed */
 		SIMD_FORCE_INLINE btVector3&  operator[](int i)
 		{ 
@@ -83,4 +91,6 @@
 		}
 		
+  /** @brief Get a const reference to a row of the matrix as a vector 
+   *  @param i Row number 0 indexed */
 		SIMD_FORCE_INLINE const btVector3& operator[](int i) const
 		{
@@ -89,7 +99,11 @@
 		}
 		
+  /** @brief Multiply by the target matrix on the right
+   *  @param m Rotation matrix to be applied 
+   * Equivilant to this = this * m */
 		btMatrix3x3& operator*=(const btMatrix3x3& m); 
 		
-	
+  /** @brief Set from a carray of btScalars 
+   *  @param m A pointer to the beginning of an array of 9 btScalars */
 	void setFromOpenGLSubMatrix(const btScalar *m)
 		{
@@ -99,5 +113,14 @@
 
 		}
-
+  /** @brief Set the values of the matrix explicitly (row major)
+   *  @param xx Top left
+   *  @param xy Top Middle
+   *  @param xz Top Right
+   *  @param yx Middle Left
+   *  @param yy Middle Middle
+   *  @param yz Middle Right
+   *  @param zx Bottom Left
+   *  @param zy Bottom Middle
+   *  @param zz Bottom Right*/
 		void setValue(const btScalar& xx, const btScalar& xy, const btScalar& xz, 
 					  const btScalar& yx, const btScalar& yy, const btScalar& yz, 
@@ -108,5 +131,7 @@
 			m_el[2].setValue(zx,zy,zz);
 		}
-  
+
+  /** @brief Set the matrix from a quaternion
+   *  @param q The Quaternion to match */  
 		void setRotation(const btQuaternion& q) 
 		{
@@ -124,33 +149,25 @@
 		
 
-
+  /** @brief Set the matrix from euler angles using YPR around YXZ respectively
+   *  @param yaw Yaw about Y axis
+   *  @param pitch Pitch about X axis
+   *  @param roll Roll about Z axis 
+   */
 		void setEulerYPR(const btScalar& yaw, const btScalar& pitch, const btScalar& roll) 
 		{
-
-			btScalar cy(btCos(yaw)); 
-			btScalar  sy(btSin(yaw)); 
-			btScalar  cp(btCos(pitch)); 
-			btScalar  sp(btSin(pitch)); 
-			btScalar  cr(btCos(roll));
-			btScalar  sr(btSin(roll));
-			btScalar  cc = cy * cr; 
-			btScalar  cs = cy * sr; 
-			btScalar  sc = sy * cr; 
-			btScalar  ss = sy * sr;
-			setValue(cc - sp * ss, -cs - sp * sc, -sy * cp,
-                     cp * sr,       cp * cr,      -sp,
-					 sc + sp * cs, -ss + sp * cc,  cy * cp);
-		
-		}
-
-	/**
-	 * setEulerZYX
-	 * @param euler a const reference to a btVector3 of euler angles
+			setEulerZYX(roll, pitch, yaw);
+		}
+
+	/** @brief Set the matrix from euler angles YPR around ZYX axes
+	 * @param eulerX Roll about X axis
+         * @param eulerY Pitch around Y axis
+         * @param eulerZ Yaw aboud Z axis
+         * 
 	 * These angles are used to produce a rotation matrix. The euler
 	 * angles are applied in ZYX order. I.e a vector is first rotated 
 	 * about X then Y and then Z
 	 **/
-	
-	void setEulerZYX(btScalar eulerX,btScalar eulerY,btScalar eulerZ) {
+	void setEulerZYX(btScalar eulerX,btScalar eulerY,btScalar eulerZ) { 
+  ///@todo proposed to reverse this since it's labeled zyx but takes arguments xyz and it will match all other parts of the code
 		btScalar ci ( btCos(eulerX)); 
 		btScalar cj ( btCos(eulerY)); 
@@ -169,4 +186,5 @@
 	}
 
+  /**@brief Set the matrix to the identity */
 		void setIdentity()
 		{ 
@@ -175,5 +193,6 @@
 					 btScalar(0.0), btScalar(0.0), btScalar(1.0)); 
 		}
-    
+  /**@brief Fill the values of the matrix into a 9 element array 
+   * @param m The array to be filled */
 		void getOpenGLSubMatrix(btScalar *m) const 
 		{
@@ -192,4 +211,6 @@
 		}
 
+  /**@brief Get the matrix represented as a quaternion 
+   * @param q The quaternion which will be set */
 		void getRotation(btQuaternion& q) const
 		{
@@ -225,33 +246,100 @@
 			q.setValue(temp[0],temp[1],temp[2],temp[3]);
 		}
-	
-		void getEuler(btScalar& yaw, btScalar& pitch, btScalar& roll) const
+
+  /**@brief Get the matrix represented as euler angles around YXZ, roundtrip with setEulerYPR
+   * @param yaw Yaw around Y axis
+   * @param pitch Pitch around X axis
+   * @param roll around Z axis */	
+		void getEulerYPR(btScalar& yaw, btScalar& pitch, btScalar& roll) const
 		{
 			
-			if (btScalar(m_el[1].z()) < btScalar(1))
-			{
-				if (btScalar(m_el[1].z()) > -btScalar(1))
-				{
-					yaw = btScalar(btAtan2(m_el[1].x(), m_el[0].x()));
-					pitch = btScalar(btAsin(-m_el[1].y()));
-					roll = btScalar(btAtan2(m_el[2].y(), m_el[2].z()));
-				}
-				else 
-				{
-					yaw = btScalar(-btAtan2(-m_el[0].y(), m_el[0].z()));
-					pitch = SIMD_HALF_PI;
-					roll = btScalar(0.0);
-				}
-			}
-			else
-			{
-				yaw = btScalar(btAtan2(-m_el[0].y(), m_el[0].z()));
-				pitch = -SIMD_HALF_PI;
-				roll = btScalar(0.0);
-			}
-		}
-		
-
-	
+			// first use the normal calculus
+			yaw = btScalar(btAtan2(m_el[1].x(), m_el[0].x()));
+			pitch = btScalar(btAsin(-m_el[2].x()));
+			roll = btScalar(btAtan2(m_el[2].y(), m_el[2].z()));
+
+			// on pitch = +/-HalfPI
+			if (btFabs(pitch)==SIMD_HALF_PI)
+			{
+				if (yaw>0)
+					yaw-=SIMD_PI;
+				else
+					yaw+=SIMD_PI;
+
+				if (roll>0)
+					roll-=SIMD_PI;
+				else
+					roll+=SIMD_PI;
+			}
+		};
+
+
+  /**@brief Get the matrix represented as euler angles around ZYX
+   * @param yaw Yaw around X axis
+   * @param pitch Pitch around Y axis
+   * @param roll around X axis 
+   * @param solution_number Which solution of two possible solutions ( 1 or 2) are possible values*/	
+  void getEulerZYX(btScalar& yaw, btScalar& pitch, btScalar& roll, unsigned int solution_number = 1) const
+  {
+    struct Euler{btScalar yaw, pitch, roll;};
+    Euler euler_out;
+    Euler euler_out2; //second solution
+    //get the pointer to the raw data
+    
+    // Check that pitch is not at a singularity
+    if (btFabs(m_el[2].x()) >= 1)
+    {
+      euler_out.yaw = 0;
+      euler_out2.yaw = 0;
+	
+      // From difference of angles formula
+      btScalar delta = btAtan2(m_el[0].x(),m_el[0].z());
+      if (m_el[2].x() > 0)  //gimbal locked up
+      {
+        euler_out.pitch = SIMD_PI / btScalar(2.0);
+        euler_out2.pitch = SIMD_PI / btScalar(2.0);
+        euler_out.roll = euler_out.pitch + delta;
+        euler_out2.roll = euler_out.pitch + delta;
+      }
+      else // gimbal locked down
+      {
+        euler_out.pitch = -SIMD_PI / btScalar(2.0);
+        euler_out2.pitch = -SIMD_PI / btScalar(2.0);
+        euler_out.roll = -euler_out.pitch + delta;
+        euler_out2.roll = -euler_out.pitch + delta;
+      }
+    }
+    else
+    {
+      euler_out.pitch = - btAsin(m_el[2].x());
+      euler_out2.pitch = SIMD_PI - euler_out.pitch;
+	
+      euler_out.roll = btAtan2(m_el[2].y()/btCos(euler_out.pitch), 
+			       m_el[2].z()/btCos(euler_out.pitch));
+      euler_out2.roll = btAtan2(m_el[2].y()/btCos(euler_out2.pitch), 
+				m_el[2].z()/btCos(euler_out2.pitch));
+	
+      euler_out.yaw = btAtan2(m_el[1].x()/btCos(euler_out.pitch), 
+			      m_el[0].x()/btCos(euler_out.pitch));
+      euler_out2.yaw = btAtan2(m_el[1].x()/btCos(euler_out2.pitch), 
+                               m_el[0].x()/btCos(euler_out2.pitch));
+    }
+    
+    if (solution_number == 1)
+    { 
+		yaw = euler_out.yaw; 
+		pitch = euler_out.pitch;
+		roll = euler_out.roll;
+    }
+    else
+    { 
+		yaw = euler_out2.yaw; 
+		pitch = euler_out2.pitch;
+		roll = euler_out2.roll;
+    }
+  }
+
+  /**@brief Create a scaled copy of the matrix 
+   * @param s Scaling vector The elements of the vector will scale each column */
 		
 		btMatrix3x3 scaled(const btVector3& s) const
@@ -262,8 +350,13 @@
 		}
 
+  /**@brief Return the determinant of the matrix */
 		btScalar            determinant() const;
+  /**@brief Return the adjoint of the matrix */
 		btMatrix3x3 adjoint() const;
+  /**@brief Return the matrix with all values non negative */
 		btMatrix3x3 absolute() const;
+  /**@brief Return the transpose of the matrix */
 		btMatrix3x3 transpose() const;
+  /**@brief Return the inverse of the matrix */
 		btMatrix3x3 inverse() const; 
 		
@@ -285,10 +378,13 @@
 		
 
-		///diagonalizes this matrix by the Jacobi method. rot stores the rotation
-		///from the coordinate system in which the matrix is diagonal to the original
-		///coordinate system, i.e., old_this = rot * new_this * rot^T. The iteration
-		///stops when all off-diagonal elements are less than the threshold multiplied
-		///by the sum of the absolute values of the diagonal, or when maxSteps have
-		///been executed. Note that this matrix is assumed to be symmetric.
+  /**@brief diagonalizes this matrix by the Jacobi method.
+   * @param rot stores the rotation from the coordinate system in which the matrix is diagonal to the original
+   * coordinate system, i.e., old_this = rot * new_this * rot^T. 
+   * @param threshold See iteration
+   * @param iteration The iteration stops when all off-diagonal elements are less than the threshold multiplied 
+   * by the sum of the absolute values of the diagonal, or when maxSteps have been executed. 
+   * 
+   * Note that this matrix is assumed to be symmetric. 
+   */
 		void diagonalize(btMatrix3x3& rot, btScalar threshold, int maxSteps)
 		{
@@ -372,9 +468,16 @@
 		
 	protected:
+  /**@brief Calculate the matrix cofactor 
+   * @param r1 The first row to use for calculating the cofactor
+   * @param c1 The first column to use for calculating the cofactor
+   * @param r1 The second row to use for calculating the cofactor
+   * @param c1 The second column to use for calculating the cofactor
+   * See http://en.wikipedia.org/wiki/Cofactor_(linear_algebra) for more details
+   */
 		btScalar cofac(int r1, int c1, int r2, int c2) const 
 		{
 			return m_el[r1][c1] * m_el[r2][c2] - m_el[r1][c2] * m_el[r2][c1];
 		}
-
+  ///Data storage for the matrix, each vector is a row of the matrix
 		btVector3 m_el[3];
 	};
@@ -495,4 +598,6 @@
 */
 
+/**@brief Equality operator between two matrices
+ * It will test all elements are equal.  */
 SIMD_FORCE_INLINE bool operator==(const btMatrix3x3& m1, const btMatrix3x3& m2)
 {
Index: code/branches/physics/src/bullet/LinearMath/btPoint3.h
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btPoint3.h	(revision 2192)
+++ 	(revision )
@@ -1,24 +1,0 @@
-/*
-Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans  http://continuousphysics.com/Bullet/
-
-This software is provided 'as-is', without any express or implied warranty.
-In no event will the authors be held liable for any damages arising from the use of this software.
-Permission is granted to anyone to use this software for any purpose, 
-including commercial applications, and to alter it and redistribute it freely, 
-subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
-2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-3. This notice may not be removed or altered from any source distribution.
-*/
-
-
-
-#ifndef btPoint3_H
-#define btPoint3_H
-
-#include "btVector3.h"
-
-typedef btVector3 btPoint3;
-
-#endif
Index: code/branches/physics/src/bullet/LinearMath/btQuadWord.h
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btQuadWord.h	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/btQuadWord.h	(revision 2430)
@@ -19,119 +19,165 @@
 #include "btScalar.h"
 #include "btMinMax.h"
-#include <math.h>
 
 
+#if defined (__CELLOS_LV2) && defined (__SPU__)
+#include <altivec.h>
+#endif
 
-///The btQuadWordStorage class is base class for btVector3 and btQuaternion. 
-///Some issues under PS3 Linux with IBM 2.1 SDK, gcc compiler prevent from using aligned quadword. todo: look into this
-///ATTRIBUTE_ALIGNED16(class) btQuadWordStorage
+/**@brief The btQuadWordStorage class is base class for btVector3 and btQuaternion. 
+ * Some issues under PS3 Linux with IBM 2.1 SDK, gcc compiler prevent from using aligned quadword.
+ */
+#ifndef USE_LIBSPE2
+ATTRIBUTE_ALIGNED16(class) btQuadWordStorage
+#else
 class btQuadWordStorage
+#endif
 {
 protected:
 
-	btScalar	m_x;
-	btScalar	m_y;
-	btScalar	m_z;
-	btScalar	m_unusedW;
-
+#if defined (__SPU__) && defined (__CELLOS_LV2__)
+	union {
+		vec_float4 mVec128;
+		btScalar	m_floats[4];
+	};
 public:
+	vec_float4	get128() const
+	{
+		return mVec128;
+	}
+#else //__CELLOS_LV2__ __SPU__
+	btScalar	m_floats[4];
+#endif //__CELLOS_LV2__ __SPU__
 
 };
 
-
-///btQuadWord is base-class for vectors, points
+/** @brief The btQuadWord is base-class for vectors, points */
 class	btQuadWord : public btQuadWordStorage
 {
 	public:
-	
-//		SIMD_FORCE_INLINE btScalar&       operator[](int i)       { return (&m_x)[i];	}      
-//		SIMD_FORCE_INLINE const btScalar& operator[](int i) const { return (&m_x)[i]; }
+  
 
-		SIMD_FORCE_INLINE const btScalar& getX() const { return m_x; }
+  /**@brief Return the x value */
+		SIMD_FORCE_INLINE const btScalar& getX() const { return m_floats[0]; }
+  /**@brief Return the y value */
+		SIMD_FORCE_INLINE const btScalar& getY() const { return m_floats[1]; }
+  /**@brief Return the z value */
+		SIMD_FORCE_INLINE const btScalar& getZ() const { return m_floats[2]; }
+  /**@brief Set the x value */
+		SIMD_FORCE_INLINE void	setX(btScalar x) { m_floats[0] = x;};
+  /**@brief Set the y value */
+		SIMD_FORCE_INLINE void	setY(btScalar y) { m_floats[1] = y;};
+  /**@brief Set the z value */
+		SIMD_FORCE_INLINE void	setZ(btScalar z) { m_floats[2] = z;};
+  /**@brief Set the w value */
+		SIMD_FORCE_INLINE void	setW(btScalar w) { m_floats[3] = w;};
+  /**@brief Return the x value */
+		SIMD_FORCE_INLINE const btScalar& x() const { return m_floats[0]; }
+  /**@brief Return the y value */
+		SIMD_FORCE_INLINE const btScalar& y() const { return m_floats[1]; }
+  /**@brief Return the z value */
+		SIMD_FORCE_INLINE const btScalar& z() const { return m_floats[2]; }
+  /**@brief Return the w value */
+		SIMD_FORCE_INLINE const btScalar& w() const { return m_floats[3]; }
 
-		SIMD_FORCE_INLINE const btScalar& getY() const { return m_y; }
+	//SIMD_FORCE_INLINE btScalar&       operator[](int i)       { return (&m_floats[0])[i];	}      
+	//SIMD_FORCE_INLINE const btScalar& operator[](int i) const { return (&m_floats[0])[i]; }
+	///operator btScalar*() replaces operator[], using implicit conversion. We added operator != and operator == to avoid pointer comparisons.
+	SIMD_FORCE_INLINE	operator       btScalar *()       { return &m_floats[0]; }
+	SIMD_FORCE_INLINE	operator const btScalar *() const { return &m_floats[0]; }
 
-		SIMD_FORCE_INLINE const btScalar& getZ() const { return m_z; }
+	SIMD_FORCE_INLINE	bool	operator==(const btQuadWord& other) const
+	{
+		return ((m_floats[3]==other.m_floats[3]) && (m_floats[2]==other.m_floats[2]) && (m_floats[1]==other.m_floats[1]) && (m_floats[0]==other.m_floats[0]));
+	}
 
-		SIMD_FORCE_INLINE void	setX(btScalar x) { m_x = x;};
+	SIMD_FORCE_INLINE	bool	operator!=(const btQuadWord& other) const
+	{
+		return !(*this == other);
+	}
 
-		SIMD_FORCE_INLINE void	setY(btScalar y) { m_y = y;};
-
-		SIMD_FORCE_INLINE void	setZ(btScalar z) { m_z = z;};
-
-		SIMD_FORCE_INLINE void	setW(btScalar w) { m_unusedW = w;};
-
-		SIMD_FORCE_INLINE const btScalar& x() const { return m_x; }
-
-		SIMD_FORCE_INLINE const btScalar& y() const { return m_y; }
-
-		SIMD_FORCE_INLINE const btScalar& z() const { return m_z; }
-
-		SIMD_FORCE_INLINE const btScalar& w() const { return m_unusedW; }
-
-
-		SIMD_FORCE_INLINE	operator       btScalar *()       { return &m_x; }
-		SIMD_FORCE_INLINE	operator const btScalar *() const { return &m_x; }
-
-
-
+  /**@brief Set x,y,z and zero w 
+   * @param x Value of x
+   * @param y Value of y
+   * @param z Value of z
+   */
 		SIMD_FORCE_INLINE void 	setValue(const btScalar& x, const btScalar& y, const btScalar& z)
 		{
-			m_x=x;
-			m_y=y;
-			m_z=z;
-			m_unusedW = 0.f;
+			m_floats[0]=x;
+			m_floats[1]=y;
+			m_floats[2]=z;
+			m_floats[3] = 0.f;
 		}
 
 /*		void getValue(btScalar *m) const 
 		{
-			m[0] = m_x;
-			m[1] = m_y;
-			m[2] = m_z;
+			m[0] = m_floats[0];
+			m[1] = m_floats[1];
+			m[2] = m_floats[2];
 		}
 */
+/**@brief Set the values 
+   * @param x Value of x
+   * @param y Value of y
+   * @param z Value of z
+   * @param w Value of w
+   */
 		SIMD_FORCE_INLINE void	setValue(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w)
 		{
-			m_x=x;
-			m_y=y;
-			m_z=z;
-			m_unusedW=w;
+			m_floats[0]=x;
+			m_floats[1]=y;
+			m_floats[2]=z;
+			m_floats[3]=w;
 		}
-
+  /**@brief No initialization constructor */
 		SIMD_FORCE_INLINE btQuadWord()
-		//	:m_x(btScalar(0.)),m_y(btScalar(0.)),m_z(btScalar(0.)),m_unusedW(btScalar(0.))
+		//	:m_floats[0](btScalar(0.)),m_floats[1](btScalar(0.)),m_floats[2](btScalar(0.)),m_floats[3](btScalar(0.))
 		{
 		}
-
+  /**@brief Copy constructor */
 		SIMD_FORCE_INLINE btQuadWord(const btQuadWordStorage& q)
 		{
 			*((btQuadWordStorage*)this) = q;
 		}
-
+  /**@brief Three argument constructor (zeros w)
+   * @param x Value of x
+   * @param y Value of y
+   * @param z Value of z
+   */
 		SIMD_FORCE_INLINE btQuadWord(const btScalar& x, const btScalar& y, const btScalar& z)		
 		{
-			m_x = x, m_y = y, m_z = z, m_unusedW = 0.0f;
+			m_floats[0] = x, m_floats[1] = y, m_floats[2] = z, m_floats[3] = 0.0f;
 		}
 
+/**@brief Initializing constructor
+   * @param x Value of x
+   * @param y Value of y
+   * @param z Value of z
+   * @param w Value of w
+   */
 		SIMD_FORCE_INLINE btQuadWord(const btScalar& x, const btScalar& y, const btScalar& z,const btScalar& w) 
 		{
-			m_x = x, m_y = y, m_z = z, m_unusedW = w;
+			m_floats[0] = x, m_floats[1] = y, m_floats[2] = z, m_floats[3] = w;
 		}
 
-
+  /**@brief Set each element to the max of the current values and the values of another btQuadWord
+   * @param other The other btQuadWord to compare with 
+   */
 		SIMD_FORCE_INLINE void	setMax(const btQuadWord& other)
 		{
-			btSetMax(m_x, other.m_x);
-			btSetMax(m_y, other.m_y);
-			btSetMax(m_z, other.m_z);
-			btSetMax(m_unusedW, other.m_unusedW);
+			btSetMax(m_floats[0], other.m_floats[0]);
+			btSetMax(m_floats[1], other.m_floats[1]);
+			btSetMax(m_floats[2], other.m_floats[2]);
+			btSetMax(m_floats[3], other.m_floats[3]);
 		}
-
+  /**@brief Set each element to the min of the current values and the values of another btQuadWord
+   * @param other The other btQuadWord to compare with 
+   */
 		SIMD_FORCE_INLINE void	setMin(const btQuadWord& other)
 		{
-			btSetMin(m_x, other.m_x);
-			btSetMin(m_y, other.m_y);
-			btSetMin(m_z, other.m_z);
-			btSetMin(m_unusedW, other.m_unusedW);
+			btSetMin(m_floats[0], other.m_floats[0]);
+			btSetMin(m_floats[1], other.m_floats[1]);
+			btSetMin(m_floats[2], other.m_floats[2]);
+			btSetMin(m_floats[3], other.m_floats[3]);
 		}
 
Index: code/branches/physics/src/bullet/LinearMath/btQuaternion.h
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btQuaternion.h	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/btQuaternion.h	(revision 2430)
@@ -18,28 +18,41 @@
 #define SIMD__QUATERNION_H_
 
+
 #include "btVector3.h"
 
-///The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatrix3x3, btVector3 and btTransform.
+/**@brief The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatrix3x3, btVector3 and btTransform. */
 class btQuaternion : public btQuadWord {
 public:
+  /**@brief No initialization constructor */
 	btQuaternion() {}
 
 	//		template <typename btScalar>
 	//		explicit Quaternion(const btScalar *v) : Tuple4<btScalar>(v) {}
-
+  /**@brief Constructor from scalars */
 	btQuaternion(const btScalar& x, const btScalar& y, const btScalar& z, const btScalar& w) 
 		: btQuadWord(x, y, z, w) 
 	{}
-
+  /**@brief Axis angle Constructor
+   * @param axis The axis which the rotation is around
+   * @param angle The magnitude of the rotation around the angle (Radians) */
 	btQuaternion(const btVector3& axis, const btScalar& angle) 
 	{ 
 		setRotation(axis, angle); 
 	}
-
+  /**@brief Constructor from Euler angles
+   * @param yaw Angle around Y unless BT_EULER_DEFAULT_ZYX defined then Z
+   * @param pitch Angle around X unless BT_EULER_DEFAULT_ZYX defined then Y
+   * @param roll Angle around Z unless BT_EULER_DEFAULT_ZYX defined then X */
 	btQuaternion(const btScalar& yaw, const btScalar& pitch, const btScalar& roll)
 	{ 
+#ifndef BT_EULER_DEFAULT_ZYX
 		setEuler(yaw, pitch, roll); 
-	}
-
+#else
+		setEulerZYX(yaw, pitch, roll); 
+#endif 
+	}
+  /**@brief Set the rotation using axis angle notation 
+   * @param axis The axis around which to rotate
+   * @param angle The magnitude of the rotation in Radians */
 	void setRotation(const btVector3& axis, const btScalar& angle)
 	{
@@ -50,5 +63,8 @@
 			btCos(angle * btScalar(0.5)));
 	}
-
+  /**@brief Set the quaternion using Euler angles
+   * @param yaw Angle around Y
+   * @param pitch Angle around X
+   * @param roll Angle around Z */
 	void setEuler(const btScalar& yaw, const btScalar& pitch, const btScalar& roll)
 	{
@@ -67,38 +83,67 @@
 			cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw);
 	}
-
-	btQuaternion& operator+=(const btQuaternion& q)
-	{
-		m_x += q.x(); m_y += q.y(); m_z += q.z(); m_unusedW += q.m_unusedW;
+  /**@brief Set the quaternion using euler angles 
+   * @param yaw Angle around Z
+   * @param pitch Angle around Y
+   * @param roll Angle around X */
+	void setEulerZYX(const btScalar& yaw, const btScalar& pitch, const btScalar& roll)
+	{
+		btScalar halfYaw = btScalar(yaw) * btScalar(0.5);  
+		btScalar halfPitch = btScalar(pitch) * btScalar(0.5);  
+		btScalar halfRoll = btScalar(roll) * btScalar(0.5);  
+		btScalar cosYaw = btCos(halfYaw);
+		btScalar sinYaw = btSin(halfYaw);
+		btScalar cosPitch = btCos(halfPitch);
+		btScalar sinPitch = btSin(halfPitch);
+		btScalar cosRoll = btCos(halfRoll);
+		btScalar sinRoll = btSin(halfRoll);
+		setValue(sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw, //x
+                         cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw, //y
+                         cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw, //z
+                         cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw); //formerly yzx
+	}
+  /**@brief Add two quaternions
+   * @param q The quaternion to add to this one */
+	SIMD_FORCE_INLINE	btQuaternion& operator+=(const btQuaternion& q)
+	{
+		m_floats[0] += q.x(); m_floats[1] += q.y(); m_floats[2] += q.z(); m_floats[3] += q.m_floats[3];
 		return *this;
 	}
 
+  /**@brief Subtract out a quaternion
+   * @param q The quaternion to subtract from this one */
 	btQuaternion& operator-=(const btQuaternion& q) 
 	{
-		m_x -= q.x(); m_y -= q.y(); m_z -= q.z(); m_unusedW -= q.m_unusedW;
+		m_floats[0] -= q.x(); m_floats[1] -= q.y(); m_floats[2] -= q.z(); m_floats[3] -= q.m_floats[3];
 		return *this;
 	}
 
+  /**@brief Scale this quaternion
+   * @param s The scalar to scale by */
 	btQuaternion& operator*=(const btScalar& s)
 	{
-		m_x *= s; m_y *= s; m_z *= s; m_unusedW *= s;
+		m_floats[0] *= s; m_floats[1] *= s; m_floats[2] *= s; m_floats[3] *= s;
 		return *this;
 	}
 
-
+  /**@brief Multiply this quaternion by q on the right
+   * @param q The other quaternion 
+   * Equivilant to this = this * q */
 	btQuaternion& operator*=(const btQuaternion& q)
 	{
-		setValue(m_unusedW * q.x() + m_x * q.m_unusedW + m_y * q.z() - m_z * q.y(),
-			m_unusedW * q.y() + m_y * q.m_unusedW + m_z * q.x() - m_x * q.z(),
-			m_unusedW * q.z() + m_z * q.m_unusedW + m_x * q.y() - m_y * q.x(),
-			m_unusedW * q.m_unusedW - m_x * q.x() - m_y * q.y() - m_z * q.z());
+		setValue(m_floats[3] * q.x() + m_floats[0] * q.m_floats[3] + m_floats[1] * q.z() - m_floats[2] * q.y(),
+			m_floats[3] * q.y() + m_floats[1] * q.m_floats[3] + m_floats[2] * q.x() - m_floats[0] * q.z(),
+			m_floats[3] * q.z() + m_floats[2] * q.m_floats[3] + m_floats[0] * q.y() - m_floats[1] * q.x(),
+			m_floats[3] * q.m_floats[3] - m_floats[0] * q.x() - m_floats[1] * q.y() - m_floats[2] * q.z());
 		return *this;
 	}
-
+  /**@brief Return the dot product between this quaternion and another
+   * @param q The other quaternion */
 	btScalar dot(const btQuaternion& q) const
 	{
-		return m_x * q.x() + m_y * q.y() + m_z * q.z() + m_unusedW * q.m_unusedW;
-	}
-
+		return m_floats[0] * q.x() + m_floats[1] * q.y() + m_floats[2] * q.z() + m_floats[3] * q.m_floats[3];
+	}
+
+  /**@brief Return the length squared of the quaternion */
 	btScalar length2() const
 	{
@@ -106,4 +151,5 @@
 	}
 
+  /**@brief Return the length of the quaternion */
 	btScalar length() const
 	{
@@ -111,4 +157,6 @@
 	}
 
+  /**@brief Normalize the quaternion 
+   * Such that x^2 + y^2 + z^2 +w^2 = 1 */
 	btQuaternion& normalize() 
 	{
@@ -116,12 +164,15 @@
 	}
 
+  /**@brief Return a scaled version of this quaternion
+   * @param s The scale factor */
 	SIMD_FORCE_INLINE btQuaternion
 	operator*(const btScalar& s) const
 	{
-		return btQuaternion(x() * s, y() * s, z() * s, m_unusedW * s);
-	}
-
-
-
+		return btQuaternion(x() * s, y() * s, z() * s, m_floats[3] * s);
+	}
+
+
+  /**@brief Return an inversely scaled versionof this quaternion
+   * @param s The inverse scale factor */
 	btQuaternion operator/(const btScalar& s) const
 	{
@@ -130,5 +181,6 @@
 	}
 
-
+  /**@brief Inversely scale this quaternion
+   * @param s The scale factor */
 	btQuaternion& operator/=(const btScalar& s) 
 	{
@@ -137,10 +189,11 @@
 	}
 
-
+  /**@brief Return a normalized version of this quaternion */
 	btQuaternion normalized() const 
 	{
 		return *this / length();
 	} 
-
+  /**@brief Return the angle between this quaternion and the other 
+   * @param q The other quaternion */
 	btScalar angle(const btQuaternion& q) const 
 	{
@@ -149,38 +202,44 @@
 		return btAcos(dot(q) / s);
 	}
-
+  /**@brief Return the angle of rotation represented by this quaternion */
 	btScalar getAngle() const 
 	{
-		btScalar s = btScalar(2.) * btAcos(m_unusedW);
+		btScalar s = btScalar(2.) * btAcos(m_floats[3]);
 		return s;
 	}
 
 
-
+  /**@brief Return the inverse of this quaternion */
 	btQuaternion inverse() const
 	{
-		return btQuaternion(-m_x, -m_y, -m_z, m_unusedW);
-	}
-
+		return btQuaternion(-m_floats[0], -m_floats[1], -m_floats[2], m_floats[3]);
+	}
+
+  /**@brief Return the sum of this quaternion and the other 
+   * @param q2 The other quaternion */
 	SIMD_FORCE_INLINE btQuaternion
 	operator+(const btQuaternion& q2) const
 	{
 		const btQuaternion& q1 = *this;
-		return btQuaternion(q1.x() + q2.x(), q1.y() + q2.y(), q1.z() + q2.z(), q1.m_unusedW + q2.m_unusedW);
-	}
-
+		return btQuaternion(q1.x() + q2.x(), q1.y() + q2.y(), q1.z() + q2.z(), q1.m_floats[3] + q2.m_floats[3]);
+	}
+
+  /**@brief Return the difference between this quaternion and the other 
+   * @param q2 The other quaternion */
 	SIMD_FORCE_INLINE btQuaternion
 	operator-(const btQuaternion& q2) const
 	{
 		const btQuaternion& q1 = *this;
-		return btQuaternion(q1.x() - q2.x(), q1.y() - q2.y(), q1.z() - q2.z(), q1.m_unusedW - q2.m_unusedW);
-	}
-
+		return btQuaternion(q1.x() - q2.x(), q1.y() - q2.y(), q1.z() - q2.z(), q1.m_floats[3] - q2.m_floats[3]);
+	}
+
+  /**@brief Return the negative of this quaternion 
+   * This simply negates each element */
 	SIMD_FORCE_INLINE btQuaternion operator-() const
 	{
 		const btQuaternion& q2 = *this;
-		return btQuaternion( - q2.x(), - q2.y(),  - q2.z(),  - q2.m_unusedW);
-	}
-
+		return btQuaternion( - q2.x(), - q2.y(),  - q2.z(),  - q2.m_floats[3]);
+	}
+  /**@todo document this and it's use */
 	SIMD_FORCE_INLINE btQuaternion farthest( const btQuaternion& qd) const 
 	{
@@ -193,4 +252,8 @@
 	}
 
+  /**@brief Return the quaternion which is the result of Spherical Linear Interpolation between this and the other quaternion
+   * @param q The other quaternion to interpolate with 
+   * @param t The ratio between this and q to interpolate.  If t = 0 the result is this, if t=1 the result is q.
+   * Slerp interpolates assuming constant velocity.  */
 	btQuaternion slerp(const btQuaternion& q, const btScalar& t) const
 	{
@@ -201,8 +264,8 @@
 			btScalar s0 = btSin((btScalar(1.0) - t) * theta);
 			btScalar s1 = btSin(t * theta);   
-			return btQuaternion((m_x * s0 + q.x() * s1) * d,
-				(m_y * s0 + q.y() * s1) * d,
-				(m_z * s0 + q.z() * s1) * d,
-				(m_unusedW * s0 + q.m_unusedW * s1) * d);
+			return btQuaternion((m_floats[0] * s0 + q.x() * s1) * d,
+				(m_floats[1] * s0 + q.y() * s1) * d,
+				(m_floats[2] * s0 + q.z() * s1) * d,
+				(m_floats[3] * s0 + q.m_floats[3] * s1) * d);
 		}
 		else
@@ -212,5 +275,5 @@
 	}
 
-	SIMD_FORCE_INLINE const btScalar& getW() const { return m_unusedW; }
+	SIMD_FORCE_INLINE const btScalar& getW() const { return m_floats[3]; }
 
 	
@@ -218,5 +281,5 @@
 
 
-
+/**@brief Return the negative of a quaternion */
 SIMD_FORCE_INLINE btQuaternion
 operator-(const btQuaternion& q)
@@ -227,5 +290,5 @@
 
 
-
+/**@brief Return the product of two quaternions */
 SIMD_FORCE_INLINE btQuaternion
 operator*(const btQuaternion& q1, const btQuaternion& q2) {
@@ -254,4 +317,5 @@
 }
 
+/**@brief Calculate the dot product between two quaternions */
 SIMD_FORCE_INLINE btScalar 
 dot(const btQuaternion& q1, const btQuaternion& q2) 
@@ -261,4 +325,5 @@
 
 
+/**@brief Return the length of a quaternion */
 SIMD_FORCE_INLINE btScalar
 length(const btQuaternion& q) 
@@ -267,4 +332,5 @@
 }
 
+/**@brief Return the angle between two quaternions*/
 SIMD_FORCE_INLINE btScalar
 angle(const btQuaternion& q1, const btQuaternion& q2) 
@@ -273,5 +339,5 @@
 }
 
-
+/**@brief Return the inverse of a quaternion*/
 SIMD_FORCE_INLINE btQuaternion
 inverse(const btQuaternion& q) 
@@ -280,4 +346,9 @@
 }
 
+/**@brief Return the result of spherical linear interpolation betwen two quaternions 
+ * @param q1 The first quaternion
+ * @param q2 The second quaternion 
+ * @param t The ration between q1 and q2.  t = 0 return q1, t=1 returns q2 
+ * Slerp assumes constant velocity between positions. */
 SIMD_FORCE_INLINE btQuaternion
 slerp(const btQuaternion& q1, const btQuaternion& q2, const btScalar& t) 
Index: code/branches/physics/src/bullet/LinearMath/btQuickprof.cpp
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btQuickprof.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/btQuickprof.cpp	(revision 2430)
@@ -111,5 +111,5 @@
 	TotalCalls = 0;
 	TotalTime = 0.0f;
-	gProfileClock.reset();
+	
 
 	if ( Child ) {
@@ -252,4 +252,5 @@
 void	CProfileManager::Reset( void )
 { 
+	gProfileClock.reset();
 	Root.Reset();
     Root.Call();
@@ -279,4 +280,67 @@
 }
 
+#include <stdio.h>
+
+void	CProfileManager::dumpRecursive(CProfileIterator* profileIterator, int spacing)
+{
+	profileIterator->First();
+	if (profileIterator->Is_Done())
+		return;
+
+	float accumulated_time=0,parent_time = profileIterator->Is_Root() ? CProfileManager::Get_Time_Since_Reset() : profileIterator->Get_Current_Parent_Total_Time();
+	int i;
+	int frames_since_reset = CProfileManager::Get_Frame_Count_Since_Reset();
+	for (i=0;i<spacing;i++)	printf(".");
+	printf("----------------------------------\n");
+	for (i=0;i<spacing;i++)	printf(".");
+	printf("Profiling: %s (total running time: %.3f ms) ---\n",	profileIterator->Get_Current_Parent_Name(), parent_time );
+	float totalTime = 0.f;
+
+	
+	int numChildren = 0;
+	
+	for (i = 0; !profileIterator->Is_Done(); i++,profileIterator->Next())
+	{
+		numChildren++;
+		float current_total_time = profileIterator->Get_Current_Total_Time();
+		accumulated_time += current_total_time;
+		float fraction = parent_time > SIMD_EPSILON ? (current_total_time / parent_time) * 100 : 0.f;
+		{
+			int i;	for (i=0;i<spacing;i++)	printf(".");
+		}
+		printf("%d -- %s (%.2f %%) :: %.3f ms / frame (%d calls)\n",i, profileIterator->Get_Current_Name(), fraction,(current_total_time / (double)frames_since_reset),profileIterator->Get_Current_Total_Calls());
+		totalTime += current_total_time;
+		//recurse into children
+	}
+
+	if (parent_time < accumulated_time)
+	{
+		printf("what's wrong\n");
+	}
+	for (i=0;i<spacing;i++)	printf(".");
+	printf("%s (%.3f %%) :: %.3f ms\n", "Unaccounted:",parent_time > SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
+	
+	for (i=0;i<numChildren;i++)
+	{
+		profileIterator->Enter_Child(i);
+		dumpRecursive(profileIterator,spacing+3);
+		profileIterator->Enter_Parent();
+	}
+}
+
+
+
+void	CProfileManager::dumpAll()
+{
+	CProfileIterator* profileIterator = 0;
+	profileIterator = CProfileManager::Get_Iterator();
+
+	dumpRecursive(profileIterator,0);
+
+	CProfileManager::Release_Iterator(profileIterator);
+}
+
+
+
 #endif //USE_BT_CLOCK
 
Index: code/branches/physics/src/bullet/LinearMath/btQuickprof.h
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btQuickprof.h	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/btQuickprof.h	(revision 2430)
@@ -11,12 +11,18 @@
 // Ogre (www.ogre3d.org).
 
+
+
 #ifndef QUICK_PROF_H
 #define QUICK_PROF_H
+
+//To disable built-in profiling, please comment out next line
+//#define BT_NO_PROFILE 1
+#ifndef BT_NO_PROFILE
 
 #include "btScalar.h"
 #include "LinearMath/btAlignedAllocator.h"
 #include <new>
-//To disable built-in profiling, please comment out next line
-//#define BT_NO_PROFILE 1
+
+
 
 
@@ -322,4 +328,8 @@
 	static	void						Release_Iterator( CProfileIterator * iterator ) { delete ( iterator); }
 
+	static void	dumpRecursive(CProfileIterator* profileIterator, int spacing);
+
+	static void	dumpAll();
+
 private:
 	static	CProfileNode			Root;
@@ -345,10 +355,12 @@
 };
 
-#if !defined(BT_NO_PROFILE)
+
 #define	BT_PROFILE( name )			CProfileSample __profile( name )
-#else
+
+#else
+
 #define	BT_PROFILE( name )
-#endif
-
+
+#endif //#ifndef BT_NO_PROFILE
 
 
Index: code/branches/physics/src/bullet/LinearMath/btScalar.h
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btScalar.h	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/btScalar.h	(revision 2430)
@@ -19,4 +19,5 @@
 
 #include <math.h>
+
 #include <stdlib.h>//size_t for MSVC 6.0
 
@@ -25,5 +26,5 @@
 #include <float.h>
 
-#define BT_BULLET_VERSION 272
+#define BT_BULLET_VERSION 273
 
 inline int	btGetVersion()
@@ -66,5 +67,5 @@
 
 		#include <assert.h>
-#if defined(DEBUG) || defined (_DEBUG)
+#ifdef BT_DEBUG
 		#define btAssert assert
 #else
@@ -86,5 +87,9 @@
 		#include <assert.h>
 		#endif
+#ifdef BT_DEBUG
 		#define btAssert assert
+#else
+		#define btAssert(x)
+#endif
 		//btFullAssert is optional, slows down a lot
 		#define btFullAssert(x)
@@ -103,5 +108,9 @@
 		#include <assert.h>
 		#endif
+#ifdef BT_DEBUG
 		#define btAssert assert
+#else
+		#define btAssert(x)
+#endif
 		//btFullAssert is optional, slows down a lot
 		#define btFullAssert(x)
Index: code/branches/physics/src/bullet/LinearMath/btStackAlloc.h
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btStackAlloc.h	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/btStackAlloc.h	(revision 2430)
@@ -24,4 +24,5 @@
 #include "btAlignedAllocator.h"
 
+///The btBlock class is an internal structure for the btStackAlloc memory allocator.
 struct btBlock
 {
Index: code/branches/physics/src/bullet/LinearMath/btTransform.h
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btTransform.h	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/btTransform.h	(revision 2430)
@@ -22,6 +22,6 @@
 
 
-///The btTransform class supports rigid transforms with only translation and rotation and no scaling/shear.
-///It can be used in combination with btVector3, btQuaternion and btMatrix3x3 linear algebra classes.
+/**@brief The btTransform class supports rigid transforms with only translation and rotation and no scaling/shear.
+ *It can be used in combination with btVector3, btQuaternion and btMatrix3x3 linear algebra classes. */
 class btTransform {
 	
@@ -29,7 +29,9 @@
 public:
 	
-	
+  /**@brief No initialization constructor */
 	btTransform() {}
-
+  /**@brief Constructor from btQuaternion (optional btVector3 )
+   * @param q Rotation from quaternion 
+   * @param c Translation from Vector (default 0,0,0) */
 	explicit SIMD_FORCE_INLINE btTransform(const btQuaternion& q, 
 		const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0))) 
@@ -38,4 +40,7 @@
 	{}
 
+  /**@brief Constructor from btMatrix3x3 (optional btVector3)
+   * @param b Rotation from Matrix 
+   * @param c Translation from Vector default (0,0,0)*/
 	explicit SIMD_FORCE_INLINE btTransform(const btMatrix3x3& b, 
 		const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0)))
@@ -43,5 +48,5 @@
 		m_origin(c)
 	{}
-
+  /**@brief Copy constructor */
 	SIMD_FORCE_INLINE btTransform (const btTransform& other)
 		: m_basis(other.m_basis),
@@ -49,5 +54,5 @@
 	{
 	}
-
+  /**@brief Assignment Operator */
 	SIMD_FORCE_INLINE btTransform& operator=(const btTransform& other)
 	{
@@ -58,4 +63,8 @@
 
 
+  /**@brief Set the current transform as the value of the product of two transforms
+   * @param t1 Transform 1
+   * @param t2 Transform 2
+   * This = Transform1 * Transform2 */
 		SIMD_FORCE_INLINE void mult(const btTransform& t1, const btTransform& t2) {
 			m_basis = t1.m_basis * t2.m_basis;
@@ -70,5 +79,5 @@
 		*/
 
-
+/**@brief Return the transform of the vector */
 	SIMD_FORCE_INLINE btVector3 operator()(const btVector3& x) const
 	{
@@ -78,4 +87,5 @@
 	}
 
+  /**@brief Return the transform of the vector */
 	SIMD_FORCE_INLINE btVector3 operator*(const btVector3& x) const
 	{
@@ -83,10 +93,21 @@
 	}
 
+  /**@brief Return the transform of the btQuaternion */
+	SIMD_FORCE_INLINE btQuaternion operator*(const btQuaternion& q) const
+	{
+		return getRotation() * q;
+	}
+
+  /**@brief Return the basis matrix for the rotation */
 	SIMD_FORCE_INLINE btMatrix3x3&       getBasis()          { return m_basis; }
+  /**@brief Return the basis matrix for the rotation */
 	SIMD_FORCE_INLINE const btMatrix3x3& getBasis()    const { return m_basis; }
 
+  /**@brief Return the origin vector translation */
 	SIMD_FORCE_INLINE btVector3&         getOrigin()         { return m_origin; }
+  /**@brief Return the origin vector translation */
 	SIMD_FORCE_INLINE const btVector3&   getOrigin()   const { return m_origin; }
 
+  /**@brief Return a quaternion representing the rotation */
 	btQuaternion getRotation() const { 
 		btQuaternion q;
@@ -96,4 +117,6 @@
 	
 	
+  /**@brief Set from an array 
+   * @param m A pointer to a 15 element array (12 rotation(row major padded on the right by 1), and 3 translation */
 	void setFromOpenGLMatrix(const btScalar *m)
 	{
@@ -102,4 +125,6 @@
 	}
 
+  /**@brief Fill an array representation
+   * @param m A pointer to a 15 element array (12 rotation(row major padded on the right by 1), and 3 translation */
 	void getOpenGLMatrix(btScalar *m) const 
 	{
@@ -111,4 +136,6 @@
 	}
 
+  /**@brief Set the translational element
+   * @param origin The vector to set the translation to */
 	SIMD_FORCE_INLINE void setOrigin(const btVector3& origin) 
 	{ 
@@ -119,5 +146,5 @@
 
 
-
+  /**@brief Set the rotational element by btMatrix3x3 */
 	SIMD_FORCE_INLINE void setBasis(const btMatrix3x3& basis)
 	{ 
@@ -125,4 +152,5 @@
 	}
 
+  /**@brief Set the rotational element by btQuaternion */
 	SIMD_FORCE_INLINE void setRotation(const btQuaternion& q)
 	{
@@ -131,5 +159,5 @@
 
 
-
+  /**@brief Set this transformation to the identity */
 	void setIdentity()
 	{
@@ -138,5 +166,6 @@
 	}
 
-	
+  /**@brief Multiply this Transform by another(this = this * another) 
+   * @param t The other transform */
 	btTransform& operator*=(const btTransform& t) 
 	{
@@ -146,4 +175,5 @@
 	}
 
+  /**@brief Return the inverse of this transform */
 	btTransform inverse() const
 	{ 
@@ -152,8 +182,13 @@
 	}
 
+  /**@brief Return the inverse of this transform times the other transform
+   * @param t The other transform 
+   * return this.inverse() * the other */
 	btTransform inverseTimes(const btTransform& t) const;  
 
+  /**@brief Return the product of this transform and the other */
 	btTransform operator*(const btTransform& t) const;
 
+  /**@brief Return an identity transform */
 	static btTransform	getIdentity()
 	{
@@ -164,6 +199,7 @@
 	
 private:
-
+  ///Storage for the rotation
 	btMatrix3x3 m_basis;
+  ///Storage for the translation
 	btVector3   m_origin;
 };
@@ -192,4 +228,5 @@
 }
 
+/**@brief Test if two transforms have all elements equal */
 SIMD_FORCE_INLINE bool operator==(const btTransform& t1, const btTransform& t2)
 {
Index: code/branches/physics/src/bullet/LinearMath/btTransformUtil.h
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btTransformUtil.h	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/btTransformUtil.h	(revision 2430)
@@ -101,4 +101,36 @@
 	}
 
+	static void	calculateVelocityQuaternion(const btVector3& pos0,const btVector3& pos1,const btQuaternion& orn0,const btQuaternion& orn1,btScalar timeStep,btVector3& linVel,btVector3& angVel)
+	{
+		linVel = (pos1 - pos0) / timeStep;
+		btVector3 axis;
+		btScalar  angle;
+		if (orn0 != orn1)
+		{
+			calculateDiffAxisAngleQuaternion(orn0,orn1,axis,angle);
+			angVel = axis * angle / timeStep;
+		} else
+		{
+			angVel.setValue(0,0,0);
+		}
+	}
+
+	static void calculateDiffAxisAngleQuaternion(const btQuaternion& orn0,const btQuaternion& orn1a,btVector3& axis,btScalar& angle)
+	{
+		btQuaternion orn1 = orn0.farthest(orn1a);
+		btQuaternion dorn = orn1 * orn0.inverse();
+		///floating point inaccuracy can lead to w component > 1..., which breaks 
+		dorn.normalize();
+		angle = dorn.getAngle();
+		axis = btVector3(dorn.x(),dorn.y(),dorn.z());
+		axis[3] = btScalar(0.);
+		//check for axis length
+		btScalar len = axis.length2();
+		if (len < SIMD_EPSILON*SIMD_EPSILON)
+			axis = btVector3(btScalar(1.),btScalar(0.),btScalar(0.));
+		else
+			axis /= btSqrt(len);
+	}
+
 	static void	calculateVelocity(const btTransform& transform0,const btTransform& transform1,btScalar timeStep,btVector3& linVel,btVector3& angVel)
 	{
@@ -112,18 +144,9 @@
 	static void calculateDiffAxisAngle(const btTransform& transform0,const btTransform& transform1,btVector3& axis,btScalar& angle)
 	{
-	
-	#ifdef USE_QUATERNION_DIFF
-		btQuaternion orn0 = transform0.getRotation();
-		btQuaternion orn1a = transform1.getRotation();
-		btQuaternion orn1 = orn0.farthest(orn1a);
-		btQuaternion dorn = orn1 * orn0.inverse();
-#else
 		btMatrix3x3 dmat = transform1.getBasis() * transform0.getBasis().inverse();
 		btQuaternion dorn;
 		dmat.getRotation(dorn);
-#endif//USE_QUATERNION_DIFF
-	
+
 		///floating point inaccuracy can lead to w component > 1..., which breaks 
-
 		dorn.normalize();
 		
@@ -141,4 +164,84 @@
 };
 
+
+///The btConvexSeparatingDistanceUtil can help speed up convex collision detection 
+///by conservatively updating a cached separating distance/vector instead of re-calculating the closest distance
+class	btConvexSeparatingDistanceUtil
+{
+	btQuaternion	m_ornA;
+	btQuaternion	m_ornB;
+	btVector3	m_posA;
+	btVector3	m_posB;
+	
+	btVector3	m_separatingNormal;
+
+	btScalar	m_boundingRadiusA;
+	btScalar	m_boundingRadiusB;
+	btScalar	m_separatingDistance;
+
+public:
+
+	btConvexSeparatingDistanceUtil(btScalar	boundingRadiusA,btScalar	boundingRadiusB)
+		:m_boundingRadiusA(boundingRadiusA),
+		m_boundingRadiusB(boundingRadiusB),
+		m_separatingDistance(0.f)
+	{
+	}
+
+	btScalar	getConservativeSeparatingDistance()
+	{
+		return m_separatingDistance;
+	}
+
+	void	updateSeparatingDistance(const btTransform& transA,const btTransform& transB)
+	{
+		const btVector3& toPosA = transA.getOrigin();
+		const btVector3& toPosB = transB.getOrigin();
+		btQuaternion toOrnA = transA.getRotation();
+		btQuaternion toOrnB = transB.getRotation();
+
+		if (m_separatingDistance>0.f)
+		{
+			
+
+			btVector3 linVelA,angVelA,linVelB,angVelB;
+			btTransformUtil::calculateVelocityQuaternion(m_posA,toPosA,m_ornA,toOrnA,btScalar(1.),linVelA,angVelA);
+			btTransformUtil::calculateVelocityQuaternion(m_posB,toPosB,m_ornB,toOrnB,btScalar(1.),linVelB,angVelB);
+			btScalar maxAngularProjectedVelocity = angVelA.length() * m_boundingRadiusA + angVelB.length() * m_boundingRadiusB;
+			btVector3 relLinVel = (linVelB-linVelA);
+			btScalar relLinVelocLength = (linVelB-linVelA).dot(m_separatingNormal);
+			if (relLinVelocLength<0.f)
+			{
+				relLinVelocLength = 0.f;
+			}
+	
+			btScalar	projectedMotion = maxAngularProjectedVelocity +relLinVelocLength;
+			m_separatingDistance -= projectedMotion;
+		}
+	
+		m_posA = toPosA;
+		m_posB = toPosB;
+		m_ornA = toOrnA;
+		m_ornB = toOrnB;
+	}
+
+	void	initSeparatingDistance(const btVector3& separatingVector,btScalar separatingDistance,const btTransform& transA,const btTransform& transB)
+	{
+		m_separatingNormal = separatingVector;
+		m_separatingDistance = separatingDistance;
+		
+		const btVector3& toPosA = transA.getOrigin();
+		const btVector3& toPosB = transB.getOrigin();
+		btQuaternion toOrnA = transA.getRotation();
+		btQuaternion toOrnB = transB.getRotation();
+		m_posA = toPosA;
+		m_posB = toPosB;
+		m_ornA = toOrnA;
+		m_ornB = toOrnB;
+	}
+
+};
+
+
 #endif //SIMD_TRANSFORM_UTIL_H
 
Index: code/branches/physics/src/bullet/LinearMath/btVector3.h
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btVector3.h	(revision 2192)
+++ code/branches/physics/src/bullet/LinearMath/btVector3.h	(revision 2430)
@@ -20,12 +20,16 @@
 #include "btQuadWord.h"
 
-///btVector3 can be used to represent 3D points and vectors.
-///It has an un-used w component to suit 16-byte alignment when btVector3 is stored in containers. This extra component can be used by derived classes (Quaternion?) or by user
-///Ideally, this class should be replaced by a platform optimized SIMD version that keeps the data in registers
+/**@brief btVector3 can be used to represent 3D points and vectors.
+ * It has an un-used w component to suit 16-byte alignment when btVector3 is stored in containers. This extra component can be used by derived classes (Quaternion?) or by user
+ * Ideally, this class should be replaced by a platform optimized SIMD version that keeps the data in registers
+ */
 class	btVector3 : public btQuadWord {
 
 public:
+  /**@brief No initialization constructor */
 	SIMD_FORCE_INLINE btVector3() {}
 
+  /**@brief Constructor from btQuadWordStorage (btVector3 inherits from this so is also valid)
+   * Note: Vector3 derives from btQuadWordStorage*/
 	SIMD_FORCE_INLINE btVector3(const btQuadWordStorage& q) 
 		: btQuadWord(q)
@@ -33,5 +37,9 @@
 	}
 	
-
+  /**@brief Constructor from scalars 
+   * @param x X value
+   * @param y Y value 
+   * @param z Z value 
+   */
 	SIMD_FORCE_INLINE btVector3(const btScalar& x, const btScalar& y, const btScalar& z) 
 		:btQuadWord(x,y,z,btScalar(0.))
@@ -45,26 +53,31 @@
 
 	
-
+/**@brief Add a vector to this one 
+ * @param The vector to add to this one */
 	SIMD_FORCE_INLINE btVector3& operator+=(const btVector3& v)
 	{
 
-		m_x += v.x(); m_y += v.y(); m_z += v.z();
+		m_floats[0] += v.x(); m_floats[1] += v.y(); m_floats[2] += v.z();
 		return *this;
 	}
 
 
-
+  /**@brief Subtract a vector from this one
+   * @param The vector to subtract */
 	SIMD_FORCE_INLINE btVector3& operator-=(const btVector3& v) 
 	{
-		m_x -= v.x(); m_y -= v.y(); m_z -= v.z();
+		m_floats[0] -= v.x(); m_floats[1] -= v.y(); m_floats[2] -= v.z();
 		return *this;
 	}
-
+  /**@brief Scale the vector
+   * @param s Scale factor */
 	SIMD_FORCE_INLINE btVector3& operator*=(const btScalar& s)
 	{
-		m_x *= s; m_y *= s; m_z *= s;
+		m_floats[0] *= s; m_floats[1] *= s; m_floats[2] *= s;
 		return *this;
 	}
 
+  /**@brief Inversely scale the vector 
+   * @param s Scale factor to divide by */
 	SIMD_FORCE_INLINE btVector3& operator/=(const btScalar& s) 
 	{
@@ -73,9 +86,12 @@
 	}
 
+  /**@brief Return the dot product
+   * @param v The other vector in the dot product */
 	SIMD_FORCE_INLINE btScalar dot(const btVector3& v) const
 	{
-		return m_x * v.x() + m_y * v.y() + m_z * v.z();
-	}
-
+		return m_floats[0] * v.x() + m_floats[1] * v.y() + m_floats[2] * v.z();
+	}
+
+  /**@brief Return the length of the vector squared */
 	SIMD_FORCE_INLINE btScalar length2() const
 	{
@@ -83,4 +99,5 @@
 	}
 
+  /**@brief Return the length of the vector */
 	SIMD_FORCE_INLINE btScalar length() const
 	{
@@ -88,8 +105,14 @@
 	}
 
+  /**@brief Return the distance squared between the ends of this and another vector
+   * This is symantically treating the vector like a point */
 	SIMD_FORCE_INLINE btScalar distance2(const btVector3& v) const;
 
+  /**@brief Return the distance between the ends of this and another vector
+   * This is symantically treating the vector like a point */
 	SIMD_FORCE_INLINE btScalar distance(const btVector3& v) const;
 
+  /**@brief Normalize this vector 
+   * x^2 + y^2 + z^2 = 1 */
 	SIMD_FORCE_INLINE btVector3& normalize() 
 	{
@@ -97,8 +120,14 @@
 	}
 
+  /**@brief Return a normalized version of this vector */
 	SIMD_FORCE_INLINE btVector3 normalized() const;
 
+  /**@brief Rotate this vector 
+   * @param wAxis The axis to rotate about 
+   * @param angle The angle to rotate by */
 	SIMD_FORCE_INLINE btVector3 rotate( const btVector3& wAxis, const btScalar angle );
 
+  /**@brief Return the angle between this and another vector
+   * @param v The other vector */
 	SIMD_FORCE_INLINE btScalar angle(const btVector3& v) const 
 	{
@@ -107,36 +136,41 @@
 		return btAcos(dot(v) / s);
 	}
-
+  /**@brief Return a vector will the absolute values of each element */
 	SIMD_FORCE_INLINE btVector3 absolute() const 
 	{
 		return btVector3(
-			btFabs(m_x), 
-			btFabs(m_y), 
-			btFabs(m_z));
-	}
-
+			btFabs(m_floats[0]), 
+			btFabs(m_floats[1]), 
+			btFabs(m_floats[2]));
+	}
+  /**@brief Return the cross product between this and another vector 
+   * @param v The other vector */
 	SIMD_FORCE_INLINE btVector3 cross(const btVector3& v) const
 	{
 		return btVector3(
-			m_y * v.z() - m_z * v.y(),
-			m_z * v.x() - m_x * v.z(),
-			m_x * v.y() - m_y * v.x());
+			m_floats[1] * v.z() - m_floats[2] * v.y(),
+			m_floats[2] * v.x() - m_floats[0] * v.z(),
+			m_floats[0] * v.y() - m_floats[1] * v.x());
 	}
 
 	SIMD_FORCE_INLINE btScalar triple(const btVector3& v1, const btVector3& v2) const
 	{
-		return m_x * (v1.y() * v2.z() - v1.z() * v2.y()) + 
-			m_y * (v1.z() * v2.x() - v1.x() * v2.z()) + 
-			m_z * (v1.x() * v2.y() - v1.y() * v2.x());
-	}
-
+		return m_floats[0] * (v1.y() * v2.z() - v1.z() * v2.y()) + 
+			m_floats[1] * (v1.z() * v2.x() - v1.x() * v2.z()) + 
+			m_floats[2] * (v1.x() * v2.y() - v1.y() * v2.x());
+	}
+
+  /**@brief Return the axis with the smallest value 
+   * Note return values are 0,1,2 for x, y, or z */
 	SIMD_FORCE_INLINE int minAxis() const
 	{
-		return m_x < m_y ? (m_x < m_z ? 0 : 2) : (m_y < m_z ? 1 : 2);
-	}
-
+		return m_floats[0] < m_floats[1] ? (m_floats[0] < m_floats[2] ? 0 : 2) : (m_floats[1] < m_floats[2] ? 1 : 2);
+	}
+
+  /**@brief Return the axis with the largest value 
+   * Note return values are 0,1,2 for x, y, or z */
 	SIMD_FORCE_INLINE int maxAxis() const 
 	{
-		return m_x < m_y ? (m_y < m_z ? 2 : 1) : (m_x < m_z ? 2 : 0);
+		return m_floats[0] < m_floats[1] ? (m_floats[1] < m_floats[2] ? 2 : 1) : (m_floats[0] < m_floats[2] ? 2 : 0);
 	}
 
@@ -154,22 +188,26 @@
 	{
 		btScalar s = btScalar(1.0) - rt;
-		m_x = s * v0.x() + rt * v1.x();
-		m_y = s * v0.y() + rt * v1.y();
-		m_z = s * v0.z() + rt * v1.z();
+		m_floats[0] = s * v0.x() + rt * v1.x();
+		m_floats[1] = s * v0.y() + rt * v1.y();
+		m_floats[2] = s * v0.z() + rt * v1.z();
 		//don't do the unused w component
 		//		m_co[3] = s * v0[3] + rt * v1[3];
 	}
 
+  /**@brief Return the linear interpolation between this and another vector 
+   * @param v The other vector 
+   * @param t The ration of this to v (t = 0 => return this, t=1 => return other) */
 	SIMD_FORCE_INLINE btVector3 lerp(const btVector3& v, const btScalar& t) const 
 	{
-		return btVector3(m_x + (v.x() - m_x) * t,
-			m_y + (v.y() - m_y) * t,
-			m_z + (v.z() - m_z) * t);
-	}
-
-
+		return btVector3(m_floats[0] + (v.x() - m_floats[0]) * t,
+			m_floats[1] + (v.y() - m_floats[1]) * t,
+			m_floats[2] + (v.z() - m_floats[2]) * t);
+	}
+
+  /**@brief Elementwise multiply this vector by the other 
+   * @param v The other vector */
 	SIMD_FORCE_INLINE btVector3& operator*=(const btVector3& v)
 	{
-		m_x *= v.x(); m_y *= v.y(); m_z *= v.z();
+		m_floats[0] *= v.x(); m_floats[1] *= v.y(); m_floats[2] *= v.z();
 		return *this;
 	}
@@ -179,4 +217,5 @@
 };
 
+/**@brief Return the sum of two vectors (Point symantics)*/
 SIMD_FORCE_INLINE btVector3 
 operator+(const btVector3& v1, const btVector3& v2) 
@@ -185,4 +224,5 @@
 }
 
+/**@brief Return the elementwise product of two vectors */
 SIMD_FORCE_INLINE btVector3 
 operator*(const btVector3& v1, const btVector3& v2) 
@@ -191,4 +231,5 @@
 }
 
+/**@brief Return the difference between two vectors */
 SIMD_FORCE_INLINE btVector3 
 operator-(const btVector3& v1, const btVector3& v2)
@@ -196,5 +237,5 @@
 	return btVector3(v1.x() - v2.x(), v1.y() - v2.y(), v1.z() - v2.z());
 }
-
+/**@brief Return the negative of the vector */
 SIMD_FORCE_INLINE btVector3 
 operator-(const btVector3& v)
@@ -203,4 +244,5 @@
 }
 
+/**@brief Return the vector scaled by s */
 SIMD_FORCE_INLINE btVector3 
 operator*(const btVector3& v, const btScalar& s)
@@ -209,4 +251,5 @@
 }
 
+/**@brief Return the vector scaled by s */
 SIMD_FORCE_INLINE btVector3 
 operator*(const btScalar& s, const btVector3& v)
@@ -215,4 +258,5 @@
 }
 
+/**@brief Return the vector inversely scaled by s */
 SIMD_FORCE_INLINE btVector3
 operator/(const btVector3& v, const btScalar& s)
@@ -222,4 +266,5 @@
 }
 
+/**@brief Return the vector inversely scaled by s */
 SIMD_FORCE_INLINE btVector3
 operator/(const btVector3& v1, const btVector3& v2)
@@ -228,4 +273,5 @@
 }
 
+/**@brief Return the dot product between two vectors */
 SIMD_FORCE_INLINE btScalar 
 dot(const btVector3& v1, const btVector3& v2) 
@@ -235,5 +281,5 @@
 
 
-
+/**@brief Return the distance squared between two vectors */
 SIMD_FORCE_INLINE btScalar
 distance2(const btVector3& v1, const btVector3& v2) 
@@ -243,4 +289,5 @@
 
 
+/**@brief Return the distance between two vectors */
 SIMD_FORCE_INLINE btScalar
 distance(const btVector3& v1, const btVector3& v2) 
@@ -249,4 +296,5 @@
 }
 
+/**@brief Return the angle between two vectors */
 SIMD_FORCE_INLINE btScalar
 angle(const btVector3& v1, const btVector3& v2) 
@@ -255,4 +303,5 @@
 }
 
+/**@brief Return the cross product of two vectors */
 SIMD_FORCE_INLINE btVector3 
 cross(const btVector3& v1, const btVector3& v2) 
@@ -267,4 +316,8 @@
 }
 
+/**@brief Return the linear interpolation between two vectors
+ * @param v1 One vector 
+ * @param v2 The other vector 
+ * @param t The ration of this to v (t = 0 => return v1, t=1 => return v2) */
 SIMD_FORCE_INLINE btVector3 
 lerp(const btVector3& v1, const btVector3& v2, const btScalar& t)
@@ -273,5 +326,5 @@
 }
 
-
+/**@brief Test if each element of the vector is equivalent */
 SIMD_FORCE_INLINE bool operator==(const btVector3& p1, const btVector3& p2) 
 {
@@ -317,5 +370,5 @@
 		: btVector3(x,y,z)
 	{
-		m_unusedW = w;
+		m_floats[3] = w;
 	}
 
@@ -324,13 +377,13 @@
 	{
 		return btVector4(
-			btFabs(m_x), 
-			btFabs(m_y), 
-			btFabs(m_z),
-			btFabs(m_unusedW));
-	}
-
-
-
-	btScalar	getW() const { return m_unusedW;}
+			btFabs(m_floats[0]), 
+			btFabs(m_floats[1]), 
+			btFabs(m_floats[2]),
+			btFabs(m_floats[3]));
+	}
+
+
+
+	btScalar	getW() const { return m_floats[3];}
 
 
@@ -339,23 +392,23 @@
 		int maxIndex = -1;
 		btScalar maxVal = btScalar(-1e30);
-		if (m_x > maxVal)
+		if (m_floats[0] > maxVal)
 		{
 			maxIndex = 0;
-			maxVal = m_x;
-		}
-		if (m_y > maxVal)
+			maxVal = m_floats[0];
+		}
+		if (m_floats[1] > maxVal)
 		{
 			maxIndex = 1;
-			maxVal = m_y;
-		}
-		if (m_z > maxVal)
+			maxVal = m_floats[1];
+		}
+		if (m_floats[2] > maxVal)
 		{
 			maxIndex = 2;
-			maxVal = m_z;
-		}
-		if (m_unusedW > maxVal)
+			maxVal = m_floats[2];
+		}
+		if (m_floats[3] > maxVal)
 		{
 			maxIndex = 3;
-			maxVal = m_unusedW;
+			maxVal = m_floats[3];
 		}
 		
@@ -372,23 +425,23 @@
 		int minIndex = -1;
 		btScalar minVal = btScalar(1e30);
-		if (m_x < minVal)
+		if (m_floats[0] < minVal)
 		{
 			minIndex = 0;
-			minVal = m_x;
-		}
-		if (m_y < minVal)
+			minVal = m_floats[0];
+		}
+		if (m_floats[1] < minVal)
 		{
 			minIndex = 1;
-			minVal = m_y;
-		}
-		if (m_z < minVal)
+			minVal = m_floats[1];
+		}
+		if (m_floats[2] < minVal)
 		{
 			minIndex = 2;
-			minVal = m_z;
-		}
-		if (m_unusedW < minVal)
+			minVal = m_floats[2];
+		}
+		if (m_floats[3] < minVal)
 		{
 			minIndex = 3;
-			minVal = m_unusedW;
+			minVal = m_floats[3];
 		}
 		
