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
 }
 
