Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btBoxShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btBoxShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btBoxShape.h	(revision 2430)
@@ -20,5 +20,5 @@
 #include "btCollisionMargin.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
-#include "LinearMath/btPoint3.h"
+#include "LinearMath/btVector3.h"
 #include "LinearMath/btMinMax.h"
 
@@ -118,5 +118,5 @@
 	virtual void	calculateLocalInertia(btScalar mass,btVector3& inertia) const;
 
-	virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const
+	virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const
 	{
 		//this plane might not be aligned...
@@ -191,5 +191,5 @@
 
 	
-	virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const
+	virtual void getEdge(int i,btVector3& pa,btVector3& pb) const
 	//virtual void getEdge(int i,Edge& edge) const
 	{
@@ -262,5 +262,5 @@
 
 	
-	virtual	bool isInside(const btPoint3& pt,btScalar tolerance) const
+	virtual	bool isInside(const btVector3& pt,btScalar tolerance) const
 	{
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp	(revision 2430)
@@ -144,8 +144,17 @@
 			{
 				int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
-
-				btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
-
-				m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());		
+				
+				if (type == PHY_FLOAT)
+				{
+					float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
+					
+					m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());		
+				}
+				else
+				{
+					double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
+					
+					m_triangle[j] = btVector3(btScalar(graphicsbase[0])*meshScaling.getX(),btScalar(graphicsbase[1])*meshScaling.getY(),btScalar(graphicsbase[2])*meshScaling.getZ());		
+				}
 			}
 
@@ -205,7 +214,16 @@
 				int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
 
-				btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
-
-				m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());		
+				if (type == PHY_FLOAT)
+				{
+					float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
+
+					m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());		
+				}
+				else
+				{
+					double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
+					
+					m_triangle[j] = btVector3(btScalar(graphicsbase[0])*meshScaling.getX(),btScalar(graphicsbase[1])*meshScaling.getY(),btScalar(graphicsbase[2])*meshScaling.getZ());		
+				}
 			}
 
@@ -282,10 +300,22 @@
 				printf("%d ,",graphicsindex);
 #endif //DEBUG_TRIANGLE_MESH
-				btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
-
-				m_triangle[j] = btVector3(
-					graphicsbase[0]*meshScaling.getX(),
-					graphicsbase[1]*meshScaling.getY(),
-					graphicsbase[2]*meshScaling.getZ());
+				if (type == PHY_FLOAT)
+				{
+					float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
+					
+					m_triangle[j] = btVector3(
+																		graphicsbase[0]*meshScaling.getX(),
+																		graphicsbase[1]*meshScaling.getY(),
+																		graphicsbase[2]*meshScaling.getZ());
+				}
+				else
+				{
+					double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
+
+					m_triangle[j] = btVector3(
+						btScalar(graphicsbase[0])*meshScaling.getX(),
+						btScalar(graphicsbase[1])*meshScaling.getY(),
+						btScalar(graphicsbase[2])*meshScaling.getZ());
+				}
 #ifdef DEBUG_TRIANGLE_MESH
 				printf("triangle vertices:%f,%f,%f\n",triangle[j].x(),triangle[j].y(),triangle[j].z());
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCapsuleShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCapsuleShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCapsuleShape.h	(revision 2430)
@@ -50,5 +50,5 @@
 			halfExtents += btVector3(getMargin(),getMargin(),getMargin());
 			btMatrix3x3 abs_b = t.getBasis().absolute();  
-			btPoint3 center = t.getOrigin();
+			btVector3 center = t.getOrigin();
 			btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));		  
 			
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp	(revision 2430)
@@ -43,6 +43,12 @@
 }
 
+btScalar	btCollisionShape::getContactBreakingThreshold() const
+{
+	///@todo make this 0.1 configurable
+	return getAngularMotionDisc() * btScalar(0.1);
+}
 btScalar	btCollisionShape::getAngularMotionDisc() const
 {
+	///@todo cache this value, to improve performance
 	btVector3	center;
 	btScalar disc;
@@ -66,5 +72,5 @@
 	// add linear motion
 	btVector3 linMotion = linvel*timeStep;
-	//todo: simd would have a vector max/min operation, instead of per-element access
+	///@todo: simd would have a vector max/min operation, instead of per-element access
 	if (linMotion.x() > btScalar(0.))
 		temporalAabbMaxx += linMotion.x(); 
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.h	(revision 2430)
@@ -20,5 +20,4 @@
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btMatrix3x3.h"
-#include "LinearMath/btPoint3.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" //for the shape types
 
@@ -47,4 +46,6 @@
 	///getAngularMotionDisc returns the maximus radius needed for Conservative Advancement to handle time-of-impact with rotations.
 	virtual btScalar	getAngularMotionDisc() const;
+
+	virtual btScalar	getContactBreakingThreshold() const;
 
 
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp	(revision 2430)
@@ -18,5 +18,5 @@
 #include "BulletCollision/BroadphaseCollision/btDbvt.h"
 
-btCompoundShape::btCompoundShape()
+btCompoundShape::btCompoundShape(bool enableDynamicAabbTree)
 : m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)),
 m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)),
@@ -26,7 +26,11 @@
 {
 	m_shapeType = COMPOUND_SHAPE_PROXYTYPE;
-	void* mem = btAlignedAlloc(sizeof(btDbvt),16);
-	m_dynamicAabbTree = new(mem) btDbvt();
-	btAssert(mem==m_dynamicAabbTree);
+
+	if (enableDynamicAabbTree)
+	{
+		void* mem = btAlignedAlloc(sizeof(btDbvt),16);
+		m_dynamicAabbTree = new(mem) btDbvt();
+		btAssert(mem==m_dynamicAabbTree);
+	}
 }
 
@@ -77,4 +81,21 @@
 }
 
+void	btCompoundShape::updateChildTransform(int childIndex, const btTransform& newChildTransform)
+{
+	m_children[childIndex].m_transform = newChildTransform;
+
+	if (m_dynamicAabbTree)
+	{
+		///update the dynamic aabb tree
+		btVector3 localAabbMin,localAabbMax;
+		m_children[childIndex].m_childShape->getAabb(newChildTransform,localAabbMin,localAabbMax);
+		ATTRIBUTE_ALIGNED16(btDbvtVolume)	bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
+		int index = m_children.size()-1;
+		m_dynamicAabbTree->update(m_children[childIndex].m_node,bounds);
+	}
+
+	recalculateLocalAabb();
+}
+
 void btCompoundShape::removeChildShapeByIndex(int childShapeIndex)
 {
@@ -88,4 +109,6 @@
 
 }
+
+
 
 void btCompoundShape::removeChildShape(btCollisionShape* shape)
@@ -100,4 +123,6 @@
 			m_children.pop_back();
 			//remove it from the m_dynamicAabbTree too
+			//@todo: this leads to problems due to caching in the btCompoundCollisionAlgorithm
+			//so effectively, removeChildShape is broken at the moment
 			//m_dynamicAabbTree->remove(m_aabbProxies[i]);
 			//m_aabbProxies.swap(i,m_children.size()-1);
@@ -142,5 +167,5 @@
 	btMatrix3x3 abs_b = trans.getBasis().absolute();  
 
-	btPoint3 center = trans(localCenter);
+	btVector3 center = trans(localCenter);
 
 	btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
@@ -181,5 +206,7 @@
 	btScalar totalMass = 0;
 	btVector3 center(0, 0, 0);
-	for (int k = 0; k < n; k++)
+	int k;
+
+	for (k = 0; k < n; k++)
 	{
 		center += m_children[k].m_transform.getOrigin() * masses[k];
@@ -190,5 +217,5 @@
 
 	btMatrix3x3 tensor(0, 0, 0, 0, 0, 0, 0, 0, 0);
-	for (int k = 0; k < n; k++)
+	for ( k = 0; k < n; k++)
 	{
 		btVector3 i;
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.h	(revision 2430)
@@ -47,15 +47,15 @@
 }
 
-/// btCompoundShape allows to store multiple other btCollisionShapes
+/// The btCompoundShape allows to store multiple other btCollisionShapes
 /// This allows for moving concave collision objects. This is more general then the static concave btBvhTriangleMeshShape.
+/// It has an (optional) dynamic aabb tree to accelerate early rejection tests. 
+/// @todo: This aabb tree can also be use to speed up ray tests on btCompoundShape, see http://code.google.com/p/bullet/issues/detail?id=25
+/// Currently, removal of child shapes is only supported when disabling the aabb tree (pass 'false' in the constructor of btCompoundShape)
 ATTRIBUTE_ALIGNED16(class) btCompoundShape	: public btCollisionShape
 {
-	//btAlignedObjectArray<btTransform>		m_childTransforms;
-	//btAlignedObjectArray<btCollisionShape*>	m_childShapes;
 	btAlignedObjectArray<btCompoundShapeChild> m_children;
 	btVector3						m_localAabbMin;
 	btVector3						m_localAabbMax;
 
-	//btOptimizedBvh*					m_aabbTree;
 	btDbvt*							m_dynamicAabbTree;
 
@@ -63,5 +63,5 @@
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
-	btCompoundShape();
+	btCompoundShape(bool enableDynamicAabbTree = true);
 
 	virtual ~btCompoundShape();
@@ -89,12 +89,15 @@
 	}
 
-	btTransform	getChildTransform(int index)
+	btTransform&	getChildTransform(int index)
 	{
 		return m_children[index].m_transform;
 	}
-	const btTransform	getChildTransform(int index) const
+	const btTransform&	getChildTransform(int index) const
 	{
 		return m_children[index].m_transform;
 	}
+
+	///set a new transform for a child, and update internal data structures (local aabb and dynamic tree)
+	void	updateChildTransform(int childIndex, const btTransform& newChildTransform);
 
 
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConcaveShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConcaveShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConcaveShape.h	(revision 2430)
@@ -21,4 +21,14 @@
 #include "btTriangleCallback.h"
 
+/// PHY_ScalarType enumerates possible scalar types.
+/// See the btStridingMeshInterface or btHeightfieldTerrainShape for its use
+typedef enum PHY_ScalarType {
+	PHY_FLOAT,
+	PHY_DOUBLE,
+	PHY_INTEGER,
+	PHY_SHORT,
+	PHY_FIXEDPOINT88,
+	PHY_UCHAR
+} PHY_ScalarType;
 
 ///The btConcaveShape class provides an interface for non-moving (static) concave shapes.
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConeShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConeShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConeShape.cpp	(revision 2430)
@@ -15,5 +15,4 @@
 
 #include "btConeShape.h"
-#include "LinearMath/btPoint3.h"
 
 
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp	(revision 2430)
@@ -23,5 +23,5 @@
 {
 	m_shapeType = CONVEX_HULL_SHAPE_PROXYTYPE;
-	m_points.resize(numPoints);
+	m_unscaledPoints.resize(numPoints);
 
 	unsigned char* pointsBaseAddress = (unsigned char*)points;
@@ -29,6 +29,6 @@
 	for (int i=0;i<numPoints;i++)
 	{
-		btPoint3* point = (btPoint3*)(pointsBaseAddress + i*stride);
-		m_points[i] = point[0];
+		btVector3* point = (btVector3*)(pointsBaseAddress + i*stride);
+		m_unscaledPoints[i] = point[0];
 	}
 
@@ -45,7 +45,7 @@
 }
 
-void btConvexHullShape::addPoint(const btPoint3& point)
+void btConvexHullShape::addPoint(const btVector3& point)
 {
-	m_points.push_back(point);
+	m_unscaledPoints.push_back(point);
 	recalcLocalAabb();
 
@@ -69,7 +69,7 @@
 
 
-	for (int i=0;i<m_points.size();i++)
+	for (int i=0;i<m_unscaledPoints.size();i++)
 	{
-		btPoint3 vtx = m_points[i] * m_localScaling;
+		btVector3 vtx = m_unscaledPoints[i] * m_localScaling;
 
 		newDot = vec.dot(vtx);
@@ -93,7 +93,7 @@
 		}
 	}
-	for (int i=0;i<m_points.size();i++)
+	for (int i=0;i<m_unscaledPoints.size();i++)
 	{
-		btPoint3 vtx = m_points[i] * m_localScaling;
+		btVector3 vtx = getScaledPoint(i);
 
 		for (int j=0;j<numVectors;j++)
@@ -146,24 +146,24 @@
 int	btConvexHullShape::getNumVertices() const
 {
-	return m_points.size();
+	return m_unscaledPoints.size();
 }
 
 int btConvexHullShape::getNumEdges() const
 {
-	return m_points.size();
+	return m_unscaledPoints.size();
 }
 
-void btConvexHullShape::getEdge(int i,btPoint3& pa,btPoint3& pb) const
+void btConvexHullShape::getEdge(int i,btVector3& pa,btVector3& pb) const
 {
 
-	int index0 = i%m_points.size();
-	int index1 = (i+1)%m_points.size();
-	pa = m_points[index0]*m_localScaling;
-	pb = m_points[index1]*m_localScaling;
+	int index0 = i%m_unscaledPoints.size();
+	int index1 = (i+1)%m_unscaledPoints.size();
+	pa = getScaledPoint(index0);
+	pb = getScaledPoint(index1);
 }
 
-void btConvexHullShape::getVertex(int i,btPoint3& vtx) const
+void btConvexHullShape::getVertex(int i,btVector3& vtx) const
 {
-	vtx = m_points[i]*m_localScaling;
+	vtx = getScaledPoint(i);
 }
 
@@ -173,5 +173,5 @@
 }
 
-void btConvexHullShape::getPlane(btVector3& ,btPoint3& ,int ) const
+void btConvexHullShape::getPlane(btVector3& ,btVector3& ,int ) const
 {
 
@@ -180,5 +180,5 @@
 
 //not yet
-bool btConvexHullShape::isInside(const btPoint3& ,btScalar ) const
+bool btConvexHullShape::isInside(const btVector3& ,btScalar ) const
 {
 	assert(0);
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.h	(revision 2430)
@@ -25,5 +25,5 @@
 ATTRIBUTE_ALIGNED16(class) btConvexHullShape : public btPolyhedralConvexShape
 {
-	btAlignedObjectArray<btPoint3>	m_points;
+	btAlignedObjectArray<btVector3>	m_unscaledPoints;
 
 public:
@@ -34,21 +34,36 @@
 	///It is easier to not pass any points in the constructor, and just add one point at a time, using addPoint.
 	///btConvexHullShape make an internal copy of the points.
-	btConvexHullShape(const btScalar* points=0,int numPoints=0, int stride=sizeof(btPoint3));
+	btConvexHullShape(const btScalar* points=0,int numPoints=0, int stride=sizeof(btVector3));
 
-	void addPoint(const btPoint3& point);
+	void addPoint(const btVector3& point);
 
-	btPoint3* getPoints()
+	
+	btVector3* getUnscaledPoints()
 	{
-		return &m_points[0];
+		return &m_unscaledPoints[0];
 	}
 
-	const btPoint3* getPoints() const
+	const btVector3* getUnscaledPoints() const
 	{
-		return &m_points[0];
+		return &m_unscaledPoints[0];
 	}
 
-	int getNumPoints() const 
+	///getPoints is obsolete, please use getUnscaledPoints
+	const btVector3* getPoints() const
 	{
-		return m_points.size();
+		return getUnscaledPoints();
+	}
+
+	
+
+
+	SIMD_FORCE_INLINE	btVector3 getScaledPoint(int i) const
+	{
+		return m_unscaledPoints[i] * m_localScaling;
+	}
+
+	SIMD_FORCE_INLINE	int getNumPoints() const 
+	{
+		return m_unscaledPoints.size();
 	}
 
@@ -65,9 +80,9 @@
 	virtual int	getNumVertices() const;
 	virtual int getNumEdges() const;
-	virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const;
-	virtual void getVertex(int i,btPoint3& vtx) const;
+	virtual void getEdge(int i,btVector3& pa,btVector3& pb) const;
+	virtual void getVertex(int i,btVector3& vtx) const;
 	virtual int	getNumPlanes() const;
-	virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const;
-	virtual	bool isInside(const btPoint3& pt,btScalar tolerance) const;
+	virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const;
+	virtual	bool isInside(const btVector3& pt,btScalar tolerance) const;
 
 	///in case we receive negative scaling
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.cpp	(revision 2430)
@@ -18,6 +18,7 @@
 
 
+
 btConvexInternalShape::btConvexInternalShape()
-: btConvexShape (), m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
+: m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
 m_collisionMargin(CONVEX_DISTANCE_MARGIN)
 {
@@ -49,5 +50,6 @@
 		minAabb[i] = tmp[i]-margin;
 	}
-};
+}
+
 
 
@@ -71,4 +73,5 @@
 
 #else
+	btAssert(0);
 	return btVector3(0,0,0);
 #endif //__SPU__
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.h	(revision 2430)
@@ -31,12 +31,5 @@
 	}
 
-
 	virtual btVector3	localGetSupportingVertex(const btVector3& vec)const;
-#ifndef __SPU__
-	virtual btVector3	localGetSupportingVertexWithoutMargin(const btVector3& vec) const= 0;
-	
-	//notice that the vectors should be unit length
-	virtual void	batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0;
-#endif //#ifndef __SPU__
 
 	const btVector3& getImplicitShapeDimensions() const
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp	(revision 2430)
@@ -18,22 +18,4 @@
 #include "LinearMath/btQuaternion.h"
 
-btConvexPointCloudShape::btConvexPointCloudShape (btVector3* points,int numPoints) : btPolyhedralConvexShape ()
-{
-	m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE;
-	m_points = points;
-	m_numPoints = numPoints;
-
-	recalcLocalAabb();
-}
-
-void btConvexPointCloudShape::setPoints (btVector3* points, int numPoints)
-{
-	m_points = points;
-	m_numPoints = numPoints;
-
-	recalcLocalAabb();
-}
-
-
 void btConvexPointCloudShape::setLocalScaling(const btVector3& scaling)
 {
@@ -42,4 +24,5 @@
 }
 
+#ifndef __SPU__
 btVector3	btConvexPointCloudShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
 {
@@ -61,5 +44,5 @@
 	for (int i=0;i<m_numPoints;i++)
 	{
-		btPoint3 vtx = m_points[i] * m_localScaling;
+		btVector3 vtx = getScaledPoint(i);
 
 		newDot = vec.dot(vtx);
@@ -85,5 +68,5 @@
 	for (int i=0;i<m_numPoints;i++)
 	{
-		btPoint3 vtx = m_points[i] * m_localScaling;
+		btVector3 vtx = getScaledPoint(i);
 
 		for (int j=0;j<numVectors;j++)
@@ -125,5 +108,5 @@
 
 
-
+#endif
 
 
@@ -144,12 +127,12 @@
 }
 
-void btConvexPointCloudShape::getEdge(int i,btPoint3& pa,btPoint3& pb) const
+void btConvexPointCloudShape::getEdge(int i,btVector3& pa,btVector3& pb) const
 {
 	btAssert (0);
 }
 
-void btConvexPointCloudShape::getVertex(int i,btPoint3& vtx) const
+void btConvexPointCloudShape::getVertex(int i,btVector3& vtx) const
 {
-	vtx = m_points[i]*m_localScaling;
+	vtx = m_unscaledPoints[i]*m_localScaling;
 }
 
@@ -159,5 +142,5 @@
 }
 
-void btConvexPointCloudShape::getPlane(btVector3& ,btPoint3& ,int ) const
+void btConvexPointCloudShape::getPlane(btVector3& ,btVector3& ,int ) const
 {
 
@@ -166,5 +149,5 @@
 
 //not yet
-bool btConvexPointCloudShape::isInside(const btPoint3& ,btScalar ) const
+bool btConvexPointCloudShape::isInside(const btVector3& ,btScalar ) const
 {
 	assert(0);
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.h	(revision 2430)
@@ -24,31 +24,55 @@
 ATTRIBUTE_ALIGNED16(class) btConvexPointCloudShape : public btPolyhedralConvexShape
 {
-	btVector3* m_points;
+	btVector3* m_unscaledPoints;
 	int m_numPoints;
+
 public:
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
-	btConvexPointCloudShape(btVector3* points,int numPoints);
+	btConvexPointCloudShape(btVector3* points,int numPoints, const btVector3& localScaling,bool computeAabb = true)
+	{
+		m_localScaling = localScaling;
+		m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE;
+		m_unscaledPoints = points;
+		m_numPoints = numPoints;
 
-	void setPoints (btVector3* points, int numPoints);
-
-	btPoint3* getPoints()
-	{
-		return m_points;
+		if (computeAabb)
+			recalcLocalAabb();
 	}
 
-	const btPoint3* getPoints() const
+	void setPoints (btVector3* points, int numPoints, bool computeAabb = true)
 	{
-		return m_points;
+		m_unscaledPoints = points;
+		m_numPoints = numPoints;
+
+		if (computeAabb)
+			recalcLocalAabb();
 	}
 
-	int getNumPoints() const 
+	SIMD_FORCE_INLINE	btVector3* getUnscaledPoints()
+	{
+		return m_unscaledPoints;
+	}
+
+	SIMD_FORCE_INLINE	const btVector3* getUnscaledPoints() const
+	{
+		return m_unscaledPoints;
+	}
+
+	SIMD_FORCE_INLINE	int getNumPoints() const 
 	{
 		return m_numPoints;
 	}
 
+	SIMD_FORCE_INLINE	btVector3	getScaledPoint( int index) const
+	{
+		return m_unscaledPoints[index] * m_localScaling;
+	}
+
+#ifndef __SPU__
 	virtual btVector3	localGetSupportingVertex(const btVector3& vec)const;
 	virtual btVector3	localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
 	virtual void	batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
+#endif
 
 
@@ -58,9 +82,9 @@
 	virtual int	getNumVertices() const;
 	virtual int getNumEdges() const;
-	virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const;
-	virtual void getVertex(int i,btPoint3& vtx) const;
+	virtual void getEdge(int i,btVector3& pa,btVector3& pb) const;
+	virtual void getVertex(int i,btVector3& vtx) const;
 	virtual int	getNumPlanes() const;
-	virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const;
-	virtual	bool isInside(const btPoint3& pt,btScalar tolerance) const;
+	virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const;
+	virtual	bool isInside(const btVector3& pt,btScalar tolerance) const;
 
 	///in case we receive negative scaling
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp	(revision 2430)
@@ -15,5 +15,4 @@
 
 #include "btConvexShape.h"
-#include "btConvexInternalShape.h"
 #include "btTriangleShape.h"
 #include "btSphereShape.h"
@@ -23,5 +22,16 @@
 #include "btConvexPointCloudShape.h"
 
-static btVector3 convexHullSupport (const btVector3& localDir, const btVector3* points, int numPoints)
+btConvexShape::btConvexShape ()
+{
+}
+
+btConvexShape::~btConvexShape()
+{
+
+}
+
+
+
+static btVector3 convexHullSupport (const btVector3& localDir, const btVector3* points, int numPoints, const btVector3& localScaling)
 {
 	btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
@@ -42,5 +52,5 @@
 	for (int i=0;i<numPoints;i++)
 	{
-		btPoint3 vtx = points[i];// * m_localScaling;
+		btVector3 vtx = points[i] * localScaling;
 
 		newDot = vec.dot(vtx);
@@ -62,8 +72,7 @@
 		return btVector3(0,0,0);
     }
-	break;
 	case BOX_SHAPE_PROXYTYPE:
 	{
-		btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
+		btBoxShape* convexShape = (btBoxShape*)this;
 		const btVector3& halfExtents = convexShape->getImplicitShapeDimensions();
 
@@ -72,5 +81,4 @@
 			btFsels(localDir.z(), halfExtents.z(), -halfExtents.z()));
 	}
-	break;
 	case TRIANGLE_SHAPE_PROXYTYPE:
 	{
@@ -82,5 +90,4 @@
 		return btVector3(sup.getX(),sup.getY(),sup.getZ());
 	}
-	break;
 	case CYLINDER_SHAPE_PROXYTYPE:
 	{
@@ -143,5 +150,4 @@
 		}
 	}
-	break;
 	case CAPSULE_SHAPE_PROXYTYPE:
 	{
@@ -200,20 +206,18 @@
 		return btVector3(supVec.getX(),supVec.getY(),supVec.getZ());	
 	}
-	break;
 	case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
 	{
 		btConvexPointCloudShape* convexPointCloudShape = (btConvexPointCloudShape*)this;
-		btVector3* points = convexPointCloudShape->getPoints ();
+		btVector3* points = convexPointCloudShape->getUnscaledPoints ();
 		int numPoints = convexPointCloudShape->getNumPoints ();
-		return convexHullSupport (localDir, points, numPoints);
+		return convexHullSupport (localDir, points, numPoints,convexPointCloudShape->getLocalScalingNV());
 	}
 	case CONVEX_HULL_SHAPE_PROXYTYPE:
 	{
 		btConvexHullShape* convexHullShape = (btConvexHullShape*)this;
-		btPoint3* points = convexHullShape->getPoints ();
+		btVector3* points = convexHullShape->getUnscaledPoints();
 		int numPoints = convexHullShape->getNumPoints ();
-		return convexHullSupport (localDir, points, numPoints);
-	}
-	break;
+		return convexHullSupport (localDir, points, numPoints,convexHullShape->getLocalScalingNV());
+	}
     default:
 #ifndef __SPU__
@@ -222,10 +226,9 @@
 		btAssert (0);
 #endif
-	break;
 	}
 
 	// should never reach here
 	btAssert (0);
-	return btPoint3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f));
+	return btVector3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f));
 }
 
@@ -238,172 +241,6 @@
 	}
 	localDirNorm.normalize ();
-	switch (m_shapeType)
-	{
-    case SPHERE_SHAPE_PROXYTYPE:
-	{
-		return btVector3(0,0,0) + getMarginNonVirtual() * localDirNorm;
-    }
-	break;
-	case BOX_SHAPE_PROXYTYPE:
-	{
-		btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
-		const btVector3& halfExtents = convexShape->getImplicitShapeDimensions();
-
-		return btVector3(localDir.getX() < 0.0f ? -halfExtents.x() : halfExtents.x(),
-						localDir.getY() < 0.0f ? -halfExtents.y() : halfExtents.y(),
-						localDir.getZ() < 0.0f ? -halfExtents.z() : halfExtents.z()) + getMarginNonVirtual() * localDirNorm;
-	}
-	break;
-	case TRIANGLE_SHAPE_PROXYTYPE:
-	{
-		btTriangleShape* triangleShape = (btTriangleShape*)this;
-		btVector3 dir(localDir.getX(),localDir.getY(),localDir.getZ());
-		btVector3* vertices = &triangleShape->m_vertices1[0];
-		btVector3 dots(dir.dot(vertices[0]), dir.dot(vertices[1]), dir.dot(vertices[2]));
-		btVector3 sup = vertices[dots.maxAxis()];
-		return btVector3(sup.getX(),sup.getY(),sup.getZ()) + getMarginNonVirtual() * localDirNorm;
-	}
-	break;
-	case CYLINDER_SHAPE_PROXYTYPE:
-	{
-		btCylinderShape* cylShape = (btCylinderShape*)this;
-		//mapping of halfextents/dimension onto radius/height depends on how cylinder local orientation is (upAxis)
-
-		btVector3 halfExtents = cylShape->getImplicitShapeDimensions();
-		btVector3 v(localDir.getX(),localDir.getY(),localDir.getZ());
-		int cylinderUpAxis = cylShape->getUpAxis();
-		int XX(1),YY(0),ZZ(2);
-
-		switch (cylinderUpAxis)
-		{
-		case 0:
-		{
-			XX = 1;
-			YY = 0;
-			ZZ = 2;
-		}
-		break;
-		case 1:
-		{
-			XX = 0;
-			YY = 1;
-			ZZ = 2;	
-		}
-		break;
-		case 2:
-		{
-			XX = 0;
-			YY = 2;
-			ZZ = 1;
-			
-		}
-		break;
-		default:
-			btAssert(0);
-		break;
-		};
-
-		btScalar radius = halfExtents[XX];
-		btScalar halfHeight = halfExtents[cylinderUpAxis];
-
-		btVector3 tmp;
-		btScalar d ;
-
-		btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
-		if (s != btScalar(0.0))
-		{
-			d = radius / s;  
-			tmp[XX] = v[XX] * d;
-			tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
-			tmp[ZZ] = v[ZZ] * d;
-			return btVector3(tmp.getX(),tmp.getY(),tmp.getZ()) + getMarginNonVirtual() * localDirNorm;
-		} else {
-			tmp[XX] = radius;
-			tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
-			tmp[ZZ] = btScalar(0.0);
-			return btVector3(tmp.getX(),tmp.getY(),tmp.getZ()) + getMarginNonVirtual() * localDirNorm;
-		}
-	}
-	break;
-	case CAPSULE_SHAPE_PROXYTYPE:
-	{
-		btVector3 vec0(localDir.getX(),localDir.getY(),localDir.getZ());
-
-		btCapsuleShape* capsuleShape = (btCapsuleShape*)this;
-		btVector3 halfExtents = capsuleShape->getImplicitShapeDimensions();
-		btScalar halfHeight = capsuleShape->getHalfHeight();
-		int capsuleUpAxis = capsuleShape->getUpAxis();
-
-		btScalar radius = capsuleShape->getRadius();
-		btVector3 supVec(0,0,0);
-
-		btScalar maxDot(btScalar(-1e30));
-
-		btVector3 vec = vec0;
-		btScalar lenSqr = vec.length2();
-		if (lenSqr < btScalar(0.0001))
-		{
-			vec.setValue(1,0,0);
-		} else
-		{
-			btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
-			vec *= rlen;
-		}
-		btVector3 vtx;
-		btScalar newDot;
-		{
-			btVector3 pos(0,0,0);
-			pos[capsuleUpAxis] = halfHeight;
-
-			vtx = pos +vec*(radius);
-			newDot = vec.dot(vtx);
-			if (newDot > maxDot)
-			{
-				maxDot = newDot;
-				supVec = vtx;
-			}
-		}
-		{
-			btVector3 pos(0,0,0);
-			pos[capsuleUpAxis] = -halfHeight;
-
-			vtx = pos +vec*(radius);
-			newDot = vec.dot(vtx);
-			if (newDot > maxDot)
-			{
-				maxDot = newDot;
-				supVec = vtx;
-			}
-		}
-		return btVector3(supVec.getX(),supVec.getY(),supVec.getZ()) + getMarginNonVirtual() * localDirNorm;
-	}
-	break;
-	case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
-	{
-		btConvexPointCloudShape* convexPointCloudShape = (btConvexPointCloudShape*)this;
-		btVector3* points = convexPointCloudShape->getPoints ();
-		int numPoints = convexPointCloudShape->getNumPoints ();
-		return convexHullSupport (localDir, points, numPoints) + getMarginNonVirtual() * localDirNorm;
-	}
-	case CONVEX_HULL_SHAPE_PROXYTYPE:
-	{
-		btConvexHullShape* convexHullShape = (btConvexHullShape*)this;
-		btPoint3* points = convexHullShape->getPoints ();
-		int numPoints = convexHullShape->getNumPoints ();
-		return convexHullSupport (localDir, points, numPoints) + getMarginNonVirtual() * localDirNorm;
-	}
-	break;
-    default:
-#ifndef __SPU__
-		return this->localGetSupportingVertex (localDir);
-#else
-		btAssert (0);
-#endif
-	break;
-	}
-
-	// should never reach here
-	btAssert (0);
-	return btPoint3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f));
+
+	return localGetSupportVertexWithoutMarginNonVirtual(localDirNorm)+ getMarginNonVirtual() * localDirNorm;
 }
 
@@ -418,11 +255,9 @@
 		return sphereShape->getRadius ();
 	}
-	break;
 	case BOX_SHAPE_PROXYTYPE:
 	{
-		btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
+		btBoxShape* convexShape = (btBoxShape*)this;
 		return convexShape->getMarginNV ();
 	}
-	break;
 	case TRIANGLE_SHAPE_PROXYTYPE:
 	{
@@ -430,5 +265,4 @@
 		return triangleShape->getMarginNV ();
 	}
-	break;
 	case CYLINDER_SHAPE_PROXYTYPE:
 	{
@@ -436,5 +270,4 @@
 		return cylShape->getMarginNV();
 	}
-	break;
 	case CAPSULE_SHAPE_PROXYTYPE:
 	{
@@ -442,5 +275,4 @@
 		return capsuleShape->getMarginNV();
 	}
-	break;
 	case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
 	/* fall through */
@@ -450,5 +282,4 @@
 		return convexHullShape->getMarginNV();
 	}
-	break;
     default:
 #ifndef __SPU__
@@ -457,5 +288,4 @@
 		btAssert (0);
 #endif
-	break;
 	}
 
@@ -484,10 +314,10 @@
 	case BOX_SHAPE_PROXYTYPE:
 	{
-		btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
+		btBoxShape* convexShape = (btBoxShape*)this;
 		float margin=convexShape->getMarginNonVirtual();
 		btVector3 halfExtents = convexShape->getImplicitShapeDimensions();
 		halfExtents += btVector3(margin,margin,margin);
 		btMatrix3x3 abs_b = t.getBasis().absolute();  
-		btPoint3 center = t.getOrigin();
+		btVector3 center = t.getOrigin();
 		btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));
 		
@@ -496,5 +326,4 @@
 		break;
 	}
-	break;
 	case TRIANGLE_SHAPE_PROXYTYPE:
 	{
@@ -524,5 +353,5 @@
 		halfExtents += btVector3(capsuleShape->getMarginNonVirtual(),capsuleShape->getMarginNonVirtual(),capsuleShape->getMarginNonVirtual());
 		btMatrix3x3 abs_b = t.getBasis().absolute();  
-		btPoint3 center = t.getOrigin();
+		btVector3 center = t.getOrigin();
 		btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));		  	
 		aabbMin = center - extent;
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexShape.h	(revision 2430)
@@ -25,6 +25,4 @@
 #include "LinearMath/btAlignedAllocator.h"
 
-//todo: get rid of this btConvexCastResult thing!
-struct btConvexCastResult;
 #define MAX_PREFERRED_PENETRATION_DIRECTIONS 10
 
@@ -39,21 +37,14 @@
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
-	btConvexShape ()
-	{
-	}
+	btConvexShape ();
 
-	virtual ~btConvexShape()
-	{
+	virtual ~btConvexShape();
 
-	}
+	virtual btVector3	localGetSupportingVertex(const btVector3& vec)const = 0;
 
-
-	virtual btVector3	localGetSupportingVertex(const btVector3& vec)const =0;
-#ifndef __SPU__
-	virtual btVector3	localGetSupportingVertexWithoutMargin(const btVector3& vec) const= 0;
-	
-	//notice that the vectors should be unit length
-	virtual void	batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0;
-#endif //#ifndef __SPU__
+	////////
+	#ifndef __SPU__
+	virtual btVector3	localGetSupportingVertexWithoutMargin(const btVector3& vec) const=0;
+	#endif //#ifndef __SPU__
 
 	btVector3 localGetSupportVertexWithoutMarginNonVirtual (const btVector3& vec) const;
@@ -61,4 +52,8 @@
 	btScalar getMarginNonVirtual () const;
 	void getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const;
+
+	
+	//notice that the vectors should be unit length
+	virtual void	batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0;
 
 	///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
@@ -78,4 +73,7 @@
 	virtual void	getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const=0;
 
+
+	
+	
 };
 
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp	(revision 2430)
@@ -109,5 +109,5 @@
 	}
 	
-	//todo: could do the batch inside the callback!
+	///@todo: could do the batch inside the callback!
 
 
@@ -164,10 +164,10 @@
 }
 
-void btConvexTriangleMeshShape::getEdge(int ,btPoint3& ,btPoint3& ) const
+void btConvexTriangleMeshShape::getEdge(int ,btVector3& ,btVector3& ) const
 {
 	btAssert(0);	
 }
 
-void btConvexTriangleMeshShape::getVertex(int ,btPoint3& ) const
+void btConvexTriangleMeshShape::getVertex(int ,btVector3& ) const
 {
 	btAssert(0);
@@ -179,5 +179,5 @@
 }
 
-void btConvexTriangleMeshShape::getPlane(btVector3& ,btPoint3& ,int  ) const
+void btConvexTriangleMeshShape::getPlane(btVector3& ,btVector3& ,int  ) const
 {
 	btAssert(0);
@@ -185,5 +185,5 @@
 
 //not yet
-bool btConvexTriangleMeshShape::isInside(const btPoint3& ,btScalar ) const
+bool btConvexTriangleMeshShape::isInside(const btVector3& ,btScalar ) const
 {
 	btAssert(0);
@@ -270,5 +270,4 @@
          btVector3 b = triangle[1] - center;
          btVector3 c = triangle[2] - center;
-         btVector3 abc = a + b + c;
          btScalar volNeg = -btFabs(a.triple(b, c)) * btScalar(1. / 6);
          for (int j = 0; j < 3; j++)
@@ -276,7 +275,5 @@
             for (int k = 0; k <= j; k++)
             {
-               i[j][k] = i[k][j] = volNeg * (center[j] * center[k]
-                 + btScalar(0.25) * (center[j] * abc[k] + center[k] * abc[j])
-                  + btScalar(0.1) * (a[j] * a[k] + b[j] * b[k] + c[j] * c[k])
+               i[j][k] = i[k][j] = volNeg * (btScalar(0.1) * (a[j] * a[k] + b[j] * b[k] + c[j] * c[k])
                   + btScalar(0.05) * (a[j] * b[k] + a[k] * b[j] + a[j] * c[k] + a[k] * c[j] + b[j] * c[k] + b[k] * c[j]));
             }
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h	(revision 2430)
@@ -35,9 +35,9 @@
 	virtual int	getNumVertices() const;
 	virtual int getNumEdges() const;
-	virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const;
-	virtual void getVertex(int i,btPoint3& vtx) const;
+	virtual void getEdge(int i,btVector3& pa,btVector3& pb) const;
+	virtual void getVertex(int i,btVector3& vtx) const;
 	virtual int	getNumPlanes() const;
-	virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const;
-	virtual	bool isInside(const btPoint3& pt,btScalar tolerance) const;
+	virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const;
+	virtual	bool isInside(const btVector3& pt,btScalar tolerance) const;
 
 	
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp	(revision 2430)
@@ -14,5 +14,4 @@
 */
 #include "btCylinderShape.h"
-#include "LinearMath/btPoint3.h"
 
 btCylinderShape::btCylinderShape (const btVector3& halfExtents)
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btEmptyShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btEmptyShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btEmptyShape.h	(revision 2430)
@@ -57,4 +57,7 @@
 	}
 
+	virtual void processAllTriangles(btTriangleCallback* ,const btVector3& ,const btVector3& ) const
+	{
+	}
 
 protected:
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp	(revision 2430)
@@ -19,51 +19,90 @@
 
 
+
+btHeightfieldTerrainShape::btHeightfieldTerrainShape
+(
+int heightStickWidth, int heightStickLength, void* heightfieldData,
+btScalar heightScale, btScalar minHeight, btScalar maxHeight,int upAxis,
+PHY_ScalarType hdt, bool flipQuadEdges
+)
+{
+	initialize(heightStickWidth, heightStickLength, heightfieldData,
+	           heightScale, minHeight, maxHeight, upAxis, hdt,
+	           flipQuadEdges);
+}
+
+
+
 btHeightfieldTerrainShape::btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength,void* heightfieldData,btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges)
-: btConcaveShape (), m_heightStickWidth(heightStickWidth),
-m_heightStickLength(heightStickLength),
-m_maxHeight(maxHeight),
-m_width((btScalar)heightStickWidth-1),
-m_length((btScalar)heightStickLength-1),
-m_heightfieldDataUnknown(heightfieldData),
-m_useFloatData(useFloatData),
-m_flipQuadEdges(flipQuadEdges),
-m_useDiamondSubdivision(false),
-m_upAxis(upAxis),
-m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
-{
+{
+	// legacy constructor: support only float or unsigned char,
+	// 	and min height is zero
+	PHY_ScalarType hdt = (useFloatData) ? PHY_FLOAT : PHY_UCHAR;
+	btScalar minHeight = 0.0;
+
+	// previously, height = uchar * maxHeight / 65535.
+	// So to preserve legacy behavior, heightScale = maxHeight / 65535
+	btScalar heightScale = maxHeight / 65535;
+
+	initialize(heightStickWidth, heightStickLength, heightfieldData,
+	           heightScale, minHeight, maxHeight, upAxis, hdt,
+	           flipQuadEdges);
+}
+
+
+
+void btHeightfieldTerrainShape::initialize
+(
+int heightStickWidth, int heightStickLength, void* heightfieldData,
+btScalar heightScale, btScalar minHeight, btScalar maxHeight, int upAxis,
+PHY_ScalarType hdt, bool flipQuadEdges
+)
+{
+	// validation
+	btAssert(heightStickWidth > 1 && "bad width");
+	btAssert(heightStickLength > 1 && "bad length");
+	btAssert(heightfieldData && "null heightfield data");
+	// btAssert(heightScale) -- do we care?  Trust caller here
+	btAssert(minHeight <= maxHeight && "bad min/max height");
+	btAssert(upAxis >= 0 && upAxis < 3 &&
+	    "bad upAxis--should be in range [0,2]");
+	btAssert(hdt != PHY_UCHAR || hdt != PHY_FLOAT || hdt != PHY_SHORT &&
+	    "Bad height data type enum");
+
+	// initialize member variables
 	m_shapeType = TERRAIN_SHAPE_PROXYTYPE;
-
-	btScalar	quantizationMargin = 1.f;
-
-	//enlarge the AABB to avoid division by zero when initializing the quantization values
-	btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin);
-
-	btVector3	halfExtents(0,0,0);
-
+	m_heightStickWidth = heightStickWidth;
+	m_heightStickLength = heightStickLength;
+	m_minHeight = minHeight;
+	m_maxHeight = maxHeight;
+	m_width = (btScalar) (heightStickWidth - 1);
+	m_length = (btScalar) (heightStickLength - 1);
+	m_heightScale = heightScale;
+	m_heightfieldDataUnknown = heightfieldData;
+	m_heightDataType = hdt;
+	m_flipQuadEdges = flipQuadEdges;
+	m_useDiamondSubdivision = false;
+	m_upAxis = upAxis;
+	m_localScaling.setValue(btScalar(1.), btScalar(1.), btScalar(1.));
+
+	// determine min/max axis-aligned bounding box (aabb) values
 	switch (m_upAxis)
 	{
 	case 0:
 		{
-			halfExtents.setValue(
-				btScalar(m_maxHeight),
-				btScalar(m_width), //?? don't know if this should change
-				btScalar(m_length));
+			m_localAabbMin.setValue(m_minHeight, 0, 0);
+			m_localAabbMax.setValue(m_maxHeight, m_width, m_length);
 			break;
 		}
 	case 1:
 		{
-			halfExtents.setValue(
-				btScalar(m_width),
-				btScalar(m_maxHeight),
-				btScalar(m_length));
+			m_localAabbMin.setValue(0, m_minHeight, 0);
+			m_localAabbMax.setValue(m_width, m_maxHeight, m_length);
 			break;
 		};
 	case 2:
 		{
-			halfExtents.setValue(
-				btScalar(m_width),
-				btScalar(m_length),
-				btScalar(m_maxHeight)
-			);
+			m_localAabbMin.setValue(0, 0, m_minHeight);
+			m_localAabbMax.setValue(m_width, m_length, m_maxHeight);
 			break;
 		}
@@ -71,15 +110,12 @@
 		{
 			//need to get valid m_upAxis
-			btAssert(0);
-		}
-	}
-
-	halfExtents*= btScalar(0.5);
-	
-	m_localAabbMin = -halfExtents - clampValue;
-	m_localAabbMax = halfExtents + clampValue;
-	btVector3 aabbSize = m_localAabbMax - m_localAabbMin;
-
-}
+			btAssert(0 && "Bad m_upAxis");
+		}
+	}
+
+	// remember origin (defined as exact middle of aabb)
+	m_localOrigin = btScalar(0.5) * (m_localAabbMin + m_localAabbMax);
+}
+
 
 
@@ -93,17 +129,18 @@
 {
 	btVector3 halfExtents = (m_localAabbMax-m_localAabbMin)* m_localScaling * btScalar(0.5);
-	halfExtents += btVector3(getMargin(),getMargin(),getMargin());
+
+	btVector3 localOrigin(0, 0, 0);
+	localOrigin[m_upAxis] = (m_minHeight + m_maxHeight) * btScalar(0.5);
+	localOrigin *= m_localScaling;
 
 	btMatrix3x3 abs_b = t.getBasis().absolute();  
-	btPoint3 center = t.getOrigin();
+	btVector3 center = t.getOrigin();
 	btVector3 extent = btVector3(abs_b[0].dot(halfExtents),
 		   abs_b[1].dot(halfExtents),
 		  abs_b[2].dot(halfExtents));
-	
+	extent += btVector3(getMargin(),getMargin(),getMargin());
 
 	aabbMin = center - extent;
 	aabbMax = center + extent;
-
-
 }
 
@@ -111,13 +148,32 @@
 {
 	btScalar val = 0.f;
-	if (m_useFloatData)
+	switch (m_heightDataType)
 	{
-		val = m_heightfieldDataFloat[(y*m_heightStickWidth)+x];
-	} else
-	{
-		//assume unsigned short int
-		unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y*m_heightStickWidth)+x];
-		val = heightFieldValue* (m_maxHeight/btScalar(65535));
-	}
+	case PHY_FLOAT:
+		{
+			val = m_heightfieldDataFloat[(y*m_heightStickWidth)+x];
+			break;
+		}
+
+	case PHY_UCHAR:
+		{
+			unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y*m_heightStickWidth)+x];
+			val = heightFieldValue * m_heightScale;
+			break;
+		}
+
+	case PHY_SHORT:
+		{
+			short hfValue = m_heightfieldDataShort[(y * m_heightStickWidth) + x];
+			val = hfValue * m_heightScale;
+			break;
+		}
+
+	default:
+		{
+			btAssert(!"Bad m_heightDataType");
+		}
+	}
+
 	return val;
 }
@@ -179,4 +235,28 @@
 
 
+
+static inline int
+getQuantized
+(
+float x
+)
+{
+	if (x < 0.0) {
+		return (int) (x - 0.5);
+	}
+	return (int) (x + 0.5);
+}
+
+
+
+/// given input vector, return quantized version
+/**
+  This routine is basically determining the gridpoint indices for a given
+  input vector, answering the question: "which gridpoint is closest to the
+  provided point?".
+
+  "with clamp" means that we restrict the point to be in the heightfield's
+  axis-aligned bounding box.
+ */
 void btHeightfieldTerrainShape::quantizeWithClamp(int* out, const btVector3& point,int /*isMax*/) const
 {
@@ -185,33 +265,41 @@
 	clampedPoint.setMin(m_localAabbMax);
 
-	btVector3 v = (clampedPoint);// - m_bvhAabbMin) * m_bvhQuantization;
-
-	//TODO: optimization: check out how to removed this btFabs
+	out[0] = getQuantized(clampedPoint.getX());
+	out[1] = getQuantized(clampedPoint.getY());
+	out[2] = getQuantized(clampedPoint.getZ());
 		
-	out[0] = (int)(v.getX() + v.getX() / btFabs(v.getX())* btScalar(0.5) );
-	out[1] = (int)(v.getY() + v.getY() / btFabs(v.getY())* btScalar(0.5) );
-	out[2] = (int)(v.getZ() + v.getZ() / btFabs(v.getZ())* btScalar(0.5) );
-	
-}
-
-
+}
+
+
+
+/// process all triangles within the provided axis-aligned bounding box
+/**
+  basic algorithm:
+    - convert input aabb to local coordinates (scale down and shift for local origin)
+    - convert input aabb to a range of heightfield grid points (quantize)
+    - iterate over all triangles in that subset of the grid
+ */
 void	btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
 {
-	(void)callback;
-	(void)aabbMax;
-	(void)aabbMin;
+	// scale down the input aabb's so they are in local (non-scaled) coordinates
+	btVector3	localAabbMin = aabbMin*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
+	btVector3	localAabbMax = aabbMax*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
+
+	// account for local origin
+	localAabbMin += m_localOrigin;
+	localAabbMax += m_localOrigin;
 
 	//quantize the aabbMin and aabbMax, and adjust the start/end ranges
-
 	int	quantizedAabbMin[3];
 	int	quantizedAabbMax[3];
-
-	btVector3	localAabbMin = aabbMin*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
-	btVector3	localAabbMax = aabbMax*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
-	
 	quantizeWithClamp(quantizedAabbMin, localAabbMin,0);
 	quantizeWithClamp(quantizedAabbMax, localAabbMax,1);
 	
-	
+	// expand the min/max quantized values
+	// this is to catch the case where the input aabb falls between grid points!
+	for (int i = 0; i < 3; ++i) {
+		quantizedAabbMin[i]--;
+		quantizedAabbMax[i]++;
+	}	
 
 	int startX=0;
@@ -224,9 +312,4 @@
 	case 0:
 		{
-			quantizedAabbMin[1]+=m_heightStickWidth/2-1;
-			quantizedAabbMax[1]+=m_heightStickWidth/2+1;
-			quantizedAabbMin[2]+=m_heightStickLength/2-1;
-			quantizedAabbMax[2]+=m_heightStickLength/2+1;
-
 			if (quantizedAabbMin[1]>startX)
 				startX = quantizedAabbMin[1];
@@ -241,9 +324,4 @@
 	case 1:
 		{
-			quantizedAabbMin[0]+=m_heightStickWidth/2-1;
-			quantizedAabbMax[0]+=m_heightStickWidth/2+1;
-			quantizedAabbMin[2]+=m_heightStickLength/2-1;
-			quantizedAabbMax[2]+=m_heightStickLength/2+1;
-
 			if (quantizedAabbMin[0]>startX)
 				startX = quantizedAabbMin[0];
@@ -258,9 +336,4 @@
 	case 2:
 		{
-			quantizedAabbMin[0]+=m_heightStickWidth/2-1;
-			quantizedAabbMax[0]+=m_heightStickWidth/2+1;
-			quantizedAabbMin[1]+=m_heightStickLength/2-1;
-			quantizedAabbMax[1]+=m_heightStickLength/2+1;
-
 			if (quantizedAabbMin[0]>startX)
 				startX = quantizedAabbMin[0];
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h	(revision 2430)
@@ -19,6 +19,43 @@
 #include "btConcaveShape.h"
 
-///The btHeightfieldTerrainShape simulates a 2D heightfield terrain collision shape. You can also use the more general btBvhTriangleMeshShape instead.
-///An example implementation of btHeightfieldTerrainShape is provided in Demos/VehicleDemo/VehicleDemo.cpp
+///btHeightfieldTerrainShape simulates a 2D heightfield terrain
+/**
+  The caller is responsible for maintaining the heightfield array; this
+  class does not make a copy.
+
+  The heightfield can be dynamic so long as the min/max height values
+  capture the extremes (heights must always be in that range).
+
+  The local origin of the heightfield is assumed to be the exact
+  center (as determined by width and length and height, with each
+  axis multiplied by the localScaling).
+
+  Most (but not all) rendering and heightfield libraries assume upAxis = 1
+  (that is, the y-axis is "up").  This class allows any of the 3 coordinates
+  to be "up".  Make sure your choice of axis is consistent with your rendering
+  system.
+
+  The heightfield heights are determined from the data type used for the
+  heightfieldData array.  
+
+   - PHY_UCHAR: height at a point is the uchar value at the
+       grid point, multipled by heightScale.  uchar isn't recommended
+       because of its inability to deal with negative values, and
+       low resolution (8-bit).
+
+   - PHY_SHORT: height at a point is the short int value at that grid
+       point, multipled by heightScale.
+
+   - PHY_FLOAT: height at a point is the float value at that grid
+       point.  heightScale is ignored when using the float heightfield
+       data type.
+
+  Whatever the caller specifies as minHeight and maxHeight will be honored.
+  The class will not inspect the heightfield to discover the actual minimum
+  or maximum heights.  These values are used to determine the heightfield's
+  axis-aligned bounding box, multiplied by localScaling.
+
+  For usage and testing see the TerrainDemo.
+ */
 class btHeightfieldTerrainShape : public btConcaveShape
 {
@@ -26,19 +63,23 @@
 	btVector3	m_localAabbMin;
 	btVector3	m_localAabbMax;
-	
+	btVector3	m_localOrigin;
+
 	///terrain data
 	int	m_heightStickWidth;
 	int m_heightStickLength;
+	btScalar	m_minHeight;
 	btScalar	m_maxHeight;
 	btScalar m_width;
 	btScalar m_length;
+	btScalar m_heightScale;
 	union
 	{
 		unsigned char*	m_heightfieldDataUnsignedChar;
+		short*		m_heightfieldDataShort;
 		btScalar*			m_heightfieldDataFloat;
 		void*			m_heightfieldDataUnknown;
 	};
-	
-	bool	m_useFloatData;
+
+	PHY_ScalarType	m_heightDataType;	
 	bool	m_flipQuadEdges;
   bool  m_useDiamondSubdivision;
@@ -52,15 +93,37 @@
 	void		getVertex(int x,int y,btVector3& vertex) const;
 
-	inline bool testQuantizedAabbAgainstQuantizedAabb(int* aabbMin1, int* aabbMax1,const  int* aabbMin2,const  int* aabbMax2) const
-	{
-		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;
-	}
+
+
+	/// protected initialization
+	/**
+	  Handles the work of constructors so that public constructors can be
+	  backwards-compatible without a lot of copy/paste.
+	 */
+	void initialize(int heightStickWidth, int heightStickLength,
+	                void* heightfieldData, btScalar heightScale,
+	                btScalar minHeight, btScalar maxHeight, int upAxis,
+	                PHY_ScalarType heightDataType, bool flipQuadEdges);
 
 public:
-	btHeightfieldTerrainShape(int heightStickWidth,int heightStickHeight,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges);
+	/// preferred constructor
+	/**
+	  This constructor supports a range of heightfield
+	  data types, and allows for a non-zero minimum height value.
+	  heightScale is needed for any integer-based heightfield data types.
+	 */
+	btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength,
+	                          void* heightfieldData, btScalar heightScale,
+	                          btScalar minHeight, btScalar maxHeight,
+	                          int upAxis, PHY_ScalarType heightDataType,
+	                          bool flipQuadEdges);
+
+	/// legacy constructor
+	/**
+	  The legacy constructor assumes the heightfield has a minimum height
+	  of zero.  Only unsigned char or floats are supported.  For legacy
+	  compatibility reasons, heightScale is calculated as maxHeight / 65535 
+	  (and is only used when useFloatData = false).
+ 	 */
+	btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges);
 
 	virtual ~btHeightfieldTerrainShape();
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp	(revision 2430)
@@ -36,5 +36,5 @@
 void	btMinkowskiSumShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
 {
-	//todo: could make recursive use of batching. probably this shape is not used frequently.
+	///@todo: could make recursive use of batching. probably this shape is not used frequently.
 	for (int i=0;i<numVectors;i++)
 	{
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.cpp	(revision 2430)
@@ -320,17 +320,17 @@
 					
 					int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
-					btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
-#ifdef DEBUG_PATCH_COLORS
-					btVector3 mycolor = color[index&3];
-					graphicsbase[8] = mycolor.getX();
-					graphicsbase[9] = mycolor.getY();
-					graphicsbase[10] = mycolor.getZ();
-#endif //DEBUG_PATCH_COLORS
-
-
-					triangleVerts[j] = btVector3(
-						graphicsbase[0]*meshScaling.getX(),
-						graphicsbase[1]*meshScaling.getY(),
-						graphicsbase[2]*meshScaling.getZ());
+					if (type == PHY_FLOAT)
+					{
+						float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
+						triangleVerts[j] = btVector3(
+							graphicsbase[0]*meshScaling.getX(),
+							graphicsbase[1]*meshScaling.getY(),
+							graphicsbase[2]*meshScaling.getZ());
+					}
+					else
+					{
+						double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
+						triangleVerts[j] = btVector3( btScalar(graphicsbase[0]*meshScaling.getX()), btScalar(graphicsbase[1]*meshScaling.getY()), btScalar(graphicsbase[2]*meshScaling.getZ()));
+					}
 				}
 
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp	(revision 2430)
@@ -16,6 +16,5 @@
 #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
 
-btPolyhedralConvexShape::btPolyhedralConvexShape()
-:btConvexInternalShape(),
+btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape(),
 m_localAabbMin(1,1,1),
 m_localAabbMax(-1,-1,-1),
@@ -25,5 +24,4 @@
 
 }
-
 
 
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h	(revision 2430)
@@ -17,5 +17,4 @@
 #define BU_SHAPE
 
-#include "LinearMath/btPoint3.h"
 #include "LinearMath/btMatrix3x3.h"
 #include "LinearMath/btAabbUtil2.h"
@@ -32,15 +31,30 @@
 	bool		m_isLocalAabbValid;
 
-	btPolyhedralConvexShape();
 public:
 
-	
+	btPolyhedralConvexShape();
 
 	//brute force implementations
+
 	virtual btVector3	localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
 	virtual void	batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
+
 	
 	virtual void	calculateLocalInertia(btScalar mass,btVector3& inertia) const;
 
+
+	void setCachedLocalAabb (const btVector3& aabbMin, const btVector3& aabbMax)
+	{
+		m_isLocalAabbValid = true;
+		m_localAabbMin = aabbMin;
+		m_localAabbMax = aabbMax;
+	}
+
+	inline void getCachedLocalAabb (btVector3& aabbMin, btVector3& aabbMax) const
+	{
+		btAssert(m_isLocalAabbValid);
+		aabbMin = m_localAabbMin;
+		aabbMax = m_localAabbMax;
+	}
 
 	inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const
@@ -61,11 +75,11 @@
 	virtual int	getNumVertices() const = 0 ;
 	virtual int getNumEdges() const = 0;
-	virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const = 0;
-	virtual void getVertex(int i,btPoint3& vtx) const = 0;
+	virtual void getEdge(int i,btVector3& pa,btVector3& pb) const = 0;
+	virtual void getVertex(int i,btVector3& vtx) const = 0;
 	virtual int	getNumPlanes() const = 0;
-	virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const = 0;
+	virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const = 0;
 //	virtual int getIndex(int i) const = 0 ; 
 
-	virtual	bool isInside(const btPoint3& pt,btScalar tolerance) const = 0;
+	virtual	bool isInside(const btVector3& pt,btScalar tolerance) const = 0;
 	
 	/// optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp	(revision 2430)
@@ -16,5 +16,5 @@
 #include "btScaledBvhTriangleMeshShape.h"
 
-btScaledBvhTriangleMeshShape::btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,btVector3 localScaling)
+btScaledBvhTriangleMeshShape::btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,const btVector3& localScaling)
 :m_localScaling(localScaling),m_bvhTriMeshShape(childShape)
 {
@@ -35,5 +35,5 @@
 public:
 
-	btScaledTriangleCallback(btTriangleCallback* originalCallback,btVector3 localScaling)
+	btScaledTriangleCallback(btTriangleCallback* originalCallback,const btVector3& localScaling)
 		:m_originalCallback(originalCallback),
 		m_localScaling(localScaling)
@@ -94,5 +94,5 @@
 	btMatrix3x3 abs_b = trans.getBasis().absolute();  
 
-	btPoint3 center = trans(localCenter);
+	btVector3 center = trans(localCenter);
 
 	btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h	(revision 2430)
@@ -33,5 +33,5 @@
 
 
-	btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,btVector3 localScaling);
+	btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,const btVector3& localScaling);
 
 	virtual ~btScaledBvhTriangleMeshShape();
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.cpp	(revision 2430)
@@ -18,12 +18,4 @@
 
 #include "LinearMath/btQuaternion.h"
-
-
-btSphereShape ::btSphereShape (btScalar radius) : btConvexInternalShape ()
-{
-	m_shapeType = SPHERE_SHAPE_PROXYTYPE;
-	m_implicitShapeDimensions.setX(radius);
-	m_collisionMargin = radius;
-}
 
 btVector3	btSphereShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.h	(revision 2430)
@@ -28,6 +28,10 @@
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
-	btSphereShape (btScalar radius);
-	
+	btSphereShape (btScalar radius) : btConvexInternalShape ()
+	{
+		m_shapeType = SPHERE_SHAPE_PROXYTYPE;
+		m_implicitShapeDimensions.setX(radius);
+		m_collisionMargin = radius;
+	}
 	
 	virtual btVector3	localGetSupportingVertex(const btVector3& vec)const;
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.h	(revision 2430)
@@ -19,14 +19,7 @@
 #include "LinearMath/btVector3.h"
 #include "btTriangleCallback.h"
+#include "btConcaveShape.h"
 
-/// PHY_ScalarType enumerates possible scalar types.
-/// See the btStridingMeshInterface for its use
-typedef enum PHY_ScalarType {
-	PHY_FLOAT,
-	PHY_DOUBLE,
-	PHY_INTEGER,
-	PHY_SHORT,
-	PHY_FIXEDPOINT88
-} PHY_ScalarType;
+
 
 ///	The btStridingMeshInterface is the interface class for high performance generic access to triangle meshes, used in combination with btBvhTriangleMeshShape and some other collision shapes.
@@ -78,6 +71,14 @@
 
 		virtual bool	hasPremadeAabb() const { return false; }
-		virtual void	setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const {}
-		virtual void	getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const {}
+		virtual void	setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const
+                {
+                        (void) aabbMin;
+                        (void) aabbMax;
+                }
+		virtual void	getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const
+        {
+            (void) aabbMin;
+            (void) aabbMax;
+        }
 
 		const btVector3&	getScaling() const {
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.cpp	(revision 2430)
@@ -23,12 +23,12 @@
 }
 
-btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0) : btPolyhedralConvexShape (),
-m_numVertices(0)
-{
-	m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
-	addVertex(pt0);
-}
-
-btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1) : btPolyhedralConvexShape (),
+btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0) : btPolyhedralConvexShape (),
+m_numVertices(0)
+{
+	m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
+	addVertex(pt0);
+}
+
+btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1) : btPolyhedralConvexShape (),
 m_numVertices(0)
 {
@@ -38,5 +38,5 @@
 }
 
-btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1,const btPoint3& pt2) : btPolyhedralConvexShape (),
+btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2) : btPolyhedralConvexShape (),
 m_numVertices(0)
 {
@@ -47,5 +47,5 @@
 }
 
-btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1,const btPoint3& pt2,const btPoint3& pt3) : btPolyhedralConvexShape (),
+btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3) : btPolyhedralConvexShape (),
 m_numVertices(0)
 {
@@ -61,5 +61,5 @@
 
 
-void btBU_Simplex1to4::addVertex(const btPoint3& pt)
+void btBU_Simplex1to4::addVertex(const btVector3& pt)
 {
 	m_vertices[m_numVertices++] = pt;
@@ -93,5 +93,5 @@
 }
 
-void btBU_Simplex1to4::getEdge(int i,btPoint3& pa,btPoint3& pb) const
+void btBU_Simplex1to4::getEdge(int i,btVector3& pa,btVector3& pb) const
 {
 	
@@ -157,5 +157,5 @@
 }
 
-void btBU_Simplex1to4::getVertex(int i,btPoint3& vtx) const
+void btBU_Simplex1to4::getVertex(int i,btVector3& vtx) const
 {
 	vtx = m_vertices[i];
@@ -184,5 +184,5 @@
 
 
-void btBU_Simplex1to4::getPlane(btVector3&, btPoint3& ,int ) const
+void btBU_Simplex1to4::getPlane(btVector3&, btVector3& ,int ) const
 {
 	
@@ -194,5 +194,5 @@
 }
 
-bool btBU_Simplex1to4::isInside(const btPoint3& ,btScalar ) const
+bool btBU_Simplex1to4::isInside(const btVector3& ,btScalar ) const
 {
 	return false;
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.h	(revision 2430)
@@ -28,13 +28,13 @@
 
 	int	m_numVertices;
-	btPoint3	m_vertices[4];
+	btVector3	m_vertices[4];
 
 public:
 	btBU_Simplex1to4();
 
-	btBU_Simplex1to4(const btPoint3& pt0);
-	btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1);
-	btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1,const btPoint3& pt2);
-	btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1,const btPoint3& pt2,const btPoint3& pt3);
+	btBU_Simplex1to4(const btVector3& pt0);
+	btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1);
+	btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2);
+	btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3);
 
     
@@ -46,5 +46,5 @@
 
 
-	void addVertex(const btPoint3& pt);
+	void addVertex(const btVector3& pt);
 
 	//PolyhedralConvexShape interface
@@ -54,15 +54,15 @@
 	virtual int getNumEdges() const;
 
-	virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const;
+	virtual void getEdge(int i,btVector3& pa,btVector3& pb) const;
 	
-	virtual void getVertex(int i,btPoint3& vtx) const;
+	virtual void getVertex(int i,btVector3& vtx) const;
 
 	virtual int	getNumPlanes() const;
 
-	virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i) const;
+	virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i) const;
 
 	virtual int getIndex(int i) const;
 
-	virtual	bool isInside(const btPoint3& pt,btScalar tolerance) const;
+	virtual	bool isInside(const btVector3& pt,btScalar tolerance) const;
 
 
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleBuffer.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleBuffer.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleBuffer.h	(revision 2430)
@@ -29,5 +29,5 @@
 };
 
-///btTriangleBuffer can be useful to collect and store overlapping triangles between AABB and concave objects that support 'processAllTriangles'
+///The btTriangleBuffer callback can be useful to collect and store overlapping triangles between AABB and concave objects that support 'processAllTriangles'
 ///Example usage of this class:
 ///			btTriangleBuffer	triBuf;
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.cpp	(revision 2430)
@@ -75,15 +75,19 @@
 }
 
-int	btTriangleMesh::findOrAddVertex(const btVector3& vertex)
+
+int	btTriangleMesh::findOrAddVertex(const btVector3& vertex, bool removeDuplicateVertices)
 {
 	//return index of new/existing vertex
-	//todo: could use acceleration structure for this
+	///@todo: could use acceleration structure for this
 	if (m_use4componentVertices)
 	{
-		for (int i=0;i< m_4componentVertices.size();i++)
-		{
-			if ((m_4componentVertices[i]-vertex).length2() <= m_weldingThreshold)
+		if (removeDuplicateVertices)
 			{
-				return i;
+			for (int i=0;i< m_4componentVertices.size();i++)
+			{
+				if ((m_4componentVertices[i]-vertex).length2() <= m_weldingThreshold)
+				{
+					return i;
+				}
 			}
 		}
@@ -97,12 +101,15 @@
 	{
 		
-		for (int i=0;i< m_3componentVertices.size();i+=3)
+		if (removeDuplicateVertices)
 		{
-			btVector3 vtx(m_3componentVertices[i],m_3componentVertices[i+1],m_3componentVertices[i+2]);
-			if ((vtx-vertex).length2() <= m_weldingThreshold)
+			for (int i=0;i< m_3componentVertices.size();i+=3)
 			{
-				return i/3;
+				btVector3 vtx(m_3componentVertices[i],m_3componentVertices[i+1],m_3componentVertices[i+2]);
+				if ((vtx-vertex).length2() <= m_weldingThreshold)
+				{
+					return i/3;
+				}
 			}
-		}
+	}
 		m_3componentVertices.push_back(vertex.getX());
 		m_3componentVertices.push_back(vertex.getY());
@@ -115,11 +122,10 @@
 }
 		
-void	btTriangleMesh::addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2)
+void	btTriangleMesh::addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2,bool removeDuplicateVertices)
 {
 	m_indexedMeshes[0].m_numTriangles++;
-		
-	addIndex(findOrAddVertex(vertex0));
-	addIndex(findOrAddVertex(vertex1));
-	addIndex(findOrAddVertex(vertex2));
+	addIndex(findOrAddVertex(vertex0,removeDuplicateVertices));
+	addIndex(findOrAddVertex(vertex1,removeDuplicateVertices));
+	addIndex(findOrAddVertex(vertex2,removeDuplicateVertices));
 }
 
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.h	(revision 2430)
@@ -26,5 +26,4 @@
 ///If you want to share triangle/index data between graphics mesh and collision mesh (btBvhTriangleMeshShape), you can directly use btTriangleIndexVertexArray or derive your own class from btStridingMeshInterface.
 ///Performance of btTriangleMesh and btTriangleIndexVertexArray used in a btBvhTriangleMeshShape is the same.
-///It has a brute-force option to weld together closeby vertices.
 class btTriangleMesh : public btTriangleIndexVertexArray
 {
@@ -43,5 +42,5 @@
 		btTriangleMesh (bool use32bitIndices=true,bool use4componentVertices=true);
 
-		int		findOrAddVertex(const btVector3& vertex);
+		int		findOrAddVertex(const btVector3& vertex, bool removeDuplicateVertices);
 		void	addIndex(int index);
 
@@ -55,6 +54,7 @@
 			return m_use4componentVertices;
 		}
-		
-		void	addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2);
+		///By default addTriangle won't search for duplicate vertices, because the search is very slow for large triangle meshes.
+		///In general it is better to directly use btTriangleIndexVertexArray instead.
+		void	addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2, bool removeDuplicateVertices=false);
 		
 		int getNumTriangles() const;
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp	(revision 2430)
@@ -54,5 +54,5 @@
 	btMatrix3x3 abs_b = trans.getBasis().absolute();  
 
-	btPoint3 center = trans(localCenter);
+	btVector3 center = trans(localCenter);
 
 	btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleShape.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleShape.h	(revision 2430)
@@ -47,5 +47,5 @@
 	}
 	
-	virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const
+	virtual void getEdge(int i,btVector3& pa,btVector3& pb) const
 	{
 		getVertex(i,pa);
@@ -89,5 +89,5 @@
 
 
-	virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i) const
+	virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i) const
 	{
 		getPlaneEquation(i,planeNormal,planeSupport);
@@ -105,5 +105,5 @@
 	}
 
-	virtual void getPlaneEquation(int i, btVector3& planeNormal,btPoint3& planeSupport) const
+	virtual void getPlaneEquation(int i, btVector3& planeNormal,btVector3& planeSupport) const
 	{
 		(void)i;
@@ -119,5 +119,5 @@
 	}
 
-		virtual	bool isInside(const btPoint3& pt,btScalar tolerance) const
+		virtual	bool isInside(const btVector3& pt,btScalar tolerance) const
 	{
 		btVector3 normal;
@@ -133,5 +133,5 @@
 			for (i=0;i<3;i++)
 			{
-				btPoint3 pa,pb;
+				btVector3 pa,pb;
 				getEdge(i,pa,pb);
 				btVector3 edge = pb-pa;
