Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btBoxShape.h
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btBoxShape.h	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btBoxShape.h	(revision 2908)
@@ -162,23 +162,29 @@
 		{
 		case 0:
-			plane.setValue(btScalar(1.),btScalar(0.),btScalar(0.),-halfExtents.x());
+			plane.setValue(btScalar(1.),btScalar(0.),btScalar(0.));
+			plane[3] = -halfExtents.x();
 			break;
 		case 1:
-			plane.setValue(btScalar(-1.),btScalar(0.),btScalar(0.),-halfExtents.x());
+			plane.setValue(btScalar(-1.),btScalar(0.),btScalar(0.));
+			plane[3] = -halfExtents.x();
 			break;
 		case 2:
-			plane.setValue(btScalar(0.),btScalar(1.),btScalar(0.),-halfExtents.y());
+			plane.setValue(btScalar(0.),btScalar(1.),btScalar(0.));
+			plane[3] = -halfExtents.y();
 			break;
 		case 3:
-			plane.setValue(btScalar(0.),btScalar(-1.),btScalar(0.),-halfExtents.y());
+			plane.setValue(btScalar(0.),btScalar(-1.),btScalar(0.));
+			plane[3] = -halfExtents.y();
 			break;
 		case 4:
-			plane.setValue(btScalar(0.),btScalar(0.),btScalar(1.),-halfExtents.z());
+			plane.setValue(btScalar(0.),btScalar(0.),btScalar(1.));
+			plane[3] = -halfExtents.z();
 			break;
 		case 5:
-			plane.setValue(btScalar(0.),btScalar(0.),btScalar(-1.),-halfExtents.z());
+			plane.setValue(btScalar(0.),btScalar(0.),btScalar(-1.));
+			plane[3] = -halfExtents.z();
 			break;
 		default:
-			btAssert(0);
+			assert(0);
 		}
 	}
@@ -307,5 +313,5 @@
 			break;
 		default:
-			btAssert(0);
+			assert(0);
 		}
 	}
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp	(revision 2908)
@@ -15,7 +15,4 @@
 
 #include "BulletCollision/CollisionShapes/btCollisionShape.h"
-
-
-btScalar gContactThresholdFactor=btScalar(0.02);
 
 
@@ -48,5 +45,6 @@
 btScalar	btCollisionShape::getContactBreakingThreshold() const
 {
-	return getAngularMotionDisc() * gContactThresholdFactor;
+	///@todo make this 0.1 configurable
+	return getAngularMotionDisc() * btScalar(0.1);
 }
 btScalar	btCollisionShape::getAngularMotionDisc() const
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp	(revision 2908)
@@ -23,6 +23,5 @@
 m_collisionMargin(btScalar(0.)),
 m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
-m_dynamicAabbTree(0),
-m_updateRevision(1)
+m_dynamicAabbTree(0)
 {
 	m_shapeType = COMPOUND_SHAPE_PROXYTYPE;
@@ -48,5 +47,4 @@
 void	btCompoundShape::addChildShape(const btTransform& localTransform,btCollisionShape* shape)
 {
-	m_updateRevision++;
 	//m_childTransforms.push_back(localTransform);
 	//m_childShapes.push_back(shape);
@@ -57,5 +55,6 @@
 	child.m_childMargin = shape->getMargin();
 
-	
+	m_children.push_back(child);
+
 	//extend the local aabbMin/aabbMax
 	btVector3 localAabbMin,localAabbMax;
@@ -76,9 +75,7 @@
 	{
 		const btDbvtVolume	bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
-		int index = m_children.size();
+		int index = m_children.size()-1;
 		child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index);
 	}
-
-	m_children.push_back(child);
 
 }
@@ -103,5 +100,4 @@
 void btCompoundShape::removeChildShapeByIndex(int childShapeIndex)
 {
-	m_updateRevision++;
 	btAssert(childShapeIndex >=0 && childShapeIndex < m_children.size());
 	if (m_dynamicAabbTree)
@@ -118,5 +114,4 @@
 void btCompoundShape::removeChildShape(btCollisionShape* shape)
 {
-	m_updateRevision++;
 	// Find the children containing the shape specified, and remove those children.
 	//note: there might be multiple children using the same shape!
@@ -145,5 +140,4 @@
 	// Recalculate the local aabb
 	// Brute force, it iterates over all the shapes left.
-
 	m_localAabbMin = btVector3(btScalar(1e30),btScalar(1e30),btScalar(1e30));
 	m_localAabbMax = btVector3(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
@@ -168,14 +162,6 @@
 {
 	btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
+	localHalfExtents += btVector3(getMargin(),getMargin(),getMargin());
 	btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);
-	
-	//avoid an illegal AABB when there are no children
-	if (!m_children.size())
-	{
-		localHalfExtents.setValue(0,0,0);
-		localCenter.setValue(0,0,0);
-	}
-	localHalfExtents += btVector3(getMargin(),getMargin(),getMargin());
-		
 
 	btMatrix3x3 abs_b = trans.getBasis().absolute();  
@@ -188,5 +174,5 @@
 	aabbMin = center-extent;
 	aabbMax = center+extent;
-	
+
 }
 
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.h
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.h	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.h	(revision 2908)
@@ -59,7 +59,4 @@
 
 	btDbvt*							m_dynamicAabbTree;
-
-	///increment m_updateRevision when adding/removing/replacing child shapes, so that some caches can be updated
-	int								m_updateRevision;
 
 public:
@@ -156,8 +153,4 @@
 	void calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const;
 
-	int	getUpdateRevision() const
-	{
-		return m_updateRevision;
-	}
 
 private:
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btConeShape.cpp
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btConeShape.cpp	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btConeShape.cpp	(revision 2908)
@@ -61,5 +61,5 @@
 		break;
 	default:
-		btAssert(0);
+		assert(0);
 	};
 }
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp	(revision 2908)
@@ -182,5 +182,5 @@
 bool btConvexHullShape::isInside(const btVector3& ,btScalar ) const
 {
-	btAssert(0);
+	assert(0);
 	return false;
 }
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp	(revision 2908)
@@ -151,5 +151,5 @@
 bool btConvexPointCloudShape::isInside(const btVector3& ,btScalar ) const
 {
-	btAssert(0);
+	assert(0);
 	return false;
 }
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp	(revision 2908)
@@ -155,4 +155,5 @@
 
 		btCapsuleShape* capsuleShape = (btCapsuleShape*)this;
+		btVector3 halfExtents = capsuleShape->getImplicitShapeDimensions();
 		btScalar halfHeight = capsuleShape->getHalfHeight();
 		int capsuleUpAxis = capsuleShape->getUpAxis();
@@ -301,6 +302,6 @@
 	{
 		btSphereShape* sphereShape = (btSphereShape*)this;
-		btScalar radius = sphereShape->getImplicitShapeDimensions().getX();// * convexShape->getLocalScaling().getX();
-		btScalar margin = radius + sphereShape->getMarginNonVirtual();
+		float radius = sphereShape->getImplicitShapeDimensions().getX();// * convexShape->getLocalScaling().getX();
+		float margin = radius + sphereShape->getMarginNonVirtual();
 		const btVector3& center = t.getOrigin();
 		btVector3 extent(margin,margin,margin);
@@ -314,5 +315,5 @@
 	{
 		btBoxShape* convexShape = (btBoxShape*)this;
-		btScalar margin=convexShape->getMarginNonVirtual();
+		float margin=convexShape->getMarginNonVirtual();
 		btVector3 halfExtents = convexShape->getImplicitShapeDimensions();
 		halfExtents += btVector3(margin,margin,margin);
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp	(revision 2908)
@@ -145,10 +145,5 @@
 }
 
-
-/// This returns the "raw" (user's initial) height, not the actual height.
-/// The actual height needs to be adjusted to be relative to the center
-///   of the heightfield's AABB.
-btScalar
-btHeightfieldTerrainShape::getRawHeightFieldValue(int x,int y) const
+btScalar	btHeightfieldTerrainShape::getHeightFieldValue(int x,int y) const
 {
 	btScalar val = 0.f;
@@ -187,7 +182,8 @@
 
 
-/// this returns the vertex in bullet-local coordinates
+
 void	btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
 {
+
 	btAssert(x>=0);
 	btAssert(y>=0);
@@ -195,5 +191,6 @@
 	btAssert(y<m_heightStickLength);
 
-	btScalar	height = getRawHeightFieldValue(x,y);
+
+	btScalar	height = getHeightFieldValue(x,y);
 
 	switch (m_upAxis)
@@ -202,5 +199,5 @@
 		{
 		vertex.setValue(
-			height - m_localOrigin.getX(),
+			height,
 			(-m_width/btScalar(2.0)) + x,
 			(-m_length/btScalar(2.0) ) + y
@@ -212,5 +209,5 @@
 			vertex.setValue(
 			(-m_width/btScalar(2.0)) + x,
-			height - m_localOrigin.getY(),
+			height,
 			(-m_length/btScalar(2.0)) + y
 			);
@@ -222,5 +219,5 @@
 			(-m_width/btScalar(2.0)) + x,
 			(-m_length/btScalar(2.0)) + y,
-			height - m_localOrigin.getZ()
+			height
 			);
 			break;
@@ -234,4 +231,5 @@
 
 	vertex*=m_localScaling;
+	
 }
 
@@ -241,5 +239,5 @@
 getQuantized
 (
-btScalar x
+float x
 )
 {
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h	(revision 2908)
@@ -30,15 +30,4 @@
   center (as determined by width and length and height, with each
   axis multiplied by the localScaling).
-
-  \b NOTE: be careful with coordinates.  If you have a heightfield with a local
-  min height of -100m, and a max height of +500m, you may be tempted to place it
-  at the origin (0,0) and expect the heights in world coordinates to be
-  -100 to +500 meters.
-  Actually, the heights will be -300 to +300m, because bullet will re-center
-  the heightfield based on its AABB (which is determined by the min/max
-  heights).  So keep in mind that once you create a btHeightfieldTerrainShape
-  object, the heights will be adjusted relative to the center of the AABB.  This
-  is different to the behavior of many rendering engines, but is useful for
-  physics engines.
 
   Most (but not all) rendering and heightfield libraries assume upAxis = 1
@@ -100,5 +89,5 @@
 	btVector3	m_localScaling;
 
-	virtual btScalar	getRawHeightFieldValue(int x,int y) const;
+	virtual btScalar	getHeightFieldValue(int x,int y) const;
 	void		quantizeWithClamp(int* out, const btVector3& point,int isMax) const;
 	void		getVertex(int x,int y,btVector3& vertex) const;
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp	(revision 2908)
@@ -29,6 +29,6 @@
 btVector3 btMinkowskiSumShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
 {
-	btVector3 supVertexA = m_transA(m_shapeA->localGetSupportingVertexWithoutMargin(vec*m_transA.getBasis()));
-	btVector3 supVertexB = m_transB(m_shapeB->localGetSupportingVertexWithoutMargin(-vec*m_transB.getBasis()));
+	btVector3 supVertexA = m_transA(m_shapeA->localGetSupportingVertexWithoutMargin(-vec*m_transA.getBasis()));
+	btVector3 supVertexB = m_transB(m_shapeB->localGetSupportingVertexWithoutMargin(vec*m_transB.getBasis()));
 	return  supVertexA - supVertexB;
 }
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h	(revision 2908)
@@ -32,10 +32,8 @@
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
-    btMultimaterialTriangleMeshShape(): btBvhTriangleMeshShape() {m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;}
+    btMultimaterialTriangleMeshShape(): btBvhTriangleMeshShape() {}
     btMultimaterialTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true):
         btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, buildBvh)
         {
-            m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;
-
             btVector3 m_triangle[3];
             const unsigned char *vertexbase;
@@ -70,6 +68,4 @@
         btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax, buildBvh)
         {
-            m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;
-
             btVector3 m_triangle[3];
             const unsigned char *vertexbase;
@@ -112,4 +108,9 @@
 */
     }
+	virtual int	getShapeType() const
+	{
+		return MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;
+	}
+	
 	//debugging
 	virtual const char*	getName()const {return "MULTIMATERIALTRIANGLEMESH";}
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btSphereShape.h
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btSphereShape.h	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btSphereShape.h	(revision 2908)
@@ -48,10 +48,4 @@
 	btScalar	getRadius() const { return m_implicitShapeDimensions.getX() * m_localScaling.getX();}
 
-	void	setUnscaledRadius(btScalar	radius)
-	{
-		m_implicitShapeDimensions.setX(radius);
-		btConvexInternalShape::setMargin(radius);
-	}
-
 	//debugging
 	virtual const char*	getName()const {return "SPHERE";}
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp	(revision 2908)
@@ -83,6 +83,5 @@
 }
 
-
-void	btTriangleIndexVertexArray::setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const
+void	btTriangleIndexVertexArray::setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax )
 {
 	m_aabbMin = aabbMin;
@@ -97,3 +96,2 @@
 }
 
-
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h	(revision 2908)
@@ -53,7 +53,7 @@
 	IndexedMeshArray	m_indexedMeshes;
 	int m_pad[2];
-	mutable int m_hasAabb; // using int instead of bool to maintain alignment
-	mutable btVector3 m_aabbMin;
-	mutable btVector3 m_aabbMax;
+	int m_hasAabb; // using int instead of bool to maintain alignment
+	btVector3 m_aabbMin;
+	btVector3 m_aabbMax;
 
 public:
@@ -107,5 +107,5 @@
 
 	virtual bool	hasPremadeAabb() const;
-	virtual void	setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const;
+	virtual void	setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax );
 	virtual void	getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const;
 
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp	(revision 2908)
@@ -1,3 +1,2 @@
-
 /*
 Bullet Continuous Collision Detection and Physics Library
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.cpp
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.cpp	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.cpp	(revision 2908)
@@ -36,5 +36,5 @@
 	{
 		m_indexedMeshes[0].m_numTriangles = m_32bitIndices.size()/3;
-		m_indexedMeshes[0].m_triangleIndexBase = 0;
+		m_indexedMeshes[0].m_triangleIndexBase = (unsigned char*) &m_32bitIndices[0];
 		m_indexedMeshes[0].m_indexType = PHY_INTEGER;
 		m_indexedMeshes[0].m_triangleIndexStride = 3*sizeof(int);
@@ -42,5 +42,5 @@
 	{
 		m_indexedMeshes[0].m_numTriangles = m_16bitIndices.size()/3;
-		m_indexedMeshes[0].m_triangleIndexBase = 0;
+		m_indexedMeshes[0].m_triangleIndexBase = (unsigned char*) &m_16bitIndices[0];
 		m_indexedMeshes[0].m_indexType = PHY_SHORT;
 		m_indexedMeshes[0].m_triangleIndexStride = 3*sizeof(short int);
@@ -50,10 +50,10 @@
 	{
 		m_indexedMeshes[0].m_numVertices = m_4componentVertices.size();
-		m_indexedMeshes[0].m_vertexBase = 0;
+		m_indexedMeshes[0].m_vertexBase = (unsigned char*)&m_4componentVertices[0];
 		m_indexedMeshes[0].m_vertexStride = sizeof(btVector3);
 	} else
 	{
 		m_indexedMeshes[0].m_numVertices = m_3componentVertices.size()/3;
-		m_indexedMeshes[0].m_vertexBase = 0;
+		m_indexedMeshes[0].m_vertexBase = (unsigned char*)&m_3componentVertices[0];
 		m_indexedMeshes[0].m_vertexStride = 3*sizeof(btScalar);
 	}
@@ -112,7 +112,7 @@
 			}
 	}
-		m_3componentVertices.push_back((float)vertex.getX());
-		m_3componentVertices.push_back((float)vertex.getY());
-		m_3componentVertices.push_back((float)vertex.getZ());
+		m_3componentVertices.push_back(vertex.getX());
+		m_3componentVertices.push_back(vertex.getY());
+		m_3componentVertices.push_back(vertex.getZ());
 		m_indexedMeshes[0].m_numVertices++;
 		m_indexedMeshes[0].m_vertexBase = (unsigned char*)&m_3componentVertices[0];
Index: code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.h
===================================================================
--- code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.h	(revision 2907)
+++ code/branches/questsystem5/src/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.h	(revision 2908)
@@ -41,5 +41,5 @@
 	virtual btVector3	localGetSupportingVertexWithoutMargin(const btVector3& vec)const
 	{
-		btAssert(0);
+		assert(0);
 		return localGetSupportingVertex(vec);
 	}
