Index: code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.h	(revision 8393)
@@ -17,6 +17,6 @@
 // 3. This notice may not be removed or altered from any source distribution.
 
-#ifndef AXIS_SWEEP_3_H
-#define AXIS_SWEEP_3_H
+#ifndef BT_AXIS_SWEEP_3_H
+#define BT_AXIS_SWEEP_3_H
 
 #include "LinearMath/btVector3.h"
Index: code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef		BROADPHASE_INTERFACE_H
-#define 	BROADPHASE_INTERFACE_H
+#ifndef		BT_BROADPHASE_INTERFACE_H
+#define 	BT_BROADPHASE_INTERFACE_H
 
 
@@ -80,3 +80,3 @@
 };
 
-#endif //BROADPHASE_INTERFACE_H
+#endif //BT_BROADPHASE_INTERFACE_H
Index: code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef BROADPHASE_PROXY_H
-#define BROADPHASE_PROXY_H
+#ifndef BT_BROADPHASE_PROXY_H
+#define BT_BROADPHASE_PROXY_H
 
 #include "LinearMath/btScalar.h" //for SIMD_FORCE_INLINE
@@ -267,4 +267,4 @@
 
 
-#endif //BROADPHASE_PROXY_H
-
+#endif //BT_BROADPHASE_PROXY_H
+
Index: code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef COLLISION_ALGORITHM_H
-#define COLLISION_ALGORITHM_H
+#ifndef BT_COLLISION_ALGORITHM_H
+#define BT_COLLISION_ALGORITHM_H
 
 #include "LinearMath/btScalar.h"
@@ -45,5 +45,5 @@
 	btPersistentManifold*	m_manifold;
 
-	int	getDispatcherId();
+//	int	getDispatcherId();
 
 };
@@ -60,5 +60,5 @@
 
 protected:
-	int	getDispatcherId();
+//	int	getDispatcherId();
 	
 public:
@@ -78,3 +78,3 @@
 
 
-#endif //COLLISION_ALGORITHM_H
+#endif //BT_COLLISION_ALGORITHM_H
Index: code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btDispatcher.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btDispatcher.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btDispatcher.h	(revision 8393)
@@ -14,7 +14,6 @@
 */
 
-#ifndef _DISPATCHER_H
-#define _DISPATCHER_H
-
+#ifndef BT_DISPATCHER_H
+#define BT_DISPATCHER_H
 #include "LinearMath/btScalar.h"
 
@@ -28,4 +27,5 @@
 class btPersistentManifold;
 class btStackAlloc;
+class btPoolAllocator;
 
 struct btDispatcherInfo
@@ -41,5 +41,5 @@
 		m_dispatchFunc(DISPATCH_DISCRETE),
 		m_timeOfImpact(btScalar(1.)),
-		m_useContinuous(false),
+		m_useContinuous(true),
 		m_debugDraw(0),
 		m_enableSatConvex(false),
@@ -49,5 +49,4 @@
 		m_useConvexConservativeDistanceUtil(false),
 		m_convexConservativeDistanceThreshold(0.0f),
-		m_convexMaxDistanceUseCPT(false),
 		m_stackAllocator(0)
 	{
@@ -66,5 +65,4 @@
 	bool		m_useConvexConservativeDistanceUtil;
 	btScalar	m_convexConservativeDistanceThreshold;
-	bool		m_convexMaxDistanceUseCPT;
 	btStackAlloc*	m_stackAllocator;
 };
@@ -99,4 +97,8 @@
 	virtual	btPersistentManifold**	getInternalManifoldPointer() = 0;
 
+	virtual	btPoolAllocator*	getInternalManifoldPool() = 0;
+
+	virtual	const btPoolAllocator*	getInternalManifoldPool() const = 0;
+
 	virtual	void* allocateCollisionAlgorithm(int size)  = 0;
 
@@ -106,3 +108,3 @@
 
 
-#endif //_DISPATCHER_H
+#endif //BT_DISPATCHER_H
Index: code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef OVERLAPPING_PAIR_CACHE_H
-#define OVERLAPPING_PAIR_CACHE_H
+#ifndef BT_OVERLAPPING_PAIR_CACHE_H
+#define BT_OVERLAPPING_PAIR_CACHE_H
 
 
@@ -465,5 +465,5 @@
 
 
-#endif //OVERLAPPING_PAIR_CACHE_H
-
-
+#endif //BT_OVERLAPPING_PAIR_CACHE_H
+
+
Index: code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef QUANTIZED_BVH_H
-#define QUANTIZED_BVH_H
+#ifndef BT_QUANTIZED_BVH_H
+#define BT_QUANTIZED_BVH_H
 
 class btSerializer;
@@ -577,3 +577,3 @@
 
 
-#endif //QUANTIZED_BVH_H
+#endif //BT_QUANTIZED_BVH_H
Index: code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef SIMPLE_BROADPHASE_H
-#define SIMPLE_BROADPHASE_H
+#ifndef BT_SIMPLE_BROADPHASE_H
+#define BT_SIMPLE_BROADPHASE_H
 
 
@@ -168,4 +168,4 @@
 
 
-#endif //SIMPLE_BROADPHASE_H
+#endif //BT_SIMPLE_BROADPHASE_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CMakeLists.txt
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CMakeLists.txt	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CMakeLists.txt	(revision 8393)
@@ -50,4 +50,5 @@
 	CollisionShapes/btConvexInternalShape.cpp
 	CollisionShapes/btConvexPointCloudShape.cpp
+	CollisionShapes/btConvexPolyhedron.cpp
 	CollisionShapes/btConvexShape.cpp
 	CollisionShapes/btConvex2dShape.cpp
@@ -88,4 +89,7 @@
 
 COMPILATION_END
+
+    # Raises compiler errors when compiled inside the compilation
+	NarrowPhaseCollision/btPolyhedralContactClipping.cpp
 
 	# Headers
@@ -140,4 +144,5 @@
 	CollisionShapes/btConvexInternalShape.h
 	CollisionShapes/btConvexPointCloudShape.h
+	CollisionShapes/btConvexPolyhedron.h
 	CollisionShapes/btConvexShape.h
 	CollisionShapes/btConvex2dShape.h
@@ -184,3 +189,4 @@
 	NarrowPhaseCollision/btSubSimplexConvexCast.h
 	NarrowPhaseCollision/btVoronoiSimplexSolver.h
+	NarrowPhaseCollision/btPolyhedralContactClipping.h
 )
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp	(revision 8393)
@@ -58,6 +58,4 @@
 }
 
-#define MAX_OVERLAP btScalar(0.)
-
 
 
@@ -94,17 +92,15 @@
 }
 
-///combined discrete/continuous sphere-triangle
 bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar contactBreakingThreshold)
 {
 
 	const btVector3* vertices = &m_triangle->getVertexPtr(0);
-	const btVector3& c = sphereCenter;
-	btScalar r = m_sphere->getRadius();
-
-	btVector3 delta (0,0,0);
+	
+	btScalar radius = m_sphere->getRadius();
+	btScalar radiusWithThreshold = radius + contactBreakingThreshold;
 
 	btVector3 normal = (vertices[1]-vertices[0]).cross(vertices[2]-vertices[0]);
 	normal.normalize();
-	btVector3 p1ToCentre = c - vertices[0];
+	btVector3 p1ToCentre = sphereCenter - vertices[0];
 	btScalar distanceFromPlane = p1ToCentre.dot(normal);
 
@@ -112,28 +108,21 @@
 	{
 		//triangle facing the other way
-	
 		distanceFromPlane *= btScalar(-1.);
 		normal *= btScalar(-1.);
 	}
 
-	btScalar contactMargin = contactBreakingThreshold;
-	bool isInsideContactPlane = distanceFromPlane < r + contactMargin;
-	bool isInsideShellPlane = distanceFromPlane < r;
-	
-	btScalar deltaDotNormal = delta.dot(normal);
-	if (!isInsideShellPlane && deltaDotNormal >= btScalar(0.0))
-		return false;
-
+	bool isInsideContactPlane = distanceFromPlane < radiusWithThreshold;
+	
 	// Check for contact / intersection
 	bool hasContact = false;
 	btVector3 contactPoint;
 	if (isInsideContactPlane) {
-		if (facecontains(c,vertices,normal)) {
+		if (facecontains(sphereCenter,vertices,normal)) {
 			// Inside the contact wedge - touches a point on the shell plane
 			hasContact = true;
-			contactPoint = c - normal*distanceFromPlane;
+			contactPoint = sphereCenter - normal*distanceFromPlane;
 		} else {
 			// Could be inside one of the contact capsules
-			btScalar contactCapsuleRadiusSqr = (r + contactMargin) * (r + contactMargin);
+			btScalar contactCapsuleRadiusSqr = radiusWithThreshold*radiusWithThreshold;
 			btVector3 nearestOnEdge;
 			for (int i = 0; i < m_triangle->getNumEdges(); i++) {
@@ -144,5 +133,5 @@
 				m_triangle->getEdge(i,pa,pb);
 
-				btScalar distanceSqr = SegmentSqrDistance(pa,pb,c, nearestOnEdge);
+				btScalar distanceSqr = SegmentSqrDistance(pa,pb,sphereCenter, nearestOnEdge);
 				if (distanceSqr < contactCapsuleRadiusSqr) {
 					// Yep, we're inside a capsule
@@ -156,22 +145,25 @@
 
 	if (hasContact) {
-		btVector3 contactToCentre = c - contactPoint;
+		btVector3 contactToCentre = sphereCenter - contactPoint;
 		btScalar distanceSqr = contactToCentre.length2();
-		if (distanceSqr < (r - MAX_OVERLAP)*(r - MAX_OVERLAP)) {
-			btScalar distance = btSqrt(distanceSqr);
-			resultNormal = contactToCentre;
-			resultNormal.normalize();
-			point = contactPoint;
-			depth = -(r-distance);
+
+		if (distanceSqr < radiusWithThreshold*radiusWithThreshold)
+		{
+			if (distanceSqr>SIMD_EPSILON)
+			{
+				btScalar distance = btSqrt(distanceSqr);
+				resultNormal = contactToCentre;
+				resultNormal.normalize();
+				point = contactPoint;
+				depth = -(radius-distance);
+			} else
+			{
+				btScalar distance = 0.f;
+				resultNormal = normal;
+				point = contactPoint;
+				depth = -radius;
+			}
 			return true;
 		}
-
-		if (delta.dot(contactToCentre) >= btScalar(0.0)) 
-			return false;
-		
-		// Moving towards the contact point -> collision
-		point = contactPoint;
-		timeOfImpact = btScalar(0.0);
-		return true;
 	}
 	
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef SPHERE_TRIANGLE_DETECTOR_H
-#define SPHERE_TRIANGLE_DETECTOR_H
+#ifndef BT_SPHERE_TRIANGLE_DETECTOR_H
+#define BT_SPHERE_TRIANGLE_DETECTOR_H
 
 #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
@@ -48,4 +48,4 @@
 	
 };
-#endif //SPHERE_TRIANGLE_DETECTOR_H
+#endif //BT_SPHERE_TRIANGLE_DETECTOR_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef BOX_2D_BOX_2D__COLLISION_ALGORITHM_H
-#define BOX_2D_BOX_2D__COLLISION_ALGORITHM_H
+#ifndef BT_BOX_2D_BOX_2D__COLLISION_ALGORITHM_H
+#define BT_BOX_2D_BOX_2D__COLLISION_ALGORITHM_H
 
 #include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h"
@@ -63,4 +63,4 @@
 };
 
-#endif //BOX_2D_BOX_2D__COLLISION_ALGORITHM_H
+#endif //BT_BOX_2D_BOX_2D__COLLISION_ALGORITHM_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef BOX_BOX__COLLISION_ALGORITHM_H
-#define BOX_BOX__COLLISION_ALGORITHM_H
+#ifndef BT_BOX_BOX__COLLISION_ALGORITHM_H
+#define BT_BOX_BOX__COLLISION_ALGORITHM_H
 
 #include "btActivatingCollisionAlgorithm.h"
@@ -63,4 +63,4 @@
 };
 
-#endif //BOX_BOX__COLLISION_ALGORITHM_H
+#endif //BT_BOX_BOX__COLLISION_ALGORITHM_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxDetector.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxDetector.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxDetector.h	(revision 8393)
@@ -17,6 +17,6 @@
 3. This notice may not be removed or altered from any source distribution.
 */
-#ifndef BOX_BOX_DETECTOR_H
-#define BOX_BOX_DETECTOR_H
+#ifndef BT_BOX_BOX_DETECTOR_H
+#define BT_BOX_BOX_DETECTOR_H
 
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionConfiguration.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionConfiguration.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionConfiguration.h	(revision 8393)
@@ -16,4 +16,5 @@
 #ifndef BT_COLLISION_CONFIGURATION
 #define BT_COLLISION_CONFIGURATION
+
 struct btCollisionAlgorithmCreateFunc;
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef COLLISION_CREATE_FUNC
-#define COLLISION_CREATE_FUNC
+#ifndef BT_COLLISION_CREATE_FUNC
+#define BT_COLLISION_CREATE_FUNC
 
 #include "LinearMath/btAlignedObjectArray.h"
@@ -42,4 +42,4 @@
 	}
 };
-#endif //COLLISION_CREATE_FUNC
+#endif //BT_COLLISION_CREATE_FUNC
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp	(revision 8393)
@@ -93,6 +93,14 @@
 	} else
 	{
-		mem = btAlignedAlloc(sizeof(btPersistentManifold),16);
-
+		//we got a pool memory overflow, by default we fallback to dynamically allocate memory. If we require a contiguous contact pool then assert.
+		if ((m_dispatcherFlags&CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION)==0)
+		{
+			mem = btAlignedAlloc(sizeof(btPersistentManifold),16);
+		} else
+		{
+			btAssert(0);
+			//make sure to increase the m_defaultMaxPersistentManifoldPoolSize in the btDefaultCollisionConstructionInfo/btDefaultCollisionConfiguration
+			return 0;
+		}
 	}
 	btPersistentManifold* manifold = new(mem) btPersistentManifold (body0,body1,0,contactBreakingThreshold,contactProcessingThreshold);
@@ -173,6 +181,5 @@
 	{
 		//broadphase filtering already deals with this
-		if ((body0->isStaticObject() || body0->isKinematicObject()) &&
-			(body1->isStaticObject() || body1->isKinematicObject()))
+		if (body0->isStaticOrKinematicObject() && body1->isStaticOrKinematicObject())
 		{
 			m_dispatcherFlags |= btCollisionDispatcher::CD_STATIC_STATIC_REPORTED;
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef COLLISION__DISPATCHER_H
-#define COLLISION__DISPATCHER_H
+#ifndef BT_COLLISION__DISPATCHER_H
+#define BT_COLLISION__DISPATCHER_H
 
 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
@@ -43,6 +43,9 @@
 class btCollisionDispatcher : public btDispatcher
 {
+
+protected:
+
 	int		m_dispatcherFlags;
-	
+
 	btAlignedObjectArray<btPersistentManifold*>	m_manifoldsPtr;
 
@@ -65,5 +68,6 @@
 	{
 		CD_STATIC_STATIC_REPORTED = 1,
-		CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2
+		CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2,
+		CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION = 4
 	};
 
@@ -75,6 +79,5 @@
 	void	setDispatcherFlags(int flags)
 	{
-        (void) flags;
-		m_dispatcherFlags = 0;
+		m_dispatcherFlags = flags;
 	}
 
@@ -154,6 +157,16 @@
 	}
 
+	virtual	btPoolAllocator*	getInternalManifoldPool()
+	{
+		return m_persistentManifoldPoolAllocator;
+	}
+
+	virtual	const btPoolAllocator*	getInternalManifoldPool() const
+	{
+		return m_persistentManifoldPoolAllocator;
+	}
+
 };
 
-#endif //COLLISION__DISPATCHER_H
+#endif //BT_COLLISION__DISPATCHER_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef COLLISION_OBJECT_H
-#define COLLISION_OBJECT_H
+#ifndef BT_COLLISION_OBJECT_H
+#define BT_COLLISION_OBJECT_H
 
 #include "LinearMath/btTransform.h"
@@ -522,3 +522,3 @@
 
 
-#endif //COLLISION_OBJECT_H
+#endif //BT_COLLISION_OBJECT_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp	(revision 8393)
@@ -29,8 +29,13 @@
 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
+#include "BulletCollision/BroadphaseCollision/btDbvt.h"
 #include "LinearMath/btAabbUtil2.h"
 #include "LinearMath/btQuickprof.h"
 #include "LinearMath/btStackAlloc.h"
 #include "LinearMath/btSerializer.h"
+#include "BulletCollision/CollisionShapes/btConvexPolyhedron.h"
+
+//#define DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION
+
 
 //#define USE_BRUTEFORCE_RAYBROADPHASE 1
@@ -151,4 +156,14 @@
 	maxAabb += contactThreshold;
 
+	if(getDispatchInfo().m_useContinuous && colObj->getInternalType()==btCollisionObject::CO_RIGID_BODY)
+	{
+		btVector3 minAabb2,maxAabb2;
+		colObj->getCollisionShape()->getAabb(colObj->getInterpolationWorldTransform(),minAabb2,maxAabb2);
+		minAabb2 -= contactThreshold;
+		maxAabb2 += contactThreshold;
+		minAabb.setMin(minAabb2);
+		maxAabb.setMax(maxAabb2);
+	}
+
 	btBroadphaseInterface* bp = (btBroadphaseInterface*)m_broadphasePairCache;
 
@@ -421,49 +436,115 @@
 		} else {
 			//			BT_PROFILE("rayTestCompound");
-			///@todo: use AABB tree or other BVH acceleration structure, see btDbvt
 			if (collisionShape->isCompound())
 			{
+				struct LocalInfoAdder2 : public RayResultCallback
+				{
+					RayResultCallback* m_userCallback;
+					int m_i;
+					
+					LocalInfoAdder2 (int i, RayResultCallback *user)
+						: m_userCallback(user), m_i(i)
+					{ 
+						m_closestHitFraction = m_userCallback->m_closestHitFraction;
+					}
+					virtual bool needsCollision(btBroadphaseProxy* p) const
+					{
+						return m_userCallback->needsCollision(p);
+					}
+
+					virtual btScalar addSingleResult (btCollisionWorld::LocalRayResult &r, bool b)
+					{
+						btCollisionWorld::LocalShapeInfo shapeInfo;
+						shapeInfo.m_shapePart = -1;
+						shapeInfo.m_triangleIndex = m_i;
+						if (r.m_localShapeInfo == NULL)
+							r.m_localShapeInfo = &shapeInfo;
+
+						const btScalar result = m_userCallback->addSingleResult(r, b);
+						m_closestHitFraction = m_userCallback->m_closestHitFraction;
+						return result;
+					}
+				};
+				
+				struct RayTester : btDbvt::ICollide
+				{
+					btCollisionObject* m_collisionObject;
+					const btCompoundShape* m_compoundShape;
+					const btTransform& m_colObjWorldTransform;
+					const btTransform& m_rayFromTrans;
+					const btTransform& m_rayToTrans;
+					RayResultCallback& m_resultCallback;
+					
+					RayTester(btCollisionObject* collisionObject,
+							const btCompoundShape* compoundShape,
+							const btTransform& colObjWorldTransform,
+							const btTransform& rayFromTrans,
+							const btTransform& rayToTrans,
+							RayResultCallback& resultCallback):
+						m_collisionObject(collisionObject),
+						m_compoundShape(compoundShape),
+						m_colObjWorldTransform(colObjWorldTransform),
+						m_rayFromTrans(rayFromTrans),
+						m_rayToTrans(rayToTrans),
+						m_resultCallback(resultCallback)
+					{
+						
+					}
+					
+					void Process(int i)
+					{
+						const btCollisionShape* childCollisionShape = m_compoundShape->getChildShape(i);
+						const btTransform& childTrans = m_compoundShape->getChildTransform(i);
+						btTransform childWorldTrans = m_colObjWorldTransform * childTrans;
+						
+						// replace collision shape so that callback can determine the triangle
+						btCollisionShape* saveCollisionShape = m_collisionObject->getCollisionShape();
+						m_collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape);
+
+						LocalInfoAdder2 my_cb(i, &m_resultCallback);
+
+						rayTestSingle(
+							m_rayFromTrans,
+							m_rayToTrans,
+							m_collisionObject,
+							childCollisionShape,
+							childWorldTrans,
+							my_cb);
+						
+						// restore
+						m_collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape);
+					}
+					
+					void Process(const btDbvtNode* leaf)
+					{
+						Process(leaf->dataAsInt);
+					}
+				};
+				
 				const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape);
-				int i=0;
-				for (i=0;i<compoundShape->getNumChildShapes();i++)
-				{
-					btTransform childTrans = compoundShape->getChildTransform(i);
-					const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i);
-					btTransform childWorldTrans = colObjWorldTransform * childTrans;
-					// replace collision shape so that callback can determine the triangle
-					btCollisionShape* saveCollisionShape = collisionObject->getCollisionShape();
-					collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape);
-                    struct LocalInfoAdder2 : public RayResultCallback {
-						RayResultCallback* m_userCallback;
-						int m_i;
-                        LocalInfoAdder2 (int i, RayResultCallback *user)
-							: m_userCallback(user),
-							m_i(i)
-						{ 
-							m_closestHitFraction = m_userCallback->m_closestHitFraction;
-						}
-						virtual btScalar addSingleResult (btCollisionWorld::LocalRayResult &r, bool b)
-                            {
-                                    btCollisionWorld::LocalShapeInfo	shapeInfo;
-                                    shapeInfo.m_shapePart = -1;
-                                    shapeInfo.m_triangleIndex = m_i;
-                                    if (r.m_localShapeInfo == NULL)
-                                        r.m_localShapeInfo = &shapeInfo;
-
-									const btScalar result = m_userCallback->addSingleResult(r, b);
-									m_closestHitFraction = m_userCallback->m_closestHitFraction;
-									return result;
-                            }
-                    };
-
-                    LocalInfoAdder2 my_cb(i, &resultCallback);
-
-					rayTestSingle(rayFromTrans,rayToTrans,
-						collisionObject,
-						childCollisionShape,
-						childWorldTrans,
-						my_cb);
-					// restore
-					collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape);
+				const btDbvt* dbvt = compoundShape->getDynamicAabbTree();
+
+
+				RayTester rayCB(
+					collisionObject,
+					compoundShape,
+					colObjWorldTransform,
+					rayFromTrans,
+					rayToTrans,
+					resultCallback);
+#ifndef	DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION
+				if (dbvt)
+				{
+					btVector3 localRayFrom = colObjWorldTransform.inverseTimes(rayFromTrans).getOrigin();
+					btVector3 localRayTo = colObjWorldTransform.inverseTimes(rayToTrans).getOrigin();
+					btDbvt::rayTest(dbvt->m_root, localRayFrom , localRayTo, rayCB);
+				}
+				else
+#endif //DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION
+				{
+					for (int i = 0, n = compoundShape->getNumChildShapes(); i < n; ++i)
+					{
+						rayCB.Process(i);
+					}	
 				}
 			}
@@ -577,4 +658,5 @@
 				BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,collisionObject,triangleMesh, colObjWorldTransform);
 				tccb.m_hitFraction = resultCallback.m_closestHitFraction;
+				tccb.m_allowedPenetration = allowedPenetration;
 				btVector3 boxMinLocal, boxMaxLocal;
 				castShape->getAabb(rotationXform, boxMinLocal, boxMaxLocal);
@@ -582,65 +664,101 @@
 			} else
 			{
-				//BT_PROFILE("convexSweepConcave");
-				btConcaveShape* concaveShape = (btConcaveShape*)collisionShape;
-				btTransform worldTocollisionObject = colObjWorldTransform.inverse();
-				btVector3 convexFromLocal = worldTocollisionObject * convexFromTrans.getOrigin();
-				btVector3 convexToLocal = worldTocollisionObject * convexToTrans.getOrigin();
-				// rotation of box in local mesh space = MeshRotation^-1 * ConvexToRotation
-				btTransform rotationXform = btTransform(worldTocollisionObject.getBasis() * convexToTrans.getBasis());
-
-				//ConvexCast::CastResult
-				struct BridgeTriangleConvexcastCallback : public btTriangleConvexcastCallback
-				{
-					btCollisionWorld::ConvexResultCallback* m_resultCallback;
-					btCollisionObject*	m_collisionObject;
-					btConcaveShape*	m_triangleMesh;
-
-					BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to,
-						btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape*	triangleMesh, const btTransform& triangleToWorld):
-					btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()),
-						m_resultCallback(resultCallback),
-						m_collisionObject(collisionObject),
-						m_triangleMesh(triangleMesh)
-					{
+				if (collisionShape->getShapeType()==STATIC_PLANE_PROXYTYPE)
+				{
+					btConvexCast::CastResult castResult;
+					castResult.m_allowedPenetration = allowedPenetration;
+					castResult.m_fraction = resultCallback.m_closestHitFraction;
+					btStaticPlaneShape* planeShape = (btStaticPlaneShape*) collisionShape;
+					btContinuousConvexCollision convexCaster1(castShape,planeShape);
+					btConvexCast* castPtr = &convexCaster1;
+
+					if (castPtr->calcTimeOfImpact(convexFromTrans,convexToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
+					{
+						//add hit
+						if (castResult.m_normal.length2() > btScalar(0.0001))
+						{
+							if (castResult.m_fraction < resultCallback.m_closestHitFraction)
+							{
+								castResult.m_normal.normalize();
+								btCollisionWorld::LocalConvexResult localConvexResult
+									(
+									collisionObject,
+									0,
+									castResult.m_normal,
+									castResult.m_hitPoint,
+									castResult.m_fraction
+									);
+
+								bool normalInWorldSpace = true;
+								resultCallback.addSingleResult(localConvexResult, normalInWorldSpace);
+							}
+						}
 					}
 
-
-					virtual btScalar reportHit(const btVector3& hitNormalLocal, const btVector3& hitPointLocal, btScalar hitFraction, int partId, int triangleIndex )
-					{
-						btCollisionWorld::LocalShapeInfo	shapeInfo;
-						shapeInfo.m_shapePart = partId;
-						shapeInfo.m_triangleIndex = triangleIndex;
-						if (hitFraction <= m_resultCallback->m_closestHitFraction)
+				} else
+				{
+					//BT_PROFILE("convexSweepConcave");
+					btConcaveShape* concaveShape = (btConcaveShape*)collisionShape;
+					btTransform worldTocollisionObject = colObjWorldTransform.inverse();
+					btVector3 convexFromLocal = worldTocollisionObject * convexFromTrans.getOrigin();
+					btVector3 convexToLocal = worldTocollisionObject * convexToTrans.getOrigin();
+					// rotation of box in local mesh space = MeshRotation^-1 * ConvexToRotation
+					btTransform rotationXform = btTransform(worldTocollisionObject.getBasis() * convexToTrans.getBasis());
+
+					//ConvexCast::CastResult
+					struct BridgeTriangleConvexcastCallback : public btTriangleConvexcastCallback
+					{
+						btCollisionWorld::ConvexResultCallback* m_resultCallback;
+						btCollisionObject*	m_collisionObject;
+						btConcaveShape*	m_triangleMesh;
+
+						BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to,
+							btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape*	triangleMesh, const btTransform& triangleToWorld):
+						btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()),
+							m_resultCallback(resultCallback),
+							m_collisionObject(collisionObject),
+							m_triangleMesh(triangleMesh)
 						{
-
-							btCollisionWorld::LocalConvexResult convexResult
-								(m_collisionObject,
-								&shapeInfo,
-								hitNormalLocal,
-								hitPointLocal,
-								hitFraction);
-
-							bool	normalInWorldSpace = false;
-
-							return m_resultCallback->addSingleResult(convexResult,normalInWorldSpace);
 						}
-						return hitFraction;
-					}
-
-				};
-
-				BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,collisionObject,concaveShape, colObjWorldTransform);
-				tccb.m_hitFraction = resultCallback.m_closestHitFraction;
-				btVector3 boxMinLocal, boxMaxLocal;
-				castShape->getAabb(rotationXform, boxMinLocal, boxMaxLocal);
-
-				btVector3 rayAabbMinLocal = convexFromLocal;
-				rayAabbMinLocal.setMin(convexToLocal);
-				btVector3 rayAabbMaxLocal = convexFromLocal;
-				rayAabbMaxLocal.setMax(convexToLocal);
-				rayAabbMinLocal += boxMinLocal;
-				rayAabbMaxLocal += boxMaxLocal;
-				concaveShape->processAllTriangles(&tccb,rayAabbMinLocal,rayAabbMaxLocal);
+
+
+						virtual btScalar reportHit(const btVector3& hitNormalLocal, const btVector3& hitPointLocal, btScalar hitFraction, int partId, int triangleIndex )
+						{
+							btCollisionWorld::LocalShapeInfo	shapeInfo;
+							shapeInfo.m_shapePart = partId;
+							shapeInfo.m_triangleIndex = triangleIndex;
+							if (hitFraction <= m_resultCallback->m_closestHitFraction)
+							{
+
+								btCollisionWorld::LocalConvexResult convexResult
+									(m_collisionObject,
+									&shapeInfo,
+									hitNormalLocal,
+									hitPointLocal,
+									hitFraction);
+
+								bool	normalInWorldSpace = false;
+
+								return m_resultCallback->addSingleResult(convexResult,normalInWorldSpace);
+							}
+							return hitFraction;
+						}
+
+					};
+
+					BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,collisionObject,concaveShape, colObjWorldTransform);
+					tccb.m_hitFraction = resultCallback.m_closestHitFraction;
+					tccb.m_allowedPenetration = allowedPenetration;
+					btVector3 boxMinLocal, boxMaxLocal;
+					castShape->getAabb(rotationXform, boxMinLocal, boxMaxLocal);
+
+					btVector3 rayAabbMinLocal = convexFromLocal;
+					rayAabbMinLocal.setMin(convexToLocal);
+					btVector3 rayAabbMaxLocal = convexFromLocal;
+					rayAabbMaxLocal.setMax(convexToLocal);
+					rayAabbMinLocal += boxMinLocal;
+					rayAabbMaxLocal += boxMaxLocal;
+					concaveShape->processAllTriangles(&tccb,rayAabbMinLocal,rayAabbMaxLocal);
+				}
 			}
 		} else {
@@ -667,4 +785,8 @@
 							{
 								m_closestHitFraction = m_userCallback->m_closestHitFraction;
+							}
+							virtual bool needsCollision(btBroadphaseProxy* p) const
+							{
+								return m_userCallback->needsCollision(p);
 							}
                             virtual btScalar addSingleResult (btCollisionWorld::LocalConvexResult&	r,	bool b)
@@ -1152,48 +1274,5 @@
 
 				int upAxis = capsuleShape->getUpAxis();
-
-
-				btVector3 capStart(0.f,0.f,0.f);
-				capStart[upAxis] = -halfHeight;
-
-				btVector3 capEnd(0.f,0.f,0.f);
-				capEnd[upAxis] = halfHeight;
-
-				// Draw the ends
-				{
-
-					btTransform childTransform = worldTransform;
-					childTransform.getOrigin() = worldTransform * capStart;
-					getDebugDrawer()->drawSphere(radius, childTransform, color);
-				}
-
-				{
-					btTransform childTransform = worldTransform;
-					childTransform.getOrigin() = worldTransform * capEnd;
-					getDebugDrawer()->drawSphere(radius, childTransform, color);
-				}
-
-				// Draw some additional lines
-				btVector3 start = worldTransform.getOrigin();
-
-
-				capStart[(upAxis+1)%3] = radius;
-				capEnd[(upAxis+1)%3] = radius;
-				getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);
-				capStart[(upAxis+1)%3] = -radius;
-				capEnd[(upAxis+1)%3] = -radius;
-				getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);
-
-				capStart[(upAxis+1)%3] = 0.f;
-				capEnd[(upAxis+1)%3] = 0.f;
-
-				capStart[(upAxis+2)%3] = radius;
-				capEnd[(upAxis+2)%3] = radius;
-				getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);
-				capStart[(upAxis+2)%3] = -radius;
-				capEnd[(upAxis+2)%3] = -radius;
-				getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);
-
-
+				getDebugDrawer()->drawCapsule(radius, halfHeight, upAxis, worldTransform, color);
 				break;
 			}
@@ -1203,28 +1282,8 @@
 				btScalar radius = coneShape->getRadius();//+coneShape->getMargin();
 				btScalar height = coneShape->getHeight();//+coneShape->getMargin();
-				btVector3 start = worldTransform.getOrigin();
 
 				int upAxis= coneShape->getConeUpIndex();
-
-
-				btVector3	offsetHeight(0,0,0);
-				offsetHeight[upAxis] = height * btScalar(0.5);
-				btVector3	offsetRadius(0,0,0);
-				offsetRadius[(upAxis+1)%3] = radius;
-				btVector3	offset2Radius(0,0,0);
-				offset2Radius[(upAxis+2)%3] = radius;
-
-				getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color);
-				getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color);
-				getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offset2Radius),color);
-				getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offset2Radius),color);
-
-				// Drawing the base of the cone
-				btVector3 yaxis(0,0,0);
-				yaxis[upAxis] = btScalar(1.0);
-				btVector3 xaxis(0,0,0);
-				xaxis[(upAxis+1)%3] = btScalar(1.0);
-				getDebugDrawer()->drawArc(start-worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,10.0);
-		break;
+				getDebugDrawer()->drawCone(radius, height, upAxis, worldTransform, color);
+				break;
 
 			}
@@ -1235,19 +1294,5 @@
 				btScalar radius = cylinder->getRadius();
 				btScalar halfHeight = cylinder->getHalfExtentsWithMargin()[upAxis];
-				btVector3 start = worldTransform.getOrigin();
-				btVector3	offsetHeight(0,0,0);
-				offsetHeight[upAxis] = halfHeight;
-				btVector3	offsetRadius(0,0,0);
-				offsetRadius[(upAxis+1)%3] = radius;
-				getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight+offsetRadius),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color);
-				getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight-offsetRadius),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color);
-
-				// Drawing top and bottom caps of the cylinder
-				btVector3 yaxis(0,0,0);
-				yaxis[upAxis] = btScalar(1.0);
-				btVector3 xaxis(0,0,0);
-				xaxis[(upAxis+1)%3] = btScalar(1.0);
-				getDebugDrawer()->drawArc(start-worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,btScalar(10.0));
-				getDebugDrawer()->drawArc(start+worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,btScalar(10.0));
+				getDebugDrawer()->drawCylinder(radius, halfHeight, upAxis, worldTransform, color);
 				break;
 			}
@@ -1258,14 +1303,5 @@
 				btScalar planeConst = staticPlaneShape->getPlaneConstant();
 				const btVector3& planeNormal = staticPlaneShape->getPlaneNormal();
-				btVector3 planeOrigin = planeNormal * planeConst;
-				btVector3 vec0,vec1;
-				btPlaneSpace1(planeNormal,vec0,vec1);
-				btScalar vecLen = 100.f;
-				btVector3 pt0 = planeOrigin + vec0*vecLen;
-				btVector3 pt1 = planeOrigin - vec0*vecLen;
-				btVector3 pt2 = planeOrigin + vec1*vecLen;
-				btVector3 pt3 = planeOrigin - vec1*vecLen;
-				getDebugDrawer()->drawLine(worldTransform*pt0,worldTransform*pt1,color);
-				getDebugDrawer()->drawLine(worldTransform*pt2,worldTransform*pt3,color);
+				getDebugDrawer()->drawPlane(planeNormal, planeConst,worldTransform, color);
 				break;
 
@@ -1305,12 +1341,42 @@
 
 					int i;
-					for (i=0;i<polyshape->getNumEdges();i++)
-					{
-						btVector3 a,b;
-						polyshape->getEdge(i,a,b);
-						btVector3 wa = worldTransform * a;
-						btVector3 wb = worldTransform * b;
-						getDebugDrawer()->drawLine(wa,wb,color);
-
+					if (polyshape->getConvexPolyhedron())
+					{
+						const btConvexPolyhedron* poly = polyshape->getConvexPolyhedron();
+						for (i=0;i<poly->m_faces.size();i++)
+						{
+							btVector3 centroid(0,0,0);
+							int numVerts = poly->m_faces[i].m_indices.size();
+							if (numVerts)
+							{
+								int lastV = poly->m_faces[i].m_indices[numVerts-1];
+								for (int v=0;v<poly->m_faces[i].m_indices.size();v++)
+								{
+									int curVert = poly->m_faces[i].m_indices[v];
+									centroid+=poly->m_vertices[curVert];
+									getDebugDrawer()->drawLine(worldTransform*poly->m_vertices[lastV],worldTransform*poly->m_vertices[curVert],color);
+									lastV = curVert;
+								}
+							}
+							centroid*= 1./btScalar(numVerts);
+
+							btVector3 normalColor(1,1,0);
+							btVector3 faceNormal(poly->m_faces[i].m_plane[0],poly->m_faces[i].m_plane[1],poly->m_faces[i].m_plane[2]);
+							getDebugDrawer()->drawLine(worldTransform*centroid,worldTransform*(centroid+faceNormal),normalColor);
+							
+							
+						}
+
+						
+					} else
+					{
+						for (i=0;i<polyshape->getNumEdges();i++)
+						{
+							btVector3 a,b;
+							polyshape->getEdge(i,a,b);
+							btVector3 wa = worldTransform * a;
+							btVector3 wb = worldTransform * b;
+							getDebugDrawer()->drawLine(wa,wb,color);
+						}
 					}
 
@@ -1381,4 +1447,19 @@
 					btVector3 colorvec(1,0,0);
 					colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
+					btVector3 contactThreshold(gContactBreakingThreshold,gContactBreakingThreshold,gContactBreakingThreshold);
+					minAabb -= contactThreshold;
+					maxAabb += contactThreshold;
+
+					btVector3 minAabb2,maxAabb2;
+
+					if(colObj->getInternalType()==btCollisionObject::CO_RIGID_BODY)
+					{
+						colObj->getCollisionShape()->getAabb(colObj->getInterpolationWorldTransform(),minAabb2,maxAabb2);
+						minAabb2 -= contactThreshold;
+						maxAabb2 += contactThreshold;
+						minAabb.setMin(minAabb2);
+						maxAabb.setMax(maxAabb2);
+					}
+
 					m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec);
 				}
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h	(revision 8393)
@@ -63,6 +63,6 @@
  
 
-#ifndef COLLISION_WORLD_H
-#define COLLISION_WORLD_H
+#ifndef BT_COLLISION_WORLD_H
+#define BT_COLLISION_WORLD_H
 
 class btStackAlloc;
@@ -507,3 +507,3 @@
 
 
-#endif //COLLISION_WORLD_H
+#endif //BT_COLLISION_WORLD_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp	(revision 8393)
@@ -235,5 +235,5 @@
 					}
 				}
-				manifoldArray.clear();
+				manifoldArray.resize(0);
 			}
 		}
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef COMPOUND_COLLISION_ALGORITHM_H
-#define COMPOUND_COLLISION_ALGORITHM_H
+#ifndef BT_COMPOUND_COLLISION_ALGORITHM_H
+#define BT_COMPOUND_COLLISION_ALGORITHM_H
 
 #include "btActivatingCollisionAlgorithm.h"
@@ -84,3 +84,3 @@
 };
 
-#endif //COMPOUND_COLLISION_ALGORITHM_H
+#endif //BT_COMPOUND_COLLISION_ALGORITHM_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef CONVEX_2D_CONVEX_2D_ALGORITHM_H
-#define CONVEX_2D_CONVEX_2D_ALGORITHM_H
+#ifndef BT_CONVEX_2D_CONVEX_2D_ALGORITHM_H
+#define BT_CONVEX_2D_CONVEX_2D_ALGORITHM_H
 
 #include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h"
@@ -93,3 +93,3 @@
 };
 
-#endif //CONVEX_2D_CONVEX_2D_ALGORITHM_H
+#endif //BT_CONVEX_2D_CONVEX_2D_ALGORITHM_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp	(revision 8393)
@@ -92,5 +92,5 @@
 
 
-	
+#if 0	
 	///debug drawing of the overlapping triangles
 	if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe ))
@@ -101,15 +101,6 @@
 		m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]),tr(triangle[2]),color);
 		m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]),tr(triangle[0]),color);
-
-		//btVector3 center = triangle[0] + triangle[1]+triangle[2];
-		//center *= btScalar(0.333333);
-		//m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(center),color);
-		//m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]),tr(center),color);
-		//m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]),tr(center),color);
-
-	}
-
-
-	//btCollisionObject* colObj = static_cast<btCollisionObject*>(m_convexProxy->m_clientObject);
+	}
+#endif
 	
 	if (m_convexBody->getCollisionShape()->isConvex())
@@ -120,5 +111,5 @@
 		btCollisionShape* tmpShape = ob->getCollisionShape();
 		ob->internalSetTemporaryCollisionShape( &tm );
-		
+
 		btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBody,m_triBody,m_manifoldPtr);
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef CONVEX_CONCAVE_COLLISION_ALGORITHM_H
-#define CONVEX_CONCAVE_COLLISION_ALGORITHM_H
+#ifndef BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H
+#define BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H
 
 #include "btActivatingCollisionAlgorithm.h"
@@ -114,3 +114,3 @@
 };
 
-#endif //CONVEX_CONCAVE_COLLISION_ALGORITHM_H
+#endif //BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp	(revision 8393)
@@ -27,4 +27,6 @@
 #include "BulletCollision/CollisionShapes/btConvexShape.h"
 #include "BulletCollision/CollisionShapes/btCapsuleShape.h"
+#include "BulletCollision/CollisionShapes/btTriangleShape.h"
+
 
 
@@ -49,5 +51,5 @@
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
-
+#include "BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h"
 
 
@@ -332,4 +334,6 @@
 
 
+
+
 #ifdef USE_SEPDISTANCE_UTIL2
 	if (dispatchInfo.m_useConvexConservativeDistanceUtil)
@@ -358,11 +362,12 @@
 #endif //USE_SEPDISTANCE_UTIL2
 	{
-		if (dispatchInfo.m_convexMaxDistanceUseCPT)
-		{
-			input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactProcessingThreshold();
-		} else
-		{
-			input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold();
-		}
+		//if (dispatchInfo.m_convexMaxDistanceUseCPT)
+		//{
+		//	input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactProcessingThreshold();
+		//} else
+		//{
+		input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold();
+//		}
+
 		input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared;
 	}
@@ -372,5 +377,5 @@
 	input.m_transformB = body1->getWorldTransform();
 
-	gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
+
 
 	
@@ -389,4 +394,98 @@
 	}
 #endif //USE_SEPDISTANCE_UTIL2
+
+	if (min0->isPolyhedral() && min1->isPolyhedral())
+	{
+
+
+		struct btDummyResult : public btDiscreteCollisionDetectorInterface::Result
+		{
+			virtual void setShapeIdentifiersA(int partId0,int index0){}
+			virtual void setShapeIdentifiersB(int partId1,int index1){}
+			virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth) 
+			{
+			}
+		};
+		
+		btDummyResult dummy;
+
+
+		btPolyhedralConvexShape* polyhedronA = (btPolyhedralConvexShape*) min0;
+		btPolyhedralConvexShape* polyhedronB = (btPolyhedralConvexShape*) min1;
+		if (polyhedronA->getConvexPolyhedron() && polyhedronB->getConvexPolyhedron())
+		{
+
+
+			gjkPairDetector.getClosestPoints(input,dummy,dispatchInfo.m_debugDraw);
+			
+
+			btScalar threshold = m_manifoldPtr->getContactBreakingThreshold();
+
+			btScalar minDist = 0.f;
+			btVector3 sepNormalWorldSpace;
+			bool foundSepAxis  = true;
+
+			if (dispatchInfo.m_enableSatConvex)
+			{
+				foundSepAxis = btPolyhedralContactClipping::findSeparatingAxis(
+					*polyhedronA->getConvexPolyhedron(), *polyhedronB->getConvexPolyhedron(),
+					body0->getWorldTransform(), 
+					body1->getWorldTransform(),
+					sepNormalWorldSpace);
+			} else
+			{
+				sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized();
+				minDist = gjkPairDetector.getCachedSeparatingDistance();
+			}
+			if (foundSepAxis)
+			{
+//				printf("sepNormalWorldSpace=%f,%f,%f\n",sepNormalWorldSpace.getX(),sepNormalWorldSpace.getY(),sepNormalWorldSpace.getZ());
+
+				btPolyhedralContactClipping::clipHullAgainstHull(sepNormalWorldSpace, *polyhedronA->getConvexPolyhedron(), *polyhedronB->getConvexPolyhedron(),
+					body0->getWorldTransform(), 
+					body1->getWorldTransform(), minDist-threshold, threshold, *resultOut);
+ 				
+			}
+			if (m_ownManifold)
+			{
+				resultOut->refreshContactPoints();
+			}
+			return;
+
+		} else
+		{
+			//we can also deal with convex versus triangle (without connectivity data)
+			if (polyhedronA->getConvexPolyhedron() && polyhedronB->getShapeType()==TRIANGLE_SHAPE_PROXYTYPE)
+			{
+				gjkPairDetector.getClosestPoints(input,dummy,dispatchInfo.m_debugDraw);
+		
+				btVector3 sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized();
+
+				btVertexArray vertices;
+				btTriangleShape* tri = (btTriangleShape*)polyhedronB;
+				vertices.push_back(	body1->getWorldTransform()*tri->m_vertices1[0]);
+				vertices.push_back(	body1->getWorldTransform()*tri->m_vertices1[1]);
+				vertices.push_back(	body1->getWorldTransform()*tri->m_vertices1[2]);
+
+				btScalar threshold = m_manifoldPtr->getContactBreakingThreshold();
+				btScalar minDist = gjkPairDetector.getCachedSeparatingDistance();
+				btPolyhedralContactClipping::clipFaceAgainstHull(sepNormalWorldSpace, *polyhedronA->getConvexPolyhedron(), 
+					body0->getWorldTransform(), vertices, minDist-threshold, threshold, *resultOut);
+				
+				
+				if (m_ownManifold)
+				{
+					resultOut->refreshContactPoints();
+				}
+				
+				return;
+			}
+			
+		}
+
+
+	}
+	
+	gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
 
 	//now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef CONVEX_CONVEX_ALGORITHM_H
-#define CONVEX_CONVEX_ALGORITHM_H
+#ifndef BT_CONVEX_CONVEX_ALGORITHM_H
+#define BT_CONVEX_CONVEX_ALGORITHM_H
 
 #include "btActivatingCollisionAlgorithm.h"
@@ -107,3 +107,3 @@
 };
 
-#endif //CONVEX_CONVEX_ALGORITHM_H
+#endif //BT_CONVEX_CONVEX_ALGORITHM_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef CONVEX_PLANE_COLLISION_ALGORITHM_H
-#define CONVEX_PLANE_COLLISION_ALGORITHM_H
+#ifndef BT_CONVEX_PLANE_COLLISION_ALGORITHM_H
+#define BT_CONVEX_PLANE_COLLISION_ALGORITHM_H
 
 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
@@ -81,4 +81,4 @@
 };
 
-#endif //CONVEX_PLANE_COLLISION_ALGORITHM_H
+#endif //BT_CONVEX_PLANE_COLLISION_ALGORITHM_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef EMPTY_ALGORITH
-#define EMPTY_ALGORITH
+#ifndef BT_EMPTY_ALGORITH
+#define BT_EMPTY_ALGORITH
 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
 #include "btCollisionCreateFunc.h"
@@ -52,3 +52,3 @@
 } ATTRIBUTE_ALIGNED(16);
 
-#endif //EMPTY_ALGORITH
+#endif //BT_EMPTY_ALGORITH
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp	(revision 8393)
@@ -2,4 +2,5 @@
 
 #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
+#include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h"
 #include "BulletCollision/CollisionShapes/btTriangleShape.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
@@ -9,5 +10,4 @@
 
 //#define DEBUG_INTERNAL_EDGE
-
 
 #ifdef DEBUG_INTERNAL_EDGE
@@ -457,6 +457,12 @@
 		return;
 
-	btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)colObj0->getRootCollisionShape();
-	btTriangleInfoMap* triangleInfoMapPtr = (btTriangleInfoMap*) trimesh->getTriangleInfoMap();
+	btBvhTriangleMeshShape* trimesh = 0;
+	
+	if( colObj0->getRootCollisionShape()->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE )
+	   trimesh = ((btScaledBvhTriangleMeshShape*)colObj0->getRootCollisionShape())->getChildShape();
+   else	   
+	   trimesh = (btBvhTriangleMeshShape*)colObj0->getRootCollisionShape();
+	   
+   	btTriangleInfoMap* triangleInfoMapPtr = (btTriangleInfoMap*) trimesh->getTriangleInfoMap();
 	if (!triangleInfoMapPtr)
 		return;
@@ -502,6 +508,54 @@
 	btVector3 localContactNormalOnB = colObj0->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
 	localContactNormalOnB.normalize();//is this necessary?
-
-	if ((info->m_edgeV0V1Angle)< SIMD_2_PI)
+	
+	// Get closest edge
+	int      bestedge=-1;
+	float    disttobestedge=BT_LARGE_FLOAT;
+	//
+	// Edge 0 -> 1
+	if (btFabs(info->m_edgeV0V1Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
+	{	
+	   btVector3 nearest;
+	   btNearestPointInLineSegment( cp.m_localPointB, v0, v1, nearest );
+	   float     len=(contact-nearest).length();
+	   //
+	   if( len < disttobestedge )
+	   {
+	      bestedge=0;
+	      disttobestedge=len;
+      }	      
+   }	   
+	// Edge 1 -> 2
+	if (btFabs(info->m_edgeV1V2Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
+	{	
+	   btVector3 nearest;
+	   btNearestPointInLineSegment( cp.m_localPointB, v1, v2, nearest );
+	   float     len=(contact-nearest).length();
+	   //
+	   if( len < disttobestedge )
+	   {
+	      bestedge=1;
+	      disttobestedge=len;
+      }	      
+   }	   
+	// Edge 2 -> 0
+	if (btFabs(info->m_edgeV2V0Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
+	{	
+	   btVector3 nearest;
+	   btNearestPointInLineSegment( cp.m_localPointB, v2, v0, nearest );
+	   float     len=(contact-nearest).length();
+	   //
+	   if( len < disttobestedge )
+	   {
+	      bestedge=2;
+	      disttobestedge=len;
+      }	      
+   }   	      	
+	
+#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
+   btVector3 upfix=tri_normal * btVector3(0.1f,0.1f,0.1f);
+   btDebugDrawLine(tr * v0 + upfix, tr * v1 + upfix, red );
+#endif   
+	if (btFabs(info->m_edgeV0V1Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
 	{
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
@@ -510,4 +564,5 @@
 		btScalar len = (contact-nearest).length();
 		if(len<triangleInfoMapPtr->m_edgeDistanceThreshold)
+		if( bestedge==0 )
 		{
 			btVector3 edge(v0-v1);
@@ -578,5 +633,9 @@
 #endif //BT_INTERNAL_EDGE_DEBUG_DRAW
 
-	if ((info->m_edgeV1V2Angle)< SIMD_2_PI)
+#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
+   btDebugDrawLine(tr * v1 + upfix, tr * v2 + upfix , green );
+#endif   
+
+	if (btFabs(info->m_edgeV1V2Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
 	{
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
@@ -588,4 +647,5 @@
 		btScalar len = (contact-nearest).length();
 		if(len<triangleInfoMapPtr->m_edgeDistanceThreshold)
+		if( bestedge==1 )
 		{
 			isNearEdge = true;
@@ -659,6 +719,9 @@
 	btDebugDrawLine(tr*nearest,tr*cp.m_localPointB,blue);
 #endif //BT_INTERNAL_EDGE_DEBUG_DRAW
-
-	if ((info->m_edgeV2V0Angle)< SIMD_2_PI)
+#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
+   btDebugDrawLine(tr * v2 + upfix, tr * v0 + upfix , blue );
+#endif   
+
+	if (btFabs(info->m_edgeV2V0Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
 	{
 
@@ -669,4 +732,5 @@
 		btScalar len = (contact-nearest).length();
 		if(len<triangleInfoMapPtr->m_edgeDistanceThreshold)
+		if( bestedge==2 )
 		{
 			isNearEdge = true;
@@ -760,9 +824,15 @@
 			} else
 			{
+				btVector3 newNormal = tri_normal *frontFacing;
+				//if the tri_normal is pointing opposite direction as the current local contact normal, skip it
+				btScalar d = newNormal.dot(localContactNormalOnB) ;
+				if (d< 0)
+				{
+					return;
+				}
 				//modify the normal to be the triangle normal (or backfacing normal)
-				cp.m_normalWorldOnB = colObj0->getWorldTransform().getBasis() *(tri_normal *frontFacing);
-			}
-			
-			
+				cp.m_normalWorldOnB = colObj0->getWorldTransform().getBasis() *newNormal;
+			}
+						
 			// Reproject collision point along normal.
 			cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.cpp	(revision 8393)
@@ -64,6 +64,7 @@
 	btAssert(m_manifoldPtr);
 	//order in manifold needs to match
-	
-	if (depth > m_manifoldPtr->getContactBreakingThreshold())
+
+//	if (depth > m_manifoldPtr->getContactBreakingThreshold())
+	if (depth > m_manifoldPtr->getContactProcessingThreshold())
 		return;
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.h	(revision 8393)
@@ -15,6 +15,6 @@
 
 
-#ifndef MANIFOLD_RESULT_H
-#define MANIFOLD_RESULT_H
+#ifndef BT_MANIFOLD_RESULT_H
+#define BT_MANIFOLD_RESULT_H
 
 class btCollisionObject;
@@ -126,3 +126,3 @@
 };
 
-#endif //MANIFOLD_RESULT_H
+#endif //BT_MANIFOLD_RESULT_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp	(revision 8393)
@@ -393,5 +393,5 @@
 
 
-			   bool islandSleeping = false;
+			   bool islandSleeping = true;
 	                
 					for (endIslandIndex = startIslandIndex;(endIslandIndex<numElem) && (getUnionFind().getElement(endIslandIndex).m_id == islandId);endIslandIndex++)
@@ -400,6 +400,6 @@
 							btCollisionObject* colObj0 = collisionObjects[i];
 							m_islandBodies.push_back(colObj0);
-							if (!colObj0->isActive())
-									islandSleeping = true;
+							if (colObj0->isActive())
+									islandSleeping = false;
 					}
 	                
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef SIMULATION_ISLAND_MANAGER_H
-#define SIMULATION_ISLAND_MANAGER_H
+#ifndef BT_SIMULATION_ISLAND_MANAGER_H
+#define BT_SIMULATION_ISLAND_MANAGER_H
 
 #include "BulletCollision/CollisionDispatch/btUnionFind.h"
@@ -78,4 +78,4 @@
 };
 
-#endif //SIMULATION_ISLAND_MANAGER_H
+#endif //BT_SIMULATION_ISLAND_MANAGER_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef SPHERE_BOX_COLLISION_ALGORITHM_H
-#define SPHERE_BOX_COLLISION_ALGORITHM_H
+#ifndef BT_SPHERE_BOX_COLLISION_ALGORITHM_H
+#define BT_SPHERE_BOX_COLLISION_ALGORITHM_H
 
 #include "btActivatingCollisionAlgorithm.h"
@@ -72,4 +72,4 @@
 };
 
-#endif //SPHERE_BOX_COLLISION_ALGORITHM_H
+#endif //BT_SPHERE_BOX_COLLISION_ALGORITHM_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef SPHERE_SPHERE_COLLISION_ALGORITHM_H
-#define SPHERE_SPHERE_COLLISION_ALGORITHM_H
+#ifndef BT_SPHERE_SPHERE_COLLISION_ALGORITHM_H
+#define BT_SPHERE_SPHERE_COLLISION_ALGORITHM_H
 
 #include "btActivatingCollisionAlgorithm.h"
@@ -63,4 +63,4 @@
 };
 
-#endif //SPHERE_SPHERE_COLLISION_ALGORITHM_H
+#endif //BT_SPHERE_SPHERE_COLLISION_ALGORITHM_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef SPHERE_TRIANGLE_COLLISION_ALGORITHM_H
-#define SPHERE_TRIANGLE_COLLISION_ALGORITHM_H
+#ifndef BT_SPHERE_TRIANGLE_COLLISION_ALGORITHM_H
+#define BT_SPHERE_TRIANGLE_COLLISION_ALGORITHM_H
 
 #include "btActivatingCollisionAlgorithm.h"
@@ -66,4 +66,4 @@
 };
 
-#endif //SPHERE_TRIANGLE_COLLISION_ALGORITHM_H
+#endif //BT_SPHERE_TRIANGLE_COLLISION_ALGORITHM_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btUnionFind.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btUnionFind.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btUnionFind.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef UNION_FIND_H
-#define UNION_FIND_H
+#ifndef BT_UNION_FIND_H
+#define BT_UNION_FIND_H
 
 #include "LinearMath/btAlignedObjectArray.h"
@@ -127,3 +127,3 @@
 
 
-#endif //UNION_FIND_H
+#endif //BT_UNION_FIND_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBox2dShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBox2dShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBox2dShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef OBB_BOX_2D_SHAPE_H
-#define OBB_BOX_2D_SHAPE_H
+#ifndef BT_OBB_BOX_2D_SHAPE_H
+#define BT_OBB_BOX_2D_SHAPE_H
 
 #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
@@ -359,5 +359,5 @@
 };
 
-#endif //OBB_BOX_2D_SHAPE_H
-
-
+#endif //BT_OBB_BOX_2D_SHAPE_H
+
+
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBoxShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBoxShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBoxShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef OBB_BOX_MINKOWSKI_H
-#define OBB_BOX_MINKOWSKI_H
+#ifndef BT_OBB_BOX_MINKOWSKI_H
+#define BT_OBB_BOX_MINKOWSKI_H
 
 #include "btPolyhedralConvexShape.h"
@@ -146,5 +146,5 @@
 	virtual void getVertex(int i,btVector3& vtx) const
 	{
-		btVector3 halfExtents = getHalfExtentsWithoutMargin();
+		btVector3 halfExtents = getHalfExtentsWithMargin();
 
 		vtx = btVector3(
@@ -314,5 +314,5 @@
 
 
-#endif //OBB_BOX_MINKOWSKI_H
-
-
+#endif //BT_OBB_BOX_MINKOWSKI_H
+
+
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp	(revision 8393)
@@ -278,5 +278,5 @@
 
 			unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
-			btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT);
+			btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT||indicestype==PHY_UCHAR);
 	
 			const btVector3& meshScaling = m_meshInterface->getScaling();
@@ -284,5 +284,5 @@
 			{
 				
-				int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
+				int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:indicestype==PHY_INTEGER?gfxbase[j]:((unsigned char*)gfxbase)[j];
 
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef BVH_TRIANGLE_MESH_SHAPE_H
-#define BVH_TRIANGLE_MESH_SHAPE_H
+#ifndef BT_BVH_TRIANGLE_MESH_SHAPE_H
+#define BT_BVH_TRIANGLE_MESH_SHAPE_H
 
 #include "btTriangleMeshShape.h"
@@ -40,5 +40,5 @@
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
-	btBvhTriangleMeshShape() : btTriangleMeshShape(0),m_bvh(0),m_triangleInfoMap(0),m_ownsBvh(false) {m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;};
+	
 	btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true);
 
@@ -137,3 +137,3 @@
 
 
-#endif //BVH_TRIANGLE_MESH_SHAPE_H
+#endif //BT_BVH_TRIANGLE_MESH_SHAPE_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCollisionMargin.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCollisionMargin.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCollisionMargin.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef COLLISION_MARGIN_H
-#define COLLISION_MARGIN_H
+#ifndef BT_COLLISION_MARGIN_H
+#define BT_COLLISION_MARGIN_H
 
 //used by Gjk and some other algorithms
@@ -23,4 +23,4 @@
 
 
-#endif //COLLISION_MARGIN_H
+#endif //BT_COLLISION_MARGIN_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCollisionShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCollisionShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCollisionShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef COLLISION_SHAPE_H
-#define COLLISION_SHAPE_H
+#ifndef BT_COLLISION_SHAPE_H
+#define BT_COLLISION_SHAPE_H
 
 #include "LinearMath/btTransform.h"
@@ -147,4 +147,4 @@
 
 
-#endif //COLLISION_SHAPE_H
+#endif //BT_COLLISION_SHAPE_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp	(revision 8393)
@@ -86,5 +86,5 @@
 }
 
-void	btCompoundShape::updateChildTransform(int childIndex, const btTransform& newChildTransform)
+void	btCompoundShape::updateChildTransform(int childIndex, const btTransform& newChildTransform,bool shouldRecalculateLocalAabb)
 {
 	m_children[childIndex].m_transform = newChildTransform;
@@ -100,5 +100,8 @@
 	}
 
-	recalculateLocalAabb();
+	if (shouldRecalculateLocalAabb)
+	{
+		recalculateLocalAabb();
+	}
 }
 
@@ -284,8 +287,10 @@
 		m_children[i].m_childShape->setLocalScaling(childScale);
 		childTrans.setOrigin((childTrans.getOrigin())*scaling);
-		updateChildTransform(i, childTrans);
-		recalculateLocalAabb();
-	}
+		updateChildTransform(i, childTrans,false);
+	}
+	
 	m_localScaling = scaling;
+	recalculateLocalAabb();
+
 }
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCompoundShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCompoundShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCompoundShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef COMPOUND_SHAPE_H
-#define COMPOUND_SHAPE_H
+#ifndef BT_COMPOUND_SHAPE_H
+#define BT_COMPOUND_SHAPE_H
 
 #include "btCollisionShape.h"
@@ -107,5 +107,5 @@
 
 	///set a new transform for a child, and update internal data structures (local aabb and dynamic tree)
-	void	updateChildTransform(int childIndex, const btTransform& newChildTransform);
+	void	updateChildTransform(int childIndex, const btTransform& newChildTransform, bool shouldRecalculateLocalAabb = true);
 
 
@@ -144,6 +144,10 @@
 	}
 
-
-	btDbvt*							getDynamicAabbTree()
+	const btDbvt*	getDynamicAabbTree() const
+	{
+		return m_dynamicAabbTree;
+	}
+	
+	btDbvt*	getDynamicAabbTree()
 	{
 		return m_dynamicAabbTree;
@@ -206,3 +210,3 @@
 
 
-#endif //COMPOUND_SHAPE_H
+#endif //BT_COMPOUND_SHAPE_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConcaveShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConcaveShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConcaveShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef CONCAVE_SHAPE_H
-#define CONCAVE_SHAPE_H
+#ifndef BT_CONCAVE_SHAPE_H
+#define BT_CONCAVE_SHAPE_H
 
 #include "btCollisionShape.h"
@@ -58,3 +58,3 @@
 };
 
-#endif //CONCAVE_SHAPE_H
+#endif //BT_CONCAVE_SHAPE_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConeShape.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConeShape.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConeShape.cpp	(revision 8393)
@@ -132,2 +132,12 @@
 
 
+void	btConeShape::setLocalScaling(const btVector3& scaling)
+{
+	int axis = m_coneIndices[1];
+	int r1 = m_coneIndices[0];
+	int r2 = m_coneIndices[2];
+	m_height *= scaling[axis] / m_localScaling[axis];
+	m_radius *= (scaling[r1] / m_localScaling[r1] + scaling[r2] / m_localScaling[r2]) / 2;
+	m_sinAngle = (m_radius / btSqrt(m_radius * m_radius + m_height * m_height));
+	btConvexInternalShape::setLocalScaling(scaling);
+}
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConeShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConeShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConeShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef CONE_MINKOWSKI_H
-#define CONE_MINKOWSKI_H
+#ifndef BT_CONE_MINKOWSKI_H
+#define BT_CONE_MINKOWSKI_H
 
 #include "btConvexInternalShape.h"
@@ -82,4 +82,7 @@
 			return m_coneIndices[1];
 		}
+
+	virtual void	setLocalScaling(const btVector3& scaling);
+
 };
 
@@ -97,4 +100,4 @@
 		btConeShapeZ(btScalar radius,btScalar height);
 };
-#endif //CONE_MINKOWSKI_H
+#endif //BT_CONE_MINKOWSKI_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvex2dShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvex2dShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvex2dShape.h	(revision 8393)
@@ -20,5 +20,5 @@
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
 
-///The btConvex2dShape allows to use arbitrary convex shapes are 2d convex shapes, with the Z component assumed to be 0.
+///The btConvex2dShape allows to use arbitrary convex shapes as 2d convex shapes, with the Z component assumed to be 0.
 ///For 2d boxes, the btBox2dShape is recommended.
 class btConvex2dShape : public btConvexShape
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexHullShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexHullShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexHullShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef CONVEX_HULL_SHAPE_H
-#define CONVEX_HULL_SHAPE_H
+#ifndef BT_CONVEX_HULL_SHAPE_H
+#define BT_CONVEX_HULL_SHAPE_H
 
 #include "btPolyhedralConvexShape.h"
@@ -117,4 +117,4 @@
 
 
-#endif //CONVEX_HULL_SHAPE_H
+#endif //BT_CONVEX_HULL_SHAPE_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexPolyhedron.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexPolyhedron.cpp	(revision 8393)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexPolyhedron.cpp	(revision 8393)
@@ -0,0 +1,185 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2011 Advanced Micro Devices, Inc.  http://bulletphysics.org
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose, 
+including commercial applications, and to alter it and redistribute it freely, 
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+
+///This file was written by Erwin Coumans
+///Separating axis rest based on work from Pierre Terdiman, see
+///And contact clipping based on work from Simon Hobbs
+
+
+#include "btConvexPolyhedron.h"
+#include "LinearMath/btHashMap.h"
+
+btConvexPolyhedron::btConvexPolyhedron()
+{
+
+}
+btConvexPolyhedron::~btConvexPolyhedron()
+{
+
+}
+
+
+inline bool IsAlmostZero(const btVector3& v)
+{
+	if(fabsf(v.x())>1e-6 || fabsf(v.y())>1e-6 || fabsf(v.z())>1e-6)	return false;
+	return true;
+}
+
+struct btInternalVertexPair
+{
+	btInternalVertexPair(short int v0,short int v1)
+		:m_v0(v0),
+		m_v1(v1)
+	{
+		if (m_v1>m_v0)
+			btSwap(m_v0,m_v1);
+	}
+	short int m_v0;
+	short int m_v1;
+	int getHash() const
+	{
+		return m_v0+(m_v1<<16);
+	}
+	bool equals(const btInternalVertexPair& other) const
+	{
+		return m_v0==other.m_v0 && m_v1==other.m_v1;
+	}
+};
+
+struct btInternalEdge
+{
+	btInternalEdge()
+		:m_face0(-1),
+		m_face1(-1)
+	{
+	}
+	short int m_face0;
+	short int m_face1;
+};
+
+//
+
+void	btConvexPolyhedron::initialize()
+{
+	btHashMap<btInternalVertexPair,btInternalEdge> edges;
+
+	float TotalArea = 0.0f;
+	
+	m_localCenter.setValue(0, 0, 0);
+	for(int i=0;i<m_faces.size();i++)
+	{
+		int numVertices = m_faces[i].m_indices.size();
+		int NbTris = numVertices;
+		for(int j=0;j<NbTris;j++)
+		{
+			int k = (j+1)%numVertices;
+			btInternalVertexPair vp(m_faces[i].m_indices[j],m_faces[i].m_indices[k]);
+			btInternalEdge* edptr = edges.find(vp);
+			btVector3 edge = m_vertices[vp.m_v1]-m_vertices[vp.m_v0];
+			edge.normalize();
+
+			bool found = false;
+
+			for (int p=0;p<m_uniqueEdges.size();p++)
+			{
+				
+				if (IsAlmostZero(m_uniqueEdges[p]-edge) || 
+					IsAlmostZero(m_uniqueEdges[p]+edge))
+				{
+					found = true;
+					break;
+				}
+			}
+
+			if (!found)
+			{
+				m_uniqueEdges.push_back(edge);
+			}
+
+			if (edptr)
+			{
+				btAssert(edptr->m_face0>=0);
+				btAssert(edptr->m_face1<0);
+				edptr->m_face1 = i;
+			} else
+			{
+				btInternalEdge ed;
+				ed.m_face0 = i;
+				edges.insert(vp,ed);
+			}
+		}
+	}
+
+	for(int i=0;i<m_faces.size();i++)
+	{
+		int numVertices = m_faces[i].m_indices.size();
+		m_faces[i].m_connectedFaces.resize(numVertices);
+
+		for(int j=0;j<numVertices;j++)
+		{
+			int k = (j+1)%numVertices;
+			btInternalVertexPair vp(m_faces[i].m_indices[j],m_faces[i].m_indices[k]);
+			btInternalEdge* edptr = edges.find(vp);
+			btAssert(edptr);
+			btAssert(edptr->m_face0>=0);
+			btAssert(edptr->m_face1>=0);
+
+			int connectedFace = (edptr->m_face0==i)?edptr->m_face1:edptr->m_face0;
+			m_faces[i].m_connectedFaces[j] = connectedFace;
+		}
+	}
+
+	for(int i=0;i<m_faces.size();i++)
+	{
+		int numVertices = m_faces[i].m_indices.size();
+		int NbTris = numVertices-2;
+		
+		const btVector3& p0 = m_vertices[m_faces[i].m_indices[0]];
+		for(int j=1;j<=NbTris;j++)
+		{
+			int k = (j+1)%numVertices;
+			const btVector3& p1 = m_vertices[m_faces[i].m_indices[j]];
+			const btVector3& p2 = m_vertices[m_faces[i].m_indices[k]];
+			float Area = ((p0 - p1).cross(p0 - p2)).length() * 0.5f;
+			btVector3 Center = (p0+p1+p2)/3.0f;
+			m_localCenter += Area * Center;
+			TotalArea += Area;
+		}
+	}
+	m_localCenter /= TotalArea;
+
+}
+
+
+void btConvexPolyhedron::project(const btTransform& trans, const btVector3& dir, float& min, float& max) const
+{
+	min = FLT_MAX;
+	max = -FLT_MAX;
+	int numVerts = m_vertices.size();
+	for(int i=0;i<numVerts;i++)
+	{
+		btVector3 pt = trans * m_vertices[i];
+		float dp = pt.dot(dir);
+		if(dp < min)	min = dp;
+		if(dp > max)	max = dp;
+	}
+	if(min>max)
+	{
+		float tmp = min;
+		min = max;
+		max = tmp;
+	}
+}
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexPolyhedron.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexPolyhedron.h	(revision 8393)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexPolyhedron.h	(revision 8393)
@@ -0,0 +1,54 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2011 Advanced Micro Devices, Inc.  http://bulletphysics.org
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose, 
+including commercial applications, and to alter it and redistribute it freely, 
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+
+///This file was written by Erwin Coumans
+
+
+#ifndef _BT_POLYHEDRAL_FEATURES_H
+#define _BT_POLYHEDRAL_FEATURES_H
+
+#include "LinearMath/btTransform.h"
+#include "LinearMath/btAlignedObjectArray.h"
+
+
+struct btFace
+{
+	btAlignedObjectArray<int>	m_indices;
+	btAlignedObjectArray<int>	m_connectedFaces;
+	float	m_plane[4];
+};
+
+
+class btConvexPolyhedron
+{
+	public:
+	btConvexPolyhedron();
+	virtual	~btConvexPolyhedron();
+
+	btAlignedObjectArray<btVector3>	m_vertices;
+	btAlignedObjectArray<btFace>	m_faces;
+	btAlignedObjectArray<btVector3> m_uniqueEdges;
+	btVector3		m_localCenter;
+
+	void	initialize();
+
+	void project(const btTransform& trans, const btVector3& dir, float& min, float& max) const;
+};
+
+	
+#endif //_BT_POLYHEDRAL_FEATURES_H
+
+
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef CONVEX_SHAPE_INTERFACE1
-#define CONVEX_SHAPE_INTERFACE1
+#ifndef BT_CONVEX_SHAPE_INTERFACE1
+#define BT_CONVEX_SHAPE_INTERFACE1
 
 #include "btCollisionShape.h"
@@ -80,3 +80,3 @@
 
 
-#endif //CONVEX_SHAPE_INTERFACE1
+#endif //BT_CONVEX_SHAPE_INTERFACE1
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h	(revision 8393)
@@ -13,6 +13,6 @@
 3. This notice may not be removed or altered from any source distribution.
 */
-#ifndef CONVEX_TRIANGLEMESH_SHAPE_H
-#define CONVEX_TRIANGLEMESH_SHAPE_H
+#ifndef BT_CONVEX_TRIANGLEMESH_SHAPE_H
+#define BT_CONVEX_TRIANGLEMESH_SHAPE_H
 
 
@@ -70,5 +70,5 @@
 
 
-#endif //CONVEX_TRIANGLEMESH_SHAPE_H
+#endif //BT_CONVEX_TRIANGLEMESH_SHAPE_H
 
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp	(revision 8393)
@@ -48,5 +48,62 @@
 void	btCylinderShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
 {
-	//approximation of box shape, todo: implement cylinder shape inertia before people notice ;-)
+
+//Until Bullet 2.77 a box approximation was used, so uncomment this if you need backwards compatibility
+//#define USE_BOX_INERTIA_APPROXIMATION 1
+#ifndef USE_BOX_INERTIA_APPROXIMATION
+
+	/*
+	cylinder is defined as following:
+	*
+	* - principle axis aligned along y by default, radius in x, z-value not used
+	* - for btCylinderShapeX: principle axis aligned along x, radius in y direction, z-value not used
+	* - for btCylinderShapeZ: principle axis aligned along z, radius in x direction, y-value not used
+	*
+	*/
+
+	btScalar radius2;	// square of cylinder radius
+	btScalar height2;	// square of cylinder height
+	btVector3 halfExtents = getHalfExtentsWithMargin();	// get cylinder dimension
+	btScalar div12 = mass / 12.f;
+	btScalar div4 = mass / 4.f;
+	btScalar div2 = mass / 2.f;
+	int idxRadius, idxHeight;
+
+	switch (m_upAxis)	// get indices of radius and height of cylinder
+	{
+		case 0:		// cylinder is aligned along x
+			idxRadius = 1;
+			idxHeight = 0;
+			break;
+		case 2:		// cylinder is aligned along z
+			idxRadius = 0;
+			idxHeight = 2;
+			break;
+		default:	// cylinder is aligned along y
+			idxRadius = 0;
+			idxHeight = 1;
+	}
+
+	// calculate squares
+	radius2 = halfExtents[idxRadius] * halfExtents[idxRadius];
+	height2 = btScalar(4.) * halfExtents[idxHeight] * halfExtents[idxHeight];
+
+	// calculate tensor terms
+	btScalar t1 = div12 * height2 + div4 * radius2;
+	btScalar t2 = div2 * radius2;
+
+	switch (m_upAxis)	// set diagonal elements of inertia tensor
+	{
+		case 0:		// cylinder is aligned along x
+			inertia.setValue(t2,t1,t1);
+			break;
+		case 2:		// cylinder is aligned along z
+			inertia.setValue(t1,t1,t2);
+			break;
+		default:	// cylinder is aligned along y
+			inertia.setValue(t1,t2,t1);
+	}
+#else //USE_BOX_INERTIA_APPROXIMATION
+	//approximation of box shape
 	btVector3 halfExtents = getHalfExtentsWithMargin();
 
@@ -58,5 +115,5 @@
 					mass/(btScalar(12.0)) * (lx*lx + lz*lz),
 					mass/(btScalar(12.0)) * (lx*lx + ly*ly));
-
+#endif //USE_BOX_INERTIA_APPROXIMATION
 }
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef CYLINDER_MINKOWSKI_H
-#define CYLINDER_MINKOWSKI_H
+#ifndef BT_CYLINDER_MINKOWSKI_H
+#define BT_CYLINDER_MINKOWSKI_H
 
 #include "btBoxShape.h"
@@ -197,4 +197,4 @@
 
 
-#endif //CYLINDER_MINKOWSKI_H
-
+#endif //BT_CYLINDER_MINKOWSKI_H
+
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btEmptyShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btEmptyShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btEmptyShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef EMPTY_SHAPE_H
-#define EMPTY_SHAPE_H
+#ifndef BT_EMPTY_SHAPE_H
+#define BT_EMPTY_SHAPE_H
 
 #include "btConcaveShape.h"
@@ -68,3 +68,3 @@
 
 
-#endif //EMPTY_SHAPE_H
+#endif //BT_EMPTY_SHAPE_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef HEIGHTFIELD_TERRAIN_SHAPE_H
-#define HEIGHTFIELD_TERRAIN_SHAPE_H
+#ifndef BT_HEIGHTFIELD_TERRAIN_SHAPE_H
+#define BT_HEIGHTFIELD_TERRAIN_SHAPE_H
 
 #include "btConcaveShape.h"
@@ -159,3 +159,3 @@
 };
 
-#endif //HEIGHTFIELD_TERRAIN_SHAPE_H
+#endif //BT_HEIGHTFIELD_TERRAIN_SHAPE_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMaterial.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMaterial.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMaterial.h	(revision 8393)
@@ -16,6 +16,6 @@
 /// This file was created by Alex Silverman
 
-#ifndef MATERIAL_H
-#define MATERIAL_H
+#ifndef BT_MATERIAL_H
+#define BT_MATERIAL_H
 
 // Material class to be used by btMultimaterialTriangleMeshShape to store triangle properties
@@ -32,4 +32,4 @@
 };
 
-#endif // MATERIAL_H
+#endif // BT_MATERIAL_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef MINKOWSKI_SUM_SHAPE_H
-#define MINKOWSKI_SUM_SHAPE_H
+#ifndef BT_MINKOWSKI_SUM_SHAPE_H
+#define BT_MINKOWSKI_SUM_SHAPE_H
 
 #include "btConvexInternalShape.h"
@@ -58,3 +58,3 @@
 };
 
-#endif //MINKOWSKI_SUM_SHAPE_H
+#endif //BT_MINKOWSKI_SUM_SHAPE_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMultiSphereShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMultiSphereShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMultiSphereShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef MULTI_SPHERE_MINKOWSKI_H
-#define MULTI_SPHERE_MINKOWSKI_H
+#ifndef BT_MULTI_SPHERE_MINKOWSKI_H
+#define BT_MULTI_SPHERE_MINKOWSKI_H
 
 #include "btConvexInternalShape.h"
@@ -97,3 +97,3 @@
 
 
-#endif //MULTI_SPHERE_MINKOWSKI_H
+#endif //BT_MULTI_SPHERE_MINKOWSKI_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h	(revision 8393)
@@ -16,6 +16,6 @@
 /// This file was created by Alex Silverman
 
-#ifndef BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H
-#define BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H
+#ifndef BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H
+#define BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H
 
 #include "btBvhTriangleMeshShape.h"
@@ -32,5 +32,4 @@
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
-    btMultimaterialTriangleMeshShape(): btBvhTriangleMeshShape() {m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;}
     btMultimaterialTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true):
         btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, buildBvh)
@@ -119,3 +118,3 @@
 ;
 
-#endif //BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H
+#endif //BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.h	(revision 8393)
@@ -16,6 +16,6 @@
 ///Contains contributions from Disney Studio's
 
-#ifndef OPTIMIZED_BVH_H
-#define OPTIMIZED_BVH_H
+#ifndef BT_OPTIMIZED_BVH_H
+#define BT_OPTIMIZED_BVH_H
 
 #include "BulletCollision/BroadphaseCollision/btQuantizedBvh.h"
@@ -61,5 +61,5 @@
 
 
-#endif //OPTIMIZED_BVH_H
+#endif //BT_OPTIMIZED_BVH_H
 
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp	(revision 8393)
@@ -15,8 +15,150 @@
 
 #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
-
-btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape()
-{
-
+#include "btConvexPolyhedron.h"
+#include "LinearMath/btConvexHullComputer.h"
+#include <new>
+
+btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape(),
+m_polyhedron(0)
+{
+
+}
+
+btPolyhedralConvexShape::~btPolyhedralConvexShape()
+{
+	if (m_polyhedron)
+	{
+		btAlignedFree(m_polyhedron);
+	}
+}
+
+bool	btPolyhedralConvexShape::initializePolyhedralFeatures()
+{
+	if (m_polyhedron)
+		btAlignedFree(m_polyhedron);
+	
+	void* mem = btAlignedAlloc(sizeof(btConvexPolyhedron),16);
+	m_polyhedron = new (mem) btConvexPolyhedron;
+
+	btAlignedObjectArray<btVector3> tmpVertices;
+	for (int i=0;i<getNumVertices();i++)
+	{
+		btVector3& newVertex = tmpVertices.expand();
+		getVertex(i,newVertex);
+	}
+
+	btConvexHullComputer conv;
+	conv.compute(&tmpVertices[0].getX(), sizeof(btVector3),tmpVertices.size(),0.f,0.f);
+
+	
+
+	btAlignedObjectArray<btVector3> faceNormals;
+	int numFaces = conv.faces.size();
+	faceNormals.resize(numFaces);
+	btConvexHullComputer* convexUtil = &conv;
+
+	
+	
+	m_polyhedron->m_faces.resize(numFaces);
+	int numVertices = convexUtil->vertices.size();
+	m_polyhedron->m_vertices.resize(numVertices);
+	for (int p=0;p<numVertices;p++)
+	{
+		m_polyhedron->m_vertices[p] = convexUtil->vertices[p];
+	}
+
+	for (int i=0;i<numFaces;i++)
+	{
+		int face = convexUtil->faces[i];
+		//printf("face=%d\n",face);
+		const btConvexHullComputer::Edge*  firstEdge = &convexUtil->edges[face];
+		const btConvexHullComputer::Edge*  edge = firstEdge;
+
+		btVector3 edges[3];
+		int numEdges = 0;
+		//compute face normals
+
+		btScalar maxCross2 = 0.f;
+		int chosenEdge = -1;
+
+		do
+		{
+			
+			int src = edge->getSourceVertex();
+			m_polyhedron->m_faces[i].m_indices.push_back(src);
+			int targ = edge->getTargetVertex();
+			btVector3 wa = convexUtil->vertices[src];
+
+			btVector3 wb = convexUtil->vertices[targ];
+			btVector3 newEdge = wb-wa;
+			newEdge.normalize();
+			if (numEdges<2)
+				edges[numEdges++] = newEdge;
+
+			edge = edge->getNextEdgeOfFace();
+		} while (edge!=firstEdge);
+
+		btScalar planeEq = 1e30f;
+
+		
+		if (numEdges==2)
+		{
+			faceNormals[i] = edges[0].cross(edges[1]);
+			faceNormals[i].normalize();
+			m_polyhedron->m_faces[i].m_plane[0] = -faceNormals[i].getX();
+			m_polyhedron->m_faces[i].m_plane[1] = -faceNormals[i].getY();
+			m_polyhedron->m_faces[i].m_plane[2] = -faceNormals[i].getZ();
+			m_polyhedron->m_faces[i].m_plane[3] = planeEq;
+
+		}
+		else
+		{
+			btAssert(0);//degenerate?
+			faceNormals[i].setZero();
+		}
+
+		for (int v=0;v<m_polyhedron->m_faces[i].m_indices.size();v++)
+		{
+			btScalar eq = m_polyhedron->m_vertices[m_polyhedron->m_faces[i].m_indices[v]].dot(faceNormals[i]);
+			if (planeEq>eq)
+			{
+				planeEq=eq;
+			}
+		}
+		m_polyhedron->m_faces[i].m_plane[3] = planeEq;
+	}
+
+
+	if (m_polyhedron->m_faces.size() && conv.vertices.size())
+	{
+
+		for (int f=0;f<m_polyhedron->m_faces.size();f++)
+		{
+			
+			btVector3 planeNormal(m_polyhedron->m_faces[f].m_plane[0],m_polyhedron->m_faces[f].m_plane[1],m_polyhedron->m_faces[f].m_plane[2]);
+			btScalar planeEq = m_polyhedron->m_faces[f].m_plane[3];
+
+			btVector3 supVec = localGetSupportingVertex(-planeNormal);
+
+			if (supVec.dot(planeNormal)<planeEq)
+			{
+				m_polyhedron->m_faces[f].m_plane[0] *= -1;
+				m_polyhedron->m_faces[f].m_plane[1] *= -1;
+				m_polyhedron->m_faces[f].m_plane[2] *= -1;
+				m_polyhedron->m_faces[f].m_plane[3] *= -1;
+				int numVerts = m_polyhedron->m_faces[f].m_indices.size();
+				for (int v=0;v<numVerts/2;v++)
+				{
+					btSwap(m_polyhedron->m_faces[f].m_indices[v],m_polyhedron->m_faces[f].m_indices[numVerts-1-v]);
+				}
+			}
+		}
+	}
+
+	
+
+	m_polyhedron->initialize();
+
+	return true;
 }
 
@@ -192,2 +334,5 @@
 }
 
+
+
+
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h	(revision 8393)
@@ -14,9 +14,10 @@
 */
 
-#ifndef BU_SHAPE
-#define BU_SHAPE
+#ifndef BT_POLYHEDRAL_CONVEX_SHAPE_H
+#define BT_POLYHEDRAL_CONVEX_SHAPE_H
 
 #include "LinearMath/btMatrix3x3.h"
 #include "btConvexInternalShape.h"
+class btConvexPolyhedron;
 
 
@@ -24,10 +25,23 @@
 class btPolyhedralConvexShape : public btConvexInternalShape
 {
+	
 
 protected:
 	
+	btConvexPolyhedron* m_polyhedron;
+
 public:
 
 	btPolyhedralConvexShape();
+
+	virtual ~btPolyhedralConvexShape();
+
+	///optional method mainly used to generate multiple contact points by clipping polyhedral features (faces/edges)
+	virtual bool	initializePolyhedralFeatures();
+
+	const btConvexPolyhedron*	getConvexPolyhedron() const
+	{
+		return m_polyhedron;
+	}
 
 	//brute force implementations
@@ -96,3 +110,3 @@
 };
 
-#endif //BU_SHAPE
+#endif //BT_POLYHEDRAL_CONVEX_SHAPE_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp	(revision 8393)
@@ -63,8 +63,10 @@
 	scaledAabbMin[1] = m_localScaling.getY() >= 0. ? aabbMin[1] * invLocalScaling[1] : aabbMax[1] * invLocalScaling[1];
 	scaledAabbMin[2] = m_localScaling.getZ() >= 0. ? aabbMin[2] * invLocalScaling[2] : aabbMax[2] * invLocalScaling[2];
+	scaledAabbMin[3] = 0.f;
 	
 	scaledAabbMax[0] = m_localScaling.getX() <= 0. ? aabbMin[0] * invLocalScaling[0] : aabbMax[0] * invLocalScaling[0];
 	scaledAabbMax[1] = m_localScaling.getY() <= 0. ? aabbMin[1] * invLocalScaling[1] : aabbMax[1] * invLocalScaling[1];
 	scaledAabbMax[2] = m_localScaling.getZ() <= 0. ? aabbMin[2] * invLocalScaling[2] : aabbMax[2] * invLocalScaling[2];
+	scaledAabbMax[3] = 0.f;
 	
 	
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef SCALED_BVH_TRIANGLE_MESH_SHAPE_H
-#define SCALED_BVH_TRIANGLE_MESH_SHAPE_H
+#ifndef BT_SCALED_BVH_TRIANGLE_MESH_SHAPE_H
+#define BT_SCALED_BVH_TRIANGLE_MESH_SHAPE_H
 
 #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
@@ -58,5 +58,36 @@
 	virtual const char*	getName()const {return "SCALEDBVHTRIANGLEMESH";}
 
+	virtual	int	calculateSerializeBufferSize() const;
+
+	///fills the dataBuffer and returns the struct name (and 0 on failure)
+	virtual	const char*	serialize(void* dataBuffer, btSerializer* serializer) const;
+
 };
 
-#endif //BVH_TRIANGLE_MESH_SHAPE_H
+///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
+struct	btScaledTriangleMeshShapeData
+{
+	btTriangleMeshShapeData	m_trimeshShapeData;
+
+	btVector3FloatData	m_localScaling;
+};
+
+
+SIMD_FORCE_INLINE	int	btScaledBvhTriangleMeshShape::calculateSerializeBufferSize() const
+{
+	return sizeof(btScaledTriangleMeshShapeData);
+}
+
+
+///fills the dataBuffer and returns the struct name (and 0 on failure)
+SIMD_FORCE_INLINE	const char*	btScaledBvhTriangleMeshShape::serialize(void* dataBuffer, btSerializer* serializer) const
+{
+	btScaledTriangleMeshShapeData* scaledMeshData = (btScaledTriangleMeshShapeData*) dataBuffer;
+	m_bvhTriMeshShape->serialize(&scaledMeshData->m_trimeshShapeData,serializer);
+	scaledMeshData->m_trimeshShapeData.m_collisionShapeData.m_shapeType = SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE;
+	m_localScaling.serializeFloat(scaledMeshData->m_localScaling);
+	return "btScaledTriangleMeshShapeData";
+}
+
+
+#endif //BT_SCALED_BVH_TRIANGLE_MESH_SHAPE_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btShapeHull.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btShapeHull.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btShapeHull.h	(revision 8393)
@@ -16,6 +16,6 @@
 ///btShapeHull implemented by John McCutchan.
 
-#ifndef _SHAPE_HULL_H
-#define _SHAPE_HULL_H
+#ifndef BT_SHAPE_HULL_H
+#define BT_SHAPE_HULL_H
 
 #include "LinearMath/btAlignedObjectArray.h"
@@ -57,3 +57,3 @@
 };
 
-#endif //_SHAPE_HULL_H
+#endif //BT_SHAPE_HULL_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btSphereShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btSphereShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btSphereShape.h	(revision 8393)
@@ -13,6 +13,6 @@
 3. This notice may not be removed or altered from any source distribution.
 */
-#ifndef SPHERE_MINKOWSKI_H
-#define SPHERE_MINKOWSKI_H
+#ifndef BT_SPHERE_MINKOWSKI_H
+#define BT_SPHERE_MINKOWSKI_H
 
 #include "btConvexInternalShape.h"
@@ -71,3 +71,3 @@
 
 
-#endif //SPHERE_MINKOWSKI_H
+#endif //BT_SPHERE_MINKOWSKI_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btStaticPlaneShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btStaticPlaneShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btStaticPlaneShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef STATIC_PLANE_SHAPE_H
-#define STATIC_PLANE_SHAPE_H
+#ifndef BT_STATIC_PLANE_SHAPE_H
+#define BT_STATIC_PLANE_SHAPE_H
 
 #include "btConcaveShape.h"
@@ -98,5 +98,5 @@
 
 
-#endif //STATIC_PLANE_SHAPE_H
+#endif //BT_STATIC_PLANE_SHAPE_H
 
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp	(revision 8393)
@@ -89,4 +89,19 @@
 					 break;
 				 }
+			case PHY_UCHAR:
+				 {
+					 for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
+					 {
+						 unsigned char* tri_indices= (unsigned char*)(indexbase+gfxindex*indexstride);
+						 graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
+						 triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
+						 graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
+						 triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),	graphicsbase[2]*meshScaling.getZ());
+						 graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
+						 triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),	graphicsbase[2]*meshScaling.getZ());
+						 callback->internalProcessTriangleIndex(triangle,part,gfxindex);
+					 }
+					 break;
+				 }
 			 default:
 				 btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
@@ -121,4 +136,19 @@
 						{
 							unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
+							graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
+							triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ());
+							graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
+							triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),  (btScalar)graphicsbase[2]*meshScaling.getZ());
+							graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
+							triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),  (btScalar)graphicsbase[2]*meshScaling.getZ());
+							callback->internalProcessTriangleIndex(triangle,part,gfxindex);
+						}
+						break;
+					}
+				case PHY_UCHAR:
+					{
+						for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
+						{
+							unsigned char* tri_indices= (unsigned char*)(indexbase+gfxindex*indexstride);
 							graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
 							triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ());
@@ -267,4 +297,22 @@
 					break;
 				}
+				case PHY_UCHAR:
+				{
+					if (numtriangles)
+					{
+						btChunk* chunk = serializer->allocate(sizeof(btCharIndexTripletData),numtriangles);
+						btCharIndexTripletData* tmpIndices = (btCharIndexTripletData*)chunk->m_oldPtr;
+						memPtr->m_3indices8 = (btCharIndexTripletData*) serializer->getUniquePointer(tmpIndices);
+						for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
+						{
+							unsigned char* tri_indices= (unsigned char*)(indexbase+gfxindex*indexstride);
+							tmpIndices[gfxindex].m_values[0] = tri_indices[0];
+							tmpIndices[gfxindex].m_values[1] = tri_indices[1];
+							tmpIndices[gfxindex].m_values[2] = tri_indices[2];
+						}
+						serializer->finalizeChunk(chunk,"btCharIndexTripletData",BT_ARRAY_CODE,(void*)chunk->m_oldPtr);
+					}
+					break;
+				}
 			default:
 				{
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef STRIDING_MESHINTERFACE_H
-#define STRIDING_MESHINTERFACE_H
+#ifndef BT_STRIDING_MESHINTERFACE_H
+#define BT_STRIDING_MESHINTERFACE_H
 
 #include "LinearMath/btVector3.h"
@@ -117,4 +117,11 @@
 };
 
+struct	btCharIndexTripletData
+{
+	unsigned char m_values[3];
+	char	m_pad;
+};
+
+
 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
 struct	btMeshPartData
@@ -125,4 +132,5 @@
 	btIntIndexData				*m_indices32;
 	btShortIntIndexTripletData	*m_3indices16;
+	btCharIndexTripletData		*m_3indices8;
 
 	btShortIntIndexData			*m_indices16;//backwards compatibility
@@ -152,3 +160,3 @@
 
 
-#endif //STRIDING_MESHINTERFACE_H
+#endif //BT_STRIDING_MESHINTERFACE_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef BU_SIMPLEX_1TO4_SHAPE
-#define BU_SIMPLEX_1TO4_SHAPE
+#ifndef BT_SIMPLEX_1TO4_SHAPE
+#define BT_SIMPLEX_1TO4_SHAPE
 
 
@@ -72,3 +72,3 @@
 };
 
-#endif //BU_SIMPLEX_1TO4_SHAPE
+#endif //BT_SIMPLEX_1TO4_SHAPE
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleCallback.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleCallback.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleCallback.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef TRIANGLE_CALLBACK_H
-#define TRIANGLE_CALLBACK_H
+#ifndef BT_TRIANGLE_CALLBACK_H
+#define BT_TRIANGLE_CALLBACK_H
 
 #include "LinearMath/btVector3.h"
@@ -40,3 +40,3 @@
 
 
-#endif //TRIANGLE_CALLBACK_H
+#endif //BT_TRIANGLE_CALLBACK_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleInfoMap.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleInfoMap.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleInfoMap.h	(revision 8393)
@@ -62,4 +62,5 @@
 	btScalar	m_equalVertexThreshold; ///used to compute connectivity: if the distance between two vertices is smaller than m_equalVertexThreshold, they are considered to be 'shared'
 	btScalar	m_edgeDistanceThreshold; ///used to determine edge contacts: if the closest distance between a contact point and an edge is smaller than this distance threshold it is considered to "hit the edge"
+	btScalar	m_maxEdgeAngleThreshold; //ignore edges that connect triangles at an angle larger than this m_maxEdgeAngleThreshold
 	btScalar	m_zeroAreaThreshold; ///used to determine if a triangle is degenerate (length squared of cross product of 2 triangle edges < threshold)
 	
@@ -72,4 +73,5 @@
 		m_edgeDistanceThreshold = btScalar(0.1);
 		m_zeroAreaThreshold = btScalar(0.0001)*btScalar(0.0001);
+		m_maxEdgeAngleThreshold = SIMD_2_PI;
 	}
 	virtual ~btTriangleInfoMap() {}
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMesh.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMesh.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMesh.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef TRIANGLE_MESH_H
-#define TRIANGLE_MESH_H
+#ifndef BT_TRIANGLE_MESH_H
+#define BT_TRIANGLE_MESH_H
 
 #include "btTriangleIndexVertexArray.h"
@@ -66,4 +66,4 @@
 };
 
-#endif //TRIANGLE_MESH_H
+#endif //BT_TRIANGLE_MESH_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef TRIANGLE_MESH_SHAPE_H
-#define TRIANGLE_MESH_SHAPE_H
+#ifndef BT_TRIANGLE_MESH_SHAPE_H
+#define BT_TRIANGLE_MESH_SHAPE_H
 
 #include "btConcaveShape.h"
@@ -87,3 +87,3 @@
 
 
-#endif //TRIANGLE_MESH_SHAPE_H
+#endif //BT_TRIANGLE_MESH_SHAPE_H
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleShape.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleShape.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleShape.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef OBB_TRIANGLE_MINKOWSKI_H
-#define OBB_TRIANGLE_MINKOWSKI_H
+#ifndef BT_OBB_TRIANGLE_MINKOWSKI_H
+#define BT_OBB_TRIANGLE_MINKOWSKI_H
 
 #include "btConvexShape.h"
@@ -179,4 +179,4 @@
 };
 
-#endif //OBB_TRIANGLE_MINKOWSKI_H
+#endif //BT_OBB_TRIANGLE_MINKOWSKI_H
 
Index: code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btUniformScalingShape.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btUniformScalingShape.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btUniformScalingShape.cpp	(revision 8393)
@@ -65,12 +65,7 @@
 
 	///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
-void btUniformScalingShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
+void btUniformScalingShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
 {
-	m_childConvexShape->getAabb(t,aabbMin,aabbMax);
-	btVector3 aabbCenter = (aabbMax+aabbMin)*btScalar(0.5);
-	btVector3 scaledAabbHalfExtends = (aabbMax-aabbMin)*btScalar(0.5)*m_uniformScalingFactor;
-
-	aabbMin = aabbCenter - scaledAabbHalfExtends;
-	aabbMax = aabbCenter + scaledAabbHalfExtends;
+	getAabbSlow(trans,aabbMin,aabbMax);
 
 }
@@ -78,10 +73,60 @@
 void btUniformScalingShape::getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
 {
-	m_childConvexShape->getAabbSlow(t,aabbMin,aabbMax);
-	btVector3 aabbCenter = (aabbMax+aabbMin)*btScalar(0.5);
-	btVector3 scaledAabbHalfExtends = (aabbMax-aabbMin)*btScalar(0.5)*m_uniformScalingFactor;
+#if 1
+	btVector3 _directions[] =
+	{
+		btVector3( 1.,  0.,  0.),
+		btVector3( 0.,  1.,  0.),
+		btVector3( 0.,  0.,  1.),
+		btVector3( -1., 0.,  0.),
+		btVector3( 0., -1.,  0.),
+		btVector3( 0.,  0., -1.)
+	};
+	
+	btVector3 _supporting[] =
+	{
+		btVector3( 0., 0., 0.),
+		btVector3( 0., 0., 0.),
+		btVector3( 0., 0., 0.),
+		btVector3( 0., 0., 0.),
+		btVector3( 0., 0., 0.),
+		btVector3( 0., 0., 0.)
+	};
 
-	aabbMin = aabbCenter - scaledAabbHalfExtends;
-	aabbMax = aabbCenter + scaledAabbHalfExtends;
+	for (int i=0;i<6;i++)
+	{
+		_directions[i] = _directions[i]*t.getBasis();
+	}
+	
+	batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
+	
+	btVector3 aabbMin1(0,0,0),aabbMax1(0,0,0);
+
+	for ( int i = 0; i < 3; ++i )
+	{
+		aabbMax1[i] = t(_supporting[i])[i];
+		aabbMin1[i] = t(_supporting[i + 3])[i];
+	}
+	btVector3 marginVec(getMargin(),getMargin(),getMargin());
+	aabbMin = aabbMin1-marginVec;
+	aabbMax = aabbMax1+marginVec;
+	
+#else
+
+	btScalar margin = getMargin();
+	for (int i=0;i<3;i++)
+	{
+		btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.));
+		vec[i] = btScalar(1.);
+		btVector3 sv = localGetSupportingVertex(vec*t.getBasis());
+		btVector3 tmp = t(sv);
+		aabbMax[i] = tmp[i]+margin;
+		vec[i] = btScalar(-1.);
+		sv = localGetSupportingVertex(vec*t.getBasis());
+		tmp = t(sv);
+		aabbMin[i] = tmp[i]-margin;
+	}
+
+#endif
 }
 
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp	(revision 8393)
@@ -23,4 +23,5 @@
 #include "btGjkPairDetector.h"
 #include "btPointCollector.h"
+#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
 
 
@@ -29,11 +30,62 @@
 :m_simplexSolver(simplexSolver),
 m_penetrationDepthSolver(penetrationDepthSolver),
-m_convexA(convexA),m_convexB(convexB)
-{
-}
+m_convexA(convexA),m_convexB1(convexB),m_planeShape(0)
+{
+}
+
+
+btContinuousConvexCollision::btContinuousConvexCollision( const btConvexShape*	convexA,const btStaticPlaneShape*	plane)
+:m_simplexSolver(0),
+m_penetrationDepthSolver(0),
+m_convexA(convexA),m_convexB1(0),m_planeShape(plane)
+{
+}
+
 
 /// This maximum should not be necessary. It allows for untested/degenerate cases in production code.
 /// You don't want your game ever to lock-up.
 #define MAX_ITERATIONS 64
+
+void btContinuousConvexCollision::computeClosestPoints( const btTransform& transA, const btTransform& transB,btPointCollector& pointCollector)
+{
+	if (m_convexB1)
+	{
+		m_simplexSolver->reset();
+		btGjkPairDetector gjk(m_convexA,m_convexB1,m_convexA->getShapeType(),m_convexB1->getShapeType(),m_convexA->getMargin(),m_convexB1->getMargin(),m_simplexSolver,m_penetrationDepthSolver);		
+		btGjkPairDetector::ClosestPointInput input;
+		input.m_transformA = transA;
+		input.m_transformB = transB;
+		gjk.getClosestPoints(input,pointCollector,0);
+	} else
+	{
+		//convex versus plane
+		const btConvexShape* convexShape = m_convexA;
+		const btStaticPlaneShape* planeShape = m_planeShape;
+		
+		bool hasCollision = false;
+		const btVector3& planeNormal = planeShape->getPlaneNormal();
+		const btScalar& planeConstant = planeShape->getPlaneConstant();
+		
+		btTransform convexWorldTransform = transA;
+		btTransform convexInPlaneTrans;
+		convexInPlaneTrans= transB.inverse() * convexWorldTransform;
+		btTransform planeInConvex;
+		planeInConvex= convexWorldTransform.inverse() * transB;
+		
+		btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);
+
+		btVector3 vtxInPlane = convexInPlaneTrans(vtx);
+		btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);
+
+		btVector3 vtxInPlaneProjected = vtxInPlane - distance*planeNormal;
+		btVector3 vtxInPlaneWorld = transB * vtxInPlaneProjected;
+		btVector3 normalOnSurfaceB = transB.getBasis() * planeNormal;
+
+		pointCollector.addContactPoint(
+			normalOnSurfaceB,
+			vtxInPlaneWorld,
+			distance);
+	}
+}
 
 bool	btContinuousConvexCollision::calcTimeOfImpact(
@@ -45,5 +97,4 @@
 {
 
-	m_simplexSolver->reset();
 
 	/// compute linear and angular velocity for this interval, to interpolate
@@ -54,5 +105,5 @@
 
 	btScalar boundingRadiusA = m_convexA->getAngularMotionDisc();
-	btScalar boundingRadiusB = m_convexB->getAngularMotionDisc();
+	btScalar boundingRadiusB = m_convexB1?m_convexB1->getAngularMotionDisc():0.f;
 
 	btScalar maxAngularProjectedVelocity = angVelA.length() * boundingRadiusA + angVelB.length() * boundingRadiusB;
@@ -65,5 +116,4 @@
 
 
-	btScalar radius = btScalar(0.001);
 
 	btScalar lambda = btScalar(0.);
@@ -84,11 +134,5 @@
 
 
-	btTransform identityTrans;
-	identityTrans.setIdentity();
-
-	btSphereShape	raySphere(btScalar(0.0));
-	raySphere.setMargin(btScalar(0.));
-
-
+	btScalar radius = 0.001f;
 //	result.drawCoordSystem(sphereTr);
 
@@ -96,14 +140,6 @@
 
 	{
-		
-		btGjkPairDetector gjk(m_convexA,m_convexB,m_convexA->getShapeType(),m_convexB->getShapeType(),m_convexA->getMargin(),m_convexB->getMargin(),m_simplexSolver,m_penetrationDepthSolver);		
-		btGjkPairDetector::ClosestPointInput input;
 	
-		//we don't use margins during CCD
-	//	gjk.setIgnoreMargin(true);
-
-		input.m_transformA = fromA;
-		input.m_transformB = fromB;
-		gjk.getClosestPoints(input,pointCollector1,0);
+		computeClosestPoints(fromA,fromB,pointCollector1);
 
 		hasResult = pointCollector1.m_hasResult;
@@ -114,9 +150,10 @@
 	{
 		btScalar dist;
-		dist = pointCollector1.m_distance;
+		dist = pointCollector1.m_distance + result.m_allowedPenetration;
 		n = pointCollector1.m_normalOnBInWorld;
-
 		btScalar projectedLinearVelocity = relLinVel.dot(n);
-		
+		if ((projectedLinearVelocity+ maxAngularProjectedVelocity)<=SIMD_EPSILON)
+			return false;
+
 		//not close enough
 		while (dist > radius)
@@ -126,17 +163,8 @@
 				result.m_debugDrawer->drawSphere(c,0.2f,btVector3(1,1,1));
 			}
-			numIter++;
-			if (numIter > maxIter)
-			{
-				return false; //todo: report a failure
-			}
 			btScalar dLambda = btScalar(0.);
 
 			projectedLinearVelocity = relLinVel.dot(n);
 
-			//calculate safe moving fraction from distance / (linear+rotational velocity)
-			
-			//btScalar clippedDist  = GEN_min(angularConservativeRadius,dist);
-			//btScalar clippedDist  = dist;
 			
 			//don't report time of impact for motion away from the contact normal (or causes minor penetration)
@@ -183,35 +211,25 @@
 
 			btPointCollector	pointCollector;
-			btGjkPairDetector gjk(m_convexA,m_convexB,m_simplexSolver,m_penetrationDepthSolver);
-			btGjkPairDetector::ClosestPointInput input;
-			input.m_transformA = interpolatedTransA;
-			input.m_transformB = interpolatedTransB;
-			gjk.getClosestPoints(input,pointCollector,0);
+			computeClosestPoints(interpolatedTransA,interpolatedTransB,pointCollector);
+
 			if (pointCollector.m_hasResult)
 			{
-				if (pointCollector.m_distance < btScalar(0.))
-				{
-					//degenerate ?!
-					result.m_fraction = lastLambda;
-					n = pointCollector.m_normalOnBInWorld;
-					result.m_normal=n;//.setValue(1,1,1);// = n;
-					result.m_hitPoint = pointCollector.m_pointInWorld;
-					return true;
-				}
+				dist = pointCollector.m_distance+result.m_allowedPenetration;
 				c = pointCollector.m_pointInWorld;		
 				n = pointCollector.m_normalOnBInWorld;
-				dist = pointCollector.m_distance;
 			} else
 			{
-				//??
-				return false;
-			}
-			
-
+				result.reportFailure(-1, numIter);
+				return false;
+			}
+
+			numIter++;
+			if (numIter > maxIter)
+			{
+				result.reportFailure(-2, numIter);
+				return false;
+			}
 		}
 	
-		if ((projectedLinearVelocity+ maxAngularProjectedVelocity)<=result.m_allowedPenetration)//SIMD_EPSILON)
-			return false;
-			
 		result.m_fraction = lambda;
 		result.m_normal = n;
@@ -222,15 +240,4 @@
 	return false;
 
-/*
-//todo:
-	//if movement away from normal, discard result
-	btVector3 move = transBLocalTo.getOrigin() - transBLocalFrom.getOrigin();
-	if (result.m_fraction < btScalar(1.))
-	{
-		if (move.dot(result.m_normal) <= btScalar(0.))
-		{
-		}
-	}
-*/
-
-}
+}
+
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h	(revision 8393)
@@ -15,6 +15,6 @@
 
 
-#ifndef CONTINUOUS_COLLISION_CONVEX_CAST_H
-#define CONTINUOUS_COLLISION_CONVEX_CAST_H
+#ifndef BT_CONTINUOUS_COLLISION_CONVEX_CAST_H
+#define BT_CONTINUOUS_COLLISION_CONVEX_CAST_H
 
 #include "btConvexCast.h"
@@ -22,4 +22,5 @@
 class btConvexPenetrationDepthSolver;
 class btConvexShape;
+class btStaticPlaneShape;
 
 /// btContinuousConvexCollision implements angular and linear time of impact for convex objects.
@@ -32,10 +33,15 @@
 	btConvexPenetrationDepthSolver*	m_penetrationDepthSolver;
 	const btConvexShape*	m_convexA;
-	const btConvexShape*	m_convexB;
+	//second object is either a convex or a plane (code sharing)
+	const btConvexShape*	m_convexB1;
+	const btStaticPlaneShape*	m_planeShape;
 
+	void computeClosestPoints( const btTransform& transA, const btTransform& transB,struct btPointCollector& pointCollector);
 
 public:
 
 	btContinuousConvexCollision (const btConvexShape*	shapeA,const btConvexShape*	shapeB ,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver);
+
+	btContinuousConvexCollision(const btConvexShape*	shapeA,const btStaticPlaneShape*	plane );
 
 	virtual bool	calcTimeOfImpact(
@@ -49,4 +55,5 @@
 };
 
-#endif //CONTINUOUS_COLLISION_CONVEX_CAST_H
 
+#endif //BT_CONTINUOUS_COLLISION_CONVEX_CAST_H
+
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btConvexCast.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btConvexCast.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btConvexCast.h	(revision 8393)
@@ -15,6 +15,6 @@
 
 
-#ifndef CONVEX_CAST_H
-#define CONVEX_CAST_H
+#ifndef BT_CONVEX_CAST_H
+#define BT_CONVEX_CAST_H
 
 #include "LinearMath/btTransform.h"
@@ -40,5 +40,5 @@
 		virtual void	DebugDraw(btScalar	fraction) {(void)fraction;}
 		virtual void	drawCoordSystem(const btTransform& trans) {(void)trans;}
-
+		virtual void	reportFailure(int errNo, int numIterations) {(void)errNo;(void)numIterations;}
 		CastResult()
 			:m_fraction(btScalar(BT_LARGE_FLOAT)),
@@ -71,3 +71,3 @@
 };
 
-#endif //CONVEX_CAST_H
+#endif //BT_CONVEX_CAST_H
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h	(revision 8393)
@@ -15,6 +15,6 @@
 
 
-#ifndef __CONVEX_PENETRATION_DEPTH_H
-#define __CONVEX_PENETRATION_DEPTH_H
+#ifndef BT_CONVEX_PENETRATION_DEPTH_H
+#define BT_CONVEX_PENETRATION_DEPTH_H
 
 class btStackAlloc;
@@ -39,4 +39,4 @@
 
 };
-#endif //CONVEX_PENETRATION_DEPTH_H
+#endif //BT_CONVEX_PENETRATION_DEPTH_H
 
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h	(revision 8393)
@@ -15,6 +15,7 @@
 
 
-#ifndef DISCRETE_COLLISION_DETECTOR1_INTERFACE_H
-#define DISCRETE_COLLISION_DETECTOR1_INTERFACE_H
+#ifndef BT_DISCRETE_COLLISION_DETECTOR1_INTERFACE_H
+#define BT_DISCRETE_COLLISION_DETECTOR1_INTERFACE_H
+
 #include "LinearMath/btTransform.h"
 #include "LinearMath/btVector3.h"
@@ -87,3 +88,4 @@
 };
 
-#endif //DISCRETE_COLLISION_DETECTOR_INTERFACE1_H
+#endif //BT_DISCRETE_COLLISION_DETECTOR1_INTERFACE_H
+
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h	(revision 8393)
@@ -16,6 +16,6 @@
 
 
-#ifndef GJK_CONVEX_CAST_H
-#define GJK_CONVEX_CAST_H
+#ifndef BT_GJK_CONVEX_CAST_H
+#define BT_GJK_CONVEX_CAST_H
 
 #include "BulletCollision/CollisionShapes/btCollisionMargin.h"
@@ -48,3 +48,3 @@
 };
 
-#endif //GJK_CONVEX_CAST_H
+#endif //BT_GJK_CONVEX_CAST_H
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.h	(revision 8393)
@@ -23,6 +23,7 @@
 GJK-EPA collision solver by Nathanael Presson, 2008
 */
-#ifndef _68DA1F85_90B7_4bb0_A705_83B4040A75C6_
-#define _68DA1F85_90B7_4bb0_A705_83B4040A75C6_
+#ifndef BT_GJK_EPA2_H
+#define BT_GJK_EPA2_H
+
 #include "BulletCollision/CollisionShapes/btConvexShape.h"
 
@@ -71,3 +72,4 @@
 };
 
-#endif
+#endif //BT_GJK_EPA2_H
+
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp	(revision 8393)
@@ -255,5 +255,4 @@
 #endif //
 			
-			m_cachedSeparatingAxis = newCachedSeparatingAxis;
 
 			//redundant m_simplexSolver->compute_points(pointOnA, pointOnB);
@@ -262,5 +261,5 @@
 			if (previousSquaredDistance - squaredDistance <= SIMD_EPSILON * previousSquaredDistance) 
 			{ 
-				m_simplexSolver->backup_closest(m_cachedSeparatingAxis);
+//				m_simplexSolver->backup_closest(m_cachedSeparatingAxis);
 				checkSimplex = true;
 				m_degenerateSimplex = 12;
@@ -268,4 +267,6 @@
 				break;
 			}
+
+			m_cachedSeparatingAxis = newCachedSeparatingAxis;
 
 			  //degeneracy, this is typically due to invalid/uninitialized worldtransforms for a btCollisionObject   
@@ -295,5 +296,5 @@
 			{
 				//do we need this backup_closest here ?
-				m_simplexSolver->backup_closest(m_cachedSeparatingAxis);
+//				m_simplexSolver->backup_closest(m_cachedSeparatingAxis);
 				m_degenerateSimplex = 13;
 				break;
@@ -304,5 +305,5 @@
 		{
 			m_simplexSolver->compute_points(pointOnA, pointOnB);
-			normalInB = pointOnA-pointOnB;
+			normalInB = m_cachedSeparatingAxis;
 			btScalar lenSqr =m_cachedSeparatingAxis.length2();
 			
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h	(revision 8393)
@@ -17,6 +17,6 @@
 
 
-#ifndef GJK_PAIR_DETECTOR_H
-#define GJK_PAIR_DETECTOR_H
+#ifndef BT_GJK_PAIR_DETECTOR_H
+#define BT_GJK_PAIR_DETECTOR_H
 
 #include "btDiscreteCollisionDetectorInterface.h"
@@ -101,3 +101,3 @@
 };
 
-#endif //GJK_PAIR_DETECTOR_H
+#endif //BT_GJK_PAIR_DETECTOR_H
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h	(revision 8393)
@@ -14,20 +14,25 @@
 */
 
-#ifndef MANIFOLD_CONTACT_POINT_H
-#define MANIFOLD_CONTACT_POINT_H
+#ifndef BT_MANIFOLD_CONTACT_POINT_H
+#define BT_MANIFOLD_CONTACT_POINT_H
 
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btTransformUtil.h"
 
-// Don't change following order of parameters
-ATTRIBUTE_ALIGNED16(struct) PfxConstraintRow {
-	btScalar mNormal[3];
-	btScalar mRhs;
-	btScalar mJacDiagInv;
-	btScalar mLowerLimit;
-	btScalar mUpperLimit;
-	btScalar mAccumImpulse;
-};
-
+#ifdef PFX_USE_FREE_VECTORMATH
+	#include "physics_effects/base_level/solver/pfx_constraint_row.h"
+typedef sce::PhysicsEffects::PfxConstraintRow btConstraintRow;
+#else
+	// Don't change following order of parameters
+	ATTRIBUTE_ALIGNED16(struct) btConstraintRow {
+		btScalar m_normal[3];
+		btScalar m_rhs;
+		btScalar m_jacDiagInv;
+		btScalar m_lowerLimit;
+		btScalar m_upperLimit;
+		btScalar m_accumImpulse;
+	};
+	typedef btConstraintRow PfxConstraintRow;
+#endif //PFX_USE_FREE_VECTORMATH
 
 
@@ -72,7 +77,7 @@
 					m_lifeTime(0)
 			{
-				mConstraintRow[0].mAccumImpulse = 0.f;
-				mConstraintRow[1].mAccumImpulse = 0.f;
-				mConstraintRow[2].mAccumImpulse = 0.f;
+				mConstraintRow[0].m_accumImpulse = 0.f;
+				mConstraintRow[1].m_accumImpulse = 0.f;
+				mConstraintRow[2].m_accumImpulse = 0.f;
 			}
 
@@ -114,5 +119,5 @@
 
 
-			PfxConstraintRow mConstraintRow[3];
+			btConstraintRow mConstraintRow[3];
 
 
@@ -151,3 +156,3 @@
 	};
 
-#endif //MANIFOLD_CONTACT_POINT_H
+#endif //BT_MANIFOLD_CONTACT_POINT_H
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef MINKOWSKI_PENETRATION_DEPTH_SOLVER_H
-#define MINKOWSKI_PENETRATION_DEPTH_SOLVER_H
+#ifndef BT_MINKOWSKI_PENETRATION_DEPTH_SOLVER_H
+#define BT_MINKOWSKI_PENETRATION_DEPTH_SOLVER_H
 
 #include "btConvexPenetrationDepthSolver.h"
@@ -37,4 +37,4 @@
 };
 
-#endif //MINKOWSKI_PENETRATION_DEPTH_SOLVER_H
+#endif //BT_MINKOWSKI_PENETRATION_DEPTH_SOLVER_H
 
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef PERSISTENT_MANIFOLD_H
-#define PERSISTENT_MANIFOLD_H
+#ifndef BT_PERSISTENT_MANIFOLD_H
+#define BT_PERSISTENT_MANIFOLD_H
 
 
@@ -33,9 +33,9 @@
 extern ContactProcessedCallback gContactProcessedCallback;
 
-
+//the enum starts at 1024 to avoid type conflicts with btTypedConstraint
 enum btContactManifoldTypes
 {
-	BT_PERSISTENT_MANIFOLD_TYPE = 1,
-	MAX_CONTACT_MANIFOLD_TYPE
+	MIN_CONTACT_MANIFOLD_TYPE = 1024,
+	BT_PERSISTENT_MANIFOLD_TYPE
 };
 
@@ -147,7 +147,7 @@
 			//get rid of duplicated userPersistentData pointer
 			m_pointCache[lastUsedIndex].m_userPersistentData = 0;
-			m_pointCache[lastUsedIndex].mConstraintRow[0].mAccumImpulse = 0.f;
-			m_pointCache[lastUsedIndex].mConstraintRow[1].mAccumImpulse = 0.f;
-			m_pointCache[lastUsedIndex].mConstraintRow[2].mAccumImpulse = 0.f;
+			m_pointCache[lastUsedIndex].mConstraintRow[0].m_accumImpulse = 0.f;
+			m_pointCache[lastUsedIndex].mConstraintRow[1].m_accumImpulse = 0.f;
+			m_pointCache[lastUsedIndex].mConstraintRow[2].m_accumImpulse = 0.f;
 
 			m_pointCache[lastUsedIndex].m_appliedImpulse = 0.f;
@@ -168,7 +168,7 @@
 #ifdef MAINTAIN_PERSISTENCY
 		int	lifeTime = m_pointCache[insertIndex].getLifeTime();
-		btScalar	appliedImpulse = m_pointCache[insertIndex].mConstraintRow[0].mAccumImpulse;
-		btScalar	appliedLateralImpulse1 = m_pointCache[insertIndex].mConstraintRow[1].mAccumImpulse;
-		btScalar	appliedLateralImpulse2 = m_pointCache[insertIndex].mConstraintRow[2].mAccumImpulse;
+		btScalar	appliedImpulse = m_pointCache[insertIndex].mConstraintRow[0].m_accumImpulse;
+		btScalar	appliedLateralImpulse1 = m_pointCache[insertIndex].mConstraintRow[1].m_accumImpulse;
+		btScalar	appliedLateralImpulse2 = m_pointCache[insertIndex].mConstraintRow[2].m_accumImpulse;
 //		bool isLateralFrictionInitialized = m_pointCache[insertIndex].m_lateralFrictionInitialized;
 		
@@ -185,7 +185,7 @@
 		m_pointCache[insertIndex].m_appliedImpulseLateral2 = appliedLateralImpulse2;
 		
-		m_pointCache[insertIndex].mConstraintRow[0].mAccumImpulse =  appliedImpulse;
-		m_pointCache[insertIndex].mConstraintRow[1].mAccumImpulse = appliedLateralImpulse1;
-		m_pointCache[insertIndex].mConstraintRow[2].mAccumImpulse = appliedLateralImpulse2;
+		m_pointCache[insertIndex].mConstraintRow[0].m_accumImpulse =  appliedImpulse;
+		m_pointCache[insertIndex].mConstraintRow[1].m_accumImpulse = appliedLateralImpulse1;
+		m_pointCache[insertIndex].mConstraintRow[2].m_accumImpulse = appliedLateralImpulse2;
 
 
@@ -200,5 +200,10 @@
 	bool validContactDistance(const btManifoldPoint& pt) const
 	{
-		return pt.m_distance1 <= getContactBreakingThreshold();
+		if (pt.m_lifeTime >1)
+		{
+			return pt.m_distance1 <= getContactBreakingThreshold();
+		}
+		return pt.m_distance1 <= getContactProcessingThreshold();
+	
 	}
 	/// calculated new worldspace coordinates and depth, and reject points that exceed the collision margin
@@ -225,3 +230,3 @@
 
 
-#endif //PERSISTENT_MANIFOLD_H
+#endif //BT_PERSISTENT_MANIFOLD_H
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPointCollector.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPointCollector.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPointCollector.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef POINT_COLLECTOR_H
-#define POINT_COLLECTOR_H
+#ifndef BT_POINT_COLLECTOR_H
+#define BT_POINT_COLLECTOR_H
 
 #include "btDiscreteCollisionDetectorInterface.h"
@@ -61,4 +61,4 @@
 };
 
-#endif //POINT_COLLECTOR_H
+#endif //BT_POINT_COLLECTOR_H
 
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp	(revision 8393)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp	(revision 8393)
@@ -0,0 +1,360 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2011 Advanced Micro Devices, Inc.  http://bulletphysics.org
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose, 
+including commercial applications, and to alter it and redistribute it freely, 
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+
+///This file was written by Erwin Coumans
+///Separating axis rest based on work from Pierre Terdiman, see
+///And contact clipping based on work from Simon Hobbs
+
+
+#include "btPolyhedralContactClipping.h"
+#include "BulletCollision/CollisionShapes/btConvexPolyhedron.h"
+
+#include <float.h> //for FLT_MAX
+
+
+// Clips a face to the back of a plane
+void btPolyhedralContactClipping::clipFace(const btVertexArray& pVtxIn, btVertexArray& ppVtxOut, const btVector3& planeNormalWS,btScalar planeEqWS)
+{
+	
+	int ve;
+	btScalar ds, de;
+	int numVerts = pVtxIn.size();
+	if (numVerts < 2)
+		return;
+
+	btVector3 firstVertex=pVtxIn[pVtxIn.size()-1];
+	btVector3 endVertex = pVtxIn[0];
+	
+	ds = planeNormalWS.dot(firstVertex)+planeEqWS;
+
+	for (ve = 0; ve < numVerts; ve++)
+	{
+		endVertex=pVtxIn[ve];
+
+		de = planeNormalWS.dot(endVertex)+planeEqWS;
+
+		if (ds<0)
+		{
+			if (de<0)
+			{
+				// Start < 0, end < 0, so output endVertex
+				ppVtxOut.push_back(endVertex);
+			}
+			else
+			{
+				// Start < 0, end >= 0, so output intersection
+				ppVtxOut.push_back( 	firstVertex.lerp(endVertex,btScalar(ds * 1.f/(ds - de))));
+			}
+		}
+		else
+		{
+			if (de<0)
+			{
+				// Start >= 0, end < 0 so output intersection and end
+				ppVtxOut.push_back(firstVertex.lerp(endVertex,btScalar(ds * 1.f/(ds - de))));
+				ppVtxOut.push_back(endVertex);
+			}
+		}
+		firstVertex = endVertex;
+		ds = de;
+	}
+}
+#include <stdio.h>
+
+
+static bool TestSepAxis(const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, const btVector3& sep_axis, float& depth)
+{
+	float Min0,Max0;
+	float Min1,Max1;
+	hullA.project(transA,sep_axis, Min0, Max0);
+	hullB.project(transB, sep_axis, Min1, Max1);
+
+	if(Max0<Min1 || Max1<Min0)
+		return false;
+
+	float d0 = Max0 - Min1;
+	assert(d0>=0.0f);
+	float d1 = Max1 - Min0;
+	assert(d1>=0.0f);
+	depth = d0<d1 ? d0:d1;
+	return true;
+}
+
+
+
+static int gActualSATPairTests=0;
+
+inline bool IsAlmostZero(const btVector3& v)
+{
+	if(fabsf(v.x())>1e-6 || fabsf(v.y())>1e-6 || fabsf(v.z())>1e-6)	return false;
+	return true;
+}
+
+
+bool btPolyhedralContactClipping::findSeparatingAxis(	const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, btVector3& sep)
+{
+	gActualSATPairTests++;
+
+#ifdef TEST_INTERNAL_OBJECTS
+	const btVector3 c0 = transA * hullA.mLocalCenter;
+	const btVector3 c1 = transB * hullB.mLocalCenter;
+	const btVector3 DeltaC2 = c0 - c1;
+#endif
+
+	float dmin = FLT_MAX;
+	int curPlaneTests=0;
+
+	int numFacesA = hullA.m_faces.size();
+	// Test normals from hullA
+	for(int i=0;i<numFacesA;i++)
+	{
+		const btVector3 Normal(hullA.m_faces[i].m_plane[0], hullA.m_faces[i].m_plane[1], hullA.m_faces[i].m_plane[2]);
+		const btVector3 faceANormalWS = transA.getBasis() * Normal;
+
+		curPlaneTests++;
+#ifdef TEST_INTERNAL_OBJECTS
+		gExpectedNbTests++;
+		if(gUseInternalObject && !TestInternalObjects(transA,transB,DeltaC2, faceANormalWS, hullA, hullB, dmin))
+			continue;
+		gActualNbTests++;
+#endif
+
+		float d;
+		if(!TestSepAxis( hullA, hullB, transA,transB, faceANormalWS, d))
+			return false;
+
+		if(d<dmin)
+		{
+			dmin = d;
+			sep = faceANormalWS;
+		}
+	}
+
+	int numFacesB = hullB.m_faces.size();
+	// Test normals from hullB
+	for(int i=0;i<numFacesB;i++)
+	{
+		const btVector3 Normal(hullB.m_faces[i].m_plane[0], hullB.m_faces[i].m_plane[1], hullB.m_faces[i].m_plane[2]);
+		const btVector3 WorldNormal = transB.getBasis() * Normal;
+
+		curPlaneTests++;
+#ifdef TEST_INTERNAL_OBJECTS
+		gExpectedNbTests++;
+		if(gUseInternalObject && !TestInternalObjects(transA,transB,DeltaC2, WorldNormal, hullA, hullB, dmin))
+			continue;
+		gActualNbTests++;
+#endif
+
+		float d;
+		if(!TestSepAxis(hullA, hullB,transA,transB, WorldNormal,d))
+			return false;
+
+		if(d<dmin)
+		{
+			dmin = d;
+			sep = WorldNormal;
+		}
+	}
+
+	btVector3 edgeAstart,edgeAend,edgeBstart,edgeBend;
+
+	int curEdgeEdge = 0;
+	// Test edges
+	for(int e0=0;e0<hullA.m_uniqueEdges.size();e0++)
+	{
+		const btVector3 edge0 = hullA.m_uniqueEdges[e0];
+		const btVector3 WorldEdge0 = transA.getBasis() * edge0;
+		for(int e1=0;e1<hullB.m_uniqueEdges.size();e1++)
+		{
+			const btVector3 edge1 = hullB.m_uniqueEdges[e1];
+			const btVector3 WorldEdge1 = transB.getBasis() * edge1;
+
+			btVector3 Cross = WorldEdge0.cross(WorldEdge1);
+			curEdgeEdge++;
+			if(!IsAlmostZero(Cross))
+			{
+				Cross = Cross.normalize();
+
+#ifdef TEST_INTERNAL_OBJECTS
+				gExpectedNbTests++;
+				if(gUseInternalObject && !TestInternalObjects(transA,transB,DeltaC2, Cross, hullA, hullB, dmin))
+					continue;
+				gActualNbTests++;
+#endif
+
+				float dist;
+				if(!TestSepAxis( hullA, hullB, transA,transB, Cross, dist))
+					return false;
+
+				if(dist<dmin)
+				{
+					dmin = dist;
+					sep = Cross;
+				}
+			}
+		}
+
+	}
+
+	const btVector3 deltaC = transB.getOrigin() - transA.getOrigin();
+	if((deltaC.dot(sep))>0.0f)
+		sep = -sep;
+
+	return true;
+}
+
+void	btPolyhedralContactClipping::clipFaceAgainstHull(const btVector3& separatingNormal, const btConvexPolyhedron& hullA,  const btTransform& transA, btVertexArray& worldVertsB1, const btScalar minDist, btScalar maxDist,btDiscreteCollisionDetectorInterface::Result& resultOut)
+{
+	btVertexArray worldVertsB2;
+	btVertexArray* pVtxIn = &worldVertsB1;
+	btVertexArray* pVtxOut = &worldVertsB2;
+	pVtxOut->reserve(pVtxIn->size());
+
+	int closestFaceA=-1;
+	{
+		btScalar dmin = FLT_MAX;
+		for(int face=0;face<hullA.m_faces.size();face++)
+		{
+			const btVector3 Normal(hullA.m_faces[face].m_plane[0], hullA.m_faces[face].m_plane[1], hullA.m_faces[face].m_plane[2]);
+			const btVector3 faceANormalWS = transA.getBasis() * Normal;
+		
+			btScalar d = faceANormalWS.dot(separatingNormal);
+			if (d < dmin)
+			{
+				dmin = d;
+				closestFaceA = face;
+			}
+		}
+	}
+	if (closestFaceA<0)
+		return;
+
+	const btFace& polyA = hullA.m_faces[closestFaceA];
+
+		// clip polygon to back of planes of all faces of hull A that are adjacent to witness face
+	int numContacts = pVtxIn->size();
+	int numVerticesA = polyA.m_indices.size();
+	for(int e0=0;e0<numVerticesA;e0++)
+	{
+		/*const btVector3& a = hullA.m_vertices[polyA.m_indices[e0]];
+		const btVector3& b = hullA.m_vertices[polyA.m_indices[(e0+1)%numVerticesA]];
+		const btVector3 edge0 = a - b;
+		const btVector3 WorldEdge0 = transA.getBasis() * edge0;
+		*/
+
+		int otherFace = polyA.m_connectedFaces[e0];
+		btVector3 localPlaneNormal (hullA.m_faces[otherFace].m_plane[0],hullA.m_faces[otherFace].m_plane[1],hullA.m_faces[otherFace].m_plane[2]);
+		btScalar localPlaneEq = hullA.m_faces[otherFace].m_plane[3];
+
+		btVector3 planeNormalWS = transA.getBasis()*localPlaneNormal;
+		btScalar planeEqWS=localPlaneEq-planeNormalWS.dot(transA.getOrigin());
+		//clip face
+
+		clipFace(*pVtxIn, *pVtxOut,planeNormalWS,planeEqWS);
+		btSwap(pVtxIn,pVtxOut);
+		pVtxOut->resize(0);
+	}
+
+
+
+//#define ONLY_REPORT_DEEPEST_POINT
+
+	btVector3 point;
+	
+
+	// only keep points that are behind the witness face
+	{
+		btVector3 localPlaneNormal (polyA.m_plane[0],polyA.m_plane[1],polyA.m_plane[2]);
+		btScalar localPlaneEq = polyA.m_plane[3];
+		btVector3 planeNormalWS = transA.getBasis()*localPlaneNormal;
+		btScalar planeEqWS=localPlaneEq-planeNormalWS.dot(transA.getOrigin());
+		for (int i=0;i<pVtxIn->size();i++)
+		{
+			
+			btScalar depth = planeNormalWS.dot(pVtxIn->at(i))+planeEqWS;
+			if (depth <=maxDist && depth >=minDist)
+			{
+				btVector3 point = pVtxIn->at(i);
+#ifdef ONLY_REPORT_DEEPEST_POINT
+				curMaxDist = depth;
+#else
+#if 0
+				if (depth<-3)
+				{
+					printf("error in btPolyhedralContactClipping depth = %f\n", depth);
+					printf("likely wrong separatingNormal passed in\n");
+				} 
+#endif				
+				resultOut.addContactPoint(separatingNormal,point,depth);
+#endif
+			}
+		}
+	}
+#ifdef ONLY_REPORT_DEEPEST_POINT
+	if (curMaxDist<maxDist)
+	{
+		resultOut.addContactPoint(separatingNormal,point,curMaxDist);
+	}
+#endif //ONLY_REPORT_DEEPEST_POINT
+
+}
+
+void	btPolyhedralContactClipping::clipHullAgainstHull(const btVector3& separatingNormal, const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, const btScalar minDist, btScalar maxDist,btDiscreteCollisionDetectorInterface::Result& resultOut)
+{
+
+	btScalar curMaxDist=maxDist;
+	int closestFaceB=-1;
+
+	{
+		btScalar dmax = -FLT_MAX;
+		for(int face=0;face<hullB.m_faces.size();face++)
+		{
+			const btVector3 Normal(hullB.m_faces[face].m_plane[0], hullB.m_faces[face].m_plane[1], hullB.m_faces[face].m_plane[2]);
+			const btVector3 WorldNormal = transB.getBasis() * Normal;
+
+			btScalar d = WorldNormal.dot(separatingNormal);
+			if (d > dmax)
+			{
+				dmax = d;
+				closestFaceB = face;
+			}
+		}
+	}
+
+
+
+	if (closestFaceB<0)
+	{
+		return;
+	}
+
+
+
+	// setup initial clip face (minimizing face from hull B)
+	btVertexArray worldVertsB1;
+	{
+		const btFace& polyB = hullB.m_faces[closestFaceB];
+		const int numVertices = polyB.m_indices.size();
+		for(int e0=0;e0<numVertices;e0++)
+		{
+			const btVector3& b = hullB.m_vertices[polyB.m_indices[e0]];
+			worldVertsB1.push_back(transB*b);
+		}
+	}
+
+	clipFaceAgainstHull(separatingNormal, hullA, transA,worldVertsB1, minDist, maxDist,resultOut);
+
+}
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h	(revision 8393)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h	(revision 8393)
@@ -0,0 +1,46 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2011 Advanced Micro Devices, Inc.  http://bulletphysics.org
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose, 
+including commercial applications, and to alter it and redistribute it freely, 
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+
+///This file was written by Erwin Coumans
+
+
+#ifndef BT_POLYHEDRAL_CONTACT_CLIPPING_H
+#define BT_POLYHEDRAL_CONTACT_CLIPPING_H
+
+
+#include "LinearMath/btAlignedObjectArray.h"
+#include "LinearMath/btTransform.h"
+#include "btDiscreteCollisionDetectorInterface.h"
+
+class btConvexPolyhedron;
+
+typedef btAlignedObjectArray<btVector3> btVertexArray;
+
+// Clips a face to the back of a plane
+struct btPolyhedralContactClipping
+{
+	static void clipHullAgainstHull(const btVector3& separatingNormal, const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, const btScalar minDist, btScalar maxDist, btDiscreteCollisionDetectorInterface::Result& resultOut);
+	static void	clipFaceAgainstHull(const btVector3& separatingNormal, const btConvexPolyhedron& hullA,  const btTransform& transA, btVertexArray& worldVertsB1, const btScalar minDist, btScalar maxDist,btDiscreteCollisionDetectorInterface::Result& resultOut);
+
+	static bool findSeparatingAxis(	const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, btVector3& sep);
+
+	///the clipFace method is used internally
+	static void clipFace(const btVertexArray& pVtxIn, btVertexArray& ppVtxOut, const btVector3& planeNormalWS,btScalar planeEqWS);
+
+};
+
+#endif // BT_POLYHEDRAL_CONTACT_CLIPPING_H
+
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btRaycastCallback.cpp
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btRaycastCallback.cpp	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btRaycastCallback.cpp	(revision 8393)
@@ -125,6 +125,7 @@
 	m_convexShapeTo = convexShapeTo;
 	m_triangleToWorld = triangleToWorld;
-	m_hitFraction = 1.0;
-    m_triangleCollisionMargin = triangleCollisionMargin;
+	m_hitFraction = 1.0f;
+	m_triangleCollisionMargin = triangleCollisionMargin;
+	m_allowedPenetration = 0.f;
 }
 
@@ -149,4 +150,5 @@
 	btConvexCast::CastResult castResult;
 	castResult.m_fraction = btScalar(1.);
+	castResult.m_allowedPenetration = m_allowedPenetration;
 	if (convexCaster.calcTimeOfImpact(m_convexShapeFrom,m_convexShapeTo,m_triangleToWorld, m_triangleToWorld, castResult))
 	{
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h	(revision 8393)
@@ -14,6 +14,6 @@
 */
 
-#ifndef RAYCAST_TRI_CALLBACK_H
-#define RAYCAST_TRI_CALLBACK_H
+#ifndef BT_RAYCAST_TRI_CALLBACK_H
+#define BT_RAYCAST_TRI_CALLBACK_H
 
 #include "BulletCollision/CollisionShapes/btTriangleCallback.h"
@@ -59,5 +59,6 @@
 	btTransform m_triangleToWorld;
 	btScalar m_hitFraction;
-    btScalar m_triangleCollisionMargin;
+	btScalar m_triangleCollisionMargin;
+	btScalar m_allowedPenetration;
 
 	btTriangleConvexcastCallback (const btConvexShape* convexShape, const btTransform& convexShapeFrom, const btTransform& convexShapeTo, const btTransform& triangleToWorld, const btScalar triangleCollisionMargin);
@@ -68,4 +69,4 @@
 };
 
-#endif //RAYCAST_TRI_CALLBACK_H
+#endif //BT_RAYCAST_TRI_CALLBACK_H
 
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h	(revision 8393)
@@ -16,6 +16,6 @@
 
 
-#ifndef SIMPLEX_SOLVER_INTERFACE_H
-#define SIMPLEX_SOLVER_INTERFACE_H
+#ifndef BT_SIMPLEX_SOLVER_INTERFACE_H
+#define BT_SIMPLEX_SOLVER_INTERFACE_H
 
 #include "LinearMath/btVector3.h"
@@ -60,4 +60,4 @@
 };
 #endif
-#endif //SIMPLEX_SOLVER_INTERFACE_H
+#endif //BT_SIMPLEX_SOLVER_INTERFACE_H
 
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h	(revision 8393)
@@ -15,6 +15,6 @@
 
 
-#ifndef SUBSIMPLEX_CONVEX_CAST_H
-#define SUBSIMPLEX_CONVEX_CAST_H
+#ifndef BT_SUBSIMPLEX_CONVEX_CAST_H
+#define BT_SUBSIMPLEX_CONVEX_CAST_H
 
 #include "btConvexCast.h"
@@ -48,3 +48,3 @@
 };
 
-#endif //SUBSIMPLEX_CONVEX_CAST_H
+#endif //BT_SUBSIMPLEX_CONVEX_CAST_H
Index: code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h
===================================================================
--- code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h	(revision 8351)
+++ code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h	(revision 8393)
@@ -16,6 +16,6 @@
 
 
-#ifndef btVoronoiSimplexSolver_H
-#define btVoronoiSimplexSolver_H
+#ifndef BT_VORONOI_SIMPLEX_SOLVER_H
+#define BT_VORONOI_SIMPLEX_SOLVER_H
 
 #include "btSimplexSolverInterface.h"
@@ -176,3 +176,4 @@
 };
 
-#endif //VoronoiSimplexSolver
+#endif //BT_VORONOI_SIMPLEX_SOLVER_H
+
