Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp	(revision 1972)
@@ -22,6 +22,6 @@
 #include <assert.h>
 
-btAxisSweep3::btAxisSweep3(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, unsigned short int maxHandles, btOverlappingPairCache* pairCache, bool disableRaycastAccelerator)
-:btAxisSweep3Internal<unsigned short int>(worldAabbMin,worldAabbMax,0xfffe,0xffff,maxHandles,pairCache,disableRaycastAccelerator)
+btAxisSweep3::btAxisSweep3(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, unsigned short int maxHandles, btOverlappingPairCache* pairCache)
+:btAxisSweep3Internal<unsigned short int>(worldAabbMin,worldAabbMax,0xfffe,0xffff,maxHandles,pairCache)
 {
 	// 1 handle is reserved as sentinel
@@ -31,6 +31,6 @@
 
 
-bt32BitAxisSweep3::bt32BitAxisSweep3(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, unsigned int maxHandles , btOverlappingPairCache* pairCache , bool disableRaycastAccelerator)
-:btAxisSweep3Internal<unsigned int>(worldAabbMin,worldAabbMax,0xfffffffe,0x7fffffff,maxHandles,pairCache,disableRaycastAccelerator)
+bt32BitAxisSweep3::bt32BitAxisSweep3(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, unsigned int maxHandles , btOverlappingPairCache* pairCache )
+:btAxisSweep3Internal<unsigned int>(worldAabbMin,worldAabbMax,0xfffffffe,0x7fffffff,maxHandles,pairCache)
 {
 	// 1 handle is reserved as sentinel
Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.h	(revision 1972)
@@ -26,5 +26,4 @@
 #include "btBroadphaseProxy.h"
 #include "btOverlappingPairCallback.h"
-#include "btDbvtBroadphase.h"
 
 //#define DEBUG_BROADPHASE 1
@@ -63,5 +62,6 @@
 		BP_FP_INT_TYPE m_minEdges[3], m_maxEdges[3];		// 6 * 2 = 12
 //		BP_FP_INT_TYPE m_uniqueId;
-		btBroadphaseProxy*	m_dbvtProxy;//for faster raycast
+		BP_FP_INT_TYPE m_pad;
+		
 		//void* m_pOwner; this is now in btBroadphaseProxy.m_clientObject
 	
@@ -95,9 +95,4 @@
 	int	m_invalidPair;
 
-	///additional dynamic aabb structure, used to accelerate ray cast queries.
-	///can be disabled using a optional argument in the constructor
-	btDbvtBroadphase*	m_raycastAccelerator;
-
-
 	// allocation/deallocation
 	BP_FP_INT_TYPE allocHandle();
@@ -114,5 +109,5 @@
 	//void RemoveOverlap(BP_FP_INT_TYPE handleA, BP_FP_INT_TYPE handleB);
 
-	
+	void quantize(BP_FP_INT_TYPE* out, const btPoint3& point, int isMax) const;
 
 	void sortMinDown(int axis, BP_FP_INT_TYPE edge, btDispatcher* dispatcher, bool updateOverlaps );
@@ -123,5 +118,5 @@
 public:
 
-	btAxisSweep3Internal(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, BP_FP_INT_TYPE handleMask, BP_FP_INT_TYPE handleSentinel, BP_FP_INT_TYPE maxHandles = 16384, btOverlappingPairCache* pairCache=0,bool disableRaycastAccelerator = false);
+	btAxisSweep3Internal(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, BP_FP_INT_TYPE handleMask, BP_FP_INT_TYPE handleSentinel, BP_FP_INT_TYPE maxHandles = 16384, btOverlappingPairCache* pairCache=0);
 
 	virtual	~btAxisSweep3Internal();
@@ -145,11 +140,4 @@
 	virtual void	destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
 	virtual void	setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher);
-	virtual void  getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
-	
-	virtual void	rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback);
-
-	void quantize(BP_FP_INT_TYPE* out, const btPoint3& point, int isMax) const;
-	///unQuantize should be conservative: aabbMin/aabbMax should be larger then 'getAabb' result
-	void unQuantize(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
 	
 	bool	testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
@@ -230,10 +218,5 @@
 		
 		Handle* handle = getHandle(handleId);
-		
-		if (m_raycastAccelerator)
-		{
-			btBroadphaseProxy* rayProxy = m_raycastAccelerator->createProxy(aabbMin,aabbMax,shapeType,userPtr,collisionFilterGroup,collisionFilterMask,dispatcher,0);
-			handle->m_dbvtProxy = rayProxy;
-		}
+				
 		return handle;
 }
@@ -245,6 +228,4 @@
 {
 	Handle* handle = static_cast<Handle*>(proxy);
-	if (m_raycastAccelerator)
-		m_raycastAccelerator->destroyProxy(handle->m_dbvtProxy,dispatcher);
 	removeHandle(static_cast<BP_FP_INT_TYPE>(handle->m_uniqueId), dispatcher);
 }
@@ -254,71 +235,14 @@
 {
 	Handle* handle = static_cast<Handle*>(proxy);
-	handle->m_aabbMin = aabbMin;
-	handle->m_aabbMax = aabbMax;
 	updateHandle(static_cast<BP_FP_INT_TYPE>(handle->m_uniqueId), aabbMin, aabbMax,dispatcher);
-	if (m_raycastAccelerator)
-		m_raycastAccelerator->setAabb(handle->m_dbvtProxy,aabbMin,aabbMax,dispatcher);
-
-}
-
-template <typename BP_FP_INT_TYPE>
-
-void	btAxisSweep3Internal<BP_FP_INT_TYPE>::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback)
-{
-	if (m_raycastAccelerator)
-	{
-		m_raycastAccelerator->rayTest(rayFrom,rayTo,rayCallback);
-	} else
-	{
-		//choose axis?
-		BP_FP_INT_TYPE axis = 0;
-		//for each proxy
-		for (BP_FP_INT_TYPE i=1;i<m_numHandles*2+1;i++)
-		{
-			if (m_pEdges[axis][i].IsMax())
-			{
-				rayCallback.process(getHandle(m_pEdges[axis][i].m_handle));
-			}
-		}
-	}
-}
-
-
-template <typename BP_FP_INT_TYPE>
-void btAxisSweep3Internal<BP_FP_INT_TYPE>::getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const
-{
-	Handle* pHandle = static_cast<Handle*>(proxy);
-	aabbMin = pHandle->m_aabbMin;
-	aabbMax = pHandle->m_aabbMax;
-}
-
-
-template <typename BP_FP_INT_TYPE>
-void btAxisSweep3Internal<BP_FP_INT_TYPE>::unQuantize(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const
-{
-	Handle* pHandle = static_cast<Handle*>(proxy);
-
-	unsigned short vecInMin[3];
-	unsigned short vecInMax[3];
-
-	vecInMin[0] = m_pEdges[0][pHandle->m_minEdges[0]].m_pos ;
-	vecInMax[0] = m_pEdges[0][pHandle->m_maxEdges[0]].m_pos +1 ;
-	vecInMin[1] = m_pEdges[1][pHandle->m_minEdges[1]].m_pos ;
-	vecInMax[1] = m_pEdges[1][pHandle->m_maxEdges[1]].m_pos +1 ;
-	vecInMin[2] = m_pEdges[2][pHandle->m_minEdges[2]].m_pos ;
-	vecInMax[2] = m_pEdges[2][pHandle->m_maxEdges[2]].m_pos +1 ;
-	
-	aabbMin.setValue((btScalar)(vecInMin[0]) / (m_quantize.getX()),(btScalar)(vecInMin[1]) / (m_quantize.getY()),(btScalar)(vecInMin[2]) / (m_quantize.getZ()));
-	aabbMin += m_worldAabbMin;
-	
-	aabbMax.setValue((btScalar)(vecInMax[0]) / (m_quantize.getX()),(btScalar)(vecInMax[1]) / (m_quantize.getY()),(btScalar)(vecInMax[2]) / (m_quantize.getZ()));
-	aabbMax += m_worldAabbMin;
-}
-
-
-
-
-template <typename BP_FP_INT_TYPE>
-btAxisSweep3Internal<BP_FP_INT_TYPE>::btAxisSweep3Internal(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, BP_FP_INT_TYPE handleMask, BP_FP_INT_TYPE handleSentinel,BP_FP_INT_TYPE userMaxHandles, btOverlappingPairCache* pairCache , bool disableRaycastAccelerator)
+
+}
+
+
+
+
+
+template <typename BP_FP_INT_TYPE>
+btAxisSweep3Internal<BP_FP_INT_TYPE>::btAxisSweep3Internal(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, BP_FP_INT_TYPE handleMask, BP_FP_INT_TYPE handleSentinel,BP_FP_INT_TYPE userMaxHandles, btOverlappingPairCache* pairCache )
 :m_bpHandleMask(handleMask),
 m_handleSentinel(handleSentinel),
@@ -326,6 +250,5 @@
 m_userPairCallback(0),
 m_ownsPairCache(false),
-m_invalidPair(0),
-m_raycastAccelerator(0)
+m_invalidPair(0)
 {
 	BP_FP_INT_TYPE maxHandles = static_cast<BP_FP_INT_TYPE>(userMaxHandles+1);//need to add one sentinel handle
@@ -336,10 +259,4 @@
 		m_pairCache = new(ptr) btHashedOverlappingPairCache();
 		m_ownsPairCache = true;
-	}
-
-	if (!disableRaycastAccelerator)
-	{
-		m_raycastAccelerator = new (btAlignedAlloc(sizeof(btDbvtBroadphase),16)) btDbvtBroadphase();//m_pairCache);
-		m_raycastAccelerator->m_deferedcollide = true;//don't add/remove pairs
 	}
 
@@ -404,7 +321,5 @@
 btAxisSweep3Internal<BP_FP_INT_TYPE>::~btAxisSweep3Internal()
 {
-	if (m_raycastAccelerator)
-		btAlignedFree (m_raycastAccelerator);
-
+	
 	for (int i = 2; i >= 0; i--)
 	{
@@ -985,5 +900,5 @@
 public:
 
-	btAxisSweep3(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, unsigned short int maxHandles = 16384, btOverlappingPairCache* pairCache = 0, bool disableRaycastAccelerator = false);
+	btAxisSweep3(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, unsigned short int maxHandles = 16384, btOverlappingPairCache* pairCache = 0);
 
 };
@@ -996,5 +911,5 @@
 public:
 
-	bt32BitAxisSweep3(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, unsigned int maxHandles = 1500000, btOverlappingPairCache* pairCache = 0, bool disableRaycastAccelerator = false);
+	bt32BitAxisSweep3(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, unsigned int maxHandles = 1500000, btOverlappingPairCache* pairCache = 0);
 
 };
Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h	(revision 1972)
@@ -24,10 +24,4 @@
 class btOverlappingPairCache;
 
-struct	btBroadphaseRayCallback
-{
-	virtual ~btBroadphaseRayCallback() {}
-	virtual bool	process(const btBroadphaseProxy* proxy) = 0;
-};
-
 #include "LinearMath/btVector3.h"
 
@@ -43,8 +37,5 @@
 	virtual void	destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher)=0;
 	virtual void	setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher)=0;
-	virtual void	getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const =0;
-
-	virtual void	rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback) = 0;
-
+	
 	///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb
 	virtual void	calculateOverlappingPairs(btDispatcher* dispatcher)=0;
Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h	(revision 1972)
@@ -18,5 +18,4 @@
 
 #include "LinearMath/btScalar.h" //for SIMD_FORCE_INLINE
-#include "LinearMath/btVector3.h"
 #include "LinearMath/btAlignedAllocator.h"
 
@@ -92,7 +91,4 @@
 	};
 
-	btVector3	m_aabbMin;
-	btVector3	m_aabbMax;
-
 	//Usually the client btCollisionObject or Rigidbody class
 	void*	m_clientObject;
@@ -116,8 +112,6 @@
 	}
 
-	btBroadphaseProxy(const btVector3& aabbMin,const btVector3& aabbMax,void* userPtr,short int collisionFilterGroup, short int collisionFilterMask,void* multiSapParentProxy=0)
-		:m_aabbMin(aabbMin),
-		m_aabbMax(aabbMax),
-		m_clientObject(userPtr),
+	btBroadphaseProxy(void* userPtr,short int collisionFilterGroup, short int collisionFilterMask,void* multiSapParentProxy=0)
+		:m_clientObject(userPtr),
 		m_collisionFilterGroup(collisionFilterGroup),
 		m_collisionFilterMask(collisionFilterMask)
Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btDbvt.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btDbvt.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btDbvt.cpp	(revision 1972)
@@ -24,6 +24,6 @@
 struct btDbvtNodeEnumerator : btDbvt::ICollide
 {
-	tConstNodeArray	nodes;
-	void Process(const btDbvtNode* n) { nodes.push_back(n); }
+tConstNodeArray	nodes;
+void Process(const btDbvtNode* n) { nodes.push_back(n); }
 };
 
@@ -31,19 +31,19 @@
 static DBVT_INLINE int			indexof(const btDbvtNode* node)
 {
-	return(node->parent->childs[1]==node);
+return(node->parent->childs[1]==node);
 }
 
 //
 static DBVT_INLINE btDbvtVolume	merge(	const btDbvtVolume& a,
-									  const btDbvtVolume& b)
+										const btDbvtVolume& b)
 {
 #if DBVT_MERGE_IMPL==DBVT_IMPL_SSE
-	DBVT_ALIGN char locals[sizeof(btDbvtAabbMm)];
-	btDbvtVolume&	res=*(btDbvtVolume*)locals;
+DBVT_ALIGN char locals[sizeof(btDbvtAabbMm)];
+btDbvtVolume&	res=*(btDbvtVolume*)locals;
 #else
-	btDbvtVolume	res;
+btDbvtVolume	res;
 #endif
-	Merge(a,b,res);
-	return(res);
+Merge(a,b,res);
+return(res);
 }
 
@@ -51,6 +51,6 @@
 static DBVT_INLINE btScalar		size(const btDbvtVolume& a)
 {
-	const btVector3	edges=a.Lengths();
-	return(	edges.x()*edges.y()*edges.z()+
+const btVector3	edges=a.Lengths();
+return(	edges.x()*edges.y()*edges.z()+
 		edges.x()+edges.y()+edges.z());
 }
@@ -59,8 +59,8 @@
 static void						getmaxdepth(const btDbvtNode* node,int depth,int& maxdepth)
 {
-	if(node->isinternal())
-	{
-		getmaxdepth(node->childs[0],depth+1,maxdepth);
-		getmaxdepth(node->childs[0],depth+1,maxdepth);
+if(node->isinternal())
+	{
+	getmaxdepth(node->childs[0],depth+1,maxdepth);
+	getmaxdepth(node->childs[0],depth+1,maxdepth);
 	} else maxdepth=btMax(maxdepth,depth);
 }
@@ -68,142 +68,142 @@
 //
 static DBVT_INLINE void			deletenode(	btDbvt* pdbvt,
-										   btDbvtNode* node)
-{
-	btAlignedFree(pdbvt->m_free);
-	pdbvt->m_free=node;
-}
-
+											btDbvtNode* node)
+{
+btAlignedFree(pdbvt->m_free);
+pdbvt->m_free=node;
+}
+	
 //
 static void						recursedeletenode(	btDbvt* pdbvt,
-												  btDbvtNode* node)
-{
-	if(!node->isleaf())
-	{
-		recursedeletenode(pdbvt,node->childs[0]);
-		recursedeletenode(pdbvt,node->childs[1]);
-	}
-	if(node==pdbvt->m_root) pdbvt->m_root=0;
-	deletenode(pdbvt,node);
+													btDbvtNode* node)
+{
+if(!node->isleaf())
+	{
+	recursedeletenode(pdbvt,node->childs[0]);
+	recursedeletenode(pdbvt,node->childs[1]);
+	}
+if(node==pdbvt->m_root) pdbvt->m_root=0;
+deletenode(pdbvt,node);
 }
 
 //
 static DBVT_INLINE btDbvtNode*	createnode(	btDbvt* pdbvt,
-										   btDbvtNode* parent,
-										   void* data)
-{
-	btDbvtNode*	node;
-	if(pdbvt->m_free)
+											btDbvtNode* parent,
+											void* data)
+{
+btDbvtNode*	node;
+if(pdbvt->m_free)
 	{ node=pdbvt->m_free;pdbvt->m_free=0; }
 	else
 	{ node=new(btAlignedAlloc(sizeof(btDbvtNode),16)) btDbvtNode(); }
-	node->parent	=	parent;
-	node->data		=	data;
-	node->childs[1]	=	0;
-	return(node);
+node->parent	=	parent;
+node->data		=	data;
+node->childs[1]	=	0;
+return(node);
 }
 
 //
 static DBVT_INLINE btDbvtNode*	createnode(	btDbvt* pdbvt,
-										   btDbvtNode* parent,
-										   const btDbvtVolume& volume,
-										   void* data)
-{
-	btDbvtNode*	node=createnode(pdbvt,parent,data);
-	node->volume=volume;
-	return(node);
+											btDbvtNode* parent,
+											const btDbvtVolume& volume,
+											void* data)
+{
+btDbvtNode*	node=createnode(pdbvt,parent,data);
+node->volume=volume;
+return(node);
 }
 
 //
 static DBVT_INLINE btDbvtNode*	createnode(	btDbvt* pdbvt,
-										   btDbvtNode* parent,
-										   const btDbvtVolume& volume0,
-										   const btDbvtVolume& volume1,
-										   void* data)
-{
-	btDbvtNode*	node=createnode(pdbvt,parent,data);
-	Merge(volume0,volume1,node->volume);
-	return(node);
+											btDbvtNode* parent,
+											const btDbvtVolume& volume0,
+											const btDbvtVolume& volume1,
+											void* data)
+{
+btDbvtNode*	node=createnode(pdbvt,parent,data);
+Merge(volume0,volume1,node->volume);
+return(node);
 }
 
 //
 static void						insertleaf(	btDbvt* pdbvt,
-										   btDbvtNode* root,
-										   btDbvtNode* leaf)
-{
-	if(!pdbvt->m_root)
-	{
-		pdbvt->m_root	=	leaf;
-		leaf->parent	=	0;
+											btDbvtNode* root,
+											btDbvtNode* leaf)
+{
+if(!pdbvt->m_root)
+	{
+	pdbvt->m_root	=	leaf;
+	leaf->parent	=	0;
 	}
 	else
 	{
-		if(!root->isleaf())
-		{
-			do	{
-				root=root->childs[Select(	leaf->volume,
-					root->childs[0]->volume,
-					root->childs[1]->volume)];
+	if(!root->isleaf())
+		{
+		do	{
+			root=root->childs[Select(	leaf->volume,
+										root->childs[0]->volume,
+										root->childs[1]->volume)];
 			} while(!root->isleaf());
 		}
-		btDbvtNode*	prev=root->parent;
-		btDbvtNode*	node=createnode(pdbvt,prev,leaf->volume,root->volume,0);
-		if(prev)
-		{
-			prev->childs[indexof(root)]	=	node;
-			node->childs[0]				=	root;root->parent=node;
-			node->childs[1]				=	leaf;leaf->parent=node;
-			do	{
-				if(!prev->volume.Contain(node->volume))
-					Merge(prev->childs[0]->volume,prev->childs[1]->volume,prev->volume);
+	btDbvtNode*	prev=root->parent;
+	btDbvtNode*	node=createnode(pdbvt,prev,leaf->volume,root->volume,0);
+	if(prev)
+		{
+		prev->childs[indexof(root)]	=	node;
+		node->childs[0]				=	root;root->parent=node;
+		node->childs[1]				=	leaf;leaf->parent=node;
+		do	{
+			if(!prev->volume.Contain(node->volume))
+				Merge(prev->childs[0]->volume,prev->childs[1]->volume,prev->volume);
 				else
-					break;
-				node=prev;
+				break;
+			node=prev;
 			} while(0!=(prev=node->parent));
 		}
 		else
 		{
-			node->childs[0]	=	root;root->parent=node;
-			node->childs[1]	=	leaf;leaf->parent=node;
-			pdbvt->m_root	=	node;
-		}
-	}
-}
-
+		node->childs[0]	=	root;root->parent=node;
+		node->childs[1]	=	leaf;leaf->parent=node;
+		pdbvt->m_root	=	node;
+		}
+	}
+}
+	
 //
 static btDbvtNode*				removeleaf(	btDbvt* pdbvt,
-										   btDbvtNode* leaf)
-{
-	if(leaf==pdbvt->m_root)
-	{
-		pdbvt->m_root=0;
-		return(0);
+											btDbvtNode* leaf)
+{
+if(leaf==pdbvt->m_root)
+	{
+	pdbvt->m_root=0;
+	return(0);
 	}
 	else
 	{
-		btDbvtNode*	parent=leaf->parent;
-		btDbvtNode*	prev=parent->parent;
-		btDbvtNode*	sibling=parent->childs[1-indexof(leaf)];			
-		if(prev)
-		{
-			prev->childs[indexof(parent)]=sibling;
-			sibling->parent=prev;
-			deletenode(pdbvt,parent);
-			while(prev)
-			{
-				const btDbvtVolume	pb=prev->volume;
-				Merge(prev->childs[0]->volume,prev->childs[1]->volume,prev->volume);
-				if(NotEqual(pb,prev->volume))
+	btDbvtNode*	parent=leaf->parent;
+	btDbvtNode*	prev=parent->parent;
+	btDbvtNode*	sibling=parent->childs[1-indexof(leaf)];			
+	if(prev)
+		{
+		prev->childs[indexof(parent)]=sibling;
+		sibling->parent=prev;
+		deletenode(pdbvt,parent);
+		while(prev)
+			{
+			const btDbvtVolume	pb=prev->volume;
+			Merge(prev->childs[0]->volume,prev->childs[1]->volume,prev->volume);
+			if(NotEqual(pb,prev->volume))
 				{
-					prev=prev->parent;
+				prev=prev->parent;
 				} else break;
 			}
-			return(prev?prev:pdbvt->m_root);
+		return(prev?prev:pdbvt->m_root);
 		}
 		else
 		{								
-			pdbvt->m_root=sibling;
-			sibling->parent=0;
-			deletenode(pdbvt,parent);
-			return(pdbvt->m_root);
+		pdbvt->m_root=sibling;
+		sibling->parent=0;
+		deletenode(pdbvt,parent);
+		return(pdbvt->m_root);
 		}			
 	}
@@ -216,13 +216,13 @@
 											int depth=-1)
 {
-	if(root->isinternal()&&depth)
-	{
-		fetchleaves(pdbvt,root->childs[0],leaves,depth-1);
-		fetchleaves(pdbvt,root->childs[1],leaves,depth-1);
-		deletenode(pdbvt,root);
+if(root->isinternal()&&depth)
+	{
+	fetchleaves(pdbvt,root->childs[0],leaves,depth-1);
+	fetchleaves(pdbvt,root->childs[1],leaves,depth-1);
+	deletenode(pdbvt,root);
 	}
 	else
 	{
-		leaves.push_back(root);
+	leaves.push_back(root);
 	}
 }
@@ -230,17 +230,17 @@
 //
 static void						split(	const tNodeArray& leaves,
-									  tNodeArray& left,
-									  tNodeArray& right,
-									  const btVector3& org,
-									  const btVector3& axis)
-{
-	left.resize(0);
-	right.resize(0);
-	for(int i=0,ni=leaves.size();i<ni;++i)
-	{
-		if(dot(axis,leaves[i]->volume.Center()-org)<0)
-			left.push_back(leaves[i]);
+										tNodeArray& left,
+										tNodeArray& right,
+										const btVector3& org,
+										const btVector3& axis)
+{
+left.resize(0);
+right.resize(0);
+for(int i=0,ni=leaves.size();i<ni;++i)
+	{
+	if(dot(axis,leaves[i]->volume.Center()-org)<0)
+		left.push_back(leaves[i]);
 		else
-			right.push_back(leaves[i]);
+		right.push_back(leaves[i]);
 	}
 }
@@ -250,47 +250,47 @@
 {
 #if DBVT_MERGE_IMPL==DBVT_IMPL_SSE
-	DBVT_ALIGN char	locals[sizeof(btDbvtVolume)];
-	btDbvtVolume&	volume=*(btDbvtVolume*)locals;
-	volume=leaves[0]->volume;
+DBVT_ALIGN char	locals[sizeof(btDbvtVolume)];
+btDbvtVolume&	volume=*(btDbvtVolume*)locals;
+volume=leaves[0]->volume;
 #else
-	btDbvtVolume volume=leaves[0]->volume;
+btDbvtVolume volume=leaves[0]->volume;
 #endif
-	for(int i=1,ni=leaves.size();i<ni;++i)
-	{
-		Merge(volume,leaves[i]->volume,volume);
-	}
-	return(volume);
+for(int i=1,ni=leaves.size();i<ni;++i)
+	{
+	Merge(volume,leaves[i]->volume,volume);
+	}
+return(volume);
 }
 
 //
 static void						bottomup(	btDbvt* pdbvt,
-										 tNodeArray& leaves)
-{
-	while(leaves.size()>1)
-	{
-		btScalar	minsize=SIMD_INFINITY;
-		int			minidx[2]={-1,-1};
-		for(int i=0;i<leaves.size();++i)
-		{
-			for(int j=i+1;j<leaves.size();++j)
-			{
-				const btScalar	sz=size(merge(leaves[i]->volume,leaves[j]->volume));
-				if(sz<minsize)
+											tNodeArray& leaves)
+{
+while(leaves.size()>1)
+	{
+	btScalar	minsize=SIMD_INFINITY;
+	int			minidx[2]={-1,-1};
+	for(int i=0;i<leaves.size();++i)
+		{
+		for(int j=i+1;j<leaves.size();++j)
+			{
+			const btScalar	sz=size(merge(leaves[i]->volume,leaves[j]->volume));
+			if(sz<minsize)
 				{
-					minsize		=	sz;
-					minidx[0]	=	i;
-					minidx[1]	=	j;
+				minsize		=	sz;
+				minidx[0]	=	i;
+				minidx[1]	=	j;
 				}
 			}
 		}
-		btDbvtNode*	n[]	=	{leaves[minidx[0]],leaves[minidx[1]]};
-		btDbvtNode*	p	=	createnode(pdbvt,0,n[0]->volume,n[1]->volume,0);
-		p->childs[0]		=	n[0];
-		p->childs[1]		=	n[1];
-		n[0]->parent		=	p;
-		n[1]->parent		=	p;
-		leaves[minidx[0]]	=	p;
-		leaves.swap(minidx[1],leaves.size()-1);
-		leaves.pop_back();
+	btDbvtNode*	n[]	=	{leaves[minidx[0]],leaves[minidx[1]]};
+	btDbvtNode*	p	=	createnode(pdbvt,0,n[0]->volume,n[1]->volume,0);
+	p->childs[0]		=	n[0];
+	p->childs[1]		=	n[1];
+	n[0]->parent		=	p;
+	n[1]->parent		=	p;
+	leaves[minidx[0]]	=	p;
+	leaves.swap(minidx[1],leaves.size()-1);
+	leaves.pop_back();
 	}
 }
@@ -301,67 +301,67 @@
 									int bu_treshold)
 {
-	static const btVector3	axis[]={btVector3(1,0,0),
-		btVector3(0,1,0),
-		btVector3(0,0,1)};
-	if(leaves.size()>1)
-	{
-		if(leaves.size()>bu_treshold)
-		{
-			const btDbvtVolume	vol=bounds(leaves);
-			const btVector3			org=vol.Center();
-			tNodeArray				sets[2];
-			int						bestaxis=-1;
-			int						bestmidp=leaves.size();
-			int						splitcount[3][2]={{0,0},{0,0},{0,0}};
-			int i;
-			for( i=0;i<leaves.size();++i)
-			{
-				const btVector3	x=leaves[i]->volume.Center()-org;
-				for(int j=0;j<3;++j)
+static const btVector3	axis[]={btVector3(1,0,0),
+								btVector3(0,1,0),
+								btVector3(0,0,1)};
+if(leaves.size()>1)
+	{
+	if(leaves.size()>bu_treshold)
+		{
+		const btDbvtVolume	vol=bounds(leaves);
+		const btVector3			org=vol.Center();
+		tNodeArray				sets[2];
+		int						bestaxis=-1;
+		int						bestmidp=leaves.size();
+		int						splitcount[3][2]={{0,0},{0,0},{0,0}};
+		int i;
+		for( i=0;i<leaves.size();++i)
+			{
+			const btVector3	x=leaves[i]->volume.Center()-org;
+			for(int j=0;j<3;++j)
 				{
-					++splitcount[j][dot(x,axis[j])>0?1:0];
+				++splitcount[j][dot(x,axis[j])>0?1:0];
 				}
 			}
-			for( i=0;i<3;++i)
-			{
-				if((splitcount[i][0]>0)&&(splitcount[i][1]>0))
+		for( i=0;i<3;++i)
+			{
+			if((splitcount[i][0]>0)&&(splitcount[i][1]>0))
 				{
-					const int	midp=(int)btFabs(btScalar(splitcount[i][0]-splitcount[i][1]));
-					if(midp<bestmidp)
+				const int	midp=(int)btFabs(btScalar(splitcount[i][0]-splitcount[i][1]));
+				if(midp<bestmidp)
 					{
-						bestaxis=i;
-						bestmidp=midp;
+					bestaxis=i;
+					bestmidp=midp;
 					}
 				}
 			}
-			if(bestaxis>=0)
-			{
-				sets[0].reserve(splitcount[bestaxis][0]);
-				sets[1].reserve(splitcount[bestaxis][1]);
-				split(leaves,sets[0],sets[1],org,axis[bestaxis]);
+		if(bestaxis>=0)
+			{
+			sets[0].reserve(splitcount[bestaxis][0]);
+			sets[1].reserve(splitcount[bestaxis][1]);
+			split(leaves,sets[0],sets[1],org,axis[bestaxis]);
 			}
 			else
 			{
-				sets[0].reserve(leaves.size()/2+1);
-				sets[1].reserve(leaves.size()/2);
-				for(int i=0,ni=leaves.size();i<ni;++i)
+			sets[0].reserve(leaves.size()/2+1);
+			sets[1].reserve(leaves.size()/2);
+			for(int i=0,ni=leaves.size();i<ni;++i)
 				{
-					sets[i&1].push_back(leaves[i]);
+				sets[i&1].push_back(leaves[i]);
 				}
 			}
-			btDbvtNode*	node=createnode(pdbvt,0,vol,0);
-			node->childs[0]=topdown(pdbvt,sets[0],bu_treshold);
-			node->childs[1]=topdown(pdbvt,sets[1],bu_treshold);
-			node->childs[0]->parent=node;
-			node->childs[1]->parent=node;
-			return(node);
+		btDbvtNode*	node=createnode(pdbvt,0,vol,0);
+		node->childs[0]=topdown(pdbvt,sets[0],bu_treshold);
+		node->childs[1]=topdown(pdbvt,sets[1],bu_treshold);
+		node->childs[0]->parent=node;
+		node->childs[1]->parent=node;
+		return(node);
 		}
 		else
 		{
-			bottomup(pdbvt,leaves);
-			return(leaves[0]);
-		}
-	}
-	return(leaves[0]);
+		bottomup(pdbvt,leaves);
+		return(leaves[0]);
+		}
+	}
+return(leaves[0]);
 }
 
@@ -369,27 +369,27 @@
 static DBVT_INLINE btDbvtNode*	sort(btDbvtNode* n,btDbvtNode*& r)
 {
-	btDbvtNode*	p=n->parent;
-	btAssert(n->isinternal());
-	if(p>n)
-	{
-		const int		i=indexof(n);
-		const int		j=1-i;
-		btDbvtNode*	s=p->childs[j];
-		btDbvtNode*	q=p->parent;
-		btAssert(n==p->childs[i]);
-		if(q) q->childs[indexof(p)]=n; else r=n;
-		s->parent=n;
-		p->parent=n;
-		n->parent=q;
-		p->childs[0]=n->childs[0];
-		p->childs[1]=n->childs[1];
-		n->childs[0]->parent=p;
-		n->childs[1]->parent=p;
-		n->childs[i]=p;
-		n->childs[j]=s;
-		btSwap(p->volume,n->volume);
-		return(p);
-	}
-	return(n);
+btDbvtNode*	p=n->parent;
+btAssert(n->isinternal());
+if(p>n)
+	{
+	const int		i=indexof(n);
+	const int		j=1-i;
+	btDbvtNode*	s=p->childs[j];
+	btDbvtNode*	q=p->parent;
+	btAssert(n==p->childs[i]);
+	if(q) q->childs[indexof(p)]=n; else r=n;
+	s->parent=n;
+	p->parent=n;
+	n->parent=q;
+	p->childs[0]=n->childs[0];
+	p->childs[1]=n->childs[1];
+	n->childs[0]->parent=p;
+	n->childs[1]->parent=p;
+	n->childs[i]=p;
+	n->childs[j]=s;
+	btSwap(p->volume,n->volume);
+	return(p);
+	}
+return(n);
 }
 
@@ -397,6 +397,6 @@
 static DBVT_INLINE btDbvtNode*	walkup(btDbvtNode* n,int count)
 {
-	while(n&&(count--)) n=n->parent;
-	return(n);
+while(n&&(count--)) n=n->parent;
+return(n);
 }
 
@@ -406,17 +406,17 @@
 
 //
-btDbvt::btDbvt()
-{
-	m_root		=	0;
-	m_free		=	0;
-	m_lkhd		=	-1;
-	m_leaves	=	0;
-	m_opath		=	0;
-}
-
-//
-btDbvt::~btDbvt()
-{
-	clear();
+				btDbvt::btDbvt()
+{
+m_root		=	0;
+m_free		=	0;
+m_lkhd		=	-1;
+m_leaves	=	0;
+m_opath		=	0;
+}
+
+//
+				btDbvt::~btDbvt()
+{
+clear();
 }
 
@@ -424,7 +424,7 @@
 void			btDbvt::clear()
 {
-	if(m_root)	recursedeletenode(this,m_root);
-	btAlignedFree(m_free);
-	m_free=0;
+if(m_root)	recursedeletenode(this,m_root);
+btAlignedFree(m_free);
+m_free=0;
 }
 
@@ -432,11 +432,11 @@
 void			btDbvt::optimizeBottomUp()
 {
-	if(m_root)
-	{
-		tNodeArray leaves;
-		leaves.reserve(m_leaves);
-		fetchleaves(this,m_root,leaves);
-		bottomup(this,leaves);
-		m_root=leaves[0];
+if(m_root)
+	{
+	tNodeArray leaves;
+	leaves.reserve(m_leaves);
+	fetchleaves(this,m_root,leaves);
+	bottomup(this,leaves);
+	m_root=leaves[0];
 	}
 }
@@ -445,10 +445,10 @@
 void			btDbvt::optimizeTopDown(int bu_treshold)
 {
-	if(m_root)
-	{
-		tNodeArray	leaves;
-		leaves.reserve(m_leaves);
-		fetchleaves(this,m_root,leaves);
-		m_root=topdown(this,leaves,bu_treshold);
+if(m_root)
+	{
+	tNodeArray	leaves;
+	leaves.reserve(m_leaves);
+	fetchleaves(this,m_root,leaves);
+	m_root=topdown(this,leaves,bu_treshold);
 	}
 }
@@ -457,17 +457,17 @@
 void			btDbvt::optimizeIncremental(int passes)
 {
-	if(passes<0) passes=m_leaves;
-	if(m_root&&(passes>0))
-	{
-		do	{
-			btDbvtNode*		node=m_root;
-			unsigned	bit=0;
-			while(node->isinternal())
-			{
-				node=sort(node,m_root)->childs[(m_opath>>bit)&1];
-				bit=(bit+1)&(sizeof(unsigned)*8-1);
-			}
-			update(node);
-			++m_opath;
+if(passes<0) passes=m_leaves;
+if(m_root&&(passes>0))
+	{
+	do	{
+		btDbvtNode*		node=m_root;
+		unsigned	bit=0;
+		while(node->isinternal())
+			{
+			node=sort(node,m_root)->childs[(m_opath>>bit)&1];
+			bit=(bit+1)&(sizeof(unsigned)*8-1);
+			}
+		update(node);
+		++m_opath;
 		} while(--passes);
 	}
@@ -477,8 +477,8 @@
 btDbvtNode*	btDbvt::insert(const btDbvtVolume& volume,void* data)
 {
-	btDbvtNode*	leaf=createnode(this,0,volume,data);
-	insertleaf(this,m_root,leaf);
-	++m_leaves;
-	return(leaf);
+btDbvtNode*	leaf=createnode(this,0,volume,data);
+insertleaf(this,m_root,leaf);
+++m_leaves;
+return(leaf);
 }
 
@@ -486,16 +486,16 @@
 void			btDbvt::update(btDbvtNode* leaf,int lookahead)
 {
-	btDbvtNode*	root=removeleaf(this,leaf);
-	if(root)
-	{
-		if(lookahead>=0)
-		{
-			for(int i=0;(i<lookahead)&&root->parent;++i)
-			{
-				root=root->parent;
+btDbvtNode*	root=removeleaf(this,leaf);
+if(root)
+	{
+	if(lookahead>=0)
+		{
+		for(int i=0;(i<lookahead)&&root->parent;++i)
+			{
+			root=root->parent;
 			}
 		} else root=m_root;
 	}
-	insertleaf(this,root,leaf);
+insertleaf(this,root,leaf);
 }
 
@@ -503,17 +503,17 @@
 void			btDbvt::update(btDbvtNode* leaf,const btDbvtVolume& volume)
 {
-	btDbvtNode*	root=removeleaf(this,leaf);
-	if(root)
-	{
-		if(m_lkhd>=0)
-		{
-			for(int i=0;(i<m_lkhd)&&root->parent;++i)
-			{
-				root=root->parent;
+btDbvtNode*	root=removeleaf(this,leaf);
+if(root)
+	{
+	if(m_lkhd>=0)
+		{
+		for(int i=0;(i<m_lkhd)&&root->parent;++i)
+			{
+			root=root->parent;
 			}
 		} else root=m_root;
 	}
-	leaf->volume=volume;
-	insertleaf(this,root,leaf);
+leaf->volume=volume;
+insertleaf(this,root,leaf);
 }
 
@@ -521,9 +521,9 @@
 bool			btDbvt::update(btDbvtNode* leaf,btDbvtVolume volume,const btVector3& velocity,btScalar margin)
 {
-	if(leaf->volume.Contain(volume)) return(false);
-	volume.Expand(btVector3(margin,margin,margin));
-	volume.SignedExpand(velocity);
-	update(leaf,volume);
-	return(true);
+if(leaf->volume.Contain(volume)) return(false);
+volume.Expand(btVector3(margin,margin,margin));
+volume.SignedExpand(velocity);
+update(leaf,volume);
+return(true);
 }
 
@@ -531,8 +531,8 @@
 bool			btDbvt::update(btDbvtNode* leaf,btDbvtVolume volume,const btVector3& velocity)
 {
-	if(leaf->volume.Contain(volume)) return(false);
-	volume.SignedExpand(velocity);
-	update(leaf,volume);
-	return(true);
+if(leaf->volume.Contain(volume)) return(false);
+volume.SignedExpand(velocity);
+update(leaf,volume);
+return(true);
 }
 
@@ -540,8 +540,8 @@
 bool			btDbvt::update(btDbvtNode* leaf,btDbvtVolume volume,btScalar margin)
 {
-	if(leaf->volume.Contain(volume)) return(false);
-	volume.Expand(btVector3(margin,margin,margin));
-	update(leaf,volume);
-	return(true);
+if(leaf->volume.Contain(volume)) return(false);
+volume.Expand(btVector3(margin,margin,margin));
+update(leaf,volume);
+return(true);
 }
 
@@ -549,7 +549,7 @@
 void			btDbvt::remove(btDbvtNode* leaf)
 {
-	removeleaf(this,leaf);
-	deletenode(this,leaf);
-	--m_leaves;
+removeleaf(this,leaf);
+deletenode(this,leaf);
+--m_leaves;
 }
 
@@ -557,22 +557,22 @@
 void			btDbvt::write(IWriter* iwriter) const
 {
-	btDbvtNodeEnumerator	nodes;
-	nodes.nodes.reserve(m_leaves*2);
-	enumNodes(m_root,nodes);
-	iwriter->Prepare(m_root,nodes.nodes.size());
-	for(int i=0;i<nodes.nodes.size();++i)
-	{
-		const btDbvtNode* n=nodes.nodes[i];
-		int			p=-1;
-		if(n->parent) p=nodes.nodes.findLinearSearch(n->parent);
-		if(n->isinternal())
-		{
-			const int	c0=nodes.nodes.findLinearSearch(n->childs[0]);
-			const int	c1=nodes.nodes.findLinearSearch(n->childs[1]);
-			iwriter->WriteNode(n,i,p,c0,c1);
+btDbvtNodeEnumerator	nodes;
+nodes.nodes.reserve(m_leaves*2);
+enumNodes(m_root,nodes);
+iwriter->Prepare(m_root,nodes.nodes.size());
+for(int i=0;i<nodes.nodes.size();++i)
+	{
+	const btDbvtNode* n=nodes.nodes[i];
+	int			p=-1;
+	if(n->parent) p=nodes.nodes.findLinearSearch(n->parent);
+	if(n->isinternal())
+		{
+		const int	c0=nodes.nodes.findLinearSearch(n->childs[0]);
+		const int	c1=nodes.nodes.findLinearSearch(n->childs[1]);
+		iwriter->WriteNode(n,i,p,c0,c1);
 		}
 		else
 		{
-			iwriter->WriteLeaf(n,i,p);
+		iwriter->WriteLeaf(n,i,p);
 		}	
 	}
@@ -582,27 +582,27 @@
 void			btDbvt::clone(btDbvt& dest,IClone* iclone) const
 {
-	dest.clear();
-	if(m_root!=0)
+dest.clear();
+if(m_root!=0)
 	{	
-		btAlignedObjectArray<sStkCLN>	stack;
-		stack.reserve(m_leaves);
-		stack.push_back(sStkCLN(m_root,0));
-		do	{
-			const int		i=stack.size()-1;
-			const sStkCLN	e=stack[i];
-			btDbvtNode*			n=createnode(&dest,e.parent,e.node->volume,e.node->data);
-			stack.pop_back();
-			if(e.parent!=0)
-				e.parent->childs[i&1]=n;
+	btAlignedObjectArray<sStkCLN>	stack;
+	stack.reserve(m_leaves);
+	stack.push_back(sStkCLN(m_root,0));
+	do	{
+		const int		i=stack.size()-1;
+		const sStkCLN	e=stack[i];
+		btDbvtNode*			n=createnode(&dest,e.parent,e.node->volume,e.node->data);
+		stack.pop_back();
+		if(e.parent!=0)
+			e.parent->childs[i&1]=n;
 			else
-				dest.m_root=n;
-			if(e.node->isinternal())
-			{
-				stack.push_back(sStkCLN(e.node->childs[0],n));
-				stack.push_back(sStkCLN(e.node->childs[1],n));
+			dest.m_root=n;
+		if(e.node->isinternal())
+			{
+			stack.push_back(sStkCLN(e.node->childs[0],n));
+			stack.push_back(sStkCLN(e.node->childs[1],n));
 			}
 			else
 			{
-				iclone->CloneLeaf(n);
+			iclone->CloneLeaf(n);
 			}
 		} while(stack.size()>0);
@@ -613,7 +613,7 @@
 int				btDbvt::maxdepth(const btDbvtNode* node)
 {
-	int	depth=0;
-	if(node) getmaxdepth(node,1,depth);
-	return(depth);
+int	depth=0;
+if(node) getmaxdepth(node,1,depth);
+return(depth);
 }
 
@@ -621,8 +621,8 @@
 int				btDbvt::countLeaves(const btDbvtNode* node)
 {
-	if(node->isinternal())
-		return(countLeaves(node->childs[0])+countLeaves(node->childs[1]));
+if(node->isinternal())
+	return(countLeaves(node->childs[0])+countLeaves(node->childs[1]));
 	else
-		return(1);
+	return(1);
 }
 
@@ -630,12 +630,12 @@
 void			btDbvt::extractLeaves(const btDbvtNode* node,btAlignedObjectArray<const btDbvtNode*>& leaves)
 {
-	if(node->isinternal())
-	{
-		extractLeaves(node->childs[0],leaves);
-		extractLeaves(node->childs[1],leaves);
+if(node->isinternal())
+	{
+	extractLeaves(node->childs[0],leaves);
+	extractLeaves(node->childs[1],leaves);
 	}
 	else
 	{
-		leaves.push_back(node);
+	leaves.push_back(node);
 	}	
 }
@@ -658,10 +658,10 @@
 
 Benchmarking dbvt...
-World scale: 100.000000
-Extents base: 1.000000
-Extents range: 4.000000
-Leaves: 8192
-sizeof(btDbvtVolume): 32 bytes
-sizeof(btDbvtNode):   44 bytes
+        World scale: 100.000000
+        Extents base: 1.000000
+        Extents range: 4.000000
+        Leaves: 8192
+        sizeof(btDbvtVolume): 32 bytes
+        sizeof(btDbvtNode):   44 bytes
 [1] btDbvtVolume intersections: 3499 ms (-1%)
 [2] btDbvtVolume merges: 1934 ms (0%)
@@ -670,5 +670,5 @@
 [5] btDbvt::collideTT xform: 7379 ms (-1%)
 [6] btDbvt::collideTT xform,self: 7270 ms (-2%)
-[7] btDbvt::rayTest: 6314 ms (0%),(332143 r/s)
+[7] btDbvt::collideRAY: 6314 ms (0%),(332143 r/s)
 [8] insert/remove: 2093 ms (0%),(1001983 ir/s)
 [9] updates (teleport): 1879 ms (-3%),(1116100 u/s)
@@ -685,91 +685,91 @@
 struct btDbvtBenchmark
 {
-	struct NilPolicy : btDbvt::ICollide
-	{
-		NilPolicy() : m_pcount(0),m_depth(-SIMD_INFINITY),m_checksort(true)		{}
-		void	Process(const btDbvtNode*,const btDbvtNode*)				{ ++m_pcount; }
-		void	Process(const btDbvtNode*)									{ ++m_pcount; }
-		void	Process(const btDbvtNode*,btScalar depth)
-		{
-			++m_pcount;
-			if(m_checksort)
+struct NilPolicy : btDbvt::ICollide
+	{
+	NilPolicy() : m_pcount(0),m_depth(-SIMD_INFINITY),m_checksort(true)		{}
+	void	Process(const btDbvtNode*,const btDbvtNode*)				{ ++m_pcount; }
+	void	Process(const btDbvtNode*)									{ ++m_pcount; }
+	void	Process(const btDbvtNode*,btScalar depth)
+		{
+		++m_pcount;
+		if(m_checksort)
 			{ if(depth>=m_depth) m_depth=depth; else printf("wrong depth: %f (should be >= %f)\r\n",depth,m_depth); }
 		}
-		int			m_pcount;
-		btScalar	m_depth;
-		bool		m_checksort;
+	int			m_pcount;
+	btScalar	m_depth;
+	bool		m_checksort;
 	};
-	struct P14 : btDbvt::ICollide
-	{
-		struct Node
-		{
-			const btDbvtNode*	leaf;
-			btScalar			depth;
+struct P14 : btDbvt::ICollide
+	{
+	struct Node
+		{
+		const btDbvtNode*	leaf;
+		btScalar			depth;
 		};
-		void Process(const btDbvtNode* leaf,btScalar depth)
-		{
-			Node	n;
-			n.leaf	=	leaf;
-			n.depth	=	depth;
-		}
-		static int sortfnc(const Node& a,const Node& b)
-		{
-			if(a.depth<b.depth) return(+1);
-			if(a.depth>b.depth) return(-1);
-			return(0);
-		}
-		btAlignedObjectArray<Node>		m_nodes;
+	void Process(const btDbvtNode* leaf,btScalar depth)
+		{
+		Node	n;
+		n.leaf	=	leaf;
+		n.depth	=	depth;
+		}
+	static int sortfnc(const Node& a,const Node& b)
+		{
+		if(a.depth<b.depth) return(+1);
+		if(a.depth>b.depth) return(-1);
+		return(0);
+		}
+	btAlignedObjectArray<Node>		m_nodes;
 	};
-	struct P15 : btDbvt::ICollide
-	{
-		struct Node
-		{
-			const btDbvtNode*	leaf;
-			btScalar			depth;
+struct P15 : btDbvt::ICollide
+	{
+	struct Node
+		{
+		const btDbvtNode*	leaf;
+		btScalar			depth;
 		};
-		void Process(const btDbvtNode* leaf)
-		{
-			Node	n;
-			n.leaf	=	leaf;
-			n.depth	=	dot(leaf->volume.Center(),m_axis);
-		}
-		static int sortfnc(const Node& a,const Node& b)
-		{
-			if(a.depth<b.depth) return(+1);
-			if(a.depth>b.depth) return(-1);
-			return(0);
-		}
-		btAlignedObjectArray<Node>		m_nodes;
-		btVector3						m_axis;
+	void Process(const btDbvtNode* leaf)
+		{
+		Node	n;
+		n.leaf	=	leaf;
+		n.depth	=	dot(leaf->volume.Center(),m_axis);
+		}
+	static int sortfnc(const Node& a,const Node& b)
+		{
+		if(a.depth<b.depth) return(+1);
+		if(a.depth>b.depth) return(-1);
+		return(0);
+		}
+	btAlignedObjectArray<Node>		m_nodes;
+	btVector3						m_axis;
 	};
-	static btScalar			RandUnit()
-	{
-		return(rand()/(btScalar)RAND_MAX);
-	}
-	static btVector3		RandVector3()
-	{
-		return(btVector3(RandUnit(),RandUnit(),RandUnit()));
-	}
-	static btVector3		RandVector3(btScalar cs)
-	{
-		return(RandVector3()*cs-btVector3(cs,cs,cs)/2);
-	}
-	static btDbvtVolume	RandVolume(btScalar cs,btScalar eb,btScalar es)
-	{
-		return(btDbvtVolume::FromCE(RandVector3(cs),btVector3(eb,eb,eb)+RandVector3()*es));
-	}
-	static btTransform		RandTransform(btScalar cs)
-	{
-		btTransform	t;
-		t.setOrigin(RandVector3(cs));
-		t.setRotation(btQuaternion(RandUnit()*SIMD_PI*2,RandUnit()*SIMD_PI*2,RandUnit()*SIMD_PI*2).normalized());
-		return(t);
-	}
-	static void				RandTree(btScalar cs,btScalar eb,btScalar es,int leaves,btDbvt& dbvt)
-	{
-		dbvt.clear();
-		for(int i=0;i<leaves;++i)
-		{
-			dbvt.insert(RandVolume(cs,eb,es),0);
+static btScalar			RandUnit()
+	{
+	return(rand()/(btScalar)RAND_MAX);
+	}
+static btVector3		RandVector3()
+	{
+	return(btVector3(RandUnit(),RandUnit(),RandUnit()));
+	}
+static btVector3		RandVector3(btScalar cs)
+	{
+	return(RandVector3()*cs-btVector3(cs,cs,cs)/2);
+	}
+static btDbvtVolume	RandVolume(btScalar cs,btScalar eb,btScalar es)
+	{
+	return(btDbvtVolume::FromCE(RandVector3(cs),btVector3(eb,eb,eb)+RandVector3()*es));
+	}
+static btTransform		RandTransform(btScalar cs)
+	{
+	btTransform	t;
+	t.setOrigin(RandVector3(cs));
+	t.setRotation(btQuaternion(RandUnit()*SIMD_PI*2,RandUnit()*SIMD_PI*2,RandUnit()*SIMD_PI*2).normalized());
+	return(t);
+	}
+static void				RandTree(btScalar cs,btScalar eb,btScalar es,int leaves,btDbvt& dbvt)
+	{
+	dbvt.clear();
+	for(int i=0;i<leaves;++i)
+		{
+		dbvt.insert(RandVolume(cs,eb,es),0);
 		}
 	}
@@ -778,512 +778,512 @@
 void			btDbvt::benchmark()
 {
-	static const btScalar	cfgVolumeCenterScale		=	100;
-	static const btScalar	cfgVolumeExentsBase			=	1;
-	static const btScalar	cfgVolumeExentsScale		=	4;
-	static const int		cfgLeaves					=	8192;
-	static const bool		cfgEnable					=	true;
-
-	//[1] btDbvtVolume intersections
-	bool					cfgBenchmark1_Enable		=	cfgEnable;
-	static const int		cfgBenchmark1_Iterations	=	8;
-	static const int		cfgBenchmark1_Reference		=	3499;
-	//[2] btDbvtVolume merges
-	bool					cfgBenchmark2_Enable		=	cfgEnable;
-	static const int		cfgBenchmark2_Iterations	=	4;
-	static const int		cfgBenchmark2_Reference		=	1945;
-	//[3] btDbvt::collideTT
-	bool					cfgBenchmark3_Enable		=	cfgEnable;
-	static const int		cfgBenchmark3_Iterations	=	512;
-	static const int		cfgBenchmark3_Reference		=	5485;
-	//[4] btDbvt::collideTT self
-	bool					cfgBenchmark4_Enable		=	cfgEnable;
-	static const int		cfgBenchmark4_Iterations	=	512;
-	static const int		cfgBenchmark4_Reference		=	2814;
-	//[5] btDbvt::collideTT xform
-	bool					cfgBenchmark5_Enable		=	cfgEnable;
-	static const int		cfgBenchmark5_Iterations	=	512;
-	static const btScalar	cfgBenchmark5_OffsetScale	=	2;
-	static const int		cfgBenchmark5_Reference		=	7379;
-	//[6] btDbvt::collideTT xform,self
-	bool					cfgBenchmark6_Enable		=	cfgEnable;
-	static const int		cfgBenchmark6_Iterations	=	512;
-	static const btScalar	cfgBenchmark6_OffsetScale	=	2;
-	static const int		cfgBenchmark6_Reference		=	7270;
-	//[7] btDbvt::rayTest
-	bool					cfgBenchmark7_Enable		=	cfgEnable;
-	static const int		cfgBenchmark7_Passes		=	32;
-	static const int		cfgBenchmark7_Iterations	=	65536;
-	static const int		cfgBenchmark7_Reference		=	6307;
-	//[8] insert/remove
-	bool					cfgBenchmark8_Enable		=	cfgEnable;
-	static const int		cfgBenchmark8_Passes		=	32;
-	static const int		cfgBenchmark8_Iterations	=	65536;
-	static const int		cfgBenchmark8_Reference		=	2105;
-	//[9] updates (teleport)
-	bool					cfgBenchmark9_Enable		=	cfgEnable;
-	static const int		cfgBenchmark9_Passes		=	32;
-	static const int		cfgBenchmark9_Iterations	=	65536;
-	static const int		cfgBenchmark9_Reference		=	1879;
-	//[10] updates (jitter)
-	bool					cfgBenchmark10_Enable		=	cfgEnable;
-	static const btScalar	cfgBenchmark10_Scale		=	cfgVolumeCenterScale/10000;
-	static const int		cfgBenchmark10_Passes		=	32;
-	static const int		cfgBenchmark10_Iterations	=	65536;
-	static const int		cfgBenchmark10_Reference	=	1244;
-	//[11] optimize (incremental)
-	bool					cfgBenchmark11_Enable		=	cfgEnable;
-	static const int		cfgBenchmark11_Passes		=	64;
-	static const int		cfgBenchmark11_Iterations	=	65536;
-	static const int		cfgBenchmark11_Reference	=	2510;
-	//[12] btDbvtVolume notequal
-	bool					cfgBenchmark12_Enable		=	cfgEnable;
-	static const int		cfgBenchmark12_Iterations	=	32;
-	static const int		cfgBenchmark12_Reference	=	3677;
-	//[13] culling(OCL+fullsort)
-	bool					cfgBenchmark13_Enable		=	cfgEnable;
-	static const int		cfgBenchmark13_Iterations	=	1024;
-	static const int		cfgBenchmark13_Reference	=	2231;
-	//[14] culling(OCL+qsort)
-	bool					cfgBenchmark14_Enable		=	cfgEnable;
-	static const int		cfgBenchmark14_Iterations	=	8192;
-	static const int		cfgBenchmark14_Reference	=	3500;
-	//[15] culling(KDOP+qsort)
-	bool					cfgBenchmark15_Enable		=	cfgEnable;
-	static const int		cfgBenchmark15_Iterations	=	8192;
-	static const int		cfgBenchmark15_Reference	=	1151;
-	//[16] insert/remove batch
-	bool					cfgBenchmark16_Enable		=	cfgEnable;
-	static const int		cfgBenchmark16_BatchCount	=	256;
-	static const int		cfgBenchmark16_Passes		=	16384;
-	static const int		cfgBenchmark16_Reference	=	5138;
-	//[17] select
-	bool					cfgBenchmark17_Enable		=	cfgEnable;
-	static const int		cfgBenchmark17_Iterations	=	4;
-	static const int		cfgBenchmark17_Reference	=	3390;
-
-	btClock					wallclock;
-	printf("Benchmarking dbvt...\r\n");
-	printf("\tWorld scale: %f\r\n",cfgVolumeCenterScale);
-	printf("\tExtents base: %f\r\n",cfgVolumeExentsBase);
-	printf("\tExtents range: %f\r\n",cfgVolumeExentsScale);
-	printf("\tLeaves: %u\r\n",cfgLeaves);
-	printf("\tsizeof(btDbvtVolume): %u bytes\r\n",sizeof(btDbvtVolume));
-	printf("\tsizeof(btDbvtNode):   %u bytes\r\n",sizeof(btDbvtNode));
-	if(cfgBenchmark1_Enable)
+static const btScalar	cfgVolumeCenterScale		=	100;
+static const btScalar	cfgVolumeExentsBase			=	1;
+static const btScalar	cfgVolumeExentsScale		=	4;
+static const int		cfgLeaves					=	8192;
+static const bool		cfgEnable					=	true;
+
+//[1] btDbvtVolume intersections
+bool					cfgBenchmark1_Enable		=	cfgEnable;
+static const int		cfgBenchmark1_Iterations	=	8;
+static const int		cfgBenchmark1_Reference		=	3499;
+//[2] btDbvtVolume merges
+bool					cfgBenchmark2_Enable		=	cfgEnable;
+static const int		cfgBenchmark2_Iterations	=	4;
+static const int		cfgBenchmark2_Reference		=	1945;
+//[3] btDbvt::collideTT
+bool					cfgBenchmark3_Enable		=	cfgEnable;
+static const int		cfgBenchmark3_Iterations	=	512;
+static const int		cfgBenchmark3_Reference		=	5485;
+//[4] btDbvt::collideTT self
+bool					cfgBenchmark4_Enable		=	cfgEnable;
+static const int		cfgBenchmark4_Iterations	=	512;
+static const int		cfgBenchmark4_Reference		=	2814;
+//[5] btDbvt::collideTT xform
+bool					cfgBenchmark5_Enable		=	cfgEnable;
+static const int		cfgBenchmark5_Iterations	=	512;
+static const btScalar	cfgBenchmark5_OffsetScale	=	2;
+static const int		cfgBenchmark5_Reference		=	7379;
+//[6] btDbvt::collideTT xform,self
+bool					cfgBenchmark6_Enable		=	cfgEnable;
+static const int		cfgBenchmark6_Iterations	=	512;
+static const btScalar	cfgBenchmark6_OffsetScale	=	2;
+static const int		cfgBenchmark6_Reference		=	7270;
+//[7] btDbvt::collideRAY
+bool					cfgBenchmark7_Enable		=	cfgEnable;
+static const int		cfgBenchmark7_Passes		=	32;
+static const int		cfgBenchmark7_Iterations	=	65536;
+static const int		cfgBenchmark7_Reference		=	6307;
+//[8] insert/remove
+bool					cfgBenchmark8_Enable		=	cfgEnable;
+static const int		cfgBenchmark8_Passes		=	32;
+static const int		cfgBenchmark8_Iterations	=	65536;
+static const int		cfgBenchmark8_Reference		=	2105;
+//[9] updates (teleport)
+bool					cfgBenchmark9_Enable		=	cfgEnable;
+static const int		cfgBenchmark9_Passes		=	32;
+static const int		cfgBenchmark9_Iterations	=	65536;
+static const int		cfgBenchmark9_Reference		=	1879;
+//[10] updates (jitter)
+bool					cfgBenchmark10_Enable		=	cfgEnable;
+static const btScalar	cfgBenchmark10_Scale		=	cfgVolumeCenterScale/10000;
+static const int		cfgBenchmark10_Passes		=	32;
+static const int		cfgBenchmark10_Iterations	=	65536;
+static const int		cfgBenchmark10_Reference	=	1244;
+//[11] optimize (incremental)
+bool					cfgBenchmark11_Enable		=	cfgEnable;
+static const int		cfgBenchmark11_Passes		=	64;
+static const int		cfgBenchmark11_Iterations	=	65536;
+static const int		cfgBenchmark11_Reference	=	2510;
+//[12] btDbvtVolume notequal
+bool					cfgBenchmark12_Enable		=	cfgEnable;
+static const int		cfgBenchmark12_Iterations	=	32;
+static const int		cfgBenchmark12_Reference	=	3677;
+//[13] culling(OCL+fullsort)
+bool					cfgBenchmark13_Enable		=	cfgEnable;
+static const int		cfgBenchmark13_Iterations	=	1024;
+static const int		cfgBenchmark13_Reference	=	2231;
+//[14] culling(OCL+qsort)
+bool					cfgBenchmark14_Enable		=	cfgEnable;
+static const int		cfgBenchmark14_Iterations	=	8192;
+static const int		cfgBenchmark14_Reference	=	3500;
+//[15] culling(KDOP+qsort)
+bool					cfgBenchmark15_Enable		=	cfgEnable;
+static const int		cfgBenchmark15_Iterations	=	8192;
+static const int		cfgBenchmark15_Reference	=	1151;
+//[16] insert/remove batch
+bool					cfgBenchmark16_Enable		=	cfgEnable;
+static const int		cfgBenchmark16_BatchCount	=	256;
+static const int		cfgBenchmark16_Passes		=	16384;
+static const int		cfgBenchmark16_Reference	=	5138;
+//[17] select
+bool					cfgBenchmark17_Enable		=	cfgEnable;
+static const int		cfgBenchmark17_Iterations	=	4;
+static const int		cfgBenchmark17_Reference	=	3390;
+
+btClock					wallclock;
+printf("Benchmarking dbvt...\r\n");
+printf("\tWorld scale: %f\r\n",cfgVolumeCenterScale);
+printf("\tExtents base: %f\r\n",cfgVolumeExentsBase);
+printf("\tExtents range: %f\r\n",cfgVolumeExentsScale);
+printf("\tLeaves: %u\r\n",cfgLeaves);
+printf("\tsizeof(btDbvtVolume): %u bytes\r\n",sizeof(btDbvtVolume));
+printf("\tsizeof(btDbvtNode):   %u bytes\r\n",sizeof(btDbvtNode));
+if(cfgBenchmark1_Enable)
 	{// Benchmark 1	
-		srand(380843);
-		btAlignedObjectArray<btDbvtVolume>	volumes;
-		btAlignedObjectArray<bool>			results;
-		volumes.resize(cfgLeaves);
-		results.resize(cfgLeaves);
-		for(int i=0;i<cfgLeaves;++i)
-		{
-			volumes[i]=btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale);
-		}
-		printf("[1] btDbvtVolume intersections: ");
-		wallclock.reset();
-		for(int i=0;i<cfgBenchmark1_Iterations;++i)
-		{
-			for(int j=0;j<cfgLeaves;++j)
-			{
-				for(int k=0;k<cfgLeaves;++k)
+	srand(380843);
+	btAlignedObjectArray<btDbvtVolume>	volumes;
+	btAlignedObjectArray<bool>			results;
+	volumes.resize(cfgLeaves);
+	results.resize(cfgLeaves);
+	for(int i=0;i<cfgLeaves;++i)
+		{
+		volumes[i]=btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale);
+		}
+	printf("[1] btDbvtVolume intersections: ");
+	wallclock.reset();
+	for(int i=0;i<cfgBenchmark1_Iterations;++i)
+		{
+		for(int j=0;j<cfgLeaves;++j)
+			{
+			for(int k=0;k<cfgLeaves;++k)
 				{
-					results[k]=Intersect(volumes[j],volumes[k]);
+				results[k]=Intersect(volumes[j],volumes[k]);
 				}
 			}
 		}
-		const int time=(int)wallclock.getTimeMilliseconds();
-		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark1_Reference)*100/time);
-	}
-	if(cfgBenchmark2_Enable)
+	const int time=(int)wallclock.getTimeMilliseconds();
+	printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark1_Reference)*100/time);
+	}
+if(cfgBenchmark2_Enable)
 	{// Benchmark 2	
-		srand(380843);
-		btAlignedObjectArray<btDbvtVolume>	volumes;
-		btAlignedObjectArray<btDbvtVolume>	results;
-		volumes.resize(cfgLeaves);
-		results.resize(cfgLeaves);
-		for(int i=0;i<cfgLeaves;++i)
-		{
-			volumes[i]=btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale);
-		}
-		printf("[2] btDbvtVolume merges: ");
-		wallclock.reset();
-		for(int i=0;i<cfgBenchmark2_Iterations;++i)
-		{
-			for(int j=0;j<cfgLeaves;++j)
-			{
-				for(int k=0;k<cfgLeaves;++k)
+	srand(380843);
+	btAlignedObjectArray<btDbvtVolume>	volumes;
+	btAlignedObjectArray<btDbvtVolume>	results;
+	volumes.resize(cfgLeaves);
+	results.resize(cfgLeaves);
+	for(int i=0;i<cfgLeaves;++i)
+		{
+		volumes[i]=btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale);
+		}
+	printf("[2] btDbvtVolume merges: ");
+	wallclock.reset();
+	for(int i=0;i<cfgBenchmark2_Iterations;++i)
+		{
+		for(int j=0;j<cfgLeaves;++j)
+			{
+			for(int k=0;k<cfgLeaves;++k)
 				{
-					Merge(volumes[j],volumes[k],results[k]);
+				Merge(volumes[j],volumes[k],results[k]);
 				}
 			}
 		}
-		const int time=(int)wallclock.getTimeMilliseconds();
-		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark2_Reference)*100/time);
-	}
-	if(cfgBenchmark3_Enable)
+	const int time=(int)wallclock.getTimeMilliseconds();
+	printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark2_Reference)*100/time);
+	}
+if(cfgBenchmark3_Enable)
 	{// Benchmark 3	
-		srand(380843);
-		btDbvt						dbvt[2];
-		btDbvtBenchmark::NilPolicy	policy;
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt[0]);
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt[1]);
-		dbvt[0].optimizeTopDown();
-		dbvt[1].optimizeTopDown();
-		printf("[3] btDbvt::collideTT: ");
-		wallclock.reset();
-		for(int i=0;i<cfgBenchmark3_Iterations;++i)
-		{
-			btDbvt::collideTT(dbvt[0].m_root,dbvt[1].m_root,policy);
-		}
-		const int time=(int)wallclock.getTimeMilliseconds();
-		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark3_Reference)*100/time);
-	}
-	if(cfgBenchmark4_Enable)
+	srand(380843);
+	btDbvt						dbvt[2];
+	btDbvtBenchmark::NilPolicy	policy;
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt[0]);
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt[1]);
+	dbvt[0].optimizeTopDown();
+	dbvt[1].optimizeTopDown();
+	printf("[3] btDbvt::collideTT: ");
+	wallclock.reset();
+	for(int i=0;i<cfgBenchmark3_Iterations;++i)
+		{
+		btDbvt::collideTT(dbvt[0].m_root,dbvt[1].m_root,policy);
+		}
+	const int time=(int)wallclock.getTimeMilliseconds();
+	printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark3_Reference)*100/time);
+	}
+if(cfgBenchmark4_Enable)
 	{// Benchmark 4
-		srand(380843);
-		btDbvt						dbvt;
-		btDbvtBenchmark::NilPolicy	policy;
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
-		dbvt.optimizeTopDown();
-		printf("[4] btDbvt::collideTT self: ");
-		wallclock.reset();
-		for(int i=0;i<cfgBenchmark4_Iterations;++i)
-		{
-			btDbvt::collideTT(dbvt.m_root,dbvt.m_root,policy);
-		}
-		const int time=(int)wallclock.getTimeMilliseconds();
-		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark4_Reference)*100/time);
-	}
-	if(cfgBenchmark5_Enable)
+	srand(380843);
+	btDbvt						dbvt;
+	btDbvtBenchmark::NilPolicy	policy;
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
+	dbvt.optimizeTopDown();
+	printf("[4] btDbvt::collideTT self: ");
+	wallclock.reset();
+	for(int i=0;i<cfgBenchmark4_Iterations;++i)
+		{
+		btDbvt::collideTT(dbvt.m_root,dbvt.m_root,policy);
+		}
+	const int time=(int)wallclock.getTimeMilliseconds();
+	printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark4_Reference)*100/time);
+	}
+if(cfgBenchmark5_Enable)
 	{// Benchmark 5	
-		srand(380843);
-		btDbvt								dbvt[2];
-		btAlignedObjectArray<btTransform>	transforms;
-		btDbvtBenchmark::NilPolicy			policy;
-		transforms.resize(cfgBenchmark5_Iterations);
-		for(int i=0;i<transforms.size();++i)
-		{
-			transforms[i]=btDbvtBenchmark::RandTransform(cfgVolumeCenterScale*cfgBenchmark5_OffsetScale);
-		}
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt[0]);
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt[1]);
-		dbvt[0].optimizeTopDown();
-		dbvt[1].optimizeTopDown();
-		printf("[5] btDbvt::collideTT xform: ");
-		wallclock.reset();
-		for(int i=0;i<cfgBenchmark5_Iterations;++i)
-		{
-			btDbvt::collideTT(dbvt[0].m_root,dbvt[1].m_root,transforms[i],policy);
-		}
-		const int time=(int)wallclock.getTimeMilliseconds();
-		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark5_Reference)*100/time);
-	}
-	if(cfgBenchmark6_Enable)
+	srand(380843);
+	btDbvt								dbvt[2];
+	btAlignedObjectArray<btTransform>	transforms;
+	btDbvtBenchmark::NilPolicy			policy;
+	transforms.resize(cfgBenchmark5_Iterations);
+	for(int i=0;i<transforms.size();++i)
+		{
+		transforms[i]=btDbvtBenchmark::RandTransform(cfgVolumeCenterScale*cfgBenchmark5_OffsetScale);
+		}
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt[0]);
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt[1]);
+	dbvt[0].optimizeTopDown();
+	dbvt[1].optimizeTopDown();
+	printf("[5] btDbvt::collideTT xform: ");
+	wallclock.reset();
+	for(int i=0;i<cfgBenchmark5_Iterations;++i)
+		{
+		btDbvt::collideTT(dbvt[0].m_root,dbvt[1].m_root,transforms[i],policy);
+		}
+	const int time=(int)wallclock.getTimeMilliseconds();
+	printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark5_Reference)*100/time);
+	}
+if(cfgBenchmark6_Enable)
 	{// Benchmark 6	
-		srand(380843);
-		btDbvt								dbvt;
-		btAlignedObjectArray<btTransform>	transforms;
-		btDbvtBenchmark::NilPolicy			policy;
-		transforms.resize(cfgBenchmark6_Iterations);
-		for(int i=0;i<transforms.size();++i)
-		{
-			transforms[i]=btDbvtBenchmark::RandTransform(cfgVolumeCenterScale*cfgBenchmark6_OffsetScale);
-		}
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
-		dbvt.optimizeTopDown();
-		printf("[6] btDbvt::collideTT xform,self: ");
-		wallclock.reset();
-		for(int i=0;i<cfgBenchmark6_Iterations;++i)
-		{
-			btDbvt::collideTT(dbvt.m_root,dbvt.m_root,transforms[i],policy);		
-		}
-		const int time=(int)wallclock.getTimeMilliseconds();
-		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark6_Reference)*100/time);
-	}
-	if(cfgBenchmark7_Enable)
+	srand(380843);
+	btDbvt								dbvt;
+	btAlignedObjectArray<btTransform>	transforms;
+	btDbvtBenchmark::NilPolicy			policy;
+	transforms.resize(cfgBenchmark6_Iterations);
+	for(int i=0;i<transforms.size();++i)
+		{
+		transforms[i]=btDbvtBenchmark::RandTransform(cfgVolumeCenterScale*cfgBenchmark6_OffsetScale);
+		}
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
+	dbvt.optimizeTopDown();
+	printf("[6] btDbvt::collideTT xform,self: ");
+	wallclock.reset();
+	for(int i=0;i<cfgBenchmark6_Iterations;++i)
+		{
+		btDbvt::collideTT(dbvt.m_root,dbvt.m_root,transforms[i],policy);		
+		}
+	const int time=(int)wallclock.getTimeMilliseconds();
+	printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark6_Reference)*100/time);
+	}
+if(cfgBenchmark7_Enable)
 	{// Benchmark 7	
-		srand(380843);
-		btDbvt								dbvt;
-		btAlignedObjectArray<btVector3>		rayorg;
-		btAlignedObjectArray<btVector3>		raydir;
-		btDbvtBenchmark::NilPolicy			policy;
-		rayorg.resize(cfgBenchmark7_Iterations);
-		raydir.resize(cfgBenchmark7_Iterations);
-		for(int i=0;i<rayorg.size();++i)
-		{
-			rayorg[i]=btDbvtBenchmark::RandVector3(cfgVolumeCenterScale*2);
-			raydir[i]=btDbvtBenchmark::RandVector3(cfgVolumeCenterScale*2);
-		}
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
-		dbvt.optimizeTopDown();
-		printf("[7] btDbvt::rayTest: ");
-		wallclock.reset();
-		for(int i=0;i<cfgBenchmark7_Passes;++i)
-		{
-			for(int j=0;j<cfgBenchmark7_Iterations;++j)
-			{
-				btDbvt::rayTest(dbvt.m_root,rayorg[j],rayorg[j]+raydir[j],policy);
-			}
-		}
-		const int	time=(int)wallclock.getTimeMilliseconds();
-		unsigned	rays=cfgBenchmark7_Passes*cfgBenchmark7_Iterations;
-		printf("%u ms (%i%%),(%u r/s)\r\n",time,(time-cfgBenchmark7_Reference)*100/time,(rays*1000)/time);
-	}
-	if(cfgBenchmark8_Enable)
+	srand(380843);
+	btDbvt								dbvt;
+	btAlignedObjectArray<btVector3>		rayorg;
+	btAlignedObjectArray<btVector3>		raydir;
+	btDbvtBenchmark::NilPolicy			policy;
+	rayorg.resize(cfgBenchmark7_Iterations);
+	raydir.resize(cfgBenchmark7_Iterations);
+	for(int i=0;i<rayorg.size();++i)
+		{
+		rayorg[i]=btDbvtBenchmark::RandVector3(cfgVolumeCenterScale*2);
+		raydir[i]=btDbvtBenchmark::RandVector3(cfgVolumeCenterScale*2);
+		}
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
+	dbvt.optimizeTopDown();
+	printf("[7] btDbvt::collideRAY: ");
+	wallclock.reset();
+	for(int i=0;i<cfgBenchmark7_Passes;++i)
+		{
+		for(int j=0;j<cfgBenchmark7_Iterations;++j)
+			{
+			btDbvt::collideRAY(dbvt.m_root,rayorg[j],raydir[j],policy);
+			}
+		}
+	const int	time=(int)wallclock.getTimeMilliseconds();
+	unsigned	rays=cfgBenchmark7_Passes*cfgBenchmark7_Iterations;
+	printf("%u ms (%i%%),(%u r/s)\r\n",time,(time-cfgBenchmark7_Reference)*100/time,(rays*1000)/time);
+	}
+if(cfgBenchmark8_Enable)
 	{// Benchmark 8	
-		srand(380843);
-		btDbvt								dbvt;
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
-		dbvt.optimizeTopDown();
-		printf("[8] insert/remove: ");
-		wallclock.reset();
-		for(int i=0;i<cfgBenchmark8_Passes;++i)
-		{
-			for(int j=0;j<cfgBenchmark8_Iterations;++j)
-			{
-				dbvt.remove(dbvt.insert(btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale),0));
-			}
-		}
-		const int	time=(int)wallclock.getTimeMilliseconds();
-		const int	ir=cfgBenchmark8_Passes*cfgBenchmark8_Iterations;
-		printf("%u ms (%i%%),(%u ir/s)\r\n",time,(time-cfgBenchmark8_Reference)*100/time,ir*1000/time);
-	}
-	if(cfgBenchmark9_Enable)
+	srand(380843);
+	btDbvt								dbvt;
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
+	dbvt.optimizeTopDown();
+	printf("[8] insert/remove: ");
+	wallclock.reset();
+	for(int i=0;i<cfgBenchmark8_Passes;++i)
+		{
+		for(int j=0;j<cfgBenchmark8_Iterations;++j)
+			{
+			dbvt.remove(dbvt.insert(btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale),0));
+			}
+		}
+	const int	time=(int)wallclock.getTimeMilliseconds();
+	const int	ir=cfgBenchmark8_Passes*cfgBenchmark8_Iterations;
+	printf("%u ms (%i%%),(%u ir/s)\r\n",time,(time-cfgBenchmark8_Reference)*100/time,ir*1000/time);
+	}
+if(cfgBenchmark9_Enable)
 	{// Benchmark 9	
-		srand(380843);
-		btDbvt										dbvt;
-		btAlignedObjectArray<const btDbvtNode*>	leaves;
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
-		dbvt.optimizeTopDown();
-		dbvt.extractLeaves(dbvt.m_root,leaves);
-		printf("[9] updates (teleport): ");
-		wallclock.reset();
-		for(int i=0;i<cfgBenchmark9_Passes;++i)
-		{
-			for(int j=0;j<cfgBenchmark9_Iterations;++j)
-			{
-				dbvt.update(const_cast<btDbvtNode*>(leaves[rand()%cfgLeaves]),
-					btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale));
-			}
-		}
-		const int	time=(int)wallclock.getTimeMilliseconds();
-		const int	up=cfgBenchmark9_Passes*cfgBenchmark9_Iterations;
-		printf("%u ms (%i%%),(%u u/s)\r\n",time,(time-cfgBenchmark9_Reference)*100/time,up*1000/time);
-	}
-	if(cfgBenchmark10_Enable)
+	srand(380843);
+	btDbvt										dbvt;
+	btAlignedObjectArray<const btDbvtNode*>	leaves;
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
+	dbvt.optimizeTopDown();
+	dbvt.extractLeaves(dbvt.m_root,leaves);
+	printf("[9] updates (teleport): ");
+	wallclock.reset();
+	for(int i=0;i<cfgBenchmark9_Passes;++i)
+		{
+		for(int j=0;j<cfgBenchmark9_Iterations;++j)
+			{
+			dbvt.update(const_cast<btDbvtNode*>(leaves[rand()%cfgLeaves]),
+						btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale));
+			}
+		}
+	const int	time=(int)wallclock.getTimeMilliseconds();
+	const int	up=cfgBenchmark9_Passes*cfgBenchmark9_Iterations;
+	printf("%u ms (%i%%),(%u u/s)\r\n",time,(time-cfgBenchmark9_Reference)*100/time,up*1000/time);
+	}
+if(cfgBenchmark10_Enable)
 	{// Benchmark 10	
-		srand(380843);
-		btDbvt										dbvt;
-		btAlignedObjectArray<const btDbvtNode*>	leaves;
-		btAlignedObjectArray<btVector3>				vectors;
-		vectors.resize(cfgBenchmark10_Iterations);
-		for(int i=0;i<vectors.size();++i)
-		{
-			vectors[i]=(btDbvtBenchmark::RandVector3()*2-btVector3(1,1,1))*cfgBenchmark10_Scale;
-		}
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
-		dbvt.optimizeTopDown();
-		dbvt.extractLeaves(dbvt.m_root,leaves);
-		printf("[10] updates (jitter): ");
-		wallclock.reset();
-
-		for(int i=0;i<cfgBenchmark10_Passes;++i)
-		{
-			for(int j=0;j<cfgBenchmark10_Iterations;++j)
+	srand(380843);
+	btDbvt										dbvt;
+	btAlignedObjectArray<const btDbvtNode*>	leaves;
+	btAlignedObjectArray<btVector3>				vectors;
+	vectors.resize(cfgBenchmark10_Iterations);
+	for(int i=0;i<vectors.size();++i)
+		{
+		vectors[i]=(btDbvtBenchmark::RandVector3()*2-btVector3(1,1,1))*cfgBenchmark10_Scale;
+		}
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
+	dbvt.optimizeTopDown();
+	dbvt.extractLeaves(dbvt.m_root,leaves);
+	printf("[10] updates (jitter): ");
+	wallclock.reset();
+	
+	for(int i=0;i<cfgBenchmark10_Passes;++i)
+		{
+		for(int j=0;j<cfgBenchmark10_Iterations;++j)
 			{			
-				const btVector3&	d=vectors[j];
-				btDbvtNode*		l=const_cast<btDbvtNode*>(leaves[rand()%cfgLeaves]);
-				btDbvtVolume		v=btDbvtVolume::FromMM(l->volume.Mins()+d,l->volume.Maxs()+d);
-				dbvt.update(l,v);
-			}
-		}
-		const int	time=(int)wallclock.getTimeMilliseconds();
-		const int	up=cfgBenchmark10_Passes*cfgBenchmark10_Iterations;
-		printf("%u ms (%i%%),(%u u/s)\r\n",time,(time-cfgBenchmark10_Reference)*100/time,up*1000/time);
-	}
-	if(cfgBenchmark11_Enable)
+			const btVector3&	d=vectors[j];
+			btDbvtNode*		l=const_cast<btDbvtNode*>(leaves[rand()%cfgLeaves]);
+			btDbvtVolume		v=btDbvtVolume::FromMM(l->volume.Mins()+d,l->volume.Maxs()+d);
+			dbvt.update(l,v);
+			}
+		}
+	const int	time=(int)wallclock.getTimeMilliseconds();
+	const int	up=cfgBenchmark10_Passes*cfgBenchmark10_Iterations;
+	printf("%u ms (%i%%),(%u u/s)\r\n",time,(time-cfgBenchmark10_Reference)*100/time,up*1000/time);
+	}
+if(cfgBenchmark11_Enable)
 	{// Benchmark 11	
-		srand(380843);
-		btDbvt										dbvt;
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
-		dbvt.optimizeTopDown();
-		printf("[11] optimize (incremental): ");
-		wallclock.reset();	
-		for(int i=0;i<cfgBenchmark11_Passes;++i)
-		{
-			dbvt.optimizeIncremental(cfgBenchmark11_Iterations);
-		}
-		const int	time=(int)wallclock.getTimeMilliseconds();
-		const int	op=cfgBenchmark11_Passes*cfgBenchmark11_Iterations;
-		printf("%u ms (%i%%),(%u o/s)\r\n",time,(time-cfgBenchmark11_Reference)*100/time,op/time*1000);
-	}
-	if(cfgBenchmark12_Enable)
+	srand(380843);
+	btDbvt										dbvt;
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
+	dbvt.optimizeTopDown();
+	printf("[11] optimize (incremental): ");
+	wallclock.reset();	
+	for(int i=0;i<cfgBenchmark11_Passes;++i)
+		{
+		dbvt.optimizeIncremental(cfgBenchmark11_Iterations);
+		}
+	const int	time=(int)wallclock.getTimeMilliseconds();
+	const int	op=cfgBenchmark11_Passes*cfgBenchmark11_Iterations;
+	printf("%u ms (%i%%),(%u o/s)\r\n",time,(time-cfgBenchmark11_Reference)*100/time,op/time*1000);
+	}
+if(cfgBenchmark12_Enable)
 	{// Benchmark 12	
-		srand(380843);
-		btAlignedObjectArray<btDbvtVolume>	volumes;
-		btAlignedObjectArray<bool>				results;
-		volumes.resize(cfgLeaves);
-		results.resize(cfgLeaves);
-		for(int i=0;i<cfgLeaves;++i)
-		{
-			volumes[i]=btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale);
-		}
-		printf("[12] btDbvtVolume notequal: ");
-		wallclock.reset();
-		for(int i=0;i<cfgBenchmark12_Iterations;++i)
-		{
-			for(int j=0;j<cfgLeaves;++j)
-			{
-				for(int k=0;k<cfgLeaves;++k)
+	srand(380843);
+	btAlignedObjectArray<btDbvtVolume>	volumes;
+	btAlignedObjectArray<bool>				results;
+	volumes.resize(cfgLeaves);
+	results.resize(cfgLeaves);
+	for(int i=0;i<cfgLeaves;++i)
+		{
+		volumes[i]=btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale);
+		}
+	printf("[12] btDbvtVolume notequal: ");
+	wallclock.reset();
+	for(int i=0;i<cfgBenchmark12_Iterations;++i)
+		{
+		for(int j=0;j<cfgLeaves;++j)
+			{
+			for(int k=0;k<cfgLeaves;++k)
 				{
-					results[k]=NotEqual(volumes[j],volumes[k]);
+				results[k]=NotEqual(volumes[j],volumes[k]);
 				}
 			}
 		}
-		const int time=(int)wallclock.getTimeMilliseconds();
-		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark12_Reference)*100/time);
-	}
-	if(cfgBenchmark13_Enable)
+	const int time=(int)wallclock.getTimeMilliseconds();
+	printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark12_Reference)*100/time);
+	}
+if(cfgBenchmark13_Enable)
 	{// Benchmark 13	
-		srand(380843);
-		btDbvt								dbvt;
-		btAlignedObjectArray<btVector3>		vectors;
-		btDbvtBenchmark::NilPolicy			policy;
-		vectors.resize(cfgBenchmark13_Iterations);
-		for(int i=0;i<vectors.size();++i)
-		{
-			vectors[i]=(btDbvtBenchmark::RandVector3()*2-btVector3(1,1,1)).normalized();
-		}
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
-		dbvt.optimizeTopDown();
-		printf("[13] culling(OCL+fullsort): ");
-		wallclock.reset();	
-		for(int i=0;i<cfgBenchmark13_Iterations;++i)
-		{
-			static const btScalar	offset=0;
-			policy.m_depth=-SIMD_INFINITY;
-			dbvt.collideOCL(dbvt.m_root,&vectors[i],&offset,vectors[i],1,policy);
-		}
-		const int	time=(int)wallclock.getTimeMilliseconds();
-		const int	t=cfgBenchmark13_Iterations;
-		printf("%u ms (%i%%),(%u t/s)\r\n",time,(time-cfgBenchmark13_Reference)*100/time,(t*1000)/time);
-	}
-	if(cfgBenchmark14_Enable)
+	srand(380843);
+	btDbvt								dbvt;
+	btAlignedObjectArray<btVector3>		vectors;
+	btDbvtBenchmark::NilPolicy			policy;
+	vectors.resize(cfgBenchmark13_Iterations);
+	for(int i=0;i<vectors.size();++i)
+		{
+		vectors[i]=(btDbvtBenchmark::RandVector3()*2-btVector3(1,1,1)).normalized();
+		}
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
+	dbvt.optimizeTopDown();
+	printf("[13] culling(OCL+fullsort): ");
+	wallclock.reset();	
+	for(int i=0;i<cfgBenchmark13_Iterations;++i)
+		{
+		static const btScalar	offset=0;
+		policy.m_depth=-SIMD_INFINITY;
+		dbvt.collideOCL(dbvt.m_root,&vectors[i],&offset,vectors[i],1,policy);
+		}
+	const int	time=(int)wallclock.getTimeMilliseconds();
+	const int	t=cfgBenchmark13_Iterations;
+	printf("%u ms (%i%%),(%u t/s)\r\n",time,(time-cfgBenchmark13_Reference)*100/time,(t*1000)/time);
+	}
+if(cfgBenchmark14_Enable)
 	{// Benchmark 14	
-		srand(380843);
-		btDbvt								dbvt;
-		btAlignedObjectArray<btVector3>		vectors;
-		btDbvtBenchmark::P14				policy;
-		vectors.resize(cfgBenchmark14_Iterations);
-		for(int i=0;i<vectors.size();++i)
-		{
-			vectors[i]=(btDbvtBenchmark::RandVector3()*2-btVector3(1,1,1)).normalized();
-		}
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
-		dbvt.optimizeTopDown();
-		policy.m_nodes.reserve(cfgLeaves);
-		printf("[14] culling(OCL+qsort): ");
-		wallclock.reset();	
-		for(int i=0;i<cfgBenchmark14_Iterations;++i)
-		{
-			static const btScalar	offset=0;
-			policy.m_nodes.resize(0);
-			dbvt.collideOCL(dbvt.m_root,&vectors[i],&offset,vectors[i],1,policy,false);
-			policy.m_nodes.quickSort(btDbvtBenchmark::P14::sortfnc);
-		}
-		const int	time=(int)wallclock.getTimeMilliseconds();
-		const int	t=cfgBenchmark14_Iterations;
-		printf("%u ms (%i%%),(%u t/s)\r\n",time,(time-cfgBenchmark14_Reference)*100/time,(t*1000)/time);
-	}
-	if(cfgBenchmark15_Enable)
+	srand(380843);
+	btDbvt								dbvt;
+	btAlignedObjectArray<btVector3>		vectors;
+	btDbvtBenchmark::P14				policy;
+	vectors.resize(cfgBenchmark14_Iterations);
+	for(int i=0;i<vectors.size();++i)
+		{
+		vectors[i]=(btDbvtBenchmark::RandVector3()*2-btVector3(1,1,1)).normalized();
+		}
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
+	dbvt.optimizeTopDown();
+	policy.m_nodes.reserve(cfgLeaves);
+	printf("[14] culling(OCL+qsort): ");
+	wallclock.reset();	
+	for(int i=0;i<cfgBenchmark14_Iterations;++i)
+		{
+		static const btScalar	offset=0;
+		policy.m_nodes.resize(0);
+		dbvt.collideOCL(dbvt.m_root,&vectors[i],&offset,vectors[i],1,policy,false);
+		policy.m_nodes.quickSort(btDbvtBenchmark::P14::sortfnc);
+		}
+	const int	time=(int)wallclock.getTimeMilliseconds();
+	const int	t=cfgBenchmark14_Iterations;
+	printf("%u ms (%i%%),(%u t/s)\r\n",time,(time-cfgBenchmark14_Reference)*100/time,(t*1000)/time);
+	}
+if(cfgBenchmark15_Enable)
 	{// Benchmark 15	
-		srand(380843);
-		btDbvt								dbvt;
-		btAlignedObjectArray<btVector3>		vectors;
-		btDbvtBenchmark::P15				policy;
-		vectors.resize(cfgBenchmark15_Iterations);
-		for(int i=0;i<vectors.size();++i)
-		{
-			vectors[i]=(btDbvtBenchmark::RandVector3()*2-btVector3(1,1,1)).normalized();
-		}
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
-		dbvt.optimizeTopDown();
-		policy.m_nodes.reserve(cfgLeaves);
-		printf("[15] culling(KDOP+qsort): ");
-		wallclock.reset();	
-		for(int i=0;i<cfgBenchmark15_Iterations;++i)
-		{
-			static const btScalar	offset=0;
-			policy.m_nodes.resize(0);
-			policy.m_axis=vectors[i];
-			dbvt.collideKDOP(dbvt.m_root,&vectors[i],&offset,1,policy);
-			policy.m_nodes.quickSort(btDbvtBenchmark::P15::sortfnc);
-		}
-		const int	time=(int)wallclock.getTimeMilliseconds();
-		const int	t=cfgBenchmark15_Iterations;
-		printf("%u ms (%i%%),(%u t/s)\r\n",time,(time-cfgBenchmark15_Reference)*100/time,(t*1000)/time);
-	}
-	if(cfgBenchmark16_Enable)
+	srand(380843);
+	btDbvt								dbvt;
+	btAlignedObjectArray<btVector3>		vectors;
+	btDbvtBenchmark::P15				policy;
+	vectors.resize(cfgBenchmark15_Iterations);
+	for(int i=0;i<vectors.size();++i)
+		{
+		vectors[i]=(btDbvtBenchmark::RandVector3()*2-btVector3(1,1,1)).normalized();
+		}
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
+	dbvt.optimizeTopDown();
+	policy.m_nodes.reserve(cfgLeaves);
+	printf("[15] culling(KDOP+qsort): ");
+	wallclock.reset();	
+	for(int i=0;i<cfgBenchmark15_Iterations;++i)
+		{
+		static const btScalar	offset=0;
+		policy.m_nodes.resize(0);
+		policy.m_axis=vectors[i];
+		dbvt.collideKDOP(dbvt.m_root,&vectors[i],&offset,1,policy);
+		policy.m_nodes.quickSort(btDbvtBenchmark::P15::sortfnc);
+		}
+	const int	time=(int)wallclock.getTimeMilliseconds();
+	const int	t=cfgBenchmark15_Iterations;
+	printf("%u ms (%i%%),(%u t/s)\r\n",time,(time-cfgBenchmark15_Reference)*100/time,(t*1000)/time);
+	}
+if(cfgBenchmark16_Enable)
 	{// Benchmark 16	
-		srand(380843);
-		btDbvt								dbvt;
-		btAlignedObjectArray<btDbvtNode*>	batch;
-		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
-		dbvt.optimizeTopDown();
-		batch.reserve(cfgBenchmark16_BatchCount);
-		printf("[16] insert/remove batch(%u): ",cfgBenchmark16_BatchCount);
-		wallclock.reset();
-		for(int i=0;i<cfgBenchmark16_Passes;++i)
-		{
-			for(int j=0;j<cfgBenchmark16_BatchCount;++j)
-			{
-				batch.push_back(dbvt.insert(btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale),0));
-			}
-			for(int j=0;j<cfgBenchmark16_BatchCount;++j)
-			{
-				dbvt.remove(batch[j]);
-			}
-			batch.resize(0);
-		}
-		const int	time=(int)wallclock.getTimeMilliseconds();
-		const int	ir=cfgBenchmark16_Passes*cfgBenchmark16_BatchCount;
-		printf("%u ms (%i%%),(%u bir/s)\r\n",time,(time-cfgBenchmark16_Reference)*100/time,int(ir*1000.0/time));
-	}
-	if(cfgBenchmark17_Enable)
+	srand(380843);
+	btDbvt								dbvt;
+	btAlignedObjectArray<btDbvtNode*>	batch;
+	btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
+	dbvt.optimizeTopDown();
+	batch.reserve(cfgBenchmark16_BatchCount);
+	printf("[16] insert/remove batch(%u): ",cfgBenchmark16_BatchCount);
+	wallclock.reset();
+	for(int i=0;i<cfgBenchmark16_Passes;++i)
+		{
+		for(int j=0;j<cfgBenchmark16_BatchCount;++j)
+			{
+			batch.push_back(dbvt.insert(btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale),0));
+			}
+		for(int j=0;j<cfgBenchmark16_BatchCount;++j)
+			{
+			dbvt.remove(batch[j]);
+			}
+		batch.resize(0);
+		}
+	const int	time=(int)wallclock.getTimeMilliseconds();
+	const int	ir=cfgBenchmark16_Passes*cfgBenchmark16_BatchCount;
+	printf("%u ms (%i%%),(%u bir/s)\r\n",time,(time-cfgBenchmark16_Reference)*100/time,int(ir*1000.0/time));
+	}
+if(cfgBenchmark17_Enable)
 	{// Benchmark 17
-		srand(380843);
-		btAlignedObjectArray<btDbvtVolume>	volumes;
-		btAlignedObjectArray<int>			results;
-		btAlignedObjectArray<int>			indices;
-		volumes.resize(cfgLeaves);
-		results.resize(cfgLeaves);
-		indices.resize(cfgLeaves);
-		for(int i=0;i<cfgLeaves;++i)
-		{
-			indices[i]=i;
-			volumes[i]=btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale);
-		}
-		for(int i=0;i<cfgLeaves;++i)
-		{
-			btSwap(indices[i],indices[rand()%cfgLeaves]);
-		}
-		printf("[17] btDbvtVolume select: ");
-		wallclock.reset();
-		for(int i=0;i<cfgBenchmark17_Iterations;++i)
-		{
-			for(int j=0;j<cfgLeaves;++j)
-			{
-				for(int k=0;k<cfgLeaves;++k)
+	srand(380843);
+	btAlignedObjectArray<btDbvtVolume>	volumes;
+	btAlignedObjectArray<int>			results;
+	btAlignedObjectArray<int>			indices;
+	volumes.resize(cfgLeaves);
+	results.resize(cfgLeaves);
+	indices.resize(cfgLeaves);
+	for(int i=0;i<cfgLeaves;++i)
+		{
+		indices[i]=i;
+		volumes[i]=btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale);
+		}
+	for(int i=0;i<cfgLeaves;++i)
+		{
+		btSwap(indices[i],indices[rand()%cfgLeaves]);
+		}
+	printf("[17] btDbvtVolume select: ");
+	wallclock.reset();
+	for(int i=0;i<cfgBenchmark17_Iterations;++i)
+		{
+		for(int j=0;j<cfgLeaves;++j)
+			{
+			for(int k=0;k<cfgLeaves;++k)
 				{
-					const int idx=indices[k];
-					results[idx]=Select(volumes[idx],volumes[j],volumes[k]);
+				const int idx=indices[k];
+				results[idx]=Select(volumes[idx],volumes[j],volumes[k]);
 				}
 			}
 		}
-		const int time=(int)wallclock.getTimeMilliseconds();
-		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark17_Reference)*100/time);
-	}
-	printf("\r\n\r\n");
+	const int time=(int)wallclock.getTimeMilliseconds();
+	printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark17_Reference)*100/time);
+	}
+printf("\r\n\r\n");
 }
 #endif
Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btDbvt.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btDbvt.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btDbvt.h	(revision 1972)
@@ -21,5 +21,4 @@
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btTransform.h"
-#include "LinearMath/btAabbUtil2.h"
 
 //
@@ -34,8 +33,8 @@
 // Template implementation of ICollide
 #ifdef WIN32
-#if (defined (_MSC_VER) && _MSC_VER >= 1400)
-#define	DBVT_USE_TEMPLATE		1
-#else
-#define	DBVT_USE_TEMPLATE		0
+	#if (defined (_MSC_VER) && _MSC_VER >= 1400)
+	#define	DBVT_USE_TEMPLATE		1
+	#else
+	#define	DBVT_USE_TEMPLATE		0
 #endif
 #else
@@ -136,41 +135,44 @@
 struct	btDbvtAabbMm
 {
-	DBVT_INLINE btVector3			Center() const	{ return((mi+mx)/2); }
-	DBVT_INLINE btVector3			Lengths() const	{ return(mx-mi); }
-	DBVT_INLINE btVector3			Extents() const	{ return((mx-mi)/2); }
-	DBVT_INLINE const btVector3&	Mins() const	{ return(mi); }
-	DBVT_INLINE const btVector3&	Maxs() const	{ return(mx); }
-	static inline btDbvtAabbMm		FromCE(const btVector3& c,const btVector3& e);
-	static inline btDbvtAabbMm		FromCR(const btVector3& c,btScalar r);
-	static inline btDbvtAabbMm		FromMM(const btVector3& mi,const btVector3& mx);
-	static inline btDbvtAabbMm		FromPoints(const btVector3* pts,int n);
-	static inline btDbvtAabbMm		FromPoints(const btVector3** ppts,int n);
-	DBVT_INLINE void				Expand(const btVector3& e);
-	DBVT_INLINE void				SignedExpand(const btVector3& e);
-	DBVT_INLINE bool				Contain(const btDbvtAabbMm& a) const;
-	DBVT_INLINE int					Classify(const btVector3& n,btScalar o,int s) const;
-	DBVT_INLINE btScalar			ProjectMinimum(const btVector3& v,unsigned signs) const;
-	DBVT_INLINE friend bool			Intersect(	const btDbvtAabbMm& a,
-		const btDbvtAabbMm& b);
-	DBVT_INLINE friend bool			Intersect(	const btDbvtAabbMm& a,
-		const btDbvtAabbMm& b,
-		const btTransform& xform);
-	DBVT_INLINE friend bool			Intersect(	const btDbvtAabbMm& a,
-		const btVector3& b);
-
-	DBVT_INLINE friend btScalar		Proximity(	const btDbvtAabbMm& a,
-		const btDbvtAabbMm& b);
-	DBVT_INLINE friend int			Select(		const btDbvtAabbMm& o,
-		const btDbvtAabbMm& a,
-		const btDbvtAabbMm& b);
-	DBVT_INLINE friend void			Merge(		const btDbvtAabbMm& a,
-		const btDbvtAabbMm& b,
-		btDbvtAabbMm& r);
-	DBVT_INLINE friend bool			NotEqual(	const btDbvtAabbMm& a,
-		const btDbvtAabbMm& b);
+DBVT_INLINE btVector3			Center() const	{ return((mi+mx)/2); }
+DBVT_INLINE btVector3			Lengths() const	{ return(mx-mi); }
+DBVT_INLINE btVector3			Extents() const	{ return((mx-mi)/2); }
+DBVT_INLINE const btVector3&	Mins() const	{ return(mi); }
+DBVT_INLINE const btVector3&	Maxs() const	{ return(mx); }
+static inline btDbvtAabbMm		FromCE(const btVector3& c,const btVector3& e);
+static inline btDbvtAabbMm		FromCR(const btVector3& c,btScalar r);
+static inline btDbvtAabbMm		FromMM(const btVector3& mi,const btVector3& mx);
+static inline btDbvtAabbMm		FromPoints(const btVector3* pts,int n);
+static inline btDbvtAabbMm		FromPoints(const btVector3** ppts,int n);
+DBVT_INLINE void				Expand(const btVector3& e);
+DBVT_INLINE void				SignedExpand(const btVector3& e);
+DBVT_INLINE bool				Contain(const btDbvtAabbMm& a) const;
+DBVT_INLINE int					Classify(const btVector3& n,btScalar o,int s) const;
+DBVT_INLINE btScalar			ProjectMinimum(const btVector3& v,unsigned signs) const;
+DBVT_INLINE friend bool			Intersect(	const btDbvtAabbMm& a,
+											const btDbvtAabbMm& b);
+DBVT_INLINE friend bool			Intersect(	const btDbvtAabbMm& a,
+											const btDbvtAabbMm& b,
+											const btTransform& xform);
+DBVT_INLINE friend bool			Intersect(	const btDbvtAabbMm& a,
+											const btVector3& b);
+DBVT_INLINE friend bool			Intersect(	const btDbvtAabbMm& a,
+											const btVector3& org,
+											const btVector3& invdir,
+											const unsigned* signs);
+DBVT_INLINE friend btScalar		Proximity(	const btDbvtAabbMm& a,
+											const btDbvtAabbMm& b);
+DBVT_INLINE friend int			Select(		const btDbvtAabbMm& o,
+											const btDbvtAabbMm& a,
+											const btDbvtAabbMm& b);
+DBVT_INLINE friend void			Merge(		const btDbvtAabbMm& a,
+											const btDbvtAabbMm& b,
+											btDbvtAabbMm& r);
+DBVT_INLINE friend bool			NotEqual(	const btDbvtAabbMm& a,
+											const btDbvtAabbMm& b);
 private:
-	DBVT_INLINE void				AddSpan(const btVector3& d,btScalar& smi,btScalar& smx) const;
+DBVT_INLINE void				AddSpan(const btVector3& d,btScalar& smi,btScalar& smx) const;
 private:
-	btVector3	mi,mx;
+btVector3	mi,mx;
 };
 
@@ -186,8 +188,8 @@
 	DBVT_INLINE bool	isinternal() const	{ return(!isleaf()); }
 	union	{
-		btDbvtNode*	childs[2];
-		void*	data;
-		int		dataAsInt;
-	};
+			btDbvtNode*	childs[2];
+			void*	data;
+			int		dataAsInt;
+			};
 };
 
@@ -196,21 +198,21 @@
 ///Unlike the btQuantizedBvh, nodes can be dynamically moved around, which allows for change in topology of the underlying data structure.
 struct	btDbvt
-{
+	{
 	/* Stack element	*/ 
 	struct	sStkNN
-	{
+		{
 		const btDbvtNode*	a;
 		const btDbvtNode*	b;
 		sStkNN() {}
 		sStkNN(const btDbvtNode* na,const btDbvtNode* nb) : a(na),b(nb) {}
-	};
+		};
 	struct	sStkNP
-	{
+		{
 		const btDbvtNode*	node;
 		int			mask;
 		sStkNP(const btDbvtNode* n,unsigned m) : node(n),mask(m) {}
-	};
+		};
 	struct	sStkNPS
-	{
+		{
 		const btDbvtNode*	node;
 		int			mask;
@@ -218,44 +220,44 @@
 		sStkNPS() {}
 		sStkNPS(const btDbvtNode* n,unsigned m,btScalar v) : node(n),mask(m),value(v) {}
-	};
+		};
 	struct	sStkCLN
-	{
+		{
 		const btDbvtNode*	node;
 		btDbvtNode*		parent;
 		sStkCLN(const btDbvtNode* n,btDbvtNode* p) : node(n),parent(p) {}
-	};
+		};
 	// Policies/Interfaces
-
+			
 	/* ICollide	*/ 
 	struct	ICollide
-	{		
+		{		
 		DBVT_VIRTUAL_DTOR(ICollide)
-			DBVT_VIRTUAL void	Process(const btDbvtNode*,const btDbvtNode*)		{}
+		DBVT_VIRTUAL void	Process(const btDbvtNode*,const btDbvtNode*)		{}
 		DBVT_VIRTUAL void	Process(const btDbvtNode*)					{}
 		DBVT_VIRTUAL void	Process(const btDbvtNode* n,btScalar)			{ Process(n); }
 		DBVT_VIRTUAL bool	Descent(const btDbvtNode*)					{ return(true); }
 		DBVT_VIRTUAL bool	AllLeaves(const btDbvtNode*)					{ return(true); }
-	};
+		};
 	/* IWriter	*/ 
 	struct	IWriter
-	{
+		{
 		virtual ~IWriter() {}
 		virtual void		Prepare(const btDbvtNode* root,int numnodes)=0;
 		virtual void		WriteNode(const btDbvtNode*,int index,int parent,int child0,int child1)=0;
 		virtual void		WriteLeaf(const btDbvtNode*,int index,int parent)=0;
-	};
+		};
 	/* IClone	*/ 
 	struct	IClone
-	{
+		{
 		virtual ~IClone()	{}
 		virtual void		CloneLeaf(btDbvtNode*) {}
-	};
-
+		};
+		
 	// Constants
 	enum	{
-		SIMPLE_STACKSIZE	=	64,
-		DOUBLE_STACKSIZE	=	SIMPLE_STACKSIZE*2
-	};
-
+			SIMPLE_STACKSIZE	=	64,
+			DOUBLE_STACKSIZE	=	SIMPLE_STACKSIZE*2
+			};
+		
 	// Fields
 	btDbvtNode*		m_root;
@@ -265,6 +267,6 @@
 	unsigned		m_opath;
 	// Methods
-	btDbvt();
-	~btDbvt();
+					btDbvt();
+					~btDbvt();
 	void			clear();
 	bool			empty() const { return(0==m_root); }
@@ -284,83 +286,83 @@
 	static int		countLeaves(const btDbvtNode* node);
 	static void		extractLeaves(const btDbvtNode* node,btAlignedObjectArray<const btDbvtNode*>& leaves);
-#if DBVT_ENABLE_BENCHMARK
+	#if DBVT_ENABLE_BENCHMARK
 	static void		benchmark();
-#else
+	#else
 	static void		benchmark(){}
-#endif
+	#endif
 	// DBVT_IPOLICY must support ICollide policy/interface
 	DBVT_PREFIX
-		static void		enumNodes(	const btDbvtNode* root,
-		DBVT_IPOLICY);
+	static void		enumNodes(	const btDbvtNode* root,
+								DBVT_IPOLICY);
 	DBVT_PREFIX
-		static void		enumLeaves(	const btDbvtNode* root,
-		DBVT_IPOLICY);
+	static void		enumLeaves(	const btDbvtNode* root,
+								DBVT_IPOLICY);
 	DBVT_PREFIX
-		static void		collideTT(	const btDbvtNode* root0,
-		const btDbvtNode* root1,
-		DBVT_IPOLICY);
+	static void		collideTT(	const btDbvtNode* root0,
+								const btDbvtNode* root1,
+								DBVT_IPOLICY);
 	DBVT_PREFIX
-		static void		collideTT(	const btDbvtNode* root0,
-		const btDbvtNode* root1,
-		const btTransform& xform,
-		DBVT_IPOLICY);
+	static void		collideTT(	const btDbvtNode* root0,
+								const btDbvtNode* root1,
+								const btTransform& xform,
+								DBVT_IPOLICY);
 	DBVT_PREFIX
-		static void		collideTT(	const btDbvtNode* root0,
-		const btTransform& xform0,
-		const btDbvtNode* root1,
-		const btTransform& xform1,
-		DBVT_IPOLICY);
+	static void		collideTT(	const btDbvtNode* root0,
+								const btTransform& xform0,
+								const btDbvtNode* root1,
+								const btTransform& xform1,
+								DBVT_IPOLICY);
 	DBVT_PREFIX
-		static void		collideTV(	const btDbvtNode* root,
-		const btDbvtVolume& volume,
-		DBVT_IPOLICY);
+	static void		collideTV(	const btDbvtNode* root,
+								const btDbvtVolume& volume,
+								DBVT_IPOLICY);
 	DBVT_PREFIX
-		static void		rayTest(	const btDbvtNode* root,
-		const btVector3& rayFrom,
-		const btVector3& rayTo,
-		DBVT_IPOLICY);
+	static void		collideRAY(	const btDbvtNode* root,
+								const btVector3& origin,
+								const btVector3& direction,
+								DBVT_IPOLICY);
 	DBVT_PREFIX
-		static void		collideKDOP(const btDbvtNode* root,
-		const btVector3* normals,
-		const btScalar* offsets,
-		int count,
-		DBVT_IPOLICY);
+	static void		collideKDOP(const btDbvtNode* root,
+								const btVector3* normals,
+								const btScalar* offsets,
+								int count,
+								DBVT_IPOLICY);
 	DBVT_PREFIX
-		static void		collideOCL(	const btDbvtNode* root,
-		const btVector3* normals,
-		const btScalar* offsets,
-		const btVector3& sortaxis,
-		int count,								
-		DBVT_IPOLICY,
-		bool fullsort=true);
+	static void		collideOCL(	const btDbvtNode* root,
+								const btVector3* normals,
+								const btScalar* offsets,
+								const btVector3& sortaxis,
+								int count,								
+								DBVT_IPOLICY,
+								bool fullsort=true);
 	DBVT_PREFIX
-		static void		collideTU(	const btDbvtNode* root,
-		DBVT_IPOLICY);
+	static void		collideTU(	const btDbvtNode* root,
+								DBVT_IPOLICY);
 	// Helpers	
 	static DBVT_INLINE int	nearest(const int* i,const btDbvt::sStkNPS* a,btScalar v,int l,int h)
-	{
+		{
 		int	m=0;
 		while(l<h)
-		{
+			{
 			m=(l+h)>>1;
 			if(a[i[m]].value>=v) l=m+1; else h=m;
+			}
+		return(h);
 		}
-		return(h);
-	}
 	static DBVT_INLINE int	allocate(	btAlignedObjectArray<int>& ifree,
-		btAlignedObjectArray<sStkNPS>& stock,
-		const sStkNPS& value)
-	{
+										btAlignedObjectArray<sStkNPS>& stock,
+										const sStkNPS& value)
+		{
 		int	i;
 		if(ifree.size()>0)
-		{ i=ifree[ifree.size()-1];ifree.pop_back();stock[i]=value; }
-		else
-		{ i=stock.size();stock.push_back(value); }
+			{ i=ifree[ifree.size()-1];ifree.pop_back();stock[i]=value; }
+			else
+			{ i=stock.size();stock.push_back(value); }
 		return(i); 
-	}
+		}
 	//
-private:
-	btDbvt(const btDbvt&)	{}	
-};
+	private:
+					btDbvt(const btDbvt&)	{}	
+	};
 
 //
@@ -371,34 +373,34 @@
 inline btDbvtAabbMm			btDbvtAabbMm::FromCE(const btVector3& c,const btVector3& e)
 {
-	btDbvtAabbMm box;
-	box.mi=c-e;box.mx=c+e;
-	return(box);
-}
-
+btDbvtAabbMm box;
+box.mi=c-e;box.mx=c+e;
+return(box);
+}
+	
 //
 inline btDbvtAabbMm			btDbvtAabbMm::FromCR(const btVector3& c,btScalar r)
 {
-	return(FromCE(c,btVector3(r,r,r)));
-}
-
+return(FromCE(c,btVector3(r,r,r)));
+}
+	
 //
 inline btDbvtAabbMm			btDbvtAabbMm::FromMM(const btVector3& mi,const btVector3& mx)
 {
-	btDbvtAabbMm box;
-	box.mi=mi;box.mx=mx;
-	return(box);
-}
-
+btDbvtAabbMm box;
+box.mi=mi;box.mx=mx;
+return(box);
+}
+	
 //
 inline btDbvtAabbMm			btDbvtAabbMm::FromPoints(const btVector3* pts,int n)
 {
-	btDbvtAabbMm box;
-	box.mi=box.mx=pts[0];
-	for(int i=1;i<n;++i)
-	{
-		box.mi.setMin(pts[i]);
-		box.mx.setMax(pts[i]);
-	}
-	return(box);
+btDbvtAabbMm box;
+box.mi=box.mx=pts[0];
+for(int i=1;i<n;++i)
+	{
+	box.mi.setMin(pts[i]);
+	box.mx.setMax(pts[i]);
+	}
+return(box);
 }
 
@@ -406,12 +408,12 @@
 inline btDbvtAabbMm			btDbvtAabbMm::FromPoints(const btVector3** ppts,int n)
 {
-	btDbvtAabbMm box;
-	box.mi=box.mx=*ppts[0];
-	for(int i=1;i<n;++i)
-	{
-		box.mi.setMin(*ppts[i]);
-		box.mx.setMax(*ppts[i]);
-	}
-	return(box);
+btDbvtAabbMm box;
+box.mi=box.mx=*ppts[0];
+for(int i=1;i<n;++i)
+	{
+	box.mi.setMin(*ppts[i]);
+	box.mx.setMax(*ppts[i]);
+	}
+return(box);
 }
 
@@ -419,19 +421,19 @@
 DBVT_INLINE void		btDbvtAabbMm::Expand(const btVector3& e)
 {
-	mi-=e;mx+=e;
-}
-
+mi-=e;mx+=e;
+}
+	
 //
 DBVT_INLINE void		btDbvtAabbMm::SignedExpand(const btVector3& e)
 {
-	if(e.x()>0) mx.setX(mx.x()+e[0]); else mi.setX(mi.x()+e[0]);
-	if(e.y()>0) mx.setY(mx.y()+e[1]); else mi.setY(mi.y()+e[1]);
-	if(e.z()>0) mx.setZ(mx.z()+e[2]); else mi.setZ(mi.z()+e[2]);
-}
-
+if(e.x()>0) mx.setX(mx.x()+e[0]); else mi.setX(mi.x()+e[0]);
+if(e.y()>0) mx.setY(mx.y()+e[1]); else mi.setY(mi.y()+e[1]);
+if(e.z()>0) mx.setZ(mx.z()+e[2]); else mi.setZ(mi.z()+e[2]);
+}
+	
 //
 DBVT_INLINE bool		btDbvtAabbMm::Contain(const btDbvtAabbMm& a) const
 {
-	return(	(mi.x()<=a.mi.x())&&
+return(	(mi.x()<=a.mi.x())&&
 		(mi.y()<=a.mi.y())&&
 		(mi.z()<=a.mi.z())&&
@@ -444,27 +446,27 @@
 DBVT_INLINE int		btDbvtAabbMm::Classify(const btVector3& n,btScalar o,int s) const
 {
-	btVector3			pi,px;
-	switch(s)
+btVector3			pi,px;
+switch(s)
 	{
 	case	(0+0+0):	px=btVector3(mi.x(),mi.y(),mi.z());
-		pi=btVector3(mx.x(),mx.y(),mx.z());break;
+						pi=btVector3(mx.x(),mx.y(),mx.z());break;
 	case	(1+0+0):	px=btVector3(mx.x(),mi.y(),mi.z());
-		pi=btVector3(mi.x(),mx.y(),mx.z());break;
+						pi=btVector3(mi.x(),mx.y(),mx.z());break;
 	case	(0+2+0):	px=btVector3(mi.x(),mx.y(),mi.z());
-		pi=btVector3(mx.x(),mi.y(),mx.z());break;
+						pi=btVector3(mx.x(),mi.y(),mx.z());break;
 	case	(1+2+0):	px=btVector3(mx.x(),mx.y(),mi.z());
-		pi=btVector3(mi.x(),mi.y(),mx.z());break;
+						pi=btVector3(mi.x(),mi.y(),mx.z());break;
 	case	(0+0+4):	px=btVector3(mi.x(),mi.y(),mx.z());
-		pi=btVector3(mx.x(),mx.y(),mi.z());break;
+						pi=btVector3(mx.x(),mx.y(),mi.z());break;
 	case	(1+0+4):	px=btVector3(mx.x(),mi.y(),mx.z());
-		pi=btVector3(mi.x(),mx.y(),mi.z());break;
+						pi=btVector3(mi.x(),mx.y(),mi.z());break;
 	case	(0+2+4):	px=btVector3(mi.x(),mx.y(),mx.z());
-		pi=btVector3(mx.x(),mi.y(),mi.z());break;
+						pi=btVector3(mx.x(),mi.y(),mi.z());break;
 	case	(1+2+4):	px=btVector3(mx.x(),mx.y(),mx.z());
-		pi=btVector3(mi.x(),mi.y(),mi.z());break;
-	}
-	if((dot(n,px)+o)<0)		return(-1);
-	if((dot(n,pi)+o)>=0)	return(+1);
-	return(0);
+						pi=btVector3(mi.x(),mi.y(),mi.z());break;
+	}
+if((dot(n,px)+o)<0)		return(-1);
+if((dot(n,pi)+o)>=0)	return(+1);
+return(0);
 }
 
@@ -472,9 +474,9 @@
 DBVT_INLINE btScalar	btDbvtAabbMm::ProjectMinimum(const btVector3& v,unsigned signs) const
 {
-	const btVector3*	b[]={&mx,&mi};
-	const btVector3		p(	b[(signs>>0)&1]->x(),
-		b[(signs>>1)&1]->y(),
-		b[(signs>>2)&1]->z());
-	return(dot(p,v));
+const btVector3*	b[]={&mx,&mi};
+const btVector3		p(	b[(signs>>0)&1]->x(),
+						b[(signs>>1)&1]->y(),
+						b[(signs>>2)&1]->z());
+return(dot(p,v));
 }
 
@@ -482,7 +484,7 @@
 DBVT_INLINE void		btDbvtAabbMm::AddSpan(const btVector3& d,btScalar& smi,btScalar& smx) const
 {
-	for(int i=0;i<3;++i)
-	{
-		if(d[i]<0)
+for(int i=0;i<3;++i)
+	{
+	if(d[i]<0)
 		{ smi+=mx[i]*d[i];smx+=mi[i]*d[i]; }
 		else
@@ -490,16 +492,16 @@
 	}
 }
-
+	
 //
 DBVT_INLINE bool		Intersect(	const btDbvtAabbMm& a,
-								  const btDbvtAabbMm& b)
+									const btDbvtAabbMm& b)
 {
 #if	DBVT_INT0_IMPL == DBVT_IMPL_SSE
-	const __m128	rt(_mm_or_ps(	_mm_cmplt_ps(_mm_load_ps(b.mx),_mm_load_ps(a.mi)),
-		_mm_cmplt_ps(_mm_load_ps(a.mx),_mm_load_ps(b.mi))));
-	const __int32*	pu((const __int32*)&rt);
-	return((pu[0]|pu[1]|pu[2])==0);
+const __m128	rt(_mm_or_ps(	_mm_cmplt_ps(_mm_load_ps(b.mx),_mm_load_ps(a.mi)),
+								_mm_cmplt_ps(_mm_load_ps(a.mx),_mm_load_ps(b.mi))));
+const __int32*	pu((const __int32*)&rt);
+return((pu[0]|pu[1]|pu[2])==0);
 #else
-	return(	(a.mi.x()<=b.mx.x())&&
+return(	(a.mi.x()<=b.mx.x())&&
 		(a.mx.x()>=b.mi.x())&&
 		(a.mi.y()<=b.mx.y())&&
@@ -512,23 +514,23 @@
 //
 DBVT_INLINE bool		Intersect(	const btDbvtAabbMm& a,
-								  const btDbvtAabbMm& b,
-								  const btTransform& xform)
-{
-	const btVector3		d0=xform*b.Center()-a.Center();
-	const btVector3		d1=d0*xform.getBasis();
-	btScalar			s0[2]={0,0};
-	btScalar			s1[2]={dot(xform.getOrigin(),d0),s1[0]};
-	a.AddSpan(d0,s0[0],s0[1]);
-	b.AddSpan(d1,s1[0],s1[1]);
-	if(s0[0]>(s1[1])) return(false);
-	if(s0[1]<(s1[0])) return(false);
-	return(true);
+									const btDbvtAabbMm& b,
+									const btTransform& xform)
+{
+const btVector3		d0=xform*b.Center()-a.Center();
+const btVector3		d1=d0*xform.getBasis();
+btScalar			s0[2]={0,0};
+btScalar			s1[2]={dot(xform.getOrigin(),d0),s1[0]};
+a.AddSpan(d0,s0[0],s0[1]);
+b.AddSpan(d1,s1[0],s1[1]);
+if(s0[0]>(s1[1])) return(false);
+if(s0[1]<(s1[0])) return(false);
+return(true);
 }
 
 //
 DBVT_INLINE bool		Intersect(	const btDbvtAabbMm& a,
-								  const btVector3& b)
-{
-	return(	(b.x()>=a.mi.x())&&
+									const btVector3& b)
+{
+return(	(b.x()>=a.mi.x())&&
 		(b.y()>=a.mi.y())&&
 		(b.z()>=a.mi.z())&&
@@ -538,28 +540,53 @@
 }
 
-
-
-
-
-//////////////////////////////////////
-
-
+//
+DBVT_INLINE bool		Intersect(	const btDbvtAabbMm& a,
+									const btVector3& org,
+									const btVector3& invdir,
+									const unsigned* signs)
+{
+#if 0
+const btVector3		b0((a.mi-org)*invdir);
+const btVector3		b1((a.mx-org)*invdir);
+const btVector3		tmin(btMin(b0[0],b1[0]),btMin(b0[1],b1[1]),btMin(b0[2],b1[2]));
+const btVector3		tmax(btMax(b0[0],b1[0]),btMax(b0[1],b1[1]),btMax(b0[2],b1[2]));
+const btScalar		tin=btMax(tmin[0],btMax(tmin[1],tmin[2]));
+const btScalar		tout=btMin(tmax[0],btMin(tmax[1],tmax[2]));
+return(tin<tout);
+#else
+const btVector3*	bounds[2]={&a.mi,&a.mx};
+btScalar			txmin=(bounds[  signs[0]]->x()-org[0])*invdir[0];
+btScalar			txmax=(bounds[1-signs[0]]->x()-org[0])*invdir[0];
+const btScalar		tymin=(bounds[  signs[1]]->y()-org[1])*invdir[1];
+const btScalar		tymax=(bounds[1-signs[1]]->y()-org[1])*invdir[1];
+if((txmin>tymax)||(tymin>txmax)) return(false);
+if(tymin>txmin) txmin=tymin;
+if(tymax<txmax) txmax=tymax;
+const btScalar		tzmin=(bounds[  signs[2]]->z()-org[2])*invdir[2];
+const btScalar		tzmax=(bounds[1-signs[2]]->z()-org[2])*invdir[2];
+if((txmin>tzmax)||(tzmin>txmax)) return(false);
+if(tzmin>txmin) txmin=tzmin;
+if(tzmax<txmax) txmax=tzmax;
+return(txmax>0);
+#endif
+}
+	
 //
 DBVT_INLINE btScalar	Proximity(	const btDbvtAabbMm& a,
-								  const btDbvtAabbMm& b)
-{
-	const btVector3	d=(a.mi+a.mx)-(b.mi+b.mx);
-	return(btFabs(d.x())+btFabs(d.y())+btFabs(d.z()));
+									const btDbvtAabbMm& b)
+{
+const btVector3	d=(a.mi+a.mx)-(b.mi+b.mx);
+return(btFabs(d.x())+btFabs(d.y())+btFabs(d.z()));
 }
 
 //
 DBVT_INLINE int			Select(	const btDbvtAabbMm& o,
-							   const btDbvtAabbMm& a,
-							   const btDbvtAabbMm& b)
+								const btDbvtAabbMm& a,
+								const btDbvtAabbMm& b)
 {
 #if	DBVT_SELECT_IMPL == DBVT_IMPL_SSE
-	static DBVT_ALIGN const unsigned __int32	mask[]={0x7fffffff,0x7fffffff,0x7fffffff,0x7fffffff};
+static DBVT_ALIGN const unsigned __int32	mask[]={0x7fffffff,0x7fffffff,0x7fffffff,0x7fffffff};
 	// TODO: the intrinsic version is 11% slower
-#if DBVT_USE_INTRINSIC_SSE
+	#if DBVT_USE_INTRINSIC_SSE
 	__m128	omi(_mm_load_ps(o.mi));
 	omi=_mm_add_ps(omi,_mm_load_ps(o.mx));
@@ -579,14 +606,14 @@
 	bmi=_mm_add_ss(bmi,_mm_shuffle_ps(bmi,bmi,1));
 	return(_mm_cmple_ss(bmi,ami).m128_u32[0]&1);
-#else
+	#else
 	DBVT_ALIGN __int32	r[1];
 	__asm
-	{
+		{
 		mov		eax,o
-			mov		ecx,a
-			mov		edx,b
-			movaps	xmm0,[eax]
+		mov		ecx,a
+		mov		edx,b
+		movaps	xmm0,[eax]
 		movaps	xmm5,mask
-			addps	xmm0,[eax+16]	
+		addps	xmm0,[eax+16]	
 		movaps	xmm1,[ecx]
 		movaps	xmm2,[edx]
@@ -594,22 +621,22 @@
 		addps	xmm2,[edx+16]
 		subps	xmm1,xmm0
-			subps	xmm2,xmm0
-			andps	xmm1,xmm5
-			andps	xmm2,xmm5
-			movhlps	xmm3,xmm1
-			movhlps	xmm4,xmm2
-			addps	xmm1,xmm3
-			addps	xmm2,xmm4
-			pshufd	xmm3,xmm1,1
-			pshufd	xmm4,xmm2,1
-			addss	xmm1,xmm3
-			addss	xmm2,xmm4
-			cmpless	xmm2,xmm1
-			movss	r,xmm2
-	}
+		subps	xmm2,xmm0
+		andps	xmm1,xmm5
+		andps	xmm2,xmm5
+		movhlps	xmm3,xmm1
+		movhlps	xmm4,xmm2
+		addps	xmm1,xmm3
+		addps	xmm2,xmm4
+		pshufd	xmm3,xmm1,1
+		pshufd	xmm4,xmm2,1
+		addss	xmm1,xmm3
+		addss	xmm2,xmm4
+		cmpless	xmm2,xmm1
+		movss	r,xmm2
+		}
 	return(r[0]&1);
-#endif
+	#endif
 #else
-	return(Proximity(o,a)<Proximity(o,b)?0:1);
+return(Proximity(o,a)<Proximity(o,b)?0:1);
 #endif
 }
@@ -617,21 +644,21 @@
 //
 DBVT_INLINE void		Merge(	const btDbvtAabbMm& a,
-							  const btDbvtAabbMm& b,
-							  btDbvtAabbMm& r)
+								const btDbvtAabbMm& b,
+								btDbvtAabbMm& r)
 {
 #if DBVT_MERGE_IMPL==DBVT_IMPL_SSE
-	__m128	ami(_mm_load_ps(a.mi));
-	__m128	amx(_mm_load_ps(a.mx));
-	__m128	bmi(_mm_load_ps(b.mi));
-	__m128	bmx(_mm_load_ps(b.mx));
-	ami=_mm_min_ps(ami,bmi);
-	amx=_mm_max_ps(amx,bmx);
-	_mm_store_ps(r.mi,ami);
-	_mm_store_ps(r.mx,amx);
+__m128	ami(_mm_load_ps(a.mi));
+__m128	amx(_mm_load_ps(a.mx));
+__m128	bmi(_mm_load_ps(b.mi));
+__m128	bmx(_mm_load_ps(b.mx));
+ami=_mm_min_ps(ami,bmi);
+amx=_mm_max_ps(amx,bmx);
+_mm_store_ps(r.mi,ami);
+_mm_store_ps(r.mx,amx);
 #else
-	for(int i=0;i<3;++i)
-	{
-		if(a.mi[i]<b.mi[i]) r.mi[i]=a.mi[i]; else r.mi[i]=b.mi[i];
-		if(a.mx[i]>b.mx[i]) r.mx[i]=a.mx[i]; else r.mx[i]=b.mx[i];
+for(int i=0;i<3;++i)
+	{
+	if(a.mi[i]<b.mi[i]) r.mi[i]=a.mi[i]; else r.mi[i]=b.mi[i];
+	if(a.mx[i]>b.mx[i]) r.mx[i]=a.mx[i]; else r.mx[i]=b.mx[i];
 	}
 #endif
@@ -640,7 +667,7 @@
 //
 DBVT_INLINE bool		NotEqual(	const btDbvtAabbMm& a,
-								 const btDbvtAabbMm& b)
-{
-	return(	(a.mi.x()!=b.mi.x())||
+									const btDbvtAabbMm& b)
+{
+return(	(a.mi.x()!=b.mi.x())||
 		(a.mi.y()!=b.mi.y())||
 		(a.mi.z()!=b.mi.z())||
@@ -657,12 +684,12 @@
 DBVT_PREFIX
 inline void		btDbvt::enumNodes(	const btDbvtNode* root,
-								  DBVT_IPOLICY)
-{
-	DBVT_CHECKTYPE
-		policy.Process(root);
-	if(root->isinternal())
-	{
-		enumNodes(root->childs[0],policy);
-		enumNodes(root->childs[1],policy);
+									DBVT_IPOLICY)
+{
+DBVT_CHECKTYPE
+policy.Process(root);
+if(root->isinternal())
+	{
+	enumNodes(root->childs[0],policy);
+	enumNodes(root->childs[1],policy);
 	}
 }
@@ -671,16 +698,16 @@
 DBVT_PREFIX
 inline void		btDbvt::enumLeaves(	const btDbvtNode* root,
-								   DBVT_IPOLICY)
-{
-	DBVT_CHECKTYPE
-		if(root->isinternal())
-		{
-			enumLeaves(root->childs[0],policy);
-			enumLeaves(root->childs[1],policy);
-		}
-		else
-		{
-			policy.Process(root);
-		}
+									DBVT_IPOLICY)
+{
+DBVT_CHECKTYPE
+if(root->isinternal())
+	{
+	enumLeaves(root->childs[0],policy);
+	enumLeaves(root->childs[1],policy);
+	}
+	else
+	{
+	policy.Process(root);
+	}
 }
 
@@ -688,119 +715,63 @@
 DBVT_PREFIX
 inline void		btDbvt::collideTT(	const btDbvtNode* root0,
-								  const btDbvtNode* root1,
-								  DBVT_IPOLICY)
-{
-	DBVT_CHECKTYPE
-		if(root0&&root1)
-		{
-			btAlignedObjectArray<sStkNN>	stack;
-			int								depth=1;
-			int								treshold=DOUBLE_STACKSIZE-4;
-			stack.resize(DOUBLE_STACKSIZE);
-			stack[0]=sStkNN(root0,root1);
-			do	{		
-				sStkNN	p=stack[--depth];
-				if(depth>treshold)
-				{
-					stack.resize(stack.size()*2);
-					treshold=stack.size()-4;
-				}
-				if(p.a==p.b)
-				{
-					if(p.a->isinternal())
+									const btDbvtNode* root1,
+									DBVT_IPOLICY)
+{
+DBVT_CHECKTYPE
+if(root0&&root1)
+	{
+	btAlignedObjectArray<sStkNN>	stack;
+	int								depth=1;
+	int								treshold=DOUBLE_STACKSIZE-4;
+	stack.resize(DOUBLE_STACKSIZE);
+	stack[0]=sStkNN(root0,root1);
+	do	{		
+		sStkNN	p=stack[--depth];
+		if(depth>treshold)
+			{
+			stack.resize(stack.size()*2);
+			treshold=stack.size()-4;
+			}
+		if(p.a==p.b)
+			{
+			if(p.a->isinternal())
+				{
+				stack[depth++]=sStkNN(p.a->childs[0],p.a->childs[0]);
+				stack[depth++]=sStkNN(p.a->childs[1],p.a->childs[1]);
+				stack[depth++]=sStkNN(p.a->childs[0],p.a->childs[1]);
+				}
+			}
+		else if(Intersect(p.a->volume,p.b->volume))
+			{
+			if(p.a->isinternal())
+				{
+				if(p.b->isinternal())
 					{
-						stack[depth++]=sStkNN(p.a->childs[0],p.a->childs[0]);
-						stack[depth++]=sStkNN(p.a->childs[1],p.a->childs[1]);
-						stack[depth++]=sStkNN(p.a->childs[0],p.a->childs[1]);
-					}
-				}
-				else if(Intersect(p.a->volume,p.b->volume))
-				{
-					if(p.a->isinternal())
-					{
-						if(p.b->isinternal())
-						{
-							stack[depth++]=sStkNN(p.a->childs[0],p.b->childs[0]);
-							stack[depth++]=sStkNN(p.a->childs[1],p.b->childs[0]);
-							stack[depth++]=sStkNN(p.a->childs[0],p.b->childs[1]);
-							stack[depth++]=sStkNN(p.a->childs[1],p.b->childs[1]);
-						}
-						else
-						{
-							stack[depth++]=sStkNN(p.a->childs[0],p.b);
-							stack[depth++]=sStkNN(p.a->childs[1],p.b);
-						}
+					stack[depth++]=sStkNN(p.a->childs[0],p.b->childs[0]);
+					stack[depth++]=sStkNN(p.a->childs[1],p.b->childs[0]);
+					stack[depth++]=sStkNN(p.a->childs[0],p.b->childs[1]);
+					stack[depth++]=sStkNN(p.a->childs[1],p.b->childs[1]);
 					}
 					else
 					{
-						if(p.b->isinternal())
-						{
-							stack[depth++]=sStkNN(p.a,p.b->childs[0]);
-							stack[depth++]=sStkNN(p.a,p.b->childs[1]);
-						}
-						else
-						{
-							policy.Process(p.a,p.b);
-						}
+					stack[depth++]=sStkNN(p.a->childs[0],p.b);
+					stack[depth++]=sStkNN(p.a->childs[1],p.b);
 					}
 				}
-			} while(depth);
-		}
-}
-
-//
-DBVT_PREFIX
-inline void		btDbvt::collideTT(	const btDbvtNode* root0,
-								  const btDbvtNode* root1,
-								  const btTransform& xform,
-								  DBVT_IPOLICY)
-{
-	DBVT_CHECKTYPE
-		if(root0&&root1)
-		{
-			btAlignedObjectArray<sStkNN>	stack;
-			int								depth=1;
-			int								treshold=DOUBLE_STACKSIZE-4;
-			stack.resize(DOUBLE_STACKSIZE);
-			stack[0]=sStkNN(root0,root1);
-			do	{
-				sStkNN	p=stack[--depth];
-				if(Intersect(p.a->volume,p.b->volume,xform))
-				{
-					if(depth>treshold)
+				else
+				{
+				if(p.b->isinternal())
 					{
-						stack.resize(stack.size()*2);
-						treshold=stack.size()-4;
-					}
-					if(p.a->isinternal())
-					{
-						if(p.b->isinternal())
-						{					
-							stack[depth++]=sStkNN(p.a->childs[0],p.b->childs[0]);
-							stack[depth++]=sStkNN(p.a->childs[1],p.b->childs[0]);
-							stack[depth++]=sStkNN(p.a->childs[0],p.b->childs[1]);
-							stack[depth++]=sStkNN(p.a->childs[1],p.b->childs[1]);
-						}
-						else
-						{
-							stack[depth++]=sStkNN(p.a->childs[0],p.b);
-							stack[depth++]=sStkNN(p.a->childs[1],p.b);
-						}
+					stack[depth++]=sStkNN(p.a,p.b->childs[0]);
+					stack[depth++]=sStkNN(p.a,p.b->childs[1]);
 					}
 					else
 					{
-						if(p.b->isinternal())
-						{
-							stack[depth++]=sStkNN(p.a,p.b->childs[0]);
-							stack[depth++]=sStkNN(p.a,p.b->childs[1]);
-						}
-						else
-						{
-							policy.Process(p.a,p.b);
-						}
+					policy.Process(p.a,p.b);
 					}
 				}
-			} while(depth);
-		}
+			}
+		} while(depth);
+	}
 }
 
@@ -808,102 +779,138 @@
 DBVT_PREFIX
 inline void		btDbvt::collideTT(	const btDbvtNode* root0,
-								  const btTransform& xform0,
-								  const btDbvtNode* root1,
-								  const btTransform& xform1,
-								  DBVT_IPOLICY)
-{
-	const btTransform	xform=xform0.inverse()*xform1;
-	collideTT(root0,root1,xform,policy);
-}
-
-//
-DBVT_PREFIX
-inline void		btDbvt::collideTV(	const btDbvtNode* root,
-								  const btDbvtVolume& vol,
-								  DBVT_IPOLICY)
-{
-	DBVT_CHECKTYPE
-		if(root)
-		{
-			ATTRIBUTE_ALIGNED16(btDbvtVolume)		volume(vol);
-			btAlignedObjectArray<const btDbvtNode*>	stack;
-			stack.reserve(SIMPLE_STACKSIZE);
-			stack.push_back(root);
-			do	{
-				const btDbvtNode*	n=stack[stack.size()-1];
-				stack.pop_back();
-				if(Intersect(n->volume,volume))
-				{
-					if(n->isinternal())
-					{
-						stack.push_back(n->childs[0]);
-						stack.push_back(n->childs[1]);
+									const btDbvtNode* root1,
+									const btTransform& xform,
+									DBVT_IPOLICY)
+{
+DBVT_CHECKTYPE
+if(root0&&root1)
+	{
+	btAlignedObjectArray<sStkNN>	stack;
+	int								depth=1;
+	int								treshold=DOUBLE_STACKSIZE-4;
+	stack.resize(DOUBLE_STACKSIZE);
+	stack[0]=sStkNN(root0,root1);
+	do	{
+		sStkNN	p=stack[--depth];
+		if(Intersect(p.a->volume,p.b->volume,xform))
+			{
+			if(depth>treshold)
+				{
+				stack.resize(stack.size()*2);
+				treshold=stack.size()-4;
+				}
+			if(p.a->isinternal())
+				{
+				if(p.b->isinternal())
+					{					
+					stack[depth++]=sStkNN(p.a->childs[0],p.b->childs[0]);
+					stack[depth++]=sStkNN(p.a->childs[1],p.b->childs[0]);
+					stack[depth++]=sStkNN(p.a->childs[0],p.b->childs[1]);
+					stack[depth++]=sStkNN(p.a->childs[1],p.b->childs[1]);
 					}
 					else
 					{
-						policy.Process(n);
+					stack[depth++]=sStkNN(p.a->childs[0],p.b);
+					stack[depth++]=sStkNN(p.a->childs[1],p.b);
 					}
 				}
-			} while(stack.size()>0);
-		}
-}
-
-
-//
-DBVT_PREFIX
-inline void		btDbvt::rayTest(	const btDbvtNode* root,
-								const btVector3& rayFrom,
-								const btVector3& rayTo,
-								DBVT_IPOLICY)
-{
-	DBVT_CHECKTYPE
-		if(root)
-		{
-			btVector3 rayDir = (rayTo-rayFrom);
-			rayDir.normalize ();
-
-			///what about division by zero? --> just set rayDirection[i] to INF/1e30
-			btVector3 rayDirectionInverse;
-			rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[0];
-			rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[1];
-			rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[2];
-			unsigned int signs[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0};
-
-
-			btVector3 resultNormal;
-
-
-			btAlignedObjectArray<const btDbvtNode*>	stack;
-			stack.reserve(SIMPLE_STACKSIZE);
-			stack.push_back(root);
-			do	{
-				const btDbvtNode*	node=stack[stack.size()-1];
-				stack.pop_back();
-
-				btVector3 bounds[2] = {node->volume.Mins(),node->volume.Maxs()};
-				btScalar lambda_max = rayDir.dot(rayTo-rayFrom);
-				btScalar tmin=1.f,lambda_min=0.f;
-				bool result1 = btRayAabb2(rayFrom,rayDirectionInverse,signs,bounds,tmin,lambda_min,lambda_max);
-
-#ifdef COMPARE_BTRAY_AABB2
-				btScalar param=1.f;
-				bool result2 = btRayAabb(rayFrom,rayTo,node->volume.Mins(),node->volume.Maxs(),param,resultNormal);
-				btAssert(result1 == result2);
-#endif //TEST_BTRAY_AABB2
-
-				if(result1)
-				{
-					if(node->isinternal())
+				else
+				{
+				if(p.b->isinternal())
 					{
-						stack.push_back(node->childs[0]);
-						stack.push_back(node->childs[1]);
+					stack[depth++]=sStkNN(p.a,p.b->childs[0]);
+					stack[depth++]=sStkNN(p.a,p.b->childs[1]);
 					}
 					else
 					{
-						policy.Process(node);
+					policy.Process(p.a,p.b);
 					}
 				}
-			} while(stack.size());
-		}
+			}
+		} while(depth);
+	}
+}
+
+//
+DBVT_PREFIX
+inline void		btDbvt::collideTT(	const btDbvtNode* root0,
+									const btTransform& xform0,
+									const btDbvtNode* root1,
+									const btTransform& xform1,
+									DBVT_IPOLICY)
+{
+const btTransform	xform=xform0.inverse()*xform1;
+collideTT(root0,root1,xform,policy);
+}
+
+//
+DBVT_PREFIX
+inline void		btDbvt::collideTV(	const btDbvtNode* root,
+									const btDbvtVolume& vol,
+									DBVT_IPOLICY)
+{
+DBVT_CHECKTYPE
+if(root)
+	{
+	ATTRIBUTE_ALIGNED16(btDbvtVolume)		volume(vol);
+	btAlignedObjectArray<const btDbvtNode*>	stack;
+	stack.reserve(SIMPLE_STACKSIZE);
+	stack.push_back(root);
+	do	{
+		const btDbvtNode*	n=stack[stack.size()-1];
+		stack.pop_back();
+		if(Intersect(n->volume,volume))
+			{
+			if(n->isinternal())
+				{
+				stack.push_back(n->childs[0]);
+				stack.push_back(n->childs[1]);
+				}
+				else
+				{
+				policy.Process(n);
+				}
+			}
+		} while(stack.size()>0);
+	}
+}
+
+//
+DBVT_PREFIX
+inline void		btDbvt::collideRAY(	const btDbvtNode* root,
+									const btVector3& origin,
+									const btVector3& direction,
+									DBVT_IPOLICY)
+{
+DBVT_CHECKTYPE
+if(root)
+	{
+	const btVector3	normal=direction.normalized();
+	const btVector3	invdir(	1/normal.x(),
+							1/normal.y(),
+							1/normal.z());
+	const unsigned	signs[]={	direction.x()<0,
+								direction.y()<0,
+								direction.z()<0};
+	btAlignedObjectArray<const btDbvtNode*>	stack;
+	stack.reserve(SIMPLE_STACKSIZE);
+	stack.push_back(root);
+	do	{
+		const btDbvtNode*	node=stack[stack.size()-1];
+		stack.pop_back();
+		if(Intersect(node->volume,origin,invdir,signs))
+			{
+			if(node->isinternal())
+				{
+				stack.push_back(node->childs[0]);
+				stack.push_back(node->childs[1]);
+				}
+				else
+				{
+				policy.Process(node);
+				}
+			}
+		} while(stack.size());
+	}
 }
 
@@ -916,29 +923,96 @@
 									DBVT_IPOLICY)
 {
-	DBVT_CHECKTYPE
-		if(root)
+DBVT_CHECKTYPE
+if(root)
+	{
+	const int						inside=(1<<count)-1;
+	btAlignedObjectArray<sStkNP>	stack;
+	int								signs[sizeof(unsigned)*8];
+	btAssert(count<int (sizeof(signs)/sizeof(signs[0])));
+	for(int i=0;i<count;++i)
 		{
-			const int						inside=(1<<count)-1;
-			btAlignedObjectArray<sStkNP>	stack;
-			int								signs[sizeof(unsigned)*8];
-			btAssert(count<int (sizeof(signs)/sizeof(signs[0])));
-			for(int i=0;i<count;++i)
-			{
-				signs[i]=	((normals[i].x()>=0)?1:0)+
+		signs[i]=	((normals[i].x()>=0)?1:0)+
 					((normals[i].y()>=0)?2:0)+
 					((normals[i].z()>=0)?4:0);
+		}
+	stack.reserve(SIMPLE_STACKSIZE);
+	stack.push_back(sStkNP(root,0));
+	do	{
+		sStkNP	se=stack[stack.size()-1];
+		bool	out=false;
+		stack.pop_back();
+		for(int i=0,j=1;(!out)&&(i<count);++i,j<<=1)
+			{
+			if(0==(se.mask&j))
+				{
+				const int	side=se.node->volume.Classify(normals[i],offsets[i],signs[i]);
+				switch(side)
+					{
+					case	-1:	out=true;break;
+					case	+1:	se.mask|=j;break;
+					}
+				}
 			}
-			stack.reserve(SIMPLE_STACKSIZE);
-			stack.push_back(sStkNP(root,0));
-			do	{
-				sStkNP	se=stack[stack.size()-1];
-				bool	out=false;
-				stack.pop_back();
-				for(int i=0,j=1;(!out)&&(i<count);++i,j<<=1)
-				{
-					if(0==(se.mask&j))
+		if(!out)
+			{
+			if((se.mask!=inside)&&(se.node->isinternal()))
+				{
+				stack.push_back(sStkNP(se.node->childs[0],se.mask));
+				stack.push_back(sStkNP(se.node->childs[1],se.mask));
+				}
+				else
+				{
+				if(policy.AllLeaves(se.node)) enumLeaves(se.node,policy);
+				}
+			}
+		} while(stack.size());
+	}
+}
+
+//
+DBVT_PREFIX
+inline void		btDbvt::collideOCL(	const btDbvtNode* root,
+									const btVector3* normals,
+									const btScalar* offsets,
+									const btVector3& sortaxis,
+									int count,
+									DBVT_IPOLICY,
+									bool fsort)
+{
+DBVT_CHECKTYPE
+if(root)
+	{
+	const unsigned					srtsgns=(sortaxis[0]>=0?1:0)+
+											(sortaxis[1]>=0?2:0)+
+											(sortaxis[2]>=0?4:0);
+	const int						inside=(1<<count)-1;
+	btAlignedObjectArray<sStkNPS>	stock;
+	btAlignedObjectArray<int>		ifree;
+	btAlignedObjectArray<int>		stack;
+	int								signs[sizeof(unsigned)*8];
+	btAssert(count<int (sizeof(signs)/sizeof(signs[0])));
+	for(int i=0;i<count;++i)
+		{
+		signs[i]=	((normals[i].x()>=0)?1:0)+
+					((normals[i].y()>=0)?2:0)+
+					((normals[i].z()>=0)?4:0);
+		}
+	stock.reserve(SIMPLE_STACKSIZE);
+	stack.reserve(SIMPLE_STACKSIZE);
+	ifree.reserve(SIMPLE_STACKSIZE);
+	stack.push_back(allocate(ifree,stock,sStkNPS(root,0,root->volume.ProjectMinimum(sortaxis,srtsgns))));
+	do	{
+		const int	id=stack[stack.size()-1];
+		sStkNPS		se=stock[id];
+		stack.pop_back();ifree.push_back(id);
+		if(se.mask!=inside)
+			{
+			bool	out=false;
+			for(int i=0,j=1;(!out)&&(i<count);++i,j<<=1)
+				{
+				if(0==(se.mask&j))
 					{
-						const int	side=se.node->volume.Classify(normals[i],offsets[i],signs[i]);
-						switch(side)
+					const int	side=se.node->volume.Classify(normals[i],offsets[i],signs[i]);
+					switch(side)
 						{
 						case	-1:	out=true;break;
@@ -947,116 +1021,49 @@
 					}
 				}
-				if(!out)
-				{
-					if((se.mask!=inside)&&(se.node->isinternal()))
+			if(out) continue;
+			}
+		if(policy.Descent(se.node))
+			{
+			if(se.node->isinternal())
+				{
+				const btDbvtNode* pns[]={	se.node->childs[0],se.node->childs[1]};
+				sStkNPS		nes[]={	sStkNPS(pns[0],se.mask,pns[0]->volume.ProjectMinimum(sortaxis,srtsgns)),
+									sStkNPS(pns[1],se.mask,pns[1]->volume.ProjectMinimum(sortaxis,srtsgns))};
+				const int	q=nes[0].value<nes[1].value?1:0;				
+				int			j=stack.size();
+				if(fsort&&(j>0))
 					{
-						stack.push_back(sStkNP(se.node->childs[0],se.mask));
-						stack.push_back(sStkNP(se.node->childs[1],se.mask));
+					/* Insert 0	*/ 
+					j=nearest(&stack[0],&stock[0],nes[q].value,0,stack.size());
+					stack.push_back(0);
+					#if DBVT_USE_MEMMOVE
+					memmove(&stack[j+1],&stack[j],sizeof(int)*(stack.size()-j-1));
+					#else
+					for(int k=stack.size()-1;k>j;--k) stack[k]=stack[k-1];
+					#endif
+					stack[j]=allocate(ifree,stock,nes[q]);
+					/* Insert 1	*/ 
+					j=nearest(&stack[0],&stock[0],nes[1-q].value,j,stack.size());
+					stack.push_back(0);
+					#if DBVT_USE_MEMMOVE
+					memmove(&stack[j+1],&stack[j],sizeof(int)*(stack.size()-j-1));
+					#else
+					for(int k=stack.size()-1;k>j;--k) stack[k]=stack[k-1];
+					#endif
+					stack[j]=allocate(ifree,stock,nes[1-q]);
 					}
 					else
 					{
-						if(policy.AllLeaves(se.node)) enumLeaves(se.node,policy);
+					stack.push_back(allocate(ifree,stock,nes[q]));
+					stack.push_back(allocate(ifree,stock,nes[1-q]));
 					}
 				}
-			} while(stack.size());
-		}
-}
-
-//
-DBVT_PREFIX
-inline void		btDbvt::collideOCL(	const btDbvtNode* root,
-								   const btVector3* normals,
-								   const btScalar* offsets,
-								   const btVector3& sortaxis,
-								   int count,
-								   DBVT_IPOLICY,
-								   bool fsort)
-{
-	DBVT_CHECKTYPE
-		if(root)
-		{
-			const unsigned					srtsgns=(sortaxis[0]>=0?1:0)+
-				(sortaxis[1]>=0?2:0)+
-				(sortaxis[2]>=0?4:0);
-			const int						inside=(1<<count)-1;
-			btAlignedObjectArray<sStkNPS>	stock;
-			btAlignedObjectArray<int>		ifree;
-			btAlignedObjectArray<int>		stack;
-			int								signs[sizeof(unsigned)*8];
-			btAssert(count<int (sizeof(signs)/sizeof(signs[0])));
-			for(int i=0;i<count;++i)
-			{
-				signs[i]=	((normals[i].x()>=0)?1:0)+
-					((normals[i].y()>=0)?2:0)+
-					((normals[i].z()>=0)?4:0);
+				else
+				{
+				policy.Process(se.node,se.value);
+				}
 			}
-			stock.reserve(SIMPLE_STACKSIZE);
-			stack.reserve(SIMPLE_STACKSIZE);
-			ifree.reserve(SIMPLE_STACKSIZE);
-			stack.push_back(allocate(ifree,stock,sStkNPS(root,0,root->volume.ProjectMinimum(sortaxis,srtsgns))));
-			do	{
-				const int	id=stack[stack.size()-1];
-				sStkNPS		se=stock[id];
-				stack.pop_back();ifree.push_back(id);
-				if(se.mask!=inside)
-				{
-					bool	out=false;
-					for(int i=0,j=1;(!out)&&(i<count);++i,j<<=1)
-					{
-						if(0==(se.mask&j))
-						{
-							const int	side=se.node->volume.Classify(normals[i],offsets[i],signs[i]);
-							switch(side)
-							{
-							case	-1:	out=true;break;
-							case	+1:	se.mask|=j;break;
-							}
-						}
-					}
-					if(out) continue;
-				}
-				if(policy.Descent(se.node))
-				{
-					if(se.node->isinternal())
-					{
-						const btDbvtNode* pns[]={	se.node->childs[0],se.node->childs[1]};
-						sStkNPS		nes[]={	sStkNPS(pns[0],se.mask,pns[0]->volume.ProjectMinimum(sortaxis,srtsgns)),
-							sStkNPS(pns[1],se.mask,pns[1]->volume.ProjectMinimum(sortaxis,srtsgns))};
-						const int	q=nes[0].value<nes[1].value?1:0;				
-						int			j=stack.size();
-						if(fsort&&(j>0))
-						{
-							/* Insert 0	*/ 
-							j=nearest(&stack[0],&stock[0],nes[q].value,0,stack.size());
-							stack.push_back(0);
-#if DBVT_USE_MEMMOVE
-							memmove(&stack[j+1],&stack[j],sizeof(int)*(stack.size()-j-1));
-#else
-							for(int k=stack.size()-1;k>j;--k) stack[k]=stack[k-1];
-#endif
-							stack[j]=allocate(ifree,stock,nes[q]);
-							/* Insert 1	*/ 
-							j=nearest(&stack[0],&stock[0],nes[1-q].value,j,stack.size());
-							stack.push_back(0);
-#if DBVT_USE_MEMMOVE
-							memmove(&stack[j+1],&stack[j],sizeof(int)*(stack.size()-j-1));
-#else
-							for(int k=stack.size()-1;k>j;--k) stack[k]=stack[k-1];
-#endif
-							stack[j]=allocate(ifree,stock,nes[1-q]);
-						}
-						else
-						{
-							stack.push_back(allocate(ifree,stock,nes[q]));
-							stack.push_back(allocate(ifree,stock,nes[1-q]));
-						}
-					}
-					else
-					{
-						policy.Process(se.node,se.value);
-					}
-				}
-			} while(stack.size());
-		}
+		} while(stack.size());
+	}
 }
 
@@ -1064,24 +1071,24 @@
 DBVT_PREFIX
 inline void		btDbvt::collideTU(	const btDbvtNode* root,
-								  DBVT_IPOLICY)
-{
-	DBVT_CHECKTYPE
-		if(root)
-		{
-			btAlignedObjectArray<const btDbvtNode*>	stack;
-			stack.reserve(SIMPLE_STACKSIZE);
-			stack.push_back(root);
-			do	{
-				const btDbvtNode*	n=stack[stack.size()-1];
-				stack.pop_back();
-				if(policy.Descent(n))
-				{
-					if(n->isinternal())
-					{ stack.push_back(n->childs[0]);stack.push_back(n->childs[1]); }
-					else
-					{ policy.Process(n); }
-				}
-			} while(stack.size()>0);
-		}
+									DBVT_IPOLICY)
+{
+DBVT_CHECKTYPE
+if(root)
+	{
+	btAlignedObjectArray<const btDbvtNode*>	stack;
+	stack.reserve(SIMPLE_STACKSIZE);
+	stack.push_back(root);
+	do	{
+		const btDbvtNode*	n=stack[stack.size()-1];
+		stack.pop_back();
+		if(policy.Descent(n))
+			{
+			if(n->isinternal())
+				{ stack.push_back(n->childs[0]);stack.push_back(n->childs[1]); }
+				else
+				{ policy.Process(n); }
+			}
+		} while(stack.size()>0);
+	}
 }
 
Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp	(revision 1972)
@@ -27,17 +27,17 @@
 #if DBVT_BP_PROFILE
 struct	ProfileScope
-{
+	{
 	__forceinline ProfileScope(btClock& clock,unsigned long& value) :
-	m_clock(&clock),m_value(&value),m_base(clock.getTimeMicroseconds())
-	{
-	}
+		m_clock(&clock),m_value(&value),m_base(clock.getTimeMicroseconds())
+		{
+		}
 	__forceinline ~ProfileScope()
-	{
+		{
 		(*m_value)+=m_clock->getTimeMicroseconds()-m_base;
-	}
+		}
 	btClock*		m_clock;
 	unsigned long*	m_value;
 	unsigned long	m_base;
-};
+	};
 #define	SPC(_value_)	ProfileScope	spc_scope(m_clock,_value_)
 #else
@@ -53,8 +53,8 @@
 static inline void	listappend(T* item,T*& list)
 {
-	item->links[0]=0;
-	item->links[1]=list;
-	if(list) list->links[0]=item;
-	list=item;
+item->links[0]=0;
+item->links[1]=list;
+if(list) list->links[0]=item;
+list=item;
 }
 
@@ -63,6 +63,6 @@
 static inline void	listremove(T* item,T*& list)
 {
-	if(item->links[0]) item->links[0]->links[1]=item->links[1]; else list=item->links[1];
-	if(item->links[1]) item->links[1]->links[0]=item->links[0];
+if(item->links[0]) item->links[0]->links[1]=item->links[1]; else list=item->links[1];
+if(item->links[1]) item->links[1]->links[0]=item->links[0];
 }
 
@@ -71,7 +71,7 @@
 static inline int	listcount(T* root)
 {
-	int	n=0;
-	while(root) { ++n;root=root->links[1]; }
-	return(n);
+int	n=0;
+while(root) { ++n;root=root->links[1]; }
+return(n);
 }
 
@@ -80,6 +80,6 @@
 static inline void	clear(T& value)
 {
-	static const struct ZeroDummy : T {} zerodummy;
-	value=zerodummy;
+static const struct ZeroDummy : T {} zerodummy;
+value=zerodummy;
 }
 
@@ -91,23 +91,23 @@
 struct	btDbvtTreeCollider : btDbvt::ICollide
 {
-	btDbvtBroadphase*	pbp;
-	btDbvtProxy*		proxy;
-	btDbvtTreeCollider(btDbvtBroadphase* p) : pbp(p) {}
-	void	Process(const btDbvtNode* na,const btDbvtNode* nb)
-	{
-		if(na!=nb)
-		{
-			btDbvtProxy*	pa=(btDbvtProxy*)na->data;
-			btDbvtProxy*	pb=(btDbvtProxy*)nb->data;
-#if DBVT_BP_SORTPAIRS
-			if(pa>pb) btSwap(pa,pb);
-#endif
-			pbp->m_paircache->addOverlappingPair(pa,pb);
-			++pbp->m_newpairs;
-		}
-	}
-	void	Process(const btDbvtNode* n)
-	{
-		Process(n,proxy->leaf);
+btDbvtBroadphase*	pbp;
+btDbvtProxy*		proxy;
+		btDbvtTreeCollider(btDbvtBroadphase* p) : pbp(p) {}
+void	Process(const btDbvtNode* na,const btDbvtNode* nb)
+	{
+	if(na!=nb)
+		{
+		btDbvtProxy*	pa=(btDbvtProxy*)na->data;
+		btDbvtProxy*	pb=(btDbvtProxy*)nb->data;
+		#if DBVT_BP_SORTPAIRS
+		if(pa>pb) btSwap(pa,pb);
+		#endif
+		pbp->m_paircache->addOverlappingPair(pa,pb);
+		++pbp->m_newpairs;
+		}
+	}
+void	Process(const btDbvtNode* n)
+	{
+	Process(n,proxy->leaf);
 	}
 };
@@ -120,29 +120,29 @@
 btDbvtBroadphase::btDbvtBroadphase(btOverlappingPairCache* paircache)
 {
-	m_deferedcollide	=	false;
-	m_needcleanup		=	true;
-	m_releasepaircache	=	(paircache!=0)?false:true;
-	m_prediction		=	1/(btScalar)2;
-	m_stageCurrent		=	0;
-	m_fixedleft			=	0;
-	m_fupdates			=	1;
-	m_dupdates			=	0;
-	m_cupdates			=	10;
-	m_newpairs			=	1;
-	m_updates_call		=	0;
-	m_updates_done		=	0;
-	m_updates_ratio		=	0;
-	m_paircache			=	paircache?
-paircache	:
-	new(btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16)) btHashedOverlappingPairCache();
-	m_gid				=	0;
-	m_pid				=	0;
-	m_cid				=	0;
-	for(int i=0;i<=STAGECOUNT;++i)
-	{
-		m_stageRoots[i]=0;
+m_deferedcollide	=	false;
+m_needcleanup		=	true;
+m_releasepaircache	=	(paircache!=0)?false:true;
+m_prediction		=	1/(btScalar)2;
+m_stageCurrent		=	0;
+m_fixedleft			=	0;
+m_fupdates			=	1;
+m_dupdates			=	0;
+m_cupdates			=	10;
+m_newpairs			=	1;
+m_updates_call		=	0;
+m_updates_done		=	0;
+m_updates_ratio		=	0;
+m_paircache			=	paircache?
+						paircache	:
+						new(btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16)) btHashedOverlappingPairCache();
+m_gid				=	0;
+m_pid				=	0;
+m_cid				=	0;
+for(int i=0;i<=STAGECOUNT;++i)
+	{
+	m_stageRoots[i]=0;
 	}
 #if DBVT_BP_PROFILE
-	clear(m_profiling);
+clear(m_profiling);
 #endif
 }
@@ -151,157 +151,114 @@
 btDbvtBroadphase::~btDbvtBroadphase()
 {
-	if(m_releasepaircache) 
-	{
-		m_paircache->~btOverlappingPairCache();
-		btAlignedFree(m_paircache);
-	}
+if(m_releasepaircache) 
+{
+	m_paircache->~btOverlappingPairCache();
+	btAlignedFree(m_paircache);
+}
 }
 
 //
 btBroadphaseProxy*				btDbvtBroadphase::createProxy(	const btVector3& aabbMin,
-															  const btVector3& aabbMax,
-															  int /*shapeType*/,
-															  void* userPtr,
-															  short int collisionFilterGroup,
-															  short int collisionFilterMask,
-															  btDispatcher* /*dispatcher*/,
-															  void* /*multiSapProxy*/)
-{
-	btDbvtProxy*		proxy=new(btAlignedAlloc(sizeof(btDbvtProxy),16)) btDbvtProxy(	aabbMin,aabbMax,userPtr,
-		collisionFilterGroup,
-		collisionFilterMask);
-
-	btDbvtAabbMm aabb = btDbvtVolume::FromMM(aabbMin,aabbMax);
-
-	//bproxy->aabb			=	btDbvtVolume::FromMM(aabbMin,aabbMax);
-	proxy->stage		=	m_stageCurrent;
-	proxy->m_uniqueId	=	++m_gid;
-	proxy->leaf			=	m_sets[0].insert(aabb,proxy);
-	listappend(proxy,m_stageRoots[m_stageCurrent]);
-	if(!m_deferedcollide)
-	{
-		btDbvtTreeCollider	collider(this);
-		collider.proxy=proxy;
-		btDbvt::collideTV(m_sets[0].m_root,aabb,collider);
-		btDbvt::collideTV(m_sets[1].m_root,aabb,collider);
-	}
-	return(proxy);
+																const btVector3& aabbMax,
+																int /*shapeType*/,
+																void* userPtr,
+																short int collisionFilterGroup,
+																short int collisionFilterMask,
+																btDispatcher* /*dispatcher*/,
+																void* /*multiSapProxy*/)
+{
+btDbvtProxy*		proxy=new(btAlignedAlloc(sizeof(btDbvtProxy),16)) btDbvtProxy(	userPtr,
+																					collisionFilterGroup,
+																					collisionFilterMask);
+proxy->aabb			=	btDbvtVolume::FromMM(aabbMin,aabbMax);
+proxy->stage		=	m_stageCurrent;
+proxy->m_uniqueId	=	++m_gid;
+proxy->leaf			=	m_sets[0].insert(proxy->aabb,proxy);
+listappend(proxy,m_stageRoots[m_stageCurrent]);
+if(!m_deferedcollide)
+	{
+	btDbvtTreeCollider	collider(this);
+	collider.proxy=proxy;
+	btDbvt::collideTV(m_sets[0].m_root,proxy->aabb,collider);
+	btDbvt::collideTV(m_sets[1].m_root,proxy->aabb,collider);
+	}
+return(proxy);
 }
 
 //
 void							btDbvtBroadphase::destroyProxy(	btBroadphaseProxy* absproxy,
-															   btDispatcher* dispatcher)
-{
-	btDbvtProxy*	proxy=(btDbvtProxy*)absproxy;
+																btDispatcher* dispatcher)
+{
+btDbvtProxy*	proxy=(btDbvtProxy*)absproxy;
+if(proxy->stage==STAGECOUNT)
+	m_sets[1].remove(proxy->leaf);
+	else
+	m_sets[0].remove(proxy->leaf);
+listremove(proxy,m_stageRoots[proxy->stage]);
+m_paircache->removeOverlappingPairsContainingProxy(proxy,dispatcher);
+btAlignedFree(proxy);
+m_needcleanup=true;
+}
+
+//
+void							btDbvtBroadphase::setAabb(		btBroadphaseProxy* absproxy,
+																const btVector3& aabbMin,
+																const btVector3& aabbMax,
+																btDispatcher* /*dispatcher*/)
+{
+btDbvtProxy*						proxy=(btDbvtProxy*)absproxy;
+ATTRIBUTE_ALIGNED16(btDbvtVolume)	aabb=btDbvtVolume::FromMM(aabbMin,aabbMax);
+#if DBVT_BP_PREVENTFALSEUPDATE
+if(NotEqual(aabb,proxy->leaf->volume))
+#endif
+	{
+	bool	docollide=false;
 	if(proxy->stage==STAGECOUNT)
+		{/* fixed -> dynamic set	*/ 
 		m_sets[1].remove(proxy->leaf);
-	else
-		m_sets[0].remove(proxy->leaf);
-	listremove(proxy,m_stageRoots[proxy->stage]);
-	m_paircache->removeOverlappingPairsContainingProxy(proxy,dispatcher);
-	btAlignedFree(proxy);
-	m_needcleanup=true;
-}
-
-void	btDbvtBroadphase::getAabb(btBroadphaseProxy* absproxy,btVector3& aabbMin, btVector3& aabbMax ) const
-{
-	btDbvtProxy*						proxy=(btDbvtProxy*)absproxy;
-	aabbMin = proxy->m_aabbMin;
-	aabbMax = proxy->m_aabbMax;
-}
-
-void	btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback)
-{
-
-	struct	BroadphaseRayTester : btDbvt::ICollide
-	{
-		btBroadphaseRayCallback& m_rayCallback;
-		BroadphaseRayTester(btBroadphaseRayCallback& orgCallback)
-			:m_rayCallback(orgCallback)
-		{
-		}
-		void					Process(const btDbvtNode* leaf)
-		{
-			btDbvtProxy*	proxy=(btDbvtProxy*)leaf->data;
-			m_rayCallback.process(proxy);
-		}
-	};	
-
-	BroadphaseRayTester callback(rayCallback);
-
-	m_sets[0].rayTest(	m_sets[0].m_root,
-		rayFrom,
-		rayTo,
-		callback);
-
-	m_sets[1].rayTest(	m_sets[1].m_root,
-		rayFrom,
-		rayTo,
-		callback);
-
-}
-
-//
-void							btDbvtBroadphase::setAabb(		btBroadphaseProxy* absproxy,
-														  const btVector3& aabbMin,
-														  const btVector3& aabbMax,
-														  btDispatcher* /*dispatcher*/)
-{
-	btDbvtProxy*						proxy=(btDbvtProxy*)absproxy;
-	ATTRIBUTE_ALIGNED16(btDbvtVolume)	aabb=btDbvtVolume::FromMM(aabbMin,aabbMax);
-#if DBVT_BP_PREVENTFALSEUPDATE
-	if(NotEqual(aabb,proxy->leaf->volume))
-#endif
-	{
-		bool	docollide=false;
-		if(proxy->stage==STAGECOUNT)
-		{/* fixed -> dynamic set	*/ 
-			m_sets[1].remove(proxy->leaf);
-			proxy->leaf=m_sets[0].insert(aabb,proxy);
-			docollide=true;
+		proxy->leaf=m_sets[0].insert(aabb,proxy);
+		docollide=true;
 		}
 		else
 		{/* dynamic set				*/ 
-			++m_updates_call;
-			if(Intersect(proxy->leaf->volume,aabb))
+		++m_updates_call;
+		if(Intersect(proxy->leaf->volume,aabb))
 			{/* Moving				*/ 
-
-				const btVector3	delta=aabbMin-proxy->m_aabbMin;
-				btVector3		velocity(((proxy->m_aabbMax-proxy->m_aabbMin)/2)*m_prediction);
-				if(delta[0]<0) velocity[0]=-velocity[0];
-				if(delta[1]<0) velocity[1]=-velocity[1];
-				if(delta[2]<0) velocity[2]=-velocity[2];
-				if	(
-#ifdef DBVT_BP_MARGIN				
-					m_sets[0].update(proxy->leaf,aabb,velocity,DBVT_BP_MARGIN)
-#else
-					m_sets[0].update(proxy->leaf,aabb,velocity)
-#endif
-					)
+			const btVector3	delta=aabbMin-proxy->aabb.Mins();
+			btVector3		velocity(aabb.Extents()*m_prediction);
+			if(delta[0]<0) velocity[0]=-velocity[0];
+			if(delta[1]<0) velocity[1]=-velocity[1];
+			if(delta[2]<0) velocity[2]=-velocity[2];
+			if	(
+				#ifdef DBVT_BP_MARGIN				
+				m_sets[0].update(proxy->leaf,aabb,velocity,DBVT_BP_MARGIN)
+				#else
+				m_sets[0].update(proxy->leaf,aabb,velocity)
+				#endif
+				)
 				{
-					++m_updates_done;
-					docollide=true;
+				++m_updates_done;
+				docollide=true;
 				}
 			}
 			else
 			{/* Teleporting			*/ 
-				m_sets[0].update(proxy->leaf,aabb);
-				++m_updates_done;
-				docollide=true;
+			m_sets[0].update(proxy->leaf,aabb);
+			++m_updates_done;
+			docollide=true;
 			}	
 		}
-		listremove(proxy,m_stageRoots[proxy->stage]);
-		proxy->m_aabbMin = aabbMin;
-		proxy->m_aabbMax = aabbMax;
-		proxy->stage	=	m_stageCurrent;
-		listappend(proxy,m_stageRoots[m_stageCurrent]);
-		if(docollide)
-		{
-			m_needcleanup=true;
-			if(!m_deferedcollide)
+	listremove(proxy,m_stageRoots[proxy->stage]);
+	proxy->aabb		=	aabb;
+	proxy->stage	=	m_stageCurrent;
+	listappend(proxy,m_stageRoots[m_stageCurrent]);
+	if(docollide)
+		{
+		m_needcleanup=true;
+		if(!m_deferedcollide)
 			{
-				btDbvtTreeCollider	collider(this);
-				btDbvt::collideTT(m_sets[1].m_root,proxy->leaf,collider);
-				btDbvt::collideTT(m_sets[0].m_root,proxy->leaf,collider);
+			btDbvtTreeCollider	collider(this);
+			btDbvt::collideTT(m_sets[1].m_root,proxy->leaf,collider);
+			btDbvt::collideTT(m_sets[0].m_root,proxy->leaf,collider);
 			}
 		}	
@@ -312,22 +269,22 @@
 void							btDbvtBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
 {
-	collide(dispatcher);
+collide(dispatcher);
 #if DBVT_BP_PROFILE
-	if(0==(m_pid%DBVT_BP_PROFILING_RATE))
+if(0==(m_pid%DBVT_BP_PROFILING_RATE))
 	{	
-		printf("fixed(%u) dynamics(%u) pairs(%u)\r\n",m_sets[1].m_leaves,m_sets[0].m_leaves,m_paircache->getNumOverlappingPairs());
-		unsigned int	total=m_profiling.m_total;
-		if(total<=0) total=1;
-		printf("ddcollide: %u%% (%uus)\r\n",(50+m_profiling.m_ddcollide*100)/total,m_profiling.m_ddcollide/DBVT_BP_PROFILING_RATE);
-		printf("fdcollide: %u%% (%uus)\r\n",(50+m_profiling.m_fdcollide*100)/total,m_profiling.m_fdcollide/DBVT_BP_PROFILING_RATE);
-		printf("cleanup:   %u%% (%uus)\r\n",(50+m_profiling.m_cleanup*100)/total,m_profiling.m_cleanup/DBVT_BP_PROFILING_RATE);
-		printf("total:     %uus\r\n",total/DBVT_BP_PROFILING_RATE);
-		const unsigned long	sum=m_profiling.m_ddcollide+
-			m_profiling.m_fdcollide+
-			m_profiling.m_cleanup;
-		printf("leaked: %u%% (%uus)\r\n",100-((50+sum*100)/total),(total-sum)/DBVT_BP_PROFILING_RATE);
-		printf("job counts: %u%%\r\n",(m_profiling.m_jobcount*100)/((m_sets[0].m_leaves+m_sets[1].m_leaves)*DBVT_BP_PROFILING_RATE));
-		clear(m_profiling);
-		m_clock.reset();
+	printf("fixed(%u) dynamics(%u) pairs(%u)\r\n",m_sets[1].m_leaves,m_sets[0].m_leaves,m_paircache->getNumOverlappingPairs());
+	unsigned int	total=m_profiling.m_total;
+	if(total<=0) total=1;
+	printf("ddcollide: %u%% (%uus)\r\n",(50+m_profiling.m_ddcollide*100)/total,m_profiling.m_ddcollide/DBVT_BP_PROFILING_RATE);
+	printf("fdcollide: %u%% (%uus)\r\n",(50+m_profiling.m_fdcollide*100)/total,m_profiling.m_fdcollide/DBVT_BP_PROFILING_RATE);
+	printf("cleanup:   %u%% (%uus)\r\n",(50+m_profiling.m_cleanup*100)/total,m_profiling.m_cleanup/DBVT_BP_PROFILING_RATE);
+	printf("total:     %uus\r\n",total/DBVT_BP_PROFILING_RATE);
+	const unsigned long	sum=m_profiling.m_ddcollide+
+							m_profiling.m_fdcollide+
+							m_profiling.m_cleanup;
+	printf("leaked: %u%% (%uus)\r\n",100-((50+sum*100)/total),(total-sum)/DBVT_BP_PROFILING_RATE);
+	printf("job counts: %u%%\r\n",(m_profiling.m_jobcount*100)/((m_sets[0].m_leaves+m_sets[1].m_leaves)*DBVT_BP_PROFILING_RATE));
+	clear(m_profiling);
+	m_clock.reset();
 	}
 #endif
@@ -337,87 +294,86 @@
 void							btDbvtBroadphase::collide(btDispatcher* dispatcher)
 {
-	SPC(m_profiling.m_total);
-	/* optimize				*/ 
-	m_sets[0].optimizeIncremental(1+(m_sets[0].m_leaves*m_dupdates)/100);
-	if(m_fixedleft)
-	{
-		const int count=1+(m_sets[1].m_leaves*m_fupdates)/100;
-		m_sets[1].optimizeIncremental(1+(m_sets[1].m_leaves*m_fupdates)/100);
-		m_fixedleft=btMax<int>(0,m_fixedleft-count);
-	}
-	/* dynamic -> fixed set	*/ 
-	m_stageCurrent=(m_stageCurrent+1)%STAGECOUNT;
-	btDbvtProxy*	current=m_stageRoots[m_stageCurrent];
-	if(current)
-	{
-		btDbvtTreeCollider	collider(this);
-		do	{
-			btDbvtProxy*	next=current->links[1];
-			listremove(current,m_stageRoots[current->stage]);
-			listappend(current,m_stageRoots[STAGECOUNT]);
-#if DBVT_BP_ACCURATESLEEPING
-			m_paircache->removeOverlappingPairsContainingProxy(current,dispatcher);
-			collider.proxy=current;
-			btDbvt::collideTV(m_sets[0].m_root,current->aabb,collider);
-			btDbvt::collideTV(m_sets[1].m_root,current->aabb,collider);
-#endif
-			m_sets[0].remove(current->leaf);
-			ATTRIBUTE_ALIGNED16(btDbvtVolume)	curAabb=btDbvtVolume::FromMM(current->m_aabbMin,current->m_aabbMax);
-			current->leaf	=	m_sets[1].insert(curAabb,current);
-			current->stage	=	STAGECOUNT;	
-			current			=	next;
+SPC(m_profiling.m_total);
+/* optimize				*/ 
+m_sets[0].optimizeIncremental(1+(m_sets[0].m_leaves*m_dupdates)/100);
+if(m_fixedleft)
+	{
+	const int count=1+(m_sets[1].m_leaves*m_fupdates)/100;
+	m_sets[1].optimizeIncremental(1+(m_sets[1].m_leaves*m_fupdates)/100);
+	m_fixedleft=btMax<int>(0,m_fixedleft-count);
+	}
+/* dynamic -> fixed set	*/ 
+m_stageCurrent=(m_stageCurrent+1)%STAGECOUNT;
+btDbvtProxy*	current=m_stageRoots[m_stageCurrent];
+if(current)
+	{
+	btDbvtTreeCollider	collider(this);
+	do	{
+		btDbvtProxy*	next=current->links[1];
+		listremove(current,m_stageRoots[current->stage]);
+		listappend(current,m_stageRoots[STAGECOUNT]);
+		#if DBVT_BP_ACCURATESLEEPING
+		m_paircache->removeOverlappingPairsContainingProxy(current,dispatcher);
+		collider.proxy=current;
+		btDbvt::collideTV(m_sets[0].m_root,current->aabb,collider);
+		btDbvt::collideTV(m_sets[1].m_root,current->aabb,collider);
+		#endif
+		m_sets[0].remove(current->leaf);
+		current->leaf	=	m_sets[1].insert(current->aabb,current);
+		current->stage	=	STAGECOUNT;	
+		current			=	next;
 		} while(current);
-		m_fixedleft=m_sets[1].m_leaves;
-		m_needcleanup=true;
-	}
-	/* collide dynamics		*/ 
-	{
-		btDbvtTreeCollider	collider(this);
-		if(m_deferedcollide)
-		{
-			SPC(m_profiling.m_fdcollide);
-			btDbvt::collideTT(m_sets[0].m_root,m_sets[1].m_root,collider);
-		}
-		if(m_deferedcollide)
-		{
-			SPC(m_profiling.m_ddcollide);
-			btDbvt::collideTT(m_sets[0].m_root,m_sets[0].m_root,collider);
-		}
-	}
-	/* clean up				*/ 
-	if(m_needcleanup)
-	{
-		SPC(m_profiling.m_cleanup);
-		btBroadphasePairArray&	pairs=m_paircache->getOverlappingPairArray();
-		if(pairs.size()>0)
-		{
-			const int	ci=pairs.size();
-			int			ni=btMin(ci,btMax<int>(m_newpairs,(ci*m_cupdates)/100));
-			for(int i=0;i<ni;++i)
+	m_fixedleft=m_sets[1].m_leaves;
+	m_needcleanup=true;
+	}
+/* collide dynamics		*/ 
+	{
+	btDbvtTreeCollider	collider(this);
+	if(m_deferedcollide)
+		{
+		SPC(m_profiling.m_fdcollide);
+		btDbvt::collideTT(m_sets[0].m_root,m_sets[1].m_root,collider);
+		}
+	if(m_deferedcollide)
+		{
+		SPC(m_profiling.m_ddcollide);
+		btDbvt::collideTT(m_sets[0].m_root,m_sets[0].m_root,collider);
+		}
+	}
+/* clean up				*/ 
+if(m_needcleanup)
+	{
+	SPC(m_profiling.m_cleanup);
+	btBroadphasePairArray&	pairs=m_paircache->getOverlappingPairArray();
+	if(pairs.size()>0)
+		{
+		const int	ci=pairs.size();
+		int			ni=btMin(ci,btMax<int>(m_newpairs,(ci*m_cupdates)/100));
+		for(int i=0;i<ni;++i)
 			{
-				btBroadphasePair&	p=pairs[(m_cid+i)%ci];
-				btDbvtProxy*		pa=(btDbvtProxy*)p.m_pProxy0;
-				btDbvtProxy*		pb=(btDbvtProxy*)p.m_pProxy1;
-				if(!Intersect(pa->leaf->volume,pb->leaf->volume))
+			btBroadphasePair&	p=pairs[(m_cid+i)%ci];
+			btDbvtProxy*		pa=(btDbvtProxy*)p.m_pProxy0;
+			btDbvtProxy*		pb=(btDbvtProxy*)p.m_pProxy1;
+			if(!Intersect(pa->leaf->volume,pb->leaf->volume))
 				{
-#if DBVT_BP_SORTPAIRS
-					if(pa>pb) btSwap(pa,pb);
-#endif
-					m_paircache->removeOverlappingPair(pa,pb,dispatcher);
-					--ni;--i;
+				#if DBVT_BP_SORTPAIRS
+				if(pa>pb) btSwap(pa,pb);
+				#endif
+				m_paircache->removeOverlappingPair(pa,pb,dispatcher);
+				--ni;--i;
 				}
 			}
-			if(pairs.size()>0) m_cid=(m_cid+ni)%pairs.size(); else m_cid=0;
-		}
-	}
-	++m_pid;
-	m_newpairs=1;
-	m_needcleanup=false;
-	if(m_updates_call>0)
+		if(pairs.size()>0) m_cid=(m_cid+ni)%pairs.size(); else m_cid=0;
+		}
+	}
+++m_pid;
+m_newpairs=1;
+m_needcleanup=false;
+if(m_updates_call>0)
 	{ m_updates_ratio=m_updates_done/(btScalar)m_updates_call; }
 	else
 	{ m_updates_ratio=0; }
-	m_updates_done/=2;
-	m_updates_call/=2;
+m_updates_done/=2;
+m_updates_call/=2;
 }
 
@@ -425,6 +381,6 @@
 void							btDbvtBroadphase::optimize()
 {
-	m_sets[0].optimizeTopDown();
-	m_sets[1].optimizeTopDown();
+m_sets[0].optimizeTopDown();
+m_sets[1].optimizeTopDown();
 }
 
@@ -432,5 +388,5 @@
 btOverlappingPairCache*			btDbvtBroadphase::getOverlappingPairCache()
 {
-	return(m_paircache);
+return(m_paircache);
 }
 
@@ -438,5 +394,5 @@
 const btOverlappingPairCache*	btDbvtBroadphase::getOverlappingPairCache() const
 {
-	return(m_paircache);
+return(m_paircache);
 }
 
@@ -447,14 +403,14 @@
 	ATTRIBUTE_ALIGNED16(btDbvtVolume)	bounds;
 
-	if(!m_sets[0].empty())
-		if(!m_sets[1].empty())	Merge(	m_sets[0].m_root->volume,
-			m_sets[1].m_root->volume,bounds);
-		else
-			bounds=m_sets[0].m_root->volume;
-	else if(!m_sets[1].empty())	bounds=m_sets[1].m_root->volume;
-	else
-		bounds=btDbvtVolume::FromCR(btVector3(0,0,0),0);
-	aabbMin=bounds.Mins();
-	aabbMax=bounds.Maxs();
+if(!m_sets[0].empty())
+	if(!m_sets[1].empty())	Merge(	m_sets[0].m_root->volume,
+									m_sets[1].m_root->volume,bounds);
+							else
+							bounds=m_sets[0].m_root->volume;
+else if(!m_sets[1].empty())	bounds=m_sets[1].m_root->volume;
+							else
+							bounds=btDbvtVolume::FromCR(btVector3(0,0,0),0);
+aabbMin=bounds.Mins();
+aabbMax=bounds.Maxs();
 }
 
@@ -467,7 +423,7 @@
 
 struct	btBroadphaseBenchmark
-{
+	{
 	struct	Experiment
-	{
+		{
 		const char*			name;
 		int					object_count;
@@ -477,7 +433,7 @@
 		btScalar			speed;
 		btScalar			amplitude;
-	};
+		};
 	struct	Object
-	{
+		{
 		btVector3			center;
 		btVector3			extents;
@@ -485,18 +441,18 @@
 		btScalar			time;
 		void				update(btScalar speed,btScalar amplitude,btBroadphaseInterface* pbi)
-		{
+			{
 			time		+=	speed;
 			center[0]	=	btCos(time*(btScalar)2.17)*amplitude+
-				btSin(time)*amplitude/2;
+							btSin(time)*amplitude/2;
 			center[1]	=	btCos(time*(btScalar)1.38)*amplitude+
-				btSin(time)*amplitude;
+							btSin(time)*amplitude;
 			center[2]	=	btSin(time*(btScalar)0.777)*amplitude;
 			pbi->setAabb(proxy,center-extents,center+extents,0);
-		}
-	};
+			}
+		};
 	static int		UnsignedRand(int range=RAND_MAX-1)	{ return(rand()%(range+1)); }
 	static btScalar	UnitRand()							{ return(UnsignedRand(16384)/(btScalar)16384); }
 	static void		OutputTime(const char* name,btClock& c,unsigned count=0)
-	{
+		{
 		const unsigned long	us=c.getTimeMicroseconds();
 		const unsigned long	ms=(us+500)/1000;
@@ -504,80 +460,80 @@
 		if(count>0)
 			printf("%s : %u us (%u ms), %.2f/s\r\n",name,us,ms,count/sec);
-		else
+			else
 			printf("%s : %u us (%u ms)\r\n",name,us,ms);
-	}
-};
+		}
+	};
 
 void							btDbvtBroadphase::benchmark(btBroadphaseInterface* pbi)
 {
-	static const btBroadphaseBenchmark::Experiment		experiments[]=
-	{
-		{"1024o.10%",1024,10,0,8192,(btScalar)0.005,(btScalar)100},
-		/*{"4096o.10%",4096,10,0,8192,(btScalar)0.005,(btScalar)100},
-		{"8192o.10%",8192,10,0,8192,(btScalar)0.005,(btScalar)100},*/
+static const btBroadphaseBenchmark::Experiment		experiments[]=
+	{
+	{"1024o.10%",1024,10,0,8192,(btScalar)0.005,(btScalar)100},
+	/*{"4096o.10%",4096,10,0,8192,(btScalar)0.005,(btScalar)100},
+	{"8192o.10%",8192,10,0,8192,(btScalar)0.005,(btScalar)100},*/
 	};
-	static const int										nexperiments=sizeof(experiments)/sizeof(experiments[0]);
-	btAlignedObjectArray<btBroadphaseBenchmark::Object*>	objects;
-	btClock													wallclock;
-	/* Begin			*/ 
-	for(int iexp=0;iexp<nexperiments;++iexp)
-	{
-		const btBroadphaseBenchmark::Experiment&	experiment=experiments[iexp];
-		const int									object_count=experiment.object_count;
-		const int									update_count=(object_count*experiment.update_count)/100;
-		const int									spawn_count=(object_count*experiment.spawn_count)/100;
-		const btScalar								speed=experiment.speed;	
-		const btScalar								amplitude=experiment.amplitude;
-		printf("Experiment #%u '%s':\r\n",iexp,experiment.name);
-		printf("\tObjects: %u\r\n",object_count);
-		printf("\tUpdate: %u\r\n",update_count);
-		printf("\tSpawn: %u\r\n",spawn_count);
-		printf("\tSpeed: %f\r\n",speed);
-		printf("\tAmplitude: %f\r\n",amplitude);
-		srand(180673);
-		/* Create objects	*/ 
-		wallclock.reset();
-		objects.reserve(object_count);
-		for(int i=0;i<object_count;++i)
-		{
-			btBroadphaseBenchmark::Object*	po=new btBroadphaseBenchmark::Object();
-			po->center[0]=btBroadphaseBenchmark::UnitRand()*50;
-			po->center[1]=btBroadphaseBenchmark::UnitRand()*50;
-			po->center[2]=btBroadphaseBenchmark::UnitRand()*50;
-			po->extents[0]=btBroadphaseBenchmark::UnitRand()*2+2;
-			po->extents[1]=btBroadphaseBenchmark::UnitRand()*2+2;
-			po->extents[2]=btBroadphaseBenchmark::UnitRand()*2+2;
-			po->time=btBroadphaseBenchmark::UnitRand()*2000;
-			po->proxy=pbi->createProxy(po->center-po->extents,po->center+po->extents,0,po,1,1,0,0);
-			objects.push_back(po);
-		}
-		btBroadphaseBenchmark::OutputTime("\tInitialization",wallclock);
-		/* First update		*/ 
-		wallclock.reset();
-		for(int i=0;i<objects.size();++i)
-		{
-			objects[i]->update(speed,amplitude,pbi);
-		}
-		btBroadphaseBenchmark::OutputTime("\tFirst update",wallclock);
-		/* Updates			*/ 
-		wallclock.reset();
-		for(int i=0;i<experiment.iterations;++i)
-		{
-			for(int j=0;j<update_count;++j)
+static const int										nexperiments=sizeof(experiments)/sizeof(experiments[0]);
+btAlignedObjectArray<btBroadphaseBenchmark::Object*>	objects;
+btClock													wallclock;
+/* Begin			*/ 
+for(int iexp=0;iexp<nexperiments;++iexp)
+	{
+	const btBroadphaseBenchmark::Experiment&	experiment=experiments[iexp];
+	const int									object_count=experiment.object_count;
+	const int									update_count=(object_count*experiment.update_count)/100;
+	const int									spawn_count=(object_count*experiment.spawn_count)/100;
+	const btScalar								speed=experiment.speed;	
+	const btScalar								amplitude=experiment.amplitude;
+	printf("Experiment #%u '%s':\r\n",iexp,experiment.name);
+	printf("\tObjects: %u\r\n",object_count);
+	printf("\tUpdate: %u\r\n",update_count);
+	printf("\tSpawn: %u\r\n",spawn_count);
+	printf("\tSpeed: %f\r\n",speed);
+	printf("\tAmplitude: %f\r\n",amplitude);
+	srand(180673);
+	/* Create objects	*/ 
+	wallclock.reset();
+	objects.reserve(object_count);
+	for(int i=0;i<object_count;++i)
+		{
+		btBroadphaseBenchmark::Object*	po=new btBroadphaseBenchmark::Object();
+		po->center[0]=btBroadphaseBenchmark::UnitRand()*50;
+		po->center[1]=btBroadphaseBenchmark::UnitRand()*50;
+		po->center[2]=btBroadphaseBenchmark::UnitRand()*50;
+		po->extents[0]=btBroadphaseBenchmark::UnitRand()*2+2;
+		po->extents[1]=btBroadphaseBenchmark::UnitRand()*2+2;
+		po->extents[2]=btBroadphaseBenchmark::UnitRand()*2+2;
+		po->time=btBroadphaseBenchmark::UnitRand()*2000;
+		po->proxy=pbi->createProxy(po->center-po->extents,po->center+po->extents,0,po,1,1,0,0);
+		objects.push_back(po);
+		}
+	btBroadphaseBenchmark::OutputTime("\tInitialization",wallclock);
+	/* First update		*/ 
+	wallclock.reset();
+	for(int i=0;i<objects.size();++i)
+		{
+		objects[i]->update(speed,amplitude,pbi);
+		}
+	btBroadphaseBenchmark::OutputTime("\tFirst update",wallclock);
+	/* Updates			*/ 
+	wallclock.reset();
+	for(int i=0;i<experiment.iterations;++i)
+		{
+		for(int j=0;j<update_count;++j)
 			{				
-				objects[j]->update(speed,amplitude,pbi);
+			objects[j]->update(speed,amplitude,pbi);
 			}
-			pbi->calculateOverlappingPairs(0);
-		}
-		btBroadphaseBenchmark::OutputTime("\tUpdate",wallclock,experiment.iterations);
-		/* Clean up			*/ 
-		wallclock.reset();
-		for(int i=0;i<objects.size();++i)
-		{
-			pbi->destroyProxy(objects[i]->proxy,0);
-			delete objects[i];
-		}
-		objects.resize(0);
-		btBroadphaseBenchmark::OutputTime("\tRelease",wallclock);
+		pbi->calculateOverlappingPairs(0);
+		}
+	btBroadphaseBenchmark::OutputTime("\tUpdate",wallclock,experiment.iterations);
+	/* Clean up			*/ 
+	wallclock.reset();
+	for(int i=0;i<objects.size();++i)
+		{
+		pbi->destroyProxy(objects[i]->proxy,0);
+		delete objects[i];
+		}
+	objects.resize(0);
+	btBroadphaseBenchmark::OutputTime("\tRelease",wallclock);
 	}
 
Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h	(revision 1972)
@@ -32,6 +32,6 @@
 
 #if DBVT_BP_PROFILE
-#define	DBVT_BP_PROFILING_RATE	256
-#include "LinearMath/btQuickprof.h"
+	#define	DBVT_BP_PROFILING_RATE	256
+	#include "LinearMath/btQuickprof.h"
 #endif
 
@@ -41,14 +41,14 @@
 struct btDbvtProxy : btBroadphaseProxy
 {
-	/* Fields		*/ 
-	//btDbvtAabbMm	aabb;
-	btDbvtNode*		leaf;
-	btDbvtProxy*	links[2];
-	int				stage;
-	/* ctor			*/ 
-	btDbvtProxy(const btVector3& aabbMin,const btVector3& aabbMax,void* userPtr,short int collisionFilterGroup, short int collisionFilterMask) :
-	btBroadphaseProxy(aabbMin,aabbMax,userPtr,collisionFilterGroup,collisionFilterMask)
+/* Fields		*/ 
+btDbvtAabbMm	aabb;
+btDbvtNode*		leaf;
+btDbvtProxy*	links[2];
+int				stage;
+/* ctor			*/ 
+btDbvtProxy(void* userPtr,short int collisionFilterGroup, short int collisionFilterMask) :
+	btBroadphaseProxy(userPtr,collisionFilterGroup,collisionFilterMask)
 	{
-		links[0]=links[1]=0;
+	links[0]=links[1]=0;
 	}
 };
@@ -61,33 +61,33 @@
 struct	btDbvtBroadphase : btBroadphaseInterface
 {
-	/* Config		*/ 
-	enum	{
+/* Config		*/ 
+enum	{
 		DYNAMIC_SET			=	0,	/* Dynamic set index	*/ 
 		FIXED_SET			=	1,	/* Fixed set index		*/ 
 		STAGECOUNT			=	2	/* Number of stages		*/ 
-	};
-	/* Fields		*/ 
-	btDbvt					m_sets[2];					// Dbvt sets
-	btDbvtProxy*			m_stageRoots[STAGECOUNT+1];	// Stages list
-	btOverlappingPairCache*	m_paircache;				// Pair cache
-	btScalar				m_prediction;				// Velocity prediction
-	int						m_stageCurrent;				// Current stage
-	int						m_fupdates;					// % of fixed updates per frame
-	int						m_dupdates;					// % of dynamic updates per frame
-	int						m_cupdates;					// % of cleanup updates per frame
-	int						m_newpairs;					// Number of pairs created
-	int						m_fixedleft;				// Fixed optimization left
-	unsigned				m_updates_call;				// Number of updates call
-	unsigned				m_updates_done;				// Number of updates done
-	btScalar				m_updates_ratio;			// m_updates_done/m_updates_call
-	int						m_pid;						// Parse id
-	int						m_cid;						// Cleanup index
-	int						m_gid;						// Gen id
-	bool					m_releasepaircache;			// Release pair cache on delete
-	bool					m_deferedcollide;			// Defere dynamic/static collision to collide call
-	bool					m_needcleanup;				// Need to run cleanup?
+		};
+/* Fields		*/ 
+btDbvt					m_sets[2];					// Dbvt sets
+btDbvtProxy*			m_stageRoots[STAGECOUNT+1];	// Stages list
+btOverlappingPairCache*	m_paircache;				// Pair cache
+btScalar				m_prediction;				// Velocity prediction
+int						m_stageCurrent;				// Current stage
+int						m_fupdates;					// % of fixed updates per frame
+int						m_dupdates;					// % of dynamic updates per frame
+int						m_cupdates;					// % of cleanup updates per frame
+int						m_newpairs;					// Number of pairs created
+int						m_fixedleft;				// Fixed optimization left
+unsigned				m_updates_call;				// Number of updates call
+unsigned				m_updates_done;				// Number of updates done
+btScalar				m_updates_ratio;			// m_updates_done/m_updates_call
+int						m_pid;						// Parse id
+int						m_cid;						// Cleanup index
+int						m_gid;						// Gen id
+bool					m_releasepaircache;			// Release pair cache on delete
+bool					m_deferedcollide;			// Defere dynamic/static collision to collide call
+bool					m_needcleanup;				// Need to run cleanup?
 #if DBVT_BP_PROFILE
-	btClock					m_clock;
-	struct	{
+btClock					m_clock;
+struct	{
 		unsigned long		m_total;
 		unsigned long		m_ddcollide;
@@ -95,24 +95,21 @@
 		unsigned long		m_cleanup;
 		unsigned long		m_jobcount;
-	}				m_profiling;
+		}				m_profiling;
 #endif
-	/* Methods		*/ 
-	btDbvtBroadphase(btOverlappingPairCache* paircache=0);
-	~btDbvtBroadphase();
-	void							collide(btDispatcher* dispatcher);
-	void							optimize();
-	/* btBroadphaseInterface Implementation	*/ 
-	btBroadphaseProxy*				createProxy(const btVector3& aabbMin,const btVector3& aabbMax,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,btDispatcher* dispatcher,void* multiSapProxy);
-	void							destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
-	void							setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher);
-	virtual void	rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback);
-
-	virtual void	getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
-	void							calculateOverlappingPairs(btDispatcher* dispatcher);
-	btOverlappingPairCache*			getOverlappingPairCache();
-	const btOverlappingPairCache*	getOverlappingPairCache() const;
-	void							getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const;
-	void							printStats();
-	static void						benchmark(btBroadphaseInterface*);
+/* Methods		*/ 
+btDbvtBroadphase(btOverlappingPairCache* paircache=0);
+~btDbvtBroadphase();
+void							collide(btDispatcher* dispatcher);
+void							optimize();
+/* btBroadphaseInterface Implementation	*/ 
+btBroadphaseProxy*				createProxy(const btVector3& aabbMin,const btVector3& aabbMax,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,btDispatcher* dispatcher,void* multiSapProxy);
+void							destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
+void							setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher);
+void							calculateOverlappingPairs(btDispatcher* dispatcher);
+btOverlappingPairCache*			getOverlappingPairCache();
+const btOverlappingPairCache*	getOverlappingPairCache() const;
+void							getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const;
+void							printStats();
+static void						benchmark(btBroadphaseInterface*);
 };
 
Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp	(revision 1972)
@@ -150,20 +150,4 @@
 
 
-void	btMultiSapBroadphase::getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const
-{
-	btMultiSapProxy* multiProxy = static_cast<btMultiSapProxy*>(proxy);
-	aabbMin = multiProxy->m_aabbMin;
-	aabbMax = multiProxy->m_aabbMax;
-}
-
-void	btMultiSapBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback)
-{
-	for (int i=0;i<m_multiSapProxies.size();i++)
-	{
-		rayCallback.process(m_multiSapProxies[i]);
-	}
-}
-
-
 //#include <stdio.h>
 
Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h	(revision 1972)
@@ -73,5 +73,5 @@
 */
 		btMultiSapProxy(const btVector3& aabbMin,  const btVector3& aabbMax,int shapeType,void* userPtr, short int collisionFilterGroup,short int collisionFilterMask)
-			:btBroadphaseProxy(aabbMin,aabbMax,userPtr,collisionFilterGroup,collisionFilterMask),
+			:btBroadphaseProxy(userPtr,collisionFilterGroup,collisionFilterMask),
 			m_aabbMin(aabbMin),
 			m_aabbMax(aabbMax),
@@ -109,7 +109,4 @@
 	virtual void	destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
 	virtual void	setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher);
-	virtual void	getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
-
-	virtual void	rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback);
 
 	void	addToChildBroadphase(btMultiSapProxy* parentMultiSapProxy, btBroadphaseProxy* childProxy, btBroadphaseInterface*	childBroadphase);
Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp	(revision 1972)
@@ -19,5 +19,4 @@
 #include "LinearMath/btIDebugDraw.h"
 
-#define RAYAABB2
 
 btQuantizedBvh::btQuantizedBvh() : m_useQuantization(false), 
@@ -26,7 +25,6 @@
 					//m_traversalMode(TRAVERSAL_RECURSIVE)
 					,m_subtreeHeaderCount(0) //PCK: add this line
-{
-	m_bvhAabbMin.setValue(-SIMD_INFINITY,-SIMD_INFINITY,-SIMD_INFINITY);
-	m_bvhAabbMax.setValue(SIMD_INFINITY,SIMD_INFINITY,SIMD_INFINITY);
+{ 
+
 }
 
@@ -122,5 +120,5 @@
 	int curIndex = m_curNodeIndex;
 
-	btAssert(numIndices>0);
+	assert(numIndices>0);
 
 	if (numIndices==1)
@@ -143,9 +141,6 @@
 	int internalNodeIndex = m_curNodeIndex;
 	
-	//set the min aabb to 'inf' or a max value, and set the max aabb to a -inf/minimum value.
-	//the aabb will be expanded during buildTree/mergeInternalNodeAabb with actual node values
-	setInternalNodeAabbMin(m_curNodeIndex,m_bvhAabbMax);//can't use btVector3(SIMD_INFINITY,SIMD_INFINITY,SIMD_INFINITY)) because of quantization
-	setInternalNodeAabbMax(m_curNodeIndex,m_bvhAabbMin);//can't use btVector3(-SIMD_INFINITY,-SIMD_INFINITY,-SIMD_INFINITY)) because of quantization
-	
+	setInternalNodeAabbMax(m_curNodeIndex,m_bvhAabbMin);
+	setInternalNodeAabbMin(m_curNodeIndex,m_bvhAabbMax);
 	
 	for (i=startIndex;i<endIndex;i++)
@@ -183,7 +178,4 @@
 			updateSubtreeHeaders(leftChildNodexIndex,rightChildNodexIndex);
 		}
-	} else
-	{
-
 	}
 
@@ -347,5 +339,4 @@
 int maxIterations = 0;
 
-
 void	btQuantizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const
 {
@@ -362,5 +353,5 @@
 	{
 		//catch bugs in tree data
-		btAssert (walkIterations < m_curNodeIndex);
+		assert (walkIterations < m_curNodeIndex);
 
 		walkIterations++;
@@ -444,95 +435,4 @@
 
 
-void	btQuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const
-{
-	btAssert(!m_useQuantization);
-
-	const btOptimizedBvhNode* rootNode = &m_contiguousNodes[0];
-	int escapeIndex, curIndex = 0;
-	int walkIterations = 0;
-	bool isLeafNode;
-	//PCK: unsigned instead of bool
-	unsigned aabbOverlap=0;
-	unsigned rayBoxOverlap=0;
-	btScalar lambda_max = 1.0;
-	
-		/* Quick pruning by quantized box */
-	btVector3 rayAabbMin = raySource;
-	btVector3 rayAabbMax = raySource;
-	rayAabbMin.setMin(rayTarget);
-	rayAabbMax.setMax(rayTarget);
-
-	/* Add box cast extents to bounding box */
-	rayAabbMin += aabbMin;
-	rayAabbMax += aabbMax;
-
-#ifdef RAYAABB2
-	btVector3 rayFrom = raySource;
-	btVector3 rayDir = (rayTarget-raySource);
-	rayDir.normalize ();
-	lambda_max = rayDir.dot(rayTarget-raySource);
-	///what about division by zero? --> just set rayDirection[i] to 1.0
-	btVector3 rayDirectionInverse;
-	rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[0];
-	rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[1];
-	rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[2];
-	unsigned int sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0};
-#endif
-
-	btVector3 bounds[2];
-
-	while (curIndex < m_curNodeIndex)
-	{
-		btScalar param = 1.0;
-		//catch bugs in tree data
-		btAssert (walkIterations < m_curNodeIndex);
-
-		walkIterations++;
-
-		bounds[0] = rootNode->m_aabbMinOrg;
-		bounds[1] = rootNode->m_aabbMaxOrg;
-		/* Add box cast extents */
-		bounds[0] += aabbMin;
-		bounds[1] += aabbMax;
-
-		aabbOverlap = TestAabbAgainstAabb2(rayAabbMin,rayAabbMax,rootNode->m_aabbMinOrg,rootNode->m_aabbMaxOrg);
-		//perhaps profile if it is worth doing the aabbOverlap test first
-
-#ifdef RAYAABB2
-			///careful with this check: need to check division by zero (above) and fix the unQuantize method
-			///thanks Joerg/hiker for the reproduction case!
-			///http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858
-		rayBoxOverlap = aabbOverlap ? btRayAabb2 (raySource, rayDirectionInverse, sign, bounds, param, 0.0f, lambda_max) : false;
-
-#else
-		btVector3 normal;
-		rayBoxOverlap = btRayAabb(raySource, rayTarget,bounds[0],bounds[1],param, normal);
-#endif
-
-		isLeafNode = rootNode->m_escapeIndex == -1;
-		
-		//PCK: unsigned instead of bool
-		if (isLeafNode && (rayBoxOverlap != 0))
-		{
-			nodeCallback->processNode(rootNode->m_subPart,rootNode->m_triangleIndex);
-		} 
-		
-		//PCK: unsigned instead of bool
-		if ((rayBoxOverlap != 0) || isLeafNode)
-		{
-			rootNode++;
-			curIndex++;
-		} else
-		{
-			escapeIndex = rootNode->m_escapeIndex;
-			rootNode += escapeIndex;
-			curIndex += escapeIndex;
-		}
-	}
-	if (maxIterations < walkIterations)
-		maxIterations = walkIterations;
-
-}
-
 
 
@@ -555,5 +455,5 @@
 
 	btScalar lambda_max = 1.0;
-
+#define RAYAABB2
 #ifdef RAYAABB2
 	btVector3 rayFrom = raySource;
@@ -603,5 +503,5 @@
 
 		//catch bugs in tree data
-		btAssert (walkIterations < subTreeSize);
+		assert (walkIterations < subTreeSize);
 
 		walkIterations++;
@@ -634,7 +534,5 @@
 			///http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858
 
-			//BT_PROFILE("btRayAabb2");
 			rayBoxOverlap = btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0f, lambda_max);
-			
 #else
 			rayBoxOverlap = true;//btRayAabb(raySource, rayTarget, bounds[0], bounds[1], param, normal);
@@ -700,5 +598,5 @@
 
 		//catch bugs in tree data
-		btAssert (walkIterations < subTreeSize);
+		assert (walkIterations < subTreeSize);
 
 		walkIterations++;
@@ -755,5 +653,16 @@
 void	btQuantizedBvh::reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget) const
 {
-	reportBoxCastOverlappingNodex(nodeCallback,raySource,rayTarget,btVector3(0,0,0),btVector3(0,0,0));
+	bool fast_path = m_useQuantization && m_traversalMode == TRAVERSAL_STACKLESS;
+	if (fast_path)
+	{
+		walkStacklessQuantizedTreeAgainstRay(nodeCallback, raySource, rayTarget, btVector3(0, 0, 0), btVector3(0, 0, 0), 0, m_curNodeIndex);
+	} else {
+		/* Otherwise fallback to AABB overlap test */
+		btVector3 aabbMin = raySource;
+		btVector3 aabbMax = raySource;
+		aabbMin.setMin(rayTarget);
+		aabbMax.setMax(rayTarget);
+		reportAabbOverlappingNodex(nodeCallback,aabbMin,aabbMax);
+	}
 }
 
@@ -761,17 +670,11 @@
 void	btQuantizedBvh::reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin,const btVector3& aabbMax) const
 {
-	//always use stackless
-
-	if (m_useQuantization)
+	bool fast_path = m_useQuantization && m_traversalMode == TRAVERSAL_STACKLESS;
+	if (fast_path)
 	{
 		walkStacklessQuantizedTreeAgainstRay(nodeCallback, raySource, rayTarget, aabbMin, aabbMax, 0, m_curNodeIndex);
-	}
-	else
-	{
-		walkStacklessTreeAgainstRay(nodeCallback, raySource, rayTarget, aabbMin, aabbMax, 0, m_curNodeIndex);
-	}
-	/*
-	{
-		//recursive traversal
+	} else {
+		/* Slow path:
+		   Construct the bounding box for the entire box cast and send that down the tree */
 		btVector3 qaabbMin = raySource;
 		btVector3 qaabbMax = raySource;
@@ -782,6 +685,4 @@
 		reportAabbOverlappingNodex(nodeCallback,qaabbMin,qaabbMax);
 	}
-	*/
-
 }
 
@@ -843,5 +744,5 @@
 bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian)
 {
-	btAssert(m_subtreeHeaderCount == m_SubtreeHeaders.size());
+	assert(m_subtreeHeaderCount == m_SubtreeHeaders.size());
 	m_subtreeHeaderCount = m_SubtreeHeaders.size();
 
Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.h	(revision 1972)
@@ -297,5 +297,4 @@
 	void	walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const;
 	void	walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax,int startNodeIndex,int endNodeIndex) const;
-	void	walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const;
 
 	///tree traversal designed for small-memory processors like PS3 SPU
Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp	(revision 1972)
@@ -89,5 +89,5 @@
 		return 0; //should never happen, but don't let the game crash ;-)
 	}
-	btAssert(aabbMin[0]<= aabbMax[0] && aabbMin[1]<= aabbMax[1] && aabbMin[2]<= aabbMax[2]);
+	assert(aabbMin[0]<= aabbMax[0] && aabbMin[1]<= aabbMax[1] && aabbMin[2]<= aabbMax[2]);
 
 	int newHandleIndex = allocHandle();
@@ -138,26 +138,12 @@
 }
 
-void	btSimpleBroadphase::getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const
-{
-	const btSimpleBroadphaseProxy* sbp = getSimpleProxyFromProxy(proxy);
-	aabbMin = sbp->m_aabbMin;
-	aabbMax = sbp->m_aabbMax;
-}
-
 void	btSimpleBroadphase::setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* /*dispatcher*/)
 {
 	btSimpleBroadphaseProxy* sbp = getSimpleProxyFromProxy(proxy);
-	sbp->m_aabbMin = aabbMin;
-	sbp->m_aabbMax = aabbMax;
-}
-
-void	btSimpleBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback)
-{
-	for (int i=0;i<m_numHandles;i++)
-	{
-		btSimpleBroadphaseProxy* proxy = &m_pHandles[i];
-		rayCallback.process(proxy);
-	}
-}
+	sbp->m_min = aabbMin;
+	sbp->m_max = aabbMax;
+}
+
+
 
 
@@ -169,7 +155,7 @@
 bool	btSimpleBroadphase::aabbOverlap(btSimpleBroadphaseProxy* proxy0,btSimpleBroadphaseProxy* proxy1)
 {
-	return proxy0->m_aabbMin[0] <= proxy1->m_aabbMax[0] && proxy1->m_aabbMin[0] <= proxy0->m_aabbMax[0] && 
-		   proxy0->m_aabbMin[1] <= proxy1->m_aabbMax[1] && proxy1->m_aabbMin[1] <= proxy0->m_aabbMax[1] &&
-		   proxy0->m_aabbMin[2] <= proxy1->m_aabbMax[2] && proxy1->m_aabbMin[2] <= proxy0->m_aabbMax[2];
+	return proxy0->m_min[0] <= proxy1->m_max[0] && proxy1->m_min[0] <= proxy0->m_max[0] && 
+		   proxy0->m_min[1] <= proxy1->m_max[1] && proxy1->m_min[1] <= proxy0->m_max[1] &&
+		   proxy0->m_min[2] <= proxy1->m_max[2] && proxy1->m_min[2] <= proxy0->m_max[2];
 
 }
Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h	(revision 1972)
@@ -23,4 +23,6 @@
 struct btSimpleBroadphaseProxy : public btBroadphaseProxy
 {
+	btVector3	m_min;
+	btVector3	m_max;
 	int			m_nextFree;
 	
@@ -31,5 +33,6 @@
 
 	btSimpleBroadphaseProxy(const btPoint3& minpt,const btPoint3& maxpt,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,void* multiSapProxy)
-	:btBroadphaseProxy(minpt,maxpt,userPtr,collisionFilterGroup,collisionFilterMask,multiSapProxy)
+	:btBroadphaseProxy(userPtr,collisionFilterGroup,collisionFilterMask,multiSapProxy),
+	m_min(minpt),m_max(maxpt)		
 	{
 		(void)shapeType;
@@ -93,10 +96,4 @@
 	}
 
-	inline const btSimpleBroadphaseProxy*	getSimpleProxyFromProxy(btBroadphaseProxy* proxy) const
-	{
-		const btSimpleBroadphaseProxy* proxy0 = static_cast<const btSimpleBroadphaseProxy*>(proxy);
-		return proxy0;
-	}
-
 
 	void	validate();
@@ -121,7 +118,4 @@
 	virtual void	destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
 	virtual void	setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher);
-	virtual void	getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
-
-	virtual void	rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback);
 		
 	btOverlappingPairCache*	getOverlappingPairCache()
Index: code/branches/physics/src/bullet/BulletCollision/CMakeLists.txt
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CMakeLists.txt	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/CMakeLists.txt	(revision 1972)
@@ -124,15 +124,4 @@
 				CollisionShapes/btUniformScalingShape.cpp
 				CollisionShapes/btUniformScalingShape.h
-				Gimpact/btContactProcessing.cpp
-				Gimpact/btGImpactShape.cpp
-				Gimpact/gim_contact.cpp
-				Gimpact/btGImpactBvh.cpp
-				Gimpact/btGenericPoolAllocator.cpp
-				Gimpact/gim_memory.cpp
-				Gimpact/btGImpactCollisionAlgorithm.cpp
-				Gimpact/btTriangleShapeEx.cpp
-				Gimpact/gim_tri_collision.cpp
-				Gimpact/btGImpactQuantizedBvh.cpp
-				Gimpact/gim_box_set.cpp
 				NarrowPhaseCollision/btContinuousConvexCollision.cpp
 				NarrowPhaseCollision/btContinuousConvexCollision.h
Index: code/branches/physics/src/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h	(revision 1972)
@@ -238,10 +238,10 @@
 
 
-	SIMD_FORCE_INLINE btBroadphaseProxy*	getBroadphaseHandle()
+	btBroadphaseProxy*	getBroadphaseHandle()
 	{
 		return m_broadphaseHandle;
 	}
 
-	SIMD_FORCE_INLINE const btBroadphaseProxy*	getBroadphaseHandle() const
+	const btBroadphaseProxy*	getBroadphaseHandle() const
 	{
 		return m_broadphaseHandle;
Index: code/branches/physics/src/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp	(revision 1972)
@@ -33,7 +33,4 @@
 #include "LinearMath/btStackAlloc.h"
 
-//#define USE_BRUTEFORCE_RAYBROADPHASE 1
-//RECALCULATE_AABB is slower, but benefit is that you don't need to call 'stepSimulation'  or 'updateAabbs' before using a rayTest
-//#define RECALCULATE_AABB_RAYCAST 1
 
 //When the user doesn't provide dispatcher or broadphase, create basic versions (and delete them in destructor)
@@ -230,5 +227,4 @@
 	if (collisionShape->isConvex())
 	{
-		BT_PROFILE("rayTestConvex");
 		btConvexCast::CastResult castResult;
 		castResult.m_fraction = resultCallback.m_closestHitFraction;
@@ -274,5 +270,4 @@
 		if (collisionShape->isConcave())
 		{
-			BT_PROFILE("rayTestConcave");
 			if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE)
 			{
@@ -380,5 +375,4 @@
 			}
 		} else {
-			BT_PROFILE("rayTestCompound");
 			//todo: use AABB tree or other BVH acceleration structure!
 			if (collisionShape->isCompound())
@@ -603,79 +597,44 @@
 }
 
-
-struct btSingleRayCallback : public btBroadphaseRayCallback
-{
-
-	btVector3	m_rayFromWorld;
-	btVector3	m_rayToWorld;
-	const btCollisionWorld*	m_world;
-	btCollisionWorld::RayResultCallback&	m_resultCallback;
-
-	btSingleRayCallback(const btVector3& rayFromWorld,const btVector3& rayToWorld,const btCollisionWorld* world,btCollisionWorld::RayResultCallback& resultCallback)
-	:m_rayFromWorld(rayFromWorld),
-	m_rayToWorld(rayToWorld),
-	m_world(world),
-	m_resultCallback(resultCallback)
-	{
-
-	}
-
-	virtual bool	process(const btBroadphaseProxy* proxy)
+void	btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const
+{
+
+
+	btTransform	rayFromTrans,rayToTrans;
+	rayFromTrans.setIdentity();
+	rayFromTrans.setOrigin(rayFromWorld);
+	rayToTrans.setIdentity();
+
+	rayToTrans.setOrigin(rayToWorld);
+
+	/// go over all objects, and if the ray intersects their aabb, do a ray-shape query using convexCaster (CCD)
+
+	int i;
+	for (i=0;i<m_collisionObjects.size();i++)
 	{
 		///terminate further ray tests, once the closestHitFraction reached zero
-		if (m_resultCallback.m_closestHitFraction == btScalar(0.f))
-			return false;
-
-		btCollisionObject*	collisionObject = (btCollisionObject*)proxy->m_clientObject;
-
+		if (resultCallback.m_closestHitFraction == btScalar(0.f))
+			break;
+
+		btCollisionObject*	collisionObject= m_collisionObjects[i];
 		//only perform raycast if filterMask matches
-		if(m_resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) 
-		{
+		if(resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) {
 			//RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
-			//btVector3 collisionObjectAabbMin,collisionObjectAabbMax;
-			
-#ifdef RECALCULATE_AABB
 			btVector3 collisionObjectAabbMin,collisionObjectAabbMax;
 			collisionObject->getCollisionShape()->getAabb(collisionObject->getWorldTransform(),collisionObjectAabbMin,collisionObjectAabbMax);
-#else
-			//getBroadphase()->getAabb(collisionObject->getBroadphaseHandle(),collisionObjectAabbMin,collisionObjectAabbMax);
-			btVector3& collisionObjectAabbMin = collisionObject->getBroadphaseHandle()->m_aabbMin;
-			btVector3& collisionObjectAabbMax = collisionObject->getBroadphaseHandle()->m_aabbMax;
-#endif
-			btScalar hitLambda = m_resultCallback.m_closestHitFraction;
+
+			btScalar hitLambda = resultCallback.m_closestHitFraction;
 			btVector3 hitNormal;
-			if (btRayAabb(m_rayFromWorld,m_rayToWorld,collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
-			{
-				btTransform	rayFromTrans,rayToTrans;
-				rayFromTrans.setIdentity();
-				rayFromTrans.setOrigin(m_rayFromWorld);
-				rayToTrans.setIdentity();
-				rayToTrans.setOrigin(m_rayToWorld);
-
-				m_world->rayTestSingle(rayFromTrans,rayToTrans,
+			if (btRayAabb(rayFromWorld,rayToWorld,collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
+			{
+				rayTestSingle(rayFromTrans,rayToTrans,
 					collisionObject,
 						collisionObject->getCollisionShape(),
 						collisionObject->getWorldTransform(),
-						m_resultCallback);
-			}
-		}
-		return true;
-	}
-};
-
-void	btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const
-{
-	BT_PROFILE("rayTest");
-	/// go over all objects, and if the ray intersects their aabb, do a ray-shape query using convexCaster (CCD)
-	btSingleRayCallback rayCB(rayFromWorld,rayToWorld,this,resultCallback);
-
-#ifndef USE_BRUTEFORCE_RAYBROADPHASE
-	m_broadphasePairCache->rayTest(rayFromWorld,rayToWorld,rayCB);
-#else
-	for (int i=0;i<this->getNumCollisionObjects();i++)
-	{
-		rayCB.process(m_collisionObjects[i]->getBroadphaseHandle());
-	}	
-#endif //USE_BRUTEFORCE_RAYBROADPHASE
+						resultCallback);
+			}
+		}
+
+	}
 
 }
Index: code/branches/physics/src/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h	(revision 1972)
@@ -108,9 +108,4 @@
 	}
 
-	const btBroadphaseInterface*	getBroadphase() const
-	{
-		return m_broadphasePairCache;
-	}
-
 	btBroadphaseInterface*	getBroadphase()
 	{
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp	(revision 1972)
@@ -18,4 +18,22 @@
 #include "LinearMath/btQuaternion.h"
 
+btConvexPointCloudShape::btConvexPointCloudShape (btVector3* points,int numPoints) : btPolyhedralConvexShape ()
+{
+	m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE;
+	m_points = points;
+	m_numPoints = numPoints;
+
+	recalcLocalAabb();
+}
+
+void btConvexPointCloudShape::setPoints (btVector3* points, int numPoints)
+{
+	m_points = points;
+	m_numPoints = numPoints;
+
+	recalcLocalAabb();
+}
+
+
 void btConvexPointCloudShape::setLocalScaling(const btVector3& scaling)
 {
@@ -24,5 +42,4 @@
 }
 
-#ifndef __SPU__
 btVector3	btConvexPointCloudShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
 {
@@ -108,5 +125,5 @@
 
 
-#endif
+
 
 
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.h	(revision 1972)
@@ -29,22 +29,7 @@
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
-	btConvexPointCloudShape(btVector3* points,int numPoints, bool computeAabb = true)
-	{
-		m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE;
-		m_points = points;
-		m_numPoints = numPoints;
+	btConvexPointCloudShape(btVector3* points,int numPoints);
 
-		if (computeAabb)
-			recalcLocalAabb();
-	}
-
-	void setPoints (btVector3* points, int numPoints, bool computeAabb = true)
-	{
-		m_points = points;
-		m_numPoints = numPoints;
-
-		if (computeAabb)
-			recalcLocalAabb();
-	}
+	void setPoints (btVector3* points, int numPoints);
 
 	btPoint3* getPoints()
@@ -63,9 +48,7 @@
 	}
 
-#ifndef __SPU__
 	virtual btVector3	localGetSupportingVertex(const btVector3& vec)const;
 	virtual btVector3	localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
 	virtual void	batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
-#endif
 
 
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp	(revision 1972)
@@ -16,5 +16,6 @@
 #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
 
-btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape(),
+btPolyhedralConvexShape::btPolyhedralConvexShape()
+:btConvexInternalShape(),
 m_localAabbMin(1,1,1),
 m_localAabbMax(-1,-1,-1),
@@ -24,4 +25,5 @@
 
 }
+
 
 
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h	(revision 1972)
@@ -32,30 +32,15 @@
 	bool		m_isLocalAabbValid;
 
+	btPolyhedralConvexShape();
 public:
 
-	btPolyhedralConvexShape();
+	
 
 	//brute force implementations
-
 	virtual btVector3	localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
 	virtual void	batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
-
 	
 	virtual void	calculateLocalInertia(btScalar mass,btVector3& inertia) const;
 
-
-	void setCachedLocalAabb (const btVector3& aabbMin, const btVector3& aabbMax)
-	{
-		m_isLocalAabbValid = true;
-		m_localAabbMin = aabbMin;
-		m_localAabbMax = aabbMax;
-	}
-
-	inline void getCachedLocalAabb (btVector3& aabbMin, btVector3& aabbMax) const
-	{
-		btAssert(m_isLocalAabbValid);
-		aabbMin = m_localAabbMin;
-		aabbMax = m_localAabbMax;
-	}
 
 	inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.cpp	(revision 1972)
@@ -18,4 +18,12 @@
 
 #include "LinearMath/btQuaternion.h"
+
+
+btSphereShape ::btSphereShape (btScalar radius) : btConvexInternalShape ()
+{
+	m_shapeType = SPHERE_SHAPE_PROXYTYPE;
+	m_implicitShapeDimensions.setX(radius);
+	m_collisionMargin = radius;
+}
 
 btVector3	btSphereShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
Index: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.h	(revision 1972)
@@ -28,10 +28,6 @@
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
-	btSphereShape (btScalar radius) : btConvexInternalShape ()
-	{
-		m_shapeType = SPHERE_SHAPE_PROXYTYPE;
-		m_implicitShapeDimensions.setX(radius);
-		m_collisionMargin = radius;
-	}
+	btSphereShape (btScalar radius);
+	
 	
 	virtual btVector3	localGetSupportingVertex(const btVector3& vec)const;
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp	(revision 1972)
@@ -886,6 +886,6 @@
 	const btVector3	delta=	results.witnesses[1]-
 							results.witnesses[0];
-	const btScalar	margin=	shape0->getMarginNonVirtual()+
-							shape1.getMarginNonVirtual();
+	const btScalar	margin=	shape0->getMargin()+
+							shape1.getMargin();
 	const btScalar	length=	delta.length();	
 	results.normal			=	delta/length;
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp	(revision 1972)
@@ -22,5 +22,5 @@
 
 #if defined(DEBUG) || defined (_DEBUG)
-//#define TEST_NON_VIRTUAL 1
+#define TEST_NON_VIRTUAL 1
 #include <stdio.h> //for debug printf
 #ifdef __SPU__
Index: code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btContactSolverInfo.h
===================================================================
--- code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btContactSolverInfo.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btContactSolverInfo.h	(revision 1972)
@@ -45,5 +45,4 @@
 
 	int			m_solverMode;
-	int	m_restingContactRestitutionThreshold;
 
 
@@ -71,5 +70,4 @@
 		m_warmstartingFactor=btScalar(0.85);
 		m_solverMode = SOLVER_RANDMIZE_ORDER | SOLVER_CACHE_FRIENDLY | SOLVER_USE_WARMSTARTING;
-		m_restingContactRestitutionThreshold = 2;//resting contact lifetime threshold to disable restitution
 	}
 };
Index: code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp	(revision 1972)
@@ -719,17 +719,9 @@
 
 							solverConstraint.m_friction = cp.m_combinedFriction;
-
-							
-							if (cp.m_lifeTime>infoGlobal.m_restingContactRestitutionThreshold)
+							solverConstraint.m_restitution =  restitutionCurve(rel_vel, cp.m_combinedRestitution);
+							if (solverConstraint.m_restitution <= btScalar(0.))
 							{
 								solverConstraint.m_restitution = 0.f;
-							} else
-							{
-								solverConstraint.m_restitution =  restitutionCurve(rel_vel, cp.m_combinedRestitution);
-								if (solverConstraint.m_restitution <= btScalar(0.))
-								{
-									solverConstraint.m_restitution = 0.f;
-								};
-							}
+							};
 
 							
@@ -994,5 +986,5 @@
 		pt->m_appliedImpulse = solveManifold.m_appliedImpulse;
 		pt->m_appliedImpulseLateral1 = m_tmpSolverFrictionConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse;
-		pt->m_appliedImpulseLateral2 = m_tmpSolverFrictionConstraintPool[solveManifold.m_frictionIndex+1].m_appliedImpulse;
+		pt->m_appliedImpulseLateral1 = m_tmpSolverFrictionConstraintPool[solveManifold.m_frictionIndex+1].m_appliedImpulse;
 
 		//do a callback here?
@@ -1229,15 +1221,10 @@
 				cpd->m_penetration = cp.getDistance();///btScalar(info.m_numIterations);
 				cpd->m_friction = cp.m_combinedFriction;
-				if (cp.m_lifeTime>info.m_restingContactRestitutionThreshold)
-				{
-					cpd->m_restitution = 0.f;
-				} else
-				{
-					cpd->m_restitution = restitutionCurve(rel_vel, combinedRestitution);
-					if (cpd->m_restitution <= btScalar(0.))
-					{
-						cpd->m_restitution = btScalar(0.0);
-					};
-				}
+				cpd->m_restitution = restitutionCurve(rel_vel, combinedRestitution);
+				if (cpd->m_restitution <= btScalar(0.))
+				{
+					cpd->m_restitution = btScalar(0.0);
+
+				};
 				
 				//restitution and penetration work in same direction so
Index: code/branches/physics/src/bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp	(revision 1972)
@@ -126,5 +126,4 @@
 void	btDiscreteDynamicsWorld::debugDrawWorld()
 {
-	BT_PROFILE("debugDrawWorld");
 
 	if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)
@@ -255,5 +254,4 @@
 void	btDiscreteDynamicsWorld::synchronizeMotionStates()
 {
-	BT_PROFILE("synchronizeMotionStates");
 	{
 		//todo: iterate over awake simulation islands!
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftBody.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftBody.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftBody.cpp	(revision 1972)
@@ -151,65 +151,65 @@
 btSoftBody::Material*		btSoftBody::appendMaterial()
 {
-	Material*	pm=new(btAlignedAlloc(sizeof(Material),16)) Material();
-	if(m_materials.size()>0)
-		*pm=*m_materials[0];
+Material*	pm=new(btAlignedAlloc(sizeof(Material),16)) Material();
+if(m_materials.size()>0)
+	*pm=*m_materials[0];
 	else
-		ZeroInitialize(*pm);
-	m_materials.push_back(pm);
-	return(pm);
+	ZeroInitialize(*pm);
+m_materials.push_back(pm);
+return(pm);
 }
 
 //
 void			btSoftBody::appendNote(	const char* text,
-									   const btVector3& o,
-									   const btVector4& c,
-									   Node* n0,
-									   Node* n1,
-									   Node* n2,
-									   Node* n3)
-{
-	Note	n;
-	ZeroInitialize(n);
-	n.m_rank		=	0;
-	n.m_text		=	text;
-	n.m_offset		=	o;
-	n.m_coords[0]	=	c.x();
-	n.m_coords[1]	=	c.y();
-	n.m_coords[2]	=	c.z();
-	n.m_coords[3]	=	c.w();
-	n.m_nodes[0]	=	n0;n.m_rank+=n0?1:0;
-	n.m_nodes[1]	=	n1;n.m_rank+=n1?1:0;
-	n.m_nodes[2]	=	n2;n.m_rank+=n2?1:0;
-	n.m_nodes[3]	=	n3;n.m_rank+=n3?1:0;
-	m_notes.push_back(n);
+										const btVector3& o,
+										const btVector4& c,
+										Node* n0,
+										Node* n1,
+										Node* n2,
+										Node* n3)
+{
+Note	n;
+ZeroInitialize(n);
+n.m_rank		=	0;
+n.m_text		=	text;
+n.m_offset		=	o;
+n.m_coords[0]	=	c.x();
+n.m_coords[1]	=	c.y();
+n.m_coords[2]	=	c.z();
+n.m_coords[3]	=	c.w();
+n.m_nodes[0]	=	n0;n.m_rank+=n0?1:0;
+n.m_nodes[1]	=	n1;n.m_rank+=n1?1:0;
+n.m_nodes[2]	=	n2;n.m_rank+=n2?1:0;
+n.m_nodes[3]	=	n3;n.m_rank+=n3?1:0;
+m_notes.push_back(n);
 }
 
 //
 void			btSoftBody::appendNote(	const char* text,
-									   const btVector3& o,
-									   Node* feature)
-{
-	appendNote(text,o,btVector4(1,0,0,0),feature);
+										const btVector3& o,
+										Node* feature)
+{
+appendNote(text,o,btVector4(1,0,0,0),feature);
 }
 
 //
 void			btSoftBody::appendNote(	const char* text,
-									   const btVector3& o,
-									   Link* feature)
-{
-	static const btScalar	w=1/(btScalar)2;
-	appendNote(text,o,btVector4(w,w,0,0),	feature->m_n[0],
-		feature->m_n[1]);
-}
-
+										const btVector3& o,
+										Link* feature)
+{
+static const btScalar	w=1/(btScalar)2;
+appendNote(text,o,btVector4(w,w,0,0),	feature->m_n[0],
+										feature->m_n[1]);
+}
+								
 //
 void			btSoftBody::appendNote(	const char* text,
-									   const btVector3& o,
-									   Face* feature)
-{
-	static const btScalar	w=1/(btScalar)3;
-	appendNote(text,o,btVector4(w,w,w,0),	feature->m_n[0],
-		feature->m_n[1],
-		feature->m_n[2]);
+										const btVector3& o,
+										Face* feature)
+{
+static const btScalar	w=1/(btScalar)3;
+appendNote(text,o,btVector4(w,w,w,0),	feature->m_n[0],
+										feature->m_n[1],
+										feature->m_n[2]);
 }
 
@@ -217,19 +217,19 @@
 void			btSoftBody::appendNode(	const btVector3& x,btScalar m)
 {
-	if(m_nodes.capacity()==m_nodes.size())
-	{
-		pointersToIndices();
-		m_nodes.reserve(m_nodes.size()*2+1);
-		indicesToPointers();
-	}
-	const btScalar	margin=getCollisionShape()->getMargin();
-	m_nodes.push_back(Node());
-	Node&			n=m_nodes[m_nodes.size()-1];
-	ZeroInitialize(n);
-	n.m_x			=	x;
-	n.m_q			=	n.m_x;
-	n.m_im			=	m>0?1/m:0;
-	n.m_material	=	m_materials[0];
-	n.m_leaf		=	m_ndbvt.insert(btDbvtVolume::FromCR(n.m_x,margin),&n);
+if(m_nodes.capacity()==m_nodes.size())
+	{
+	pointersToIndices();
+	m_nodes.reserve(m_nodes.size()*2+1);
+	indicesToPointers();
+	}
+const btScalar	margin=getCollisionShape()->getMargin();
+m_nodes.push_back(Node());
+Node&			n=m_nodes[m_nodes.size()-1];
+ZeroInitialize(n);
+n.m_x			=	x;
+n.m_q			=	n.m_x;
+n.m_im			=	m>0?1/m:0;
+n.m_material	=	m_materials[0];
+n.m_leaf		=	m_ndbvt.insert(btDbvtVolume::FromCR(n.m_x,margin),&n);
 }
 
@@ -237,10 +237,10 @@
 void			btSoftBody::appendLink(int model,Material* mat)
 {
-	Link	l;
-	if(model>=0)
-		l=m_links[model];
+Link	l;
+if(model>=0)
+	l=m_links[model];
 	else
 	{ ZeroInitialize(l);l.m_material=mat?mat:m_materials[0]; }
-	m_links.push_back(l);
+m_links.push_back(l);
 }
 
@@ -274,10 +274,10 @@
 void			btSoftBody::appendFace(int model,Material* mat)
 {
-	Face	f;
-	if(model>=0)
+Face	f;
+if(model>=0)
 	{ f=m_faces[model]; }
 	else
 	{ ZeroInitialize(f);f.m_material=mat?mat:m_materials[0]; }
-	m_faces.push_back(f);
+m_faces.push_back(f);
 }
 
@@ -320,13 +320,13 @@
 void			btSoftBody::appendLinearJoint(const LJoint::Specs& specs,Cluster* body0,Body body1)
 {
-	LJoint*		pj	=	new(btAlignedAlloc(sizeof(LJoint),16)) LJoint();
-	pj->m_bodies[0]	=	body0;
-	pj->m_bodies[1]	=	body1;
-	pj->m_refs[0]	=	pj->m_bodies[0].xform().inverse()*specs.position;
-	pj->m_refs[1]	=	pj->m_bodies[1].xform().inverse()*specs.position;
-	pj->m_cfm		=	specs.cfm;
-	pj->m_erp		=	specs.erp;
-	pj->m_split		=	specs.split;
-	m_joints.push_back(pj);
+LJoint*		pj	=	new(btAlignedAlloc(sizeof(LJoint),16)) LJoint();
+pj->m_bodies[0]	=	body0;
+pj->m_bodies[1]	=	body1;
+pj->m_refs[0]	=	pj->m_bodies[0].xform().inverse()*specs.position;
+pj->m_refs[1]	=	pj->m_bodies[1].xform().inverse()*specs.position;
+pj->m_cfm		=	specs.cfm;
+pj->m_erp		=	specs.erp;
+pj->m_split		=	specs.split;
+m_joints.push_back(pj);
 }
 
@@ -334,5 +334,5 @@
 void			btSoftBody::appendLinearJoint(const LJoint::Specs& specs,Body body)
 {
-	appendLinearJoint(specs,m_clusters[0],body);
+appendLinearJoint(specs,m_clusters[0],body);
 }
 
@@ -340,5 +340,5 @@
 void			btSoftBody::appendLinearJoint(const LJoint::Specs& specs,btSoftBody* body)
 {
-	appendLinearJoint(specs,m_clusters[0],body->m_clusters[0]);
+appendLinearJoint(specs,m_clusters[0],body->m_clusters[0]);
 }
 
@@ -346,14 +346,14 @@
 void			btSoftBody::appendAngularJoint(const AJoint::Specs& specs,Cluster* body0,Body body1)
 {
-	AJoint*		pj	=	new(btAlignedAlloc(sizeof(AJoint),16)) AJoint();
-	pj->m_bodies[0]	=	body0;
-	pj->m_bodies[1]	=	body1;
-	pj->m_refs[0]	=	pj->m_bodies[0].xform().inverse().getBasis()*specs.axis;
-	pj->m_refs[1]	=	pj->m_bodies[1].xform().inverse().getBasis()*specs.axis;
-	pj->m_cfm		=	specs.cfm;
-	pj->m_erp		=	specs.erp;
-	pj->m_split		=	specs.split;
-	pj->m_icontrol	=	specs.icontrol;
-	m_joints.push_back(pj);
+AJoint*		pj	=	new(btAlignedAlloc(sizeof(AJoint),16)) AJoint();
+pj->m_bodies[0]	=	body0;
+pj->m_bodies[1]	=	body1;
+pj->m_refs[0]	=	pj->m_bodies[0].xform().inverse().getBasis()*specs.axis;
+pj->m_refs[1]	=	pj->m_bodies[1].xform().inverse().getBasis()*specs.axis;
+pj->m_cfm		=	specs.cfm;
+pj->m_erp		=	specs.erp;
+pj->m_split		=	specs.split;
+pj->m_icontrol	=	specs.icontrol;
+m_joints.push_back(pj);
 }
 
@@ -361,5 +361,5 @@
 void			btSoftBody::appendAngularJoint(const AJoint::Specs& specs,Body body)
 {
-	appendAngularJoint(specs,m_clusters[0],body);
+appendAngularJoint(specs,m_clusters[0],body);
 }
 
@@ -367,5 +367,5 @@
 void			btSoftBody::appendAngularJoint(const AJoint::Specs& specs,btSoftBody* body)
 {
-	appendAngularJoint(specs,m_clusters[0],body->m_clusters[0]);
+appendAngularJoint(specs,m_clusters[0],body->m_clusters[0]);
 }
 
@@ -456,6 +456,6 @@
 			const Face&		f=m_faces[i];
 			const btScalar	twicearea=AreaOf(	f.m_n[0]->m_x,
-				f.m_n[1]->m_x,
-				f.m_n[2]->m_x);
+												f.m_n[1]->m_x,
+												f.m_n[2]->m_x);
 			for(int j=0;j<3;++j)
 			{
@@ -503,8 +503,8 @@
 void			btSoftBody::translate(const btVector3& trs)
 {
-	btTransform	t;
-	t.setIdentity();
-	t.setOrigin(trs);
-	transform(t);
+btTransform	t;
+t.setIdentity();
+t.setOrigin(trs);
+transform(t);
 }
 
@@ -512,8 +512,8 @@
 void			btSoftBody::rotate(	const btQuaternion& rot)
 {
-	btTransform	t;
-	t.setIdentity();
-	t.setRotation(rot);
-	transform(t);
+btTransform	t;
+t.setIdentity();
+t.setRotation(rot);
+transform(t);
 }
 
@@ -554,6 +554,6 @@
 		Node&	n=m_nodes[i];
 		m_pose.m_wgh[i]=	n.m_im>0					?
-			1/(m_nodes[i].m_im*tmass)	:
-		kmass/tmass;
+							1/(m_nodes[i].m_im*tmass)	:
+							kmass/tmass;
 	}
 	/* Pos		*/ 
@@ -570,8 +570,8 @@
 	/* Aqq		*/ 
 	m_pose.m_aqq[0]	=
-		m_pose.m_aqq[1]	=
-		m_pose.m_aqq[2]	=	btVector3(0,0,0);
+	m_pose.m_aqq[1]	=
+	m_pose.m_aqq[2]	=	btVector3(0,0,0);
 	for( i=0,ni=m_nodes.size();i<ni;++i)
-	{
+		{
 		const btVector3&	q=m_pose.m_pos[i];
 		const btVector3		mq=m_pose.m_wgh[i]*q;
@@ -579,5 +579,5 @@
 		m_pose.m_aqq[1]+=mq.y()*q;
 		m_pose.m_aqq[2]+=mq.z()*q;
-	}
+		}
 	m_pose.m_aqq=m_pose.m_aqq.inverse();
 	updateConstants();
@@ -606,5 +606,5 @@
 int				btSoftBody::clusterCount() const
 {
-	return(m_clusters.size());
+return(m_clusters.size());
 }
 
@@ -612,10 +612,10 @@
 btVector3		btSoftBody::clusterCom(const Cluster* cluster)
 {
-	btVector3		com(0,0,0);
-	for(int i=0,ni=cluster->m_nodes.size();i<ni;++i)
-	{
-		com+=cluster->m_nodes[i]->m_x*cluster->m_masses[i];
-	}
-	return(com*cluster->m_imass);
+btVector3		com(0,0,0);
+for(int i=0,ni=cluster->m_nodes.size();i<ni;++i)
+	{
+	com+=cluster->m_nodes[i]->m_x*cluster->m_masses[i];
+	}
+return(com*cluster->m_imass);
 }
 
@@ -623,5 +623,5 @@
 btVector3		btSoftBody::clusterCom(int cluster) const
 {
-	return(clusterCom(m_clusters[cluster]));
+return(clusterCom(m_clusters[cluster]));
 }
 
@@ -629,5 +629,5 @@
 btVector3		btSoftBody::clusterVelocity(const Cluster* cluster,const btVector3& rpos)
 {
-	return(cluster->m_lv+cross(cluster->m_av,rpos));
+return(cluster->m_lv+cross(cluster->m_av,rpos));
 }
 
@@ -635,9 +635,9 @@
 void			btSoftBody::clusterVImpulse(Cluster* cluster,const btVector3& rpos,const btVector3& impulse)
 {
-	const btVector3	li=cluster->m_imass*impulse;
-	const btVector3	ai=cluster->m_invwi*cross(rpos,impulse);
-	cluster->m_vimpulses[0]+=li;cluster->m_lv+=li;
-	cluster->m_vimpulses[1]+=ai;cluster->m_av+=ai;
-	cluster->m_nvimpulses++;
+const btVector3	li=cluster->m_imass*impulse;
+const btVector3	ai=cluster->m_invwi*cross(rpos,impulse);
+cluster->m_vimpulses[0]+=li;cluster->m_lv+=li;
+cluster->m_vimpulses[1]+=ai;cluster->m_av+=ai;
+cluster->m_nvimpulses++;
 }
 
@@ -645,9 +645,9 @@
 void			btSoftBody::clusterDImpulse(Cluster* cluster,const btVector3& rpos,const btVector3& impulse)
 {
-	const btVector3	li=cluster->m_imass*impulse;
-	const btVector3	ai=cluster->m_invwi*cross(rpos,impulse);
-	cluster->m_dimpulses[0]+=li;
-	cluster->m_dimpulses[1]+=ai;
-	cluster->m_ndimpulses++;
+const btVector3	li=cluster->m_imass*impulse;
+const btVector3	ai=cluster->m_invwi*cross(rpos,impulse);
+cluster->m_dimpulses[0]+=li;
+cluster->m_dimpulses[1]+=ai;
+cluster->m_ndimpulses++;
 }
 
@@ -655,6 +655,6 @@
 void			btSoftBody::clusterImpulse(Cluster* cluster,const btVector3& rpos,const Impulse& impulse)
 {
-	if(impulse.m_asVelocity)	clusterVImpulse(cluster,rpos,impulse.m_velocity);
-	if(impulse.m_asDrift)		clusterDImpulse(cluster,rpos,impulse.m_drift);
+if(impulse.m_asVelocity)	clusterVImpulse(cluster,rpos,impulse.m_velocity);
+if(impulse.m_asDrift)		clusterDImpulse(cluster,rpos,impulse.m_drift);
 }
 
@@ -662,7 +662,7 @@
 void			btSoftBody::clusterVAImpulse(Cluster* cluster,const btVector3& impulse)
 {
-	const btVector3	ai=cluster->m_invwi*impulse;
-	cluster->m_vimpulses[1]+=ai;cluster->m_av+=ai;
-	cluster->m_nvimpulses++;
+const btVector3	ai=cluster->m_invwi*impulse;
+cluster->m_vimpulses[1]+=ai;cluster->m_av+=ai;
+cluster->m_nvimpulses++;
 }
 
@@ -670,7 +670,7 @@
 void			btSoftBody::clusterDAImpulse(Cluster* cluster,const btVector3& impulse)
 {
-	const btVector3	ai=cluster->m_invwi*impulse;
-	cluster->m_dimpulses[1]+=ai;
-	cluster->m_ndimpulses++;
+const btVector3	ai=cluster->m_invwi*impulse;
+cluster->m_dimpulses[1]+=ai;
+cluster->m_ndimpulses++;
 }
 
@@ -678,6 +678,6 @@
 void			btSoftBody::clusterAImpulse(Cluster* cluster,const Impulse& impulse)
 {
-	if(impulse.m_asVelocity)	clusterVAImpulse(cluster,impulse.m_velocity);
-	if(impulse.m_asDrift)		clusterDAImpulse(cluster,impulse.m_drift);
+if(impulse.m_asVelocity)	clusterVAImpulse(cluster,impulse.m_velocity);
+if(impulse.m_asDrift)		clusterDAImpulse(cluster,impulse.m_drift);
 }
 
@@ -685,6 +685,6 @@
 void			btSoftBody::clusterDCImpulse(Cluster* cluster,const btVector3& impulse)
 {
-	cluster->m_dimpulses[0]+=impulse*cluster->m_imass;
-	cluster->m_ndimpulses++;
+cluster->m_dimpulses[0]+=impulse*cluster->m_imass;
+cluster->m_ndimpulses++;
 }
 
@@ -754,7 +754,7 @@
 void			btSoftBody::randomizeConstraints()
 {
-	unsigned long	seed=243703;
+unsigned long	seed=243703;
 #define NEXTRAND (seed=(1664525L*seed+1013904223L)&0xffffffff)
-	int i,ni;
+int i,ni;
 
 	for(i=0,ni=m_links.size();i<ni;++i)
@@ -772,9 +772,9 @@
 void			btSoftBody::releaseCluster(int index)
 {
-	Cluster*	c=m_clusters[index];
-	if(c->m_leaf) m_cdbvt.remove(c->m_leaf);
-	c->~Cluster();
-	btAlignedFree(c);
-	m_clusters.remove(c);
+Cluster*	c=m_clusters[index];
+if(c->m_leaf) m_cdbvt.remove(c->m_leaf);
+c->~Cluster();
+btAlignedFree(c);
+m_clusters.remove(c);
 }
 
@@ -782,5 +782,5 @@
 void			btSoftBody::releaseClusters()
 {
-	while(m_clusters.size()>0) releaseCluster(0);
+while(m_clusters.size()>0) releaseCluster(0);
 }
 
@@ -788,95 +788,95 @@
 int				btSoftBody::generateClusters(int k,int maxiterations)
 {
-	int i;
-	releaseClusters();
-	m_clusters.resize(btMin(k,m_nodes.size()));
-	for(i=0;i<m_clusters.size();++i)
-	{
-		m_clusters[i]			=	new(btAlignedAlloc(sizeof(Cluster),16)) Cluster();
-		m_clusters[i]->m_collide=	true;
-	}
-	k=m_clusters.size();
-	if(k>0)
-	{
-		/* Initialize		*/ 
-		btAlignedObjectArray<btVector3>	centers;
-		btVector3						cog(0,0,0);
-		int								i;
+int i;
+releaseClusters();
+m_clusters.resize(btMin(k,m_nodes.size()));
+for(i=0;i<m_clusters.size();++i)
+	{
+	m_clusters[i]			=	new(btAlignedAlloc(sizeof(Cluster),16)) Cluster();
+	m_clusters[i]->m_collide=	true;
+	}
+k=m_clusters.size();
+if(k>0)
+	{
+	/* Initialize		*/ 
+	btAlignedObjectArray<btVector3>	centers;
+	btVector3						cog(0,0,0);
+	int								i;
+	for(i=0;i<m_nodes.size();++i)
+		{
+		cog+=m_nodes[i].m_x;
+		m_clusters[(i*29873)%m_clusters.size()]->m_nodes.push_back(&m_nodes[i]);
+		}
+	cog/=(btScalar)m_nodes.size();
+	centers.resize(k,cog);
+	/* Iterate			*/ 
+	const btScalar	slope=16;
+	bool			changed;
+	int				iterations=0;
+	do	{
+		const btScalar	w=2-btMin<btScalar>(1,iterations/slope);
+		changed=false;
+		iterations++;	
+		int i;
+
+		for(i=0;i<k;++i)
+			{
+			btVector3	c(0,0,0);
+			for(int j=0;j<m_clusters[i]->m_nodes.size();++j)
+				{
+				c+=m_clusters[i]->m_nodes[j]->m_x;
+				}
+			if(m_clusters[i]->m_nodes.size())
+				{
+				c			/=	(btScalar)m_clusters[i]->m_nodes.size();
+				c			=	centers[i]+(c-centers[i])*w;
+				changed		|=	((c-centers[i]).length2()>SIMD_EPSILON);
+				centers[i]	=	c;
+				m_clusters[i]->m_nodes.resize(0);
+				}			
+			}
 		for(i=0;i<m_nodes.size();++i)
-		{
-			cog+=m_nodes[i].m_x;
-			m_clusters[(i*29873)%m_clusters.size()]->m_nodes.push_back(&m_nodes[i]);
-		}
-		cog/=(btScalar)m_nodes.size();
-		centers.resize(k,cog);
-		/* Iterate			*/ 
-		const btScalar	slope=16;
-		bool			changed;
-		int				iterations=0;
-		do	{
-			const btScalar	w=2-btMin<btScalar>(1,iterations/slope);
-			changed=false;
-			iterations++;	
-			int i;
-
-			for(i=0;i<k;++i)
-			{
-				btVector3	c(0,0,0);
-				for(int j=0;j<m_clusters[i]->m_nodes.size();++j)
+			{
+			const btVector3	nx=m_nodes[i].m_x;
+			int				kbest=0;
+			btScalar		kdist=ClusterMetric(centers[0],nx);
+			for(int j=1;j<k;++j)
 				{
-					c+=m_clusters[i]->m_nodes[j]->m_x;
-				}
-				if(m_clusters[i]->m_nodes.size())
-				{
-					c			/=	(btScalar)m_clusters[i]->m_nodes.size();
-					c			=	centers[i]+(c-centers[i])*w;
-					changed		|=	((c-centers[i]).length2()>SIMD_EPSILON);
-					centers[i]	=	c;
-					m_clusters[i]->m_nodes.resize(0);
-				}			
-			}
-			for(i=0;i<m_nodes.size();++i)
-			{
-				const btVector3	nx=m_nodes[i].m_x;
-				int				kbest=0;
-				btScalar		kdist=ClusterMetric(centers[0],nx);
-				for(int j=1;j<k;++j)
-				{
-					const btScalar	d=ClusterMetric(centers[j],nx);
-					if(d<kdist)
+				const btScalar	d=ClusterMetric(centers[j],nx);
+				if(d<kdist)
 					{
-						kbest=j;
-						kdist=d;
+					kbest=j;
+					kdist=d;
 					}
 				}
-				m_clusters[kbest]->m_nodes.push_back(&m_nodes[i]);
+			m_clusters[kbest]->m_nodes.push_back(&m_nodes[i]);
 			}		
 		} while(changed&&(iterations<maxiterations));
-		/* Merge		*/ 
-		btAlignedObjectArray<int>	cids;
-		cids.resize(m_nodes.size(),-1);
-		for(i=0;i<m_clusters.size();++i)
-		{
-			for(int j=0;j<m_clusters[i]->m_nodes.size();++j)
-			{
-				cids[int(m_clusters[i]->m_nodes[j]-&m_nodes[0])]=i;
-			}
-		}
-		for(i=0;i<m_faces.size();++i)
-		{
-			const int idx[]={	int(m_faces[i].m_n[0]-&m_nodes[0]),
-				int(m_faces[i].m_n[1]-&m_nodes[0]),
-				int(m_faces[i].m_n[2]-&m_nodes[0])};
-			for(int j=0;j<3;++j)
-			{
-				const int cid=cids[idx[j]];
-				for(int q=1;q<3;++q)
+	/* Merge		*/ 
+	btAlignedObjectArray<int>	cids;
+	cids.resize(m_nodes.size(),-1);
+	for(i=0;i<m_clusters.size();++i)
+		{
+		for(int j=0;j<m_clusters[i]->m_nodes.size();++j)
+			{
+			cids[int(m_clusters[i]->m_nodes[j]-&m_nodes[0])]=i;
+			}
+		}
+	for(i=0;i<m_faces.size();++i)
+		{
+		const int idx[]={	int(m_faces[i].m_n[0]-&m_nodes[0]),
+							int(m_faces[i].m_n[1]-&m_nodes[0]),
+							int(m_faces[i].m_n[2]-&m_nodes[0])};
+		for(int j=0;j<3;++j)
+			{
+			const int cid=cids[idx[j]];
+			for(int q=1;q<3;++q)
 				{
-					const int kid=idx[(j+q)%3];
-					if(cids[kid]!=cid)
+				const int kid=idx[(j+q)%3];
+				if(cids[kid]!=cid)
 					{
-						if(m_clusters[cid]->m_nodes.findLinearSearch(&m_nodes[kid])==m_clusters[cid]->m_nodes.size())
+					if(m_clusters[cid]->m_nodes.findLinearSearch(&m_nodes[kid])==m_clusters[cid]->m_nodes.size())
 						{
-							m_clusters[cid]->m_nodes.push_back(&m_nodes[kid]);
+						m_clusters[cid]->m_nodes.push_back(&m_nodes[kid]);
 						}
 					}
@@ -884,28 +884,28 @@
 			}
 		}
-		/* Master		*/ 
-		if(m_clusters.size()>1)
-		{
-			Cluster*	pmaster=new(btAlignedAlloc(sizeof(Cluster),16)) Cluster();
-			pmaster->m_collide	=	false;
-			pmaster->m_nodes.reserve(m_nodes.size());
-			for(int i=0;i<m_nodes.size();++i) pmaster->m_nodes.push_back(&m_nodes[i]);
-			m_clusters.push_back(pmaster);
-			btSwap(m_clusters[0],m_clusters[m_clusters.size()-1]);
-		}
-		/* Terminate	*/ 
-		for(i=0;i<m_clusters.size();++i)
-		{
-			if(m_clusters[i]->m_nodes.size()==0)
-			{
-				releaseCluster(i--);
-			}
-		}
-
-		initializeClusters();
-		updateClusters();
-		return(m_clusters.size());
-	}
-	return(0);
+	/* Master		*/ 
+	if(m_clusters.size()>1)
+		{
+		Cluster*	pmaster=new(btAlignedAlloc(sizeof(Cluster),16)) Cluster();
+		pmaster->m_collide	=	false;
+		pmaster->m_nodes.reserve(m_nodes.size());
+		for(int i=0;i<m_nodes.size();++i) pmaster->m_nodes.push_back(&m_nodes[i]);
+		m_clusters.push_back(pmaster);
+		btSwap(m_clusters[0],m_clusters[m_clusters.size()-1]);
+		}
+	/* Terminate	*/ 
+	for(i=0;i<m_clusters.size();++i)
+		{
+		if(m_clusters[i]->m_nodes.size()==0)
+			{
+			releaseCluster(i--);
+			}
+		}
+		
+	initializeClusters();
+	updateClusters();
+	return(m_clusters.size());
+	}
+return(0);
 }
 
@@ -913,62 +913,62 @@
 void			btSoftBody::refine(ImplicitFn* ifn,btScalar accurary,bool cut)
 {
-	const Node*			nbase = &m_nodes[0];
-	int					ncount = m_nodes.size();
-	btSymMatrix<int>	edges(ncount,-2);
-	int					newnodes=0;
-	int i,j,k,ni;
-
-	/* Filter out		*/ 
-	for(i=0;i<m_links.size();++i)
-	{
-		Link&	l=m_links[i];
-		if(l.m_bbending)
-		{
-			if(!SameSign(ifn->Eval(l.m_n[0]->m_x),ifn->Eval(l.m_n[1]->m_x)))
-			{
-				btSwap(m_links[i],m_links[m_links.size()-1]);
-				m_links.pop_back();--i;
+const Node*			nbase = &m_nodes[0];
+int					ncount = m_nodes.size();
+btSymMatrix<int>	edges(ncount,-2);
+int					newnodes=0;
+int i,j,k,ni;
+
+/* Filter out		*/ 
+for(i=0;i<m_links.size();++i)
+	{
+	Link&	l=m_links[i];
+	if(l.m_bbending)
+		{
+		if(!SameSign(ifn->Eval(l.m_n[0]->m_x),ifn->Eval(l.m_n[1]->m_x)))
+			{
+			btSwap(m_links[i],m_links[m_links.size()-1]);
+			m_links.pop_back();--i;
 			}
 		}	
 	}
-	/* Fill edges		*/ 
-	for(i=0;i<m_links.size();++i)
-	{
-		Link&	l=m_links[i];
-		edges(int(l.m_n[0]-nbase),int(l.m_n[1]-nbase))=-1;
-	}
-	for(i=0;i<m_faces.size();++i)
+/* Fill edges		*/ 
+for(i=0;i<m_links.size();++i)
+	{
+	Link&	l=m_links[i];
+	edges(int(l.m_n[0]-nbase),int(l.m_n[1]-nbase))=-1;
+	}
+for(i=0;i<m_faces.size();++i)
 	{	
-		Face&	f=m_faces[i];
-		edges(int(f.m_n[0]-nbase),int(f.m_n[1]-nbase))=-1;
-		edges(int(f.m_n[1]-nbase),int(f.m_n[2]-nbase))=-1;
-		edges(int(f.m_n[2]-nbase),int(f.m_n[0]-nbase))=-1;
-	}
-	/* Intersect		*/ 
-	for(i=0;i<ncount;++i)
-	{
-		for(j=i+1;j<ncount;++j)
-		{
-			if(edges(i,j)==-1)
-			{
-				Node&			a=m_nodes[i];
-				Node&			b=m_nodes[j];
-				const btScalar	t=ImplicitSolve(ifn,a.m_x,b.m_x,accurary);
-				if(t>0)
+	Face&	f=m_faces[i];
+	edges(int(f.m_n[0]-nbase),int(f.m_n[1]-nbase))=-1;
+	edges(int(f.m_n[1]-nbase),int(f.m_n[2]-nbase))=-1;
+	edges(int(f.m_n[2]-nbase),int(f.m_n[0]-nbase))=-1;
+	}
+/* Intersect		*/ 
+for(i=0;i<ncount;++i)
+	{
+	for(j=i+1;j<ncount;++j)
+		{
+		if(edges(i,j)==-1)
+			{
+			Node&			a=m_nodes[i];
+			Node&			b=m_nodes[j];
+			const btScalar	t=ImplicitSolve(ifn,a.m_x,b.m_x,accurary);
+			if(t>0)
 				{
-					const btVector3	x=Lerp(a.m_x,b.m_x,t);
-					const btVector3	v=Lerp(a.m_v,b.m_v,t);
-					btScalar		m=0;
-					if(a.m_im>0)
+				const btVector3	x=Lerp(a.m_x,b.m_x,t);
+				const btVector3	v=Lerp(a.m_v,b.m_v,t);
+				btScalar		m=0;
+				if(a.m_im>0)
 					{
-						if(b.m_im>0)
+					if(b.m_im>0)
 						{
-							const btScalar	ma=1/a.m_im;
-							const btScalar	mb=1/b.m_im;
-							const btScalar	mc=Lerp(ma,mb,t);
-							const btScalar	f=(ma+mb)/(ma+mb+mc);
-							a.m_im=1/(ma*f);
-							b.m_im=1/(mb*f);
-							m=mc*f;
+						const btScalar	ma=1/a.m_im;
+						const btScalar	mb=1/b.m_im;
+						const btScalar	mc=Lerp(ma,mb,t);
+						const btScalar	f=(ma+mb)/(ma+mb+mc);
+						a.m_im=1/(ma*f);
+						b.m_im=1/(mb*f);
+						m=mc*f;
 						}
 						else
@@ -977,186 +977,186 @@
 					else
 					{
-						if(b.m_im>0)
+					if(b.m_im>0)
 						{ b.m_im/=0.5;m=1/b.m_im; }
 						else
-							m=0;
+						m=0;
 					}
-					appendNode(x,m);
-					edges(i,j)=m_nodes.size()-1;
-					m_nodes[edges(i,j)].m_v=v;
-					++newnodes;
+				appendNode(x,m);
+				edges(i,j)=m_nodes.size()-1;
+				m_nodes[edges(i,j)].m_v=v;
+				++newnodes;
 				}
 			}
 		}
 	}
+nbase=&m_nodes[0];
+/* Refine links		*/ 
+for(i=0,ni=m_links.size();i<ni;++i)
+	{
+	Link&		feat=m_links[i];
+	const int	idx[]={	int(feat.m_n[0]-nbase),
+						int(feat.m_n[1]-nbase)};
+	if((idx[0]<ncount)&&(idx[1]<ncount))
+		{
+		const int ni=edges(idx[0],idx[1]);
+		if(ni>0)
+			{
+			appendLink(i);
+			Link*		pft[]={	&m_links[i],
+								&m_links[m_links.size()-1]};			
+			pft[0]->m_n[0]=&m_nodes[idx[0]];
+			pft[0]->m_n[1]=&m_nodes[ni];
+			pft[1]->m_n[0]=&m_nodes[ni];
+			pft[1]->m_n[1]=&m_nodes[idx[1]];
+			}
+		}
+	}
+/* Refine faces		*/ 
+for(i=0;i<m_faces.size();++i)
+	{
+	const Face&	feat=m_faces[i];
+	const int	idx[]={	int(feat.m_n[0]-nbase),
+						int(feat.m_n[1]-nbase),
+						int(feat.m_n[2]-nbase)};
+	for(j=2,k=0;k<3;j=k++)
+		{
+		if((idx[j]<ncount)&&(idx[k]<ncount))
+			{
+			const int ni=edges(idx[j],idx[k]);
+			if(ni>0)
+				{
+				appendFace(i);
+				const int	l=(k+1)%3;
+				Face*		pft[]={	&m_faces[i],
+									&m_faces[m_faces.size()-1]};
+				pft[0]->m_n[0]=&m_nodes[idx[l]];
+				pft[0]->m_n[1]=&m_nodes[idx[j]];
+				pft[0]->m_n[2]=&m_nodes[ni];
+				pft[1]->m_n[0]=&m_nodes[ni];
+				pft[1]->m_n[1]=&m_nodes[idx[k]];
+				pft[1]->m_n[2]=&m_nodes[idx[l]];
+				appendLink(ni,idx[l],pft[0]->m_material);
+				--i;break;
+				}
+			}
+		}
+	}
+/* Cut				*/ 
+if(cut)
+	{	
+	btAlignedObjectArray<int>	cnodes;
+	const int					pcount=ncount;
+	int							i;
+	ncount=m_nodes.size();
+	cnodes.resize(ncount,0);
+	/* Nodes		*/ 
+	for(i=0;i<ncount;++i)
+		{
+		const btVector3	x=m_nodes[i].m_x;
+		if((i>=pcount)||(btFabs(ifn->Eval(x))<accurary))
+			{
+			const btVector3	v=m_nodes[i].m_v;
+			btScalar		m=getMass(i);
+			if(m>0) { m*=0.5;m_nodes[i].m_im/=0.5; }
+			appendNode(x,m);
+			cnodes[i]=m_nodes.size()-1;
+			m_nodes[cnodes[i]].m_v=v;
+			}
+		}
 	nbase=&m_nodes[0];
-	/* Refine links		*/ 
+	/* Links		*/ 
 	for(i=0,ni=m_links.size();i<ni;++i)
-	{
-		Link&		feat=m_links[i];
-		const int	idx[]={	int(feat.m_n[0]-nbase),
-			int(feat.m_n[1]-nbase)};
-		if((idx[0]<ncount)&&(idx[1]<ncount))
-		{
-			const int ni=edges(idx[0],idx[1]);
-			if(ni>0)
-			{
-				appendLink(i);
-				Link*		pft[]={	&m_links[i],
-					&m_links[m_links.size()-1]};			
-				pft[0]->m_n[0]=&m_nodes[idx[0]];
-				pft[0]->m_n[1]=&m_nodes[ni];
-				pft[1]->m_n[0]=&m_nodes[ni];
-				pft[1]->m_n[1]=&m_nodes[idx[1]];
-			}
-		}
-	}
-	/* Refine faces		*/ 
-	for(i=0;i<m_faces.size();++i)
-	{
-		const Face&	feat=m_faces[i];
-		const int	idx[]={	int(feat.m_n[0]-nbase),
-			int(feat.m_n[1]-nbase),
-			int(feat.m_n[2]-nbase)};
-		for(j=2,k=0;k<3;j=k++)
-		{
-			if((idx[j]<ncount)&&(idx[k]<ncount))
-			{
-				const int ni=edges(idx[j],idx[k]);
-				if(ni>0)
+		{
+		const int		id[]={	int(m_links[i].m_n[0]-nbase),
+								int(m_links[i].m_n[1]-nbase)};
+		int				todetach=0;
+		if(cnodes[id[0]]&&cnodes[id[1]])
+			{
+			appendLink(i);
+			todetach=m_links.size()-1;
+			}
+		else
+			{
+			if((	(ifn->Eval(m_nodes[id[0]].m_x)<accurary)&&
+					(ifn->Eval(m_nodes[id[1]].m_x)<accurary)))
+				todetach=i;
+			}
+		if(todetach)
+			{
+			Link&	l=m_links[todetach];
+			for(int j=0;j<2;++j)
 				{
-					appendFace(i);
-					const int	l=(k+1)%3;
-					Face*		pft[]={	&m_faces[i],
-						&m_faces[m_faces.size()-1]};
-					pft[0]->m_n[0]=&m_nodes[idx[l]];
-					pft[0]->m_n[1]=&m_nodes[idx[j]];
-					pft[0]->m_n[2]=&m_nodes[ni];
-					pft[1]->m_n[0]=&m_nodes[ni];
-					pft[1]->m_n[1]=&m_nodes[idx[k]];
-					pft[1]->m_n[2]=&m_nodes[idx[l]];
-					appendLink(ni,idx[l],pft[0]->m_material);
-					--i;break;
+				int cn=cnodes[int(l.m_n[j]-nbase)];
+				if(cn) l.m_n[j]=&m_nodes[cn];
+				}			
+			}
+		}
+	/* Faces		*/ 
+	for(i=0,ni=m_faces.size();i<ni;++i)
+		{
+		Node**			n=	m_faces[i].m_n;
+		if(	(ifn->Eval(n[0]->m_x)<accurary)&&
+			(ifn->Eval(n[1]->m_x)<accurary)&&
+			(ifn->Eval(n[2]->m_x)<accurary))
+			{
+			for(int j=0;j<3;++j)
+				{
+				int cn=cnodes[int(n[j]-nbase)];
+				if(cn) n[j]=&m_nodes[cn];
 				}
 			}
 		}
-	}
-	/* Cut				*/ 
-	if(cut)
-	{	
-		btAlignedObjectArray<int>	cnodes;
-		const int					pcount=ncount;
-		int							i;
-		ncount=m_nodes.size();
-		cnodes.resize(ncount,0);
-		/* Nodes		*/ 
-		for(i=0;i<ncount;++i)
-		{
-			const btVector3	x=m_nodes[i].m_x;
-			if((i>=pcount)||(btFabs(ifn->Eval(x))<accurary))
-			{
-				const btVector3	v=m_nodes[i].m_v;
-				btScalar		m=getMass(i);
-				if(m>0) { m*=0.5;m_nodes[i].m_im/=0.5; }
-				appendNode(x,m);
-				cnodes[i]=m_nodes.size()-1;
-				m_nodes[cnodes[i]].m_v=v;
-			}
-		}
-		nbase=&m_nodes[0];
-		/* Links		*/ 
-		for(i=0,ni=m_links.size();i<ni;++i)
-		{
-			const int		id[]={	int(m_links[i].m_n[0]-nbase),
-				int(m_links[i].m_n[1]-nbase)};
-			int				todetach=0;
-			if(cnodes[id[0]]&&cnodes[id[1]])
-			{
-				appendLink(i);
-				todetach=m_links.size()-1;
-			}
-			else
-			{
-				if((	(ifn->Eval(m_nodes[id[0]].m_x)<accurary)&&
-					(ifn->Eval(m_nodes[id[1]].m_x)<accurary)))
-					todetach=i;
-			}
-			if(todetach)
-			{
-				Link&	l=m_links[todetach];
-				for(int j=0;j<2;++j)
-				{
-					int cn=cnodes[int(l.m_n[j]-nbase)];
-					if(cn) l.m_n[j]=&m_nodes[cn];
-				}			
-			}
-		}
-		/* Faces		*/ 
-		for(i=0,ni=m_faces.size();i<ni;++i)
-		{
-			Node**			n=	m_faces[i].m_n;
-			if(	(ifn->Eval(n[0]->m_x)<accurary)&&
-				(ifn->Eval(n[1]->m_x)<accurary)&&
-				(ifn->Eval(n[2]->m_x)<accurary))
-			{
-				for(int j=0;j<3;++j)
-				{
-					int cn=cnodes[int(n[j]-nbase)];
-					if(cn) n[j]=&m_nodes[cn];
-				}
-			}
-		}
-		/* Clean orphans	*/ 
-		int							nnodes=m_nodes.size();
-		btAlignedObjectArray<int>	ranks;
-		btAlignedObjectArray<int>	todelete;
-		ranks.resize(nnodes,0);
-		for(i=0,ni=m_links.size();i<ni;++i)
-		{
-			for(int j=0;j<2;++j) ranks[int(m_links[i].m_n[j]-nbase)]++;
-		}
-		for(i=0,ni=m_faces.size();i<ni;++i)
-		{
-			for(int j=0;j<3;++j) ranks[int(m_faces[i].m_n[j]-nbase)]++;
-		}
-		for(i=0;i<m_links.size();++i)
-		{
-			const int	id[]={	int(m_links[i].m_n[0]-nbase),
-				int(m_links[i].m_n[1]-nbase)};
-			const bool	sg[]={	ranks[id[0]]==1,
-				ranks[id[1]]==1};
-			if(sg[0]||sg[1])
-			{
-				--ranks[id[0]];
-				--ranks[id[1]];
-				btSwap(m_links[i],m_links[m_links.size()-1]);
-				m_links.pop_back();--i;
-			}
-		}
-#if 0	
-		for(i=nnodes-1;i>=0;--i)
-		{
-			if(!ranks[i]) todelete.push_back(i);
+	/* Clean orphans	*/ 
+	int							nnodes=m_nodes.size();
+	btAlignedObjectArray<int>	ranks;
+	btAlignedObjectArray<int>	todelete;
+	ranks.resize(nnodes,0);
+	for(i=0,ni=m_links.size();i<ni;++i)
+		{
+		for(int j=0;j<2;++j) ranks[int(m_links[i].m_n[j]-nbase)]++;
+		}
+	for(i=0,ni=m_faces.size();i<ni;++i)
+		{
+		for(int j=0;j<3;++j) ranks[int(m_faces[i].m_n[j]-nbase)]++;
+		}
+	for(i=0;i<m_links.size();++i)
+		{
+		const int	id[]={	int(m_links[i].m_n[0]-nbase),
+							int(m_links[i].m_n[1]-nbase)};
+		const bool	sg[]={	ranks[id[0]]==1,
+							ranks[id[1]]==1};
+		if(sg[0]||sg[1])
+			{
+			--ranks[id[0]];
+			--ranks[id[1]];
+			btSwap(m_links[i],m_links[m_links.size()-1]);
+			m_links.pop_back();--i;
+			}
+		}
+	#if 0	
+	for(i=nnodes-1;i>=0;--i)
+		{
+		if(!ranks[i]) todelete.push_back(i);
 		}	
-		if(todelete.size())
+	if(todelete.size())
 		{		
-			btAlignedObjectArray<int>&	map=ranks;
-			for(int i=0;i<nnodes;++i) map[i]=i;
-			PointersToIndices(this);
-			for(int i=0,ni=todelete.size();i<ni;++i)
-			{
-				int		j=todelete[i];
-				int&	a=map[j];
-				int&	b=map[--nnodes];
-				m_ndbvt.remove(m_nodes[a].m_leaf);m_nodes[a].m_leaf=0;
-				btSwap(m_nodes[a],m_nodes[b]);
-				j=a;a=b;b=j;			
-			}
-			IndicesToPointers(this,&map[0]);
-			m_nodes.resize(nnodes);
-		}
-#endif
-	}
-	m_bUpdateRtCst=true;
+		btAlignedObjectArray<int>&	map=ranks;
+		for(int i=0;i<nnodes;++i) map[i]=i;
+		PointersToIndices(this);
+		for(int i=0,ni=todelete.size();i<ni;++i)
+			{
+			int		j=todelete[i];
+			int&	a=map[j];
+			int&	b=map[--nnodes];
+			m_ndbvt.remove(m_nodes[a].m_leaf);m_nodes[a].m_leaf=0;
+			btSwap(m_nodes[a],m_nodes[b]);
+			j=a;a=b;b=j;			
+			}
+		IndicesToPointers(this,&map[0]);
+		m_nodes.resize(nnodes);
+		}
+	#endif
+	}
+m_bUpdateRtCst=true;
 }
 
@@ -1164,5 +1164,5 @@
 bool			btSoftBody::cutLink(const Node* node0,const Node* node1,btScalar position)
 {
-	return(cutLink(int(node0-&m_nodes[0]),int(node1-&m_nodes[0]),position));
+return(cutLink(int(node0-&m_nodes[0]),int(node1-&m_nodes[0]),position));
 }
 
@@ -1170,70 +1170,68 @@
 bool			btSoftBody::cutLink(int node0,int node1,btScalar position)
 {
-	bool			done=false;
-	int i,ni;
-	const btVector3	d=m_nodes[node0].m_x-m_nodes[node1].m_x;
-	const btVector3	x=Lerp(m_nodes[node0].m_x,m_nodes[node1].m_x,position);
-	const btVector3	v=Lerp(m_nodes[node0].m_v,m_nodes[node1].m_v,position);
-	const btScalar	m=1;
-	appendNode(x,m);
-	appendNode(x,m);
-	Node*			pa=&m_nodes[node0];
-	Node*			pb=&m_nodes[node1];
-	Node*			pn[2]={	&m_nodes[m_nodes.size()-2],
-		&m_nodes[m_nodes.size()-1]};
-	pn[0]->m_v=v;
-	pn[1]->m_v=v;
-	for(i=0,ni=m_links.size();i<ni;++i)
-	{
-		const int mtch=MatchEdge(m_links[i].m_n[0],m_links[i].m_n[1],pa,pb);
+bool			done=false;
+int i,ni;
+const btVector3	d=m_nodes[node0].m_x-m_nodes[node1].m_x;
+const btVector3	x=Lerp(m_nodes[node0].m_x,m_nodes[node1].m_x,position);
+const btVector3	v=Lerp(m_nodes[node0].m_v,m_nodes[node1].m_v,position);
+const btScalar	m=1;
+appendNode(x,m);
+appendNode(x,m);
+Node*			pa=&m_nodes[node0];
+Node*			pb=&m_nodes[node1];
+Node*			pn[2]={	&m_nodes[m_nodes.size()-2],
+						&m_nodes[m_nodes.size()-1]};
+pn[0]->m_v=v;
+pn[1]->m_v=v;
+for(i=0,ni=m_links.size();i<ni;++i)
+	{
+	const int mtch=MatchEdge(m_links[i].m_n[0],m_links[i].m_n[1],pa,pb);
+	if(mtch!=-1)
+		{
+		appendLink(i);
+		Link*	pft[]={&m_links[i],&m_links[m_links.size()-1]};
+		pft[0]->m_n[1]=pn[mtch];
+		pft[1]->m_n[0]=pn[1-mtch];
+		done=true;
+		}
+	}
+for(i=0,ni=m_faces.size();i<ni;++i)
+	{
+	for(int k=2,l=0;l<3;k=l++)
+		{
+		const int mtch=MatchEdge(m_faces[i].m_n[k],m_faces[i].m_n[l],pa,pb);
 		if(mtch!=-1)
-		{
-			appendLink(i);
-			Link*	pft[]={&m_links[i],&m_links[m_links.size()-1]};
-			pft[0]->m_n[1]=pn[mtch];
-			pft[1]->m_n[0]=pn[1-mtch];
-			done=true;
-		}
-	}
-	for(i=0,ni=m_faces.size();i<ni;++i)
-	{
-		for(int k=2,l=0;l<3;k=l++)
-		{
-			const int mtch=MatchEdge(m_faces[i].m_n[k],m_faces[i].m_n[l],pa,pb);
-			if(mtch!=-1)
-			{
-				appendFace(i);
-				Face*	pft[]={&m_faces[i],&m_faces[m_faces.size()-1]};
-				pft[0]->m_n[l]=pn[mtch];
-				pft[1]->m_n[k]=pn[1-mtch];
-				appendLink(pn[0],pft[0]->m_n[(l+1)%3],pft[0]->m_material,true);
-				appendLink(pn[1],pft[0]->m_n[(l+1)%3],pft[0]->m_material,true);
-			}
-		}
-	}
-	if(!done)
-	{
-		m_ndbvt.remove(pn[0]->m_leaf);
-		m_ndbvt.remove(pn[1]->m_leaf);
-		m_nodes.pop_back();
-		m_nodes.pop_back();
-	}
-	return(done);
-}
-
-//
-bool			btSoftBody::rayTest(const btVector3& rayFrom,
-									const btVector3& rayTo,
-									sRayCast& results)
-{
-	if(m_faces.size()&&m_fdbvt.empty()) 
-		initializeFaceTree();
-
-	results.body	=	this;
-	results.fraction = 1.f;
-	results.feature	=	eFeature::None;
-	results.index	=	-1;
-
-	return(rayTest(rayFrom,rayTo,results.fraction,results.feature,results.index,false)!=0);
+			{
+			appendFace(i);
+			Face*	pft[]={&m_faces[i],&m_faces[m_faces.size()-1]};
+			pft[0]->m_n[l]=pn[mtch];
+			pft[1]->m_n[k]=pn[1-mtch];
+			appendLink(pn[0],pft[0]->m_n[(l+1)%3],pft[0]->m_material,true);
+			appendLink(pn[1],pft[0]->m_n[(l+1)%3],pft[0]->m_material,true);
+			}
+		}
+	}
+if(!done)
+	{
+	m_ndbvt.remove(pn[0]->m_leaf);
+	m_ndbvt.remove(pn[1]->m_leaf);
+	m_nodes.pop_back();
+	m_nodes.pop_back();
+	}
+return(done);
+}
+
+//
+bool			btSoftBody::rayCast(const btVector3& org,
+									const btVector3& dir,
+									sRayCast& results,
+									btScalar maxtime)
+{
+if(m_faces.size()&&m_fdbvt.empty()) initializeFaceTree();
+results.body	=	this;
+results.time	=	maxtime;
+results.feature	=	eFeature::None;
+results.index	=	-1;
+return(rayCast(org,dir,results.time,results.feature,results.index,false)!=0);
 }
 
@@ -1241,24 +1239,24 @@
 void			btSoftBody::setSolver(eSolverPresets::_ preset)
 {
-	m_cfg.m_vsequence.clear();
-	m_cfg.m_psequence.clear();
-	m_cfg.m_dsequence.clear();
-	switch(preset)
+m_cfg.m_vsequence.clear();
+m_cfg.m_psequence.clear();
+m_cfg.m_dsequence.clear();
+switch(preset)
 	{
 	case	eSolverPresets::Positions:
-		m_cfg.m_psequence.push_back(ePSolver::Anchors);
-		m_cfg.m_psequence.push_back(ePSolver::RContacts);
-		m_cfg.m_psequence.push_back(ePSolver::SContacts);
-		m_cfg.m_psequence.push_back(ePSolver::Linear);	
-		break;	
+	m_cfg.m_psequence.push_back(ePSolver::Anchors);
+	m_cfg.m_psequence.push_back(ePSolver::RContacts);
+	m_cfg.m_psequence.push_back(ePSolver::SContacts);
+	m_cfg.m_psequence.push_back(ePSolver::Linear);	
+	break;	
 	case	eSolverPresets::Velocities:
-		m_cfg.m_vsequence.push_back(eVSolver::Linear);
-
-		m_cfg.m_psequence.push_back(ePSolver::Anchors);
-		m_cfg.m_psequence.push_back(ePSolver::RContacts);
-		m_cfg.m_psequence.push_back(ePSolver::SContacts);
-
-		m_cfg.m_dsequence.push_back(ePSolver::Linear);
-		break;
+	m_cfg.m_vsequence.push_back(eVSolver::Linear);
+	
+	m_cfg.m_psequence.push_back(ePSolver::Anchors);
+	m_cfg.m_psequence.push_back(ePSolver::RContacts);
+	m_cfg.m_psequence.push_back(ePSolver::SContacts);
+	
+	m_cfg.m_dsequence.push_back(ePSolver::Linear);
+	break;
 	}
 }
@@ -1276,9 +1274,9 @@
 		m_fdbvt.clear();
 		if(m_cfg.collisions&fCollision::VF_SS)
-		{
+			{
 			initializeFaceTree();			
-		}
-	}
-
+			}
+	}
+		
 	/* Prepare				*/ 
 	m_sst.sdt		=	dt*m_cfg.timescale;
@@ -1308,39 +1306,39 @@
 		Node&	n=m_nodes[i];
 		m_ndbvt.update(	n.m_leaf,
-			btDbvtVolume::FromCR(n.m_x,m_sst.radmrg),
-			n.m_v*m_sst.velmrg,
-			m_sst.updmrg);
+						btDbvtVolume::FromCR(n.m_x,m_sst.radmrg),
+						n.m_v*m_sst.velmrg,
+						m_sst.updmrg);
 	}
 	/* Faces				*/ 
 	if(!m_fdbvt.empty())
-	{
+		{
 		for(int i=0;i<m_faces.size();++i)
-		{
+			{
 			Face&			f=m_faces[i];
 			const btVector3	v=(	f.m_n[0]->m_v+
-				f.m_n[1]->m_v+
-				f.m_n[2]->m_v)/3;
+								f.m_n[1]->m_v+
+								f.m_n[2]->m_v)/3;
 			m_fdbvt.update(	f.m_leaf,
-				VolumeOf(f,m_sst.radmrg),
-				v*m_sst.velmrg,
-				m_sst.updmrg);
-		}
-	}
+							VolumeOf(f,m_sst.radmrg),
+							v*m_sst.velmrg,
+							m_sst.updmrg);
+			}
+		}
 	/* Pose					*/ 
 	updatePose();
 	/* Match				*/ 
 	if(m_pose.m_bframe&&(m_cfg.kMT>0))
-	{
+		{
 		const btMatrix3x3	posetrs=m_pose.m_rot;
 		for(int i=0,ni=m_nodes.size();i<ni;++i)
-		{
+			{
 			Node&	n=m_nodes[i];
 			if(n.m_im>0)
-			{
+				{
 				const btVector3	x=posetrs*m_pose.m_pos[i]+m_pose.m_com;
 				n.m_x=Lerp(n.m_x,x,m_cfg.kMT);
-			}
-		}
-	}
+				}
+			}
+		}
 	/* Clear contacts		*/ 
 	m_rcontacts.resize(0);
@@ -1355,92 +1353,92 @@
 void			btSoftBody::solveConstraints()
 {
-	/* Apply clusters		*/ 
-	applyClusters(false);
-	/* Prepare links		*/ 
-
-	int i,ni;
-
-	for(i=0,ni=m_links.size();i<ni;++i)
-	{
-		Link&	l=m_links[i];
-		l.m_c3		=	l.m_n[1]->m_q-l.m_n[0]->m_q;
-		l.m_c2		=	1/(l.m_c3.length2()*l.m_c0);
-	}
-	/* Prepare anchors		*/ 
-	for(i=0,ni=m_anchors.size();i<ni;++i)
-	{
-		Anchor&			a=m_anchors[i];
-		const btVector3	ra=a.m_body->getWorldTransform().getBasis()*a.m_local;
-		a.m_c0	=	ImpulseMatrix(	m_sst.sdt,
-			a.m_node->m_im,
-			a.m_body->getInvMass(),
-			a.m_body->getInvInertiaTensorWorld(),
-			ra);
-		a.m_c1	=	ra;
-		a.m_c2	=	m_sst.sdt*a.m_node->m_im;
-		a.m_body->activate();
-	}
-	/* Solve velocities		*/ 
-	if(m_cfg.viterations>0)
-	{
-		/* Solve			*/ 
-		for(int isolve=0;isolve<m_cfg.viterations;++isolve)
-		{
-			for(int iseq=0;iseq<m_cfg.m_vsequence.size();++iseq)
-			{
-				getSolver(m_cfg.m_vsequence[iseq])(this,1);
-			}
-		}
-		/* Update			*/ 
-		for(i=0,ni=m_nodes.size();i<ni;++i)
-		{
-			Node&	n=m_nodes[i];
-			n.m_x	=	n.m_q+n.m_v*m_sst.sdt;
-		}
-	}
-	/* Solve positions		*/ 
-	if(m_cfg.piterations>0)
-	{
-		for(int isolve=0;isolve<m_cfg.piterations;++isolve)
-		{
-			const btScalar ti=isolve/(btScalar)m_cfg.piterations;
-			for(int iseq=0;iseq<m_cfg.m_psequence.size();++iseq)
-			{
-				getSolver(m_cfg.m_psequence[iseq])(this,1,ti);
-			}
-		}
-		const btScalar	vc=m_sst.isdt*(1-m_cfg.kDP);
-		for(i=0,ni=m_nodes.size();i<ni;++i)
-		{
-			Node&	n=m_nodes[i];
-			n.m_v	=	(n.m_x-n.m_q)*vc;
-			n.m_f	=	btVector3(0,0,0);		
-		}
-	}
-	/* Solve drift			*/ 
-	if(m_cfg.diterations>0)
-	{
-		const btScalar	vcf=m_cfg.kVCF*m_sst.isdt;
-		for(i=0,ni=m_nodes.size();i<ni;++i)
-		{
-			Node&	n=m_nodes[i];
-			n.m_q	=	n.m_x;
-		}
-		for(int idrift=0;idrift<m_cfg.diterations;++idrift)
-		{
-			for(int iseq=0;iseq<m_cfg.m_dsequence.size();++iseq)
-			{
-				getSolver(m_cfg.m_dsequence[iseq])(this,1,0);
-			}
-		}
-		for(int i=0,ni=m_nodes.size();i<ni;++i)
-		{
-			Node&	n=m_nodes[i];
-			n.m_v	+=	(n.m_x-n.m_q)*vcf;
-		}
-	}
-	/* Apply clusters		*/ 
-	dampClusters();
-	applyClusters(true);
+/* Apply clusters		*/ 
+applyClusters(false);
+/* Prepare links		*/ 
+
+int i,ni;
+
+for(i=0,ni=m_links.size();i<ni;++i)
+	{
+	Link&	l=m_links[i];
+	l.m_c3		=	l.m_n[1]->m_q-l.m_n[0]->m_q;
+	l.m_c2		=	1/(l.m_c3.length2()*l.m_c0);
+	}
+/* Prepare anchors		*/ 
+for(i=0,ni=m_anchors.size();i<ni;++i)
+	{
+	Anchor&			a=m_anchors[i];
+	const btVector3	ra=a.m_body->getWorldTransform().getBasis()*a.m_local;
+	a.m_c0	=	ImpulseMatrix(	m_sst.sdt,
+								a.m_node->m_im,
+								a.m_body->getInvMass(),
+								a.m_body->getInvInertiaTensorWorld(),
+								ra);
+	a.m_c1	=	ra;
+	a.m_c2	=	m_sst.sdt*a.m_node->m_im;
+	a.m_body->activate();
+	}
+/* Solve velocities		*/ 
+if(m_cfg.viterations>0)
+	{
+	/* Solve			*/ 
+	for(int isolve=0;isolve<m_cfg.viterations;++isolve)
+		{
+		for(int iseq=0;iseq<m_cfg.m_vsequence.size();++iseq)
+			{
+			getSolver(m_cfg.m_vsequence[iseq])(this,1);
+			}
+		}
+	/* Update			*/ 
+	for(i=0,ni=m_nodes.size();i<ni;++i)
+		{
+		Node&	n=m_nodes[i];
+		n.m_x	=	n.m_q+n.m_v*m_sst.sdt;
+		}
+	}
+/* Solve positions		*/ 
+if(m_cfg.piterations>0)
+	{
+	for(int isolve=0;isolve<m_cfg.piterations;++isolve)
+		{
+		const btScalar ti=isolve/(btScalar)m_cfg.piterations;
+		for(int iseq=0;iseq<m_cfg.m_psequence.size();++iseq)
+			{
+			getSolver(m_cfg.m_psequence[iseq])(this,1,ti);
+			}
+		}
+	const btScalar	vc=m_sst.isdt*(1-m_cfg.kDP);
+	for(i=0,ni=m_nodes.size();i<ni;++i)
+		{
+		Node&	n=m_nodes[i];
+		n.m_v	=	(n.m_x-n.m_q)*vc;
+		n.m_f	=	btVector3(0,0,0);		
+		}
+	}
+/* Solve drift			*/ 
+if(m_cfg.diterations>0)
+	{
+	const btScalar	vcf=m_cfg.kVCF*m_sst.isdt;
+	for(i=0,ni=m_nodes.size();i<ni;++i)
+		{
+		Node&	n=m_nodes[i];
+		n.m_q	=	n.m_x;
+		}
+	for(int idrift=0;idrift<m_cfg.diterations;++idrift)
+		{
+		for(int iseq=0;iseq<m_cfg.m_dsequence.size();++iseq)
+			{
+			getSolver(m_cfg.m_dsequence[iseq])(this,1,0);
+			}
+		}
+	for(int i=0,ni=m_nodes.size();i<ni;++i)
+		{
+		Node&	n=m_nodes[i];
+		n.m_v	+=	(n.m_x-n.m_q)*vcf;
+		}
+	}
+/* Apply clusters		*/ 
+dampClusters();
+applyClusters(true);
 }
 
@@ -1448,9 +1446,9 @@
 void			btSoftBody::staticSolve(int iterations)
 {
-	for(int isolve=0;isolve<iterations;++isolve)
-	{
-		for(int iseq=0;iseq<m_cfg.m_psequence.size();++iseq)
-		{
-			getSolver(m_cfg.m_psequence[iseq])(this,1,0);
+for(int isolve=0;isolve<iterations;++isolve)
+	{
+	for(int iseq=0;iseq<m_cfg.m_psequence.size();++iseq)
+		{
+		getSolver(m_cfg.m_psequence[iseq])(this,1,0);
 		}
 	}
@@ -1460,5 +1458,5 @@
 void			btSoftBody::solveCommonConstraints(btSoftBody** /*bodies*/,int /*count*/,int /*iterations*/)
 {
-	/// placeholder
+/// placeholder
 }
 
@@ -1466,27 +1464,27 @@
 void			btSoftBody::solveClusters(const btAlignedObjectArray<btSoftBody*>& bodies)
 {
-	const int	nb=bodies.size();
-	int			iterations=0;
-	int i;
-
-	for(i=0;i<nb;++i)
-	{
-		iterations=btMax(iterations,bodies[i]->m_cfg.citerations);
-	}
-	for(i=0;i<nb;++i)
-	{
-		bodies[i]->prepareClusters(iterations);
-	}
-	for(i=0;i<iterations;++i)
-	{
-		const btScalar sor=1;
-		for(int j=0;j<nb;++j)
-		{
-			bodies[j]->solveClusters(sor);
-		}
-	}
-	for(i=0;i<nb;++i)
-	{
-		bodies[i]->cleanupClusters();
+const int	nb=bodies.size();
+int			iterations=0;
+int i;
+
+for(i=0;i<nb;++i)
+	{
+	iterations=btMax(iterations,bodies[i]->m_cfg.citerations);
+	}
+for(i=0;i<nb;++i)
+	{
+	bodies[i]->prepareClusters(iterations);
+	}
+for(i=0;i<iterations;++i)
+	{
+	const btScalar sor=1;
+	for(int j=0;j<nb;++j)
+		{
+		bodies[j]->solveClusters(sor);
+		}
+	}
+for(i=0;i<nb;++i)
+	{
+	bodies[i]->cleanupClusters();
 	}
 }
@@ -1500,52 +1498,46 @@
 
 //
-btSoftBody::RayFromToCaster::RayFromToCaster(const btVector3& rayFrom,const btVector3& rayTo,btScalar mxt)
-{
-	m_rayFrom = rayFrom;
-	m_rayNormalizedDirection = (rayTo-rayFrom);
-	m_rayTo = rayTo;
-	m_mint	=	mxt;
-	m_face	=	0;
-	m_tests	=	0;
-}
-
-//
-void				btSoftBody::RayFromToCaster::Process(const btDbvtNode* leaf)
-{
-	btSoftBody::Face&	f=*(btSoftBody::Face*)leaf->data;
-	const btScalar		t=rayFromToTriangle(	m_rayFrom,m_rayTo,m_rayNormalizedDirection,
-		f.m_n[0]->m_x,
-		f.m_n[1]->m_x,
-		f.m_n[2]->m_x,
-		m_mint);
-	if((t>0)&&(t<m_mint)) 
-	{ 
-		m_mint=t;m_face=&f; 
-	}
-	++m_tests;
-}
-
-//
-btScalar			btSoftBody::RayFromToCaster::rayFromToTriangle(	const btVector3& rayFrom,
-																   const btVector3& rayTo,
-																   const btVector3& rayNormalizedDirection,
-																   const btVector3& a,
-																   const btVector3& b,
-																   const btVector3& c,
-																   btScalar maxt)
+					btSoftBody::RayCaster::RayCaster(const btVector3& org,const btVector3& dir,btScalar mxt)
+{
+o		=	org;
+d		=	dir;
+mint	=	mxt;
+face	=	0;
+tests	=	0;
+}
+
+//
+void				btSoftBody::RayCaster::Process(const btDbvtNode* leaf)
+{
+btSoftBody::Face&	f=*(btSoftBody::Face*)leaf->data;
+const btScalar		t=rayTriangle(	o,d,
+									f.m_n[0]->m_x,
+									f.m_n[1]->m_x,
+									f.m_n[2]->m_x,
+									mint);
+if((t>0)&&(t<mint)) { mint=t;face=&f; }
+++tests;
+}
+
+//
+btScalar			btSoftBody::RayCaster::rayTriangle(	const btVector3& org,
+														const btVector3& dir,
+														const btVector3& a,
+														const btVector3& b,
+														const btVector3& c,
+														btScalar maxt)
 {
 	static const btScalar	ceps=-SIMD_EPSILON*10;
 	static const btScalar	teps=SIMD_EPSILON*10;
-
 	const btVector3			n=cross(b-a,c-a);
 	const btScalar			d=dot(a,n);
-	const btScalar			den=dot(rayNormalizedDirection,n);
+	const btScalar			den=dot(dir,n);
 	if(!btFuzzyZero(den))
 	{
-		const btScalar		num=dot(rayFrom,n)-d;
+		const btScalar		num=dot(org,n)-d;
 		const btScalar		t=-num/den;
 		if((t>teps)&&(t<maxt))
 		{
-			const btVector3	hit=rayFrom+rayNormalizedDirection*t;
+			const btVector3	hit=org+dir*t;
 			if(	(dot(n,cross(a-hit,b-hit))>ceps)	&&			
 				(dot(n,cross(b-hit,c-hit))>ceps)	&&
@@ -1569,7 +1561,7 @@
 	{
 		if(m_nodes[i].m_leaf)
-		{
+			{
 			m_nodes[i].m_leaf->data=*(void**)&i;
-		}
+			}
 	}
 	for(i=0,ni=m_links.size();i<ni;++i)
@@ -1584,19 +1576,19 @@
 		m_faces[i].m_n[2]=PTR2IDX(m_faces[i].m_n[2],base);
 		if(m_faces[i].m_leaf)
-		{
+			{
 			m_faces[i].m_leaf->data=*(void**)&i;
-		}
+			}
 	}
 	for(i=0,ni=m_anchors.size();i<ni;++i)
-	{
+		{
 		m_anchors[i].m_node=PTR2IDX(m_anchors[i].m_node,base);
-	}
+		}
 	for(i=0,ni=m_notes.size();i<ni;++i)
-	{
+		{
 		for(int j=0;j<m_notes[i].m_rank;++j)
-		{
+			{
 			m_notes[i].m_nodes[j]=PTR2IDX(m_notes[i].m_nodes[j],base);
-		}
-	}
+			}
+		}
 #undef	PTR2IDX
 }
@@ -1606,5 +1598,5 @@
 {
 #define	IDX2PTR(_p_,_b_)	map?(&(_b_)[map[(((char*)_p_)-(char*)0)]]):	\
-	(&(_b_)[(((char*)_p_)-(char*)0)])
+								(&(_b_)[(((char*)_p_)-(char*)0)])
 	btSoftBody::Node*	base=&m_nodes[0];
 	int i,ni;
@@ -1613,7 +1605,7 @@
 	{
 		if(m_nodes[i].m_leaf)
-		{
+			{
 			m_nodes[i].m_leaf->data=&m_nodes[i];
-		}
+			}
 	}
 	for(i=0,ni=m_links.size();i<ni;++i)
@@ -1628,66 +1620,61 @@
 		m_faces[i].m_n[2]=IDX2PTR(m_faces[i].m_n[2],base);
 		if(m_faces[i].m_leaf)
-		{
+			{
 			m_faces[i].m_leaf->data=&m_faces[i];
-		}
+			}
 	}
 	for(i=0,ni=m_anchors.size();i<ni;++i)
-	{
+		{
 		m_anchors[i].m_node=IDX2PTR(m_anchors[i].m_node,base);
-	}
+		}
 	for(i=0,ni=m_notes.size();i<ni;++i)
-	{
+		{
 		for(int j=0;j<m_notes[i].m_rank;++j)
-		{
+			{
 			m_notes[i].m_nodes[j]=IDX2PTR(m_notes[i].m_nodes[j],base);
-		}
-	}
+			}
+		}
 #undef	IDX2PTR
 }
 
 //
-int					btSoftBody::rayTest(const btVector3& rayFrom,const btVector3& rayTo,
+int					btSoftBody::rayCast(const btVector3& org,const btVector3& dir,
 										btScalar& mint,eFeature::_& feature,int& index,bool bcountonly) const
 {
 	int	cnt=0;
 	if(bcountonly||m_fdbvt.empty())
-	{/* Full search	*/ 
-		btVector3 dir = rayTo-rayFrom;
-		dir.normalize();
-
+		{/* Full search	*/ 
 		for(int i=0,ni=m_faces.size();i<ni;++i)
-		{
+			{
 			const btSoftBody::Face&	f=m_faces[i];
-
-			const btScalar			t=RayFromToCaster::rayFromToTriangle(	rayFrom,rayTo,dir,
-				f.m_n[0]->m_x,
-				f.m_n[1]->m_x,
-				f.m_n[2]->m_x,
-				mint);
+			const btScalar			t=RayCaster::rayTriangle(	org,dir,
+																f.m_n[0]->m_x,
+																f.m_n[1]->m_x,
+																f.m_n[2]->m_x,
+																mint);
 			if(t>0)
-			{
+				{
 				++cnt;
 				if(!bcountonly)
-				{
+					{
 					feature=btSoftBody::eFeature::Face;
 					index=i;
 					mint=t;
+					}
 				}
 			}
 		}
-	}
-	else
-	{/* Use dbvt	*/ 
-		RayFromToCaster	collider(rayFrom,rayTo,mint);
-
-		btDbvt::rayTest(m_fdbvt.m_root,rayFrom,rayTo,collider);
-		if(collider.m_face)
-		{
-			mint=collider.m_mint;
+		else
+		{/* Use dbvt	*/ 
+		RayCaster	collider(org,dir,mint);
+		btDbvt::collideRAY(m_fdbvt.m_root,org,dir,collider);
+		if(collider.face)
+			{
+			mint=collider.mint;
 			feature=btSoftBody::eFeature::Face;
-			index=(int)(collider.m_face-&m_faces[0]);
+			index=(int)(collider.face-&m_faces[0]);
 			cnt=1;
-		}
-	}
+			}
+		}
 	return(cnt);
 }
@@ -1696,9 +1683,9 @@
 void			btSoftBody::initializeFaceTree()
 {
-	m_fdbvt.clear();
-	for(int i=0;i<m_faces.size();++i)
-	{
-		Face&	f=m_faces[i];
-		f.m_leaf=m_fdbvt.insert(VolumeOf(f,0),&f);
+m_fdbvt.clear();
+for(int i=0;i<m_faces.size();++i)
+	{
+	Face&	f=m_faces[i];
+	f.m_leaf=m_fdbvt.insert(VolumeOf(f,0),&f);
 	}
 }
@@ -1707,20 +1694,20 @@
 btVector3		btSoftBody::evaluateCom() const
 {
-	btVector3	com(0,0,0);
-	if(m_pose.m_bframe)
-	{
-		for(int i=0,ni=m_nodes.size();i<ni;++i)
-		{
-			com+=m_nodes[i].m_x*m_pose.m_wgh[i];
+btVector3	com(0,0,0);
+if(m_pose.m_bframe)
+	{
+	for(int i=0,ni=m_nodes.size();i<ni;++i)
+		{
+		com+=m_nodes[i].m_x*m_pose.m_wgh[i];
 		}
 	}
 	return(com);
 }
-
+	
 //
 bool				btSoftBody::checkContact(	btRigidBody* prb,
-											 const btVector3& x,
-											 btScalar margin,
-											 btSoftBody::sCti& cti) const
+												const btVector3& x,
+												btScalar margin,
+												btSoftBody::sCti& cti) const
 {
 	btVector3			nrm;
@@ -1728,7 +1715,7 @@
 	const btTransform&	wtr=prb->getInterpolationWorldTransform();
 	btScalar			dst=m_worldInfo->m_sparsesdf.Evaluate(	wtr.invXform(x),
-		shp,
-		nrm,
-		margin);
+																shp,
+																nrm,
+																margin);
 	if(dst<0)
 	{
@@ -1736,5 +1723,5 @@
 		cti.m_normal	=	wtr.getBasis()*nrm;
 		cti.m_offset	=	-dot(	cti.m_normal,
-			x-cti.m_normal*dst);
+									x-cti.m_normal*dst);
 		return(true);
 	}
@@ -1756,5 +1743,5 @@
 		btSoftBody::Face&	f=m_faces[i];
 		const btVector3		n=cross(f.m_n[1]->m_x-f.m_n[0]->m_x,
-			f.m_n[2]->m_x-f.m_n[0]->m_x);
+									f.m_n[2]->m_x-f.m_n[0]->m_x);
 		f.m_normal=n.normalized();
 		f.m_n[0]->m_n+=n;
@@ -1774,26 +1761,26 @@
 {
 	if(m_ndbvt.m_root)
-	{
+		{
 		const btVector3&	mins=m_ndbvt.m_root->volume.Mins();
 		const btVector3&	maxs=m_ndbvt.m_root->volume.Maxs();
 		const btScalar		csm=getCollisionShape()->getMargin();
 		const btVector3		mrg=btVector3(	csm,
-			csm,
-			csm)*1; // ??? to investigate...
+											csm,
+											csm)*1; // ??? to investigate...
 		m_bounds[0]=mins-mrg;
 		m_bounds[1]=maxs+mrg;
-		if(0!=getBroadphaseHandle())
-		{					
-			m_worldInfo->m_broadphase->setAabb(	getBroadphaseHandle(),
-				m_bounds[0],
-				m_bounds[1],
-				m_worldInfo->m_dispatcher);
-		}
-	}
-	else
-	{
+			if(0!=getBroadphaseHandle())
+			{					
+				m_worldInfo->m_broadphase->setAabb(	getBroadphaseHandle(),
+													m_bounds[0],
+													m_bounds[1],
+													m_worldInfo->m_dispatcher);
+			}
+		}
+		else
+		{
 		m_bounds[0]=
-			m_bounds[1]=btVector3(0,0,0);
-	}		
+		m_bounds[1]=btVector3(0,0,0);
+		}		
 }
 
@@ -1826,10 +1813,10 @@
 		pose.m_scl=pose.m_aqq*r.transpose()*Apq;
 		if(m_cfg.maxvolume>1)
-		{
+			{
 			const btScalar	idet=Clamp<btScalar>(	1/pose.m_scl.determinant(),
-				1,m_cfg.maxvolume);
+													1,m_cfg.maxvolume);
 			pose.m_scl=Mul(pose.m_scl,idet);
-		}
-
+			}
+		
 	}
 }
@@ -1886,102 +1873,102 @@
 	int i;
 
-	for( i=0;i<m_clusters.size();++i)
-	{
-		Cluster&	c=*m_clusters[i];
-		c.m_imass=0;
-		c.m_masses.resize(c.m_nodes.size());
-		for(int j=0;j<c.m_nodes.size();++j)
-		{
-			c.m_masses[j]	=	c.m_nodes[j]->m_im>0?1/c.m_nodes[j]->m_im:0;
-			c.m_imass		+=	c.m_masses[j];
-		}
-		c.m_imass		=	1/c.m_imass;
-		c.m_com			=	btSoftBody::clusterCom(&c);
-		c.m_lv			=	btVector3(0,0,0);
-		c.m_av			=	btVector3(0,0,0);
-		c.m_leaf		=	0;
-		/* Inertia	*/ 
-		btMatrix3x3&	ii=c.m_locii;
-		ii[0]=ii[1]=ii[2]=btVector3(0,0,0);
-		{
-			int i,ni;
-
-			for(i=0,ni=c.m_nodes.size();i<ni;++i)
-			{
-				const btVector3	k=c.m_nodes[i]->m_x-c.m_com;
-				const btVector3	q=k*k;
-				const btScalar	m=c.m_masses[i];
-				ii[0][0]	+=	m*(q[1]+q[2]);
-				ii[1][1]	+=	m*(q[0]+q[2]);
-				ii[2][2]	+=	m*(q[0]+q[1]);
-				ii[0][1]	-=	m*k[0]*k[1];
-				ii[0][2]	-=	m*k[0]*k[2];
-				ii[1][2]	-=	m*k[1]*k[2];
-			}
-		}
-		ii[1][0]=ii[0][1];
-		ii[2][0]=ii[0][2];
-		ii[2][1]=ii[1][2];
-		ii=ii.inverse();
-		/* Frame	*/ 
-		c.m_framexform.setIdentity();
+for( i=0;i<m_clusters.size();++i)
+	{
+	Cluster&	c=*m_clusters[i];
+	c.m_imass=0;
+	c.m_masses.resize(c.m_nodes.size());
+	for(int j=0;j<c.m_nodes.size();++j)
+		{
+		c.m_masses[j]	=	c.m_nodes[j]->m_im>0?1/c.m_nodes[j]->m_im:0;
+		c.m_imass		+=	c.m_masses[j];
+		}
+	c.m_imass		=	1/c.m_imass;
+	c.m_com			=	btSoftBody::clusterCom(&c);
+	c.m_lv			=	btVector3(0,0,0);
+	c.m_av			=	btVector3(0,0,0);
+	c.m_leaf		=	0;
+	/* Inertia	*/ 
+	btMatrix3x3&	ii=c.m_locii;
+	ii[0]=ii[1]=ii[2]=btVector3(0,0,0);
+	{
+		int i,ni;
+
+		for(i=0,ni=c.m_nodes.size();i<ni;++i)
+		{
+			const btVector3	k=c.m_nodes[i]->m_x-c.m_com;
+			const btVector3	q=k*k;
+			const btScalar	m=c.m_masses[i];
+			ii[0][0]	+=	m*(q[1]+q[2]);
+			ii[1][1]	+=	m*(q[0]+q[2]);
+			ii[2][2]	+=	m*(q[0]+q[1]);
+			ii[0][1]	-=	m*k[0]*k[1];
+			ii[0][2]	-=	m*k[0]*k[2];
+			ii[1][2]	-=	m*k[1]*k[2];
+		}
+	}
+	ii[1][0]=ii[0][1];
+	ii[2][0]=ii[0][2];
+	ii[2][1]=ii[1][2];
+	ii=ii.inverse();
+	/* Frame	*/ 
+	c.m_framexform.setIdentity();
+	c.m_framexform.setOrigin(c.m_com);
+	c.m_framerefs.resize(c.m_nodes.size());
+	{
+		int i;
+		for(i=0;i<c.m_framerefs.size();++i)
+			{
+			c.m_framerefs[i]=c.m_nodes[i]->m_x-c.m_com;
+			}
+		}
+	}
+}
+
+//
+void					btSoftBody::updateClusters()
+{
+BT_PROFILE("UpdateClusters");
+int i;
+
+for(i=0;i<m_clusters.size();++i)
+	{
+	btSoftBody::Cluster&	c=*m_clusters[i];
+	const int				n=c.m_nodes.size();
+	const btScalar			invn=1/(btScalar)n;
+	if(n)
+		{
+		/* Frame				*/ 
+		const btScalar	eps=btScalar(0.0001);
+		btMatrix3x3		m,r,s;
+		m[0]=m[1]=m[2]=btVector3(0,0,0);
+		m[0][0]=eps*1;
+		m[1][1]=eps*2;
+		m[2][2]=eps*3;
+		c.m_com=clusterCom(&c);
+		for(int i=0;i<c.m_nodes.size();++i)
+			{
+			const btVector3		a=c.m_nodes[i]->m_x-c.m_com;
+			const btVector3&	b=c.m_framerefs[i];
+			m[0]+=a[0]*b;m[1]+=a[1]*b;m[2]+=a[2]*b;
+			}
+		PolarDecompose(m,r,s);
 		c.m_framexform.setOrigin(c.m_com);
-		c.m_framerefs.resize(c.m_nodes.size());
-		{
-			int i;
-			for(i=0;i<c.m_framerefs.size();++i)
-			{
-				c.m_framerefs[i]=c.m_nodes[i]->m_x-c.m_com;
-			}
-		}
-	}
-}
-
-//
-void					btSoftBody::updateClusters()
-{
-	BT_PROFILE("UpdateClusters");
-	int i;
-
-	for(i=0;i<m_clusters.size();++i)
-	{
-		btSoftBody::Cluster&	c=*m_clusters[i];
-		const int				n=c.m_nodes.size();
-		const btScalar			invn=1/(btScalar)n;
-		if(n)
-		{
-			/* Frame				*/ 
-			const btScalar	eps=btScalar(0.0001);
-			btMatrix3x3		m,r,s;
-			m[0]=m[1]=m[2]=btVector3(0,0,0);
-			m[0][0]=eps*1;
-			m[1][1]=eps*2;
-			m[2][2]=eps*3;
-			c.m_com=clusterCom(&c);
-			for(int i=0;i<c.m_nodes.size();++i)
-			{
-				const btVector3		a=c.m_nodes[i]->m_x-c.m_com;
-				const btVector3&	b=c.m_framerefs[i];
-				m[0]+=a[0]*b;m[1]+=a[1]*b;m[2]+=a[2]*b;
-			}
-			PolarDecompose(m,r,s);
-			c.m_framexform.setOrigin(c.m_com);
-			c.m_framexform.setBasis(r);		
-			/* Inertia			*/ 
-#if 1/* Constant	*/ 
-			c.m_invwi=c.m_framexform.getBasis()*c.m_locii*c.m_framexform.getBasis().transpose();
-#else
-#if 0/* Sphere	*/ 
+		c.m_framexform.setBasis(r);		
+		/* Inertia			*/ 
+		#if 1/* Constant	*/ 
+		c.m_invwi=c.m_framexform.getBasis()*c.m_locii*c.m_framexform.getBasis().transpose();
+		#else
+			#if 0/* Sphere	*/ 
 			const btScalar	rk=(2*c.m_extents.length2())/(5*c.m_imass);
 			const btVector3	inertia(rk,rk,rk);
 			const btVector3	iin(btFabs(inertia[0])>SIMD_EPSILON?1/inertia[0]:0,
-				btFabs(inertia[1])>SIMD_EPSILON?1/inertia[1]:0,
-				btFabs(inertia[2])>SIMD_EPSILON?1/inertia[2]:0);
-
+								btFabs(inertia[1])>SIMD_EPSILON?1/inertia[1]:0,
+								btFabs(inertia[2])>SIMD_EPSILON?1/inertia[2]:0);
+			
 			c.m_invwi=c.m_xform.getBasis().scaled(iin)*c.m_xform.getBasis().transpose();
-#else/* Actual	*/ 		
+			#else/* Actual	*/ 		
 			c.m_invwi[0]=c.m_invwi[1]=c.m_invwi[2]=btVector3(0,0,0);
 			for(int i=0;i<n;++i)
-			{
+				{
 				const btVector3	k=c.m_nodes[i]->m_x-c.m_com;
 				const btVector3		q=k*k;
@@ -1993,161 +1980,161 @@
 				c.m_invwi[0][2]	-=	m*k[0]*k[2];
 				c.m_invwi[1][2]	-=	m*k[1]*k[2];
-			}
+				}
 			c.m_invwi[1][0]=c.m_invwi[0][1];
 			c.m_invwi[2][0]=c.m_invwi[0][2];
 			c.m_invwi[2][1]=c.m_invwi[1][2];
 			c.m_invwi=c.m_invwi.inverse();
-#endif
-#endif
-			/* Velocities			*/ 
-			c.m_lv=btVector3(0,0,0);
-			c.m_av=btVector3(0,0,0);
-			{
-				int i;
-
-				for(i=0;i<n;++i)
+			#endif
+		#endif
+		/* Velocities			*/ 
+		c.m_lv=btVector3(0,0,0);
+		c.m_av=btVector3(0,0,0);
+		{
+			int i;
+
+			for(i=0;i<n;++i)
+			{
+				const btVector3	v=c.m_nodes[i]->m_v*c.m_masses[i];
+				c.m_lv	+=	v;
+				c.m_av	+=	cross(c.m_nodes[i]->m_x-c.m_com,v);
+			}
+		}
+		c.m_lv=c.m_imass*c.m_lv*(1-c.m_ldamping);
+		c.m_av=c.m_invwi*c.m_av*(1-c.m_adamping);
+		c.m_vimpulses[0]	=
+		c.m_vimpulses[1]	= btVector3(0,0,0);
+		c.m_dimpulses[0]	=
+		c.m_dimpulses[1]	= btVector3(0,0,0);
+		c.m_nvimpulses		= 0;
+		c.m_ndimpulses		= 0;
+		/* Matching				*/ 
+		if(c.m_matching>0)
+			{
+			for(int j=0;j<c.m_nodes.size();++j)
 				{
-					const btVector3	v=c.m_nodes[i]->m_v*c.m_masses[i];
-					c.m_lv	+=	v;
-					c.m_av	+=	cross(c.m_nodes[i]->m_x-c.m_com,v);
+				Node&			n=*c.m_nodes[j];
+				const btVector3	x=c.m_framexform*c.m_framerefs[j];
+				n.m_x=Lerp(n.m_x,x,c.m_matching);
 				}
 			}
-			c.m_lv=c.m_imass*c.m_lv*(1-c.m_ldamping);
-			c.m_av=c.m_invwi*c.m_av*(1-c.m_adamping);
-			c.m_vimpulses[0]	=
-				c.m_vimpulses[1]	= btVector3(0,0,0);
-			c.m_dimpulses[0]	=
-				c.m_dimpulses[1]	= btVector3(0,0,0);
-			c.m_nvimpulses		= 0;
-			c.m_ndimpulses		= 0;
-			/* Matching				*/ 
-			if(c.m_matching>0)
-			{
-				for(int j=0;j<c.m_nodes.size();++j)
+		/* Dbvt					*/ 
+		if(c.m_collide)
+			{
+			btVector3	mi=c.m_nodes[0]->m_x;
+			btVector3	mx=mi;
+			for(int j=1;j<n;++j)
 				{
-					Node&			n=*c.m_nodes[j];
-					const btVector3	x=c.m_framexform*c.m_framerefs[j];
-					n.m_x=Lerp(n.m_x,x,c.m_matching);
+				mi.setMin(c.m_nodes[j]->m_x);
+				mx.setMax(c.m_nodes[j]->m_x);
+				}			
+			const ATTRIBUTE_ALIGNED16(btDbvtVolume)	bounds=btDbvtVolume::FromMM(mi,mx);
+			if(c.m_leaf)
+				m_cdbvt.update(c.m_leaf,bounds,c.m_lv*m_sst.sdt*3,m_sst.radmrg);
+				else
+				c.m_leaf=m_cdbvt.insert(bounds,&c);
+			}
+		}
+	}
+}
+
+//
+void					btSoftBody::cleanupClusters()
+{
+for(int i=0;i<m_joints.size();++i)
+	{
+	m_joints[i]->Terminate(m_sst.sdt);
+	if(m_joints[i]->m_delete)
+		{
+		btAlignedFree(m_joints[i]);
+		m_joints.remove(m_joints[i--]);
+		}	
+	}
+}
+
+//
+void					btSoftBody::prepareClusters(int iterations)
+{
+for(int i=0;i<m_joints.size();++i)
+	{
+	m_joints[i]->Prepare(m_sst.sdt,iterations);
+	}
+}
+
+
+//
+void					btSoftBody::solveClusters(btScalar sor)
+{
+for(int i=0,ni=m_joints.size();i<ni;++i)
+	{
+	m_joints[i]->Solve(m_sst.sdt,sor);
+	}
+}
+
+//
+void					btSoftBody::applyClusters(bool drift)
+{
+BT_PROFILE("ApplyClusters");
+const btScalar					f0=m_sst.sdt;
+const btScalar					f1=f0/2;
+btAlignedObjectArray<btVector3>	deltas;
+btAlignedObjectArray<btScalar>	weights;
+deltas.resize(m_nodes.size(),btVector3(0,0,0));
+weights.resize(m_nodes.size(),0);
+int i;
+
+if(drift)
+	{
+	for(i=0;i<m_clusters.size();++i)
+		{
+		Cluster&	c=*m_clusters[i];
+		if(c.m_ndimpulses)
+			{
+			c.m_dimpulses[0]/=(btScalar)c.m_ndimpulses;
+			c.m_dimpulses[1]/=(btScalar)c.m_ndimpulses;
+			}
+		}
+	}
+for(i=0;i<m_clusters.size();++i)
+	{
+	Cluster&	c=*m_clusters[i];	
+	if(0<(drift?c.m_ndimpulses:c.m_nvimpulses))
+		{
+		const btVector3		v=(drift?c.m_dimpulses[0]:c.m_vimpulses[0])*m_sst.sdt;
+		const btVector3		w=(drift?c.m_dimpulses[1]:c.m_vimpulses[1])*m_sst.sdt;
+		for(int j=0;j<c.m_nodes.size();++j)
+			{
+			const int			idx=int(c.m_nodes[j]-&m_nodes[0]);
+			const btVector3&	x=c.m_nodes[j]->m_x;
+			const btScalar		q=c.m_masses[j];
+			deltas[idx]		+=	(v+cross(w,x-c.m_com))*q;
+			weights[idx]	+=	q;
+			}
+		}
+	}
+	for(i=0;i<deltas.size();++i)
+	{
+		if(weights[i]>0) m_nodes[i].m_x+=deltas[i]/weights[i];
+	}
+}
+
+//
+void					btSoftBody::dampClusters()
+{
+	int i;
+
+for(i=0;i<m_clusters.size();++i)
+	{
+	Cluster&	c=*m_clusters[i];	
+	if(c.m_ndamping>0)
+		{
+		for(int j=0;j<c.m_nodes.size();++j)
+			{
+			Node&			n=*c.m_nodes[j];
+			if(n.m_im>0)
+				{
+				const btVector3	vx=c.m_lv+cross(c.m_av,c.m_nodes[j]->m_q-c.m_com);
+				n.m_v	+=	c.m_ndamping*(vx-n.m_v);
 				}
 			}
-			/* Dbvt					*/ 
-			if(c.m_collide)
-			{
-				btVector3	mi=c.m_nodes[0]->m_x;
-				btVector3	mx=mi;
-				for(int j=1;j<n;++j)
-				{
-					mi.setMin(c.m_nodes[j]->m_x);
-					mx.setMax(c.m_nodes[j]->m_x);
-				}			
-				const ATTRIBUTE_ALIGNED16(btDbvtVolume)	bounds=btDbvtVolume::FromMM(mi,mx);
-				if(c.m_leaf)
-					m_cdbvt.update(c.m_leaf,bounds,c.m_lv*m_sst.sdt*3,m_sst.radmrg);
-				else
-					c.m_leaf=m_cdbvt.insert(bounds,&c);
-			}
-		}
-	}
-}
-
-//
-void					btSoftBody::cleanupClusters()
-{
-	for(int i=0;i<m_joints.size();++i)
-	{
-		m_joints[i]->Terminate(m_sst.sdt);
-		if(m_joints[i]->m_delete)
-		{
-			btAlignedFree(m_joints[i]);
-			m_joints.remove(m_joints[i--]);
-		}	
-	}
-}
-
-//
-void					btSoftBody::prepareClusters(int iterations)
-{
-	for(int i=0;i<m_joints.size();++i)
-	{
-		m_joints[i]->Prepare(m_sst.sdt,iterations);
-	}
-}
-
-
-//
-void					btSoftBody::solveClusters(btScalar sor)
-{
-	for(int i=0,ni=m_joints.size();i<ni;++i)
-	{
-		m_joints[i]->Solve(m_sst.sdt,sor);
-	}
-}
-
-//
-void					btSoftBody::applyClusters(bool drift)
-{
-	BT_PROFILE("ApplyClusters");
-	const btScalar					f0=m_sst.sdt;
-	const btScalar					f1=f0/2;
-	btAlignedObjectArray<btVector3>	deltas;
-	btAlignedObjectArray<btScalar>	weights;
-	deltas.resize(m_nodes.size(),btVector3(0,0,0));
-	weights.resize(m_nodes.size(),0);
-	int i;
-
-	if(drift)
-	{
-		for(i=0;i<m_clusters.size();++i)
-		{
-			Cluster&	c=*m_clusters[i];
-			if(c.m_ndimpulses)
-			{
-				c.m_dimpulses[0]/=(btScalar)c.m_ndimpulses;
-				c.m_dimpulses[1]/=(btScalar)c.m_ndimpulses;
-			}
-		}
-	}
-	for(i=0;i<m_clusters.size();++i)
-	{
-		Cluster&	c=*m_clusters[i];	
-		if(0<(drift?c.m_ndimpulses:c.m_nvimpulses))
-		{
-			const btVector3		v=(drift?c.m_dimpulses[0]:c.m_vimpulses[0])*m_sst.sdt;
-			const btVector3		w=(drift?c.m_dimpulses[1]:c.m_vimpulses[1])*m_sst.sdt;
-			for(int j=0;j<c.m_nodes.size();++j)
-			{
-				const int			idx=int(c.m_nodes[j]-&m_nodes[0]);
-				const btVector3&	x=c.m_nodes[j]->m_x;
-				const btScalar		q=c.m_masses[j];
-				deltas[idx]		+=	(v+cross(w,x-c.m_com))*q;
-				weights[idx]	+=	q;
-			}
-		}
-	}
-	for(i=0;i<deltas.size();++i)
-	{
-		if(weights[i]>0) m_nodes[i].m_x+=deltas[i]/weights[i];
-	}
-}
-
-//
-void					btSoftBody::dampClusters()
-{
-	int i;
-
-	for(i=0;i<m_clusters.size();++i)
-	{
-		Cluster&	c=*m_clusters[i];	
-		if(c.m_ndamping>0)
-		{
-			for(int j=0;j<c.m_nodes.size();++j)
-			{
-				Node&			n=*c.m_nodes[j];
-				if(n.m_im>0)
-				{
-					const btVector3	vx=c.m_lv+cross(c.m_av,c.m_nodes[j]->m_q-c.m_com);
-					n.m_v	+=	c.m_ndamping*(vx-n.m_v);
-				}
-			}
 		}
 	}
@@ -2157,6 +2144,6 @@
 void				btSoftBody::Joint::Prepare(btScalar dt,int)
 {
-	m_bodies[0].activate();
-	m_bodies[1].activate();
+m_bodies[0].activate();
+m_bodies[1].activate();
 }
 
@@ -2164,108 +2151,108 @@
 void				btSoftBody::LJoint::Prepare(btScalar dt,int iterations)
 {
-	static const btScalar	maxdrift=4;
-	Joint::Prepare(dt,iterations);
-	m_rpos[0]		=	m_bodies[0].xform()*m_refs[0];
-	m_rpos[1]		=	m_bodies[1].xform()*m_refs[1];
-	m_drift			=	Clamp(m_rpos[0]-m_rpos[1],maxdrift)*m_erp/dt;
-	m_rpos[0]		-=	m_bodies[0].xform().getOrigin();
-	m_rpos[1]		-=	m_bodies[1].xform().getOrigin();
-	m_massmatrix	=	ImpulseMatrix(	m_bodies[0].invMass(),m_bodies[0].invWorldInertia(),m_rpos[0],
-		m_bodies[1].invMass(),m_bodies[1].invWorldInertia(),m_rpos[1]);
+static const btScalar	maxdrift=4;
+Joint::Prepare(dt,iterations);
+m_rpos[0]		=	m_bodies[0].xform()*m_refs[0];
+m_rpos[1]		=	m_bodies[1].xform()*m_refs[1];
+m_drift			=	Clamp(m_rpos[0]-m_rpos[1],maxdrift)*m_erp/dt;
+m_rpos[0]		-=	m_bodies[0].xform().getOrigin();
+m_rpos[1]		-=	m_bodies[1].xform().getOrigin();
+m_massmatrix	=	ImpulseMatrix(	m_bodies[0].invMass(),m_bodies[0].invWorldInertia(),m_rpos[0],
+									m_bodies[1].invMass(),m_bodies[1].invWorldInertia(),m_rpos[1]);
+if(m_split>0)
+	{
+	m_sdrift	=	m_massmatrix*(m_drift*m_split);
+	m_drift		*=	1-m_split;
+	}
+m_drift	/=(btScalar)iterations;
+}
+
+//
+void				btSoftBody::LJoint::Solve(btScalar dt,btScalar sor)
+{
+const btVector3		va=m_bodies[0].velocity(m_rpos[0]);
+const btVector3		vb=m_bodies[1].velocity(m_rpos[1]);
+const btVector3		vr=va-vb;
+btSoftBody::Impulse	impulse;
+impulse.m_asVelocity	=	1;
+impulse.m_velocity		=	m_massmatrix*(m_drift+vr*m_cfm)*sor;
+m_bodies[0].applyImpulse(-impulse,m_rpos[0]);
+m_bodies[1].applyImpulse( impulse,m_rpos[1]);
+}
+
+//
+void				btSoftBody::LJoint::Terminate(btScalar dt)
+{
+if(m_split>0)
+	{
+	m_bodies[0].applyDImpulse(-m_sdrift,m_rpos[0]);
+	m_bodies[1].applyDImpulse( m_sdrift,m_rpos[1]);
+	}
+}
+
+//
+void				btSoftBody::AJoint::Prepare(btScalar dt,int iterations)
+{
+static const btScalar	maxdrift=SIMD_PI/16;
+m_icontrol->Prepare(this);
+Joint::Prepare(dt,iterations);
+m_axis[0]	=	m_bodies[0].xform().getBasis()*m_refs[0];
+m_axis[1]	=	m_bodies[1].xform().getBasis()*m_refs[1];
+m_drift		=	NormalizeAny(cross(m_axis[1],m_axis[0]));
+m_drift		*=	btMin(maxdrift,btAcos(Clamp<btScalar>(dot(m_axis[0],m_axis[1]),-1,+1)));
+m_drift		*=	m_erp/dt;
+m_massmatrix=	AngularImpulseMatrix(m_bodies[0].invWorldInertia(),m_bodies[1].invWorldInertia());
+if(m_split>0)
+	{
+	m_sdrift	=	m_massmatrix*(m_drift*m_split);
+	m_drift		*=	1-m_split;
+	}
+m_drift	/=(btScalar)iterations;
+}
+
+//
+void				btSoftBody::AJoint::Solve(btScalar dt,btScalar sor)
+{
+const btVector3		va=m_bodies[0].angularVelocity();
+const btVector3		vb=m_bodies[1].angularVelocity();
+const btVector3		vr=va-vb;
+const btScalar		sp=dot(vr,m_axis[0]);
+const btVector3		vc=vr-m_axis[0]*m_icontrol->Speed(this,sp);
+btSoftBody::Impulse	impulse;
+impulse.m_asVelocity	=	1;
+impulse.m_velocity		=	m_massmatrix*(m_drift+vc*m_cfm)*sor;
+m_bodies[0].applyAImpulse(-impulse);
+m_bodies[1].applyAImpulse( impulse);
+}
+
+//
+void				btSoftBody::AJoint::Terminate(btScalar dt)
+{
+if(m_split>0)
+	{
+	m_bodies[0].applyDAImpulse(-m_sdrift);
+	m_bodies[1].applyDAImpulse( m_sdrift);
+	}
+}
+
+//
+void				btSoftBody::CJoint::Prepare(btScalar dt,int iterations)
+{
+Joint::Prepare(dt,iterations);
+const bool	dodrift=(m_life==0);
+m_delete=(++m_life)>m_maxlife;
+if(dodrift)
+	{
+	m_drift=m_drift*m_erp/dt;
 	if(m_split>0)
-	{
+		{
 		m_sdrift	=	m_massmatrix*(m_drift*m_split);
 		m_drift		*=	1-m_split;
-	}
-	m_drift	/=(btScalar)iterations;
-}
-
-//
-void				btSoftBody::LJoint::Solve(btScalar dt,btScalar sor)
-{
-	const btVector3		va=m_bodies[0].velocity(m_rpos[0]);
-	const btVector3		vb=m_bodies[1].velocity(m_rpos[1]);
-	const btVector3		vr=va-vb;
-	btSoftBody::Impulse	impulse;
-	impulse.m_asVelocity	=	1;
-	impulse.m_velocity		=	m_massmatrix*(m_drift+vr*m_cfm)*sor;
-	m_bodies[0].applyImpulse(-impulse,m_rpos[0]);
-	m_bodies[1].applyImpulse( impulse,m_rpos[1]);
-}
-
-//
-void				btSoftBody::LJoint::Terminate(btScalar dt)
-{
-	if(m_split>0)
-	{
-		m_bodies[0].applyDImpulse(-m_sdrift,m_rpos[0]);
-		m_bodies[1].applyDImpulse( m_sdrift,m_rpos[1]);
-	}
-}
-
-//
-void				btSoftBody::AJoint::Prepare(btScalar dt,int iterations)
-{
-	static const btScalar	maxdrift=SIMD_PI/16;
-	m_icontrol->Prepare(this);
-	Joint::Prepare(dt,iterations);
-	m_axis[0]	=	m_bodies[0].xform().getBasis()*m_refs[0];
-	m_axis[1]	=	m_bodies[1].xform().getBasis()*m_refs[1];
-	m_drift		=	NormalizeAny(cross(m_axis[1],m_axis[0]));
-	m_drift		*=	btMin(maxdrift,btAcos(Clamp<btScalar>(dot(m_axis[0],m_axis[1]),-1,+1)));
-	m_drift		*=	m_erp/dt;
-	m_massmatrix=	AngularImpulseMatrix(m_bodies[0].invWorldInertia(),m_bodies[1].invWorldInertia());
-	if(m_split>0)
-	{
-		m_sdrift	=	m_massmatrix*(m_drift*m_split);
-		m_drift		*=	1-m_split;
-	}
-	m_drift	/=(btScalar)iterations;
-}
-
-//
-void				btSoftBody::AJoint::Solve(btScalar dt,btScalar sor)
-{
-	const btVector3		va=m_bodies[0].angularVelocity();
-	const btVector3		vb=m_bodies[1].angularVelocity();
-	const btVector3		vr=va-vb;
-	const btScalar		sp=dot(vr,m_axis[0]);
-	const btVector3		vc=vr-m_axis[0]*m_icontrol->Speed(this,sp);
-	btSoftBody::Impulse	impulse;
-	impulse.m_asVelocity	=	1;
-	impulse.m_velocity		=	m_massmatrix*(m_drift+vc*m_cfm)*sor;
-	m_bodies[0].applyAImpulse(-impulse);
-	m_bodies[1].applyAImpulse( impulse);
-}
-
-//
-void				btSoftBody::AJoint::Terminate(btScalar dt)
-{
-	if(m_split>0)
-	{
-		m_bodies[0].applyDAImpulse(-m_sdrift);
-		m_bodies[1].applyDAImpulse( m_sdrift);
-	}
-}
-
-//
-void				btSoftBody::CJoint::Prepare(btScalar dt,int iterations)
-{
-	Joint::Prepare(dt,iterations);
-	const bool	dodrift=(m_life==0);
-	m_delete=(++m_life)>m_maxlife;
-	if(dodrift)
-	{
-		m_drift=m_drift*m_erp/dt;
-		if(m_split>0)
-		{
-			m_sdrift	=	m_massmatrix*(m_drift*m_split);
-			m_drift		*=	1-m_split;
-		}
-		m_drift/=(btScalar)iterations;
+		}
+	m_drift/=(btScalar)iterations;
 	}
 	else
 	{
-		m_drift=m_sdrift=btVector3(0,0,0);
+	m_drift=m_sdrift=btVector3(0,0,0);
 	}
 }
@@ -2274,20 +2261,20 @@
 void				btSoftBody::CJoint::Solve(btScalar dt,btScalar sor)
 {
-	const btVector3		va=m_bodies[0].velocity(m_rpos[0]);
-	const btVector3		vb=m_bodies[1].velocity(m_rpos[1]);
-	const btVector3		vrel=va-vb;
-	const btScalar		rvac=dot(vrel,m_normal);
-	btSoftBody::Impulse	impulse;
-	impulse.m_asVelocity	=	1;
-	impulse.m_velocity		=	m_drift;
-	if(rvac<0)
-	{
-		const btVector3	iv=m_normal*rvac;
-		const btVector3	fv=vrel-iv;
-		impulse.m_velocity	+=	iv+fv*m_friction;
-	}
-	impulse.m_velocity=m_massmatrix*impulse.m_velocity*sor;
-	m_bodies[0].applyImpulse(-impulse,m_rpos[0]);
-	m_bodies[1].applyImpulse( impulse,m_rpos[1]);
+const btVector3		va=m_bodies[0].velocity(m_rpos[0]);
+const btVector3		vb=m_bodies[1].velocity(m_rpos[1]);
+const btVector3		vrel=va-vb;
+const btScalar		rvac=dot(vrel,m_normal);
+btSoftBody::Impulse	impulse;
+impulse.m_asVelocity	=	1;
+impulse.m_velocity		=	m_drift;
+if(rvac<0)
+	{
+	const btVector3	iv=m_normal*rvac;
+	const btVector3	fv=vrel-iv;
+	impulse.m_velocity	+=	iv+fv*m_friction;
+	}
+impulse.m_velocity=m_massmatrix*impulse.m_velocity*sor;
+m_bodies[0].applyImpulse(-impulse,m_rpos[0]);
+m_bodies[1].applyImpulse( impulse,m_rpos[1]);
 }
 
@@ -2295,8 +2282,8 @@
 void				btSoftBody::CJoint::Terminate(btScalar dt)
 {
-	if(m_split>0)
-	{
-		m_bodies[0].applyDImpulse(-m_sdrift,m_rpos[0]);
-		m_bodies[1].applyDImpulse( m_sdrift,m_rpos[1]);
+if(m_split>0)
+	{
+	m_bodies[0].applyDImpulse(-m_sdrift,m_rpos[0]);
+	m_bodies[1].applyDImpulse( m_sdrift,m_rpos[1]);
 	}
 }
@@ -2316,12 +2303,12 @@
 	const bool						as_volume=kVC>0;
 	const bool						as_aero=	as_lift		||
-		as_drag		;
+												as_drag		;
 	const bool						as_vaero=	as_aero		&&
-		(m_cfg.aeromodel<btSoftBody::eAeroModel::F_TwoSided);
+												(m_cfg.aeromodel<btSoftBody::eAeroModel::F_TwoSided);
 	const bool						as_faero=	as_aero		&&
-		(m_cfg.aeromodel>=btSoftBody::eAeroModel::F_TwoSided);
+												(m_cfg.aeromodel>=btSoftBody::eAeroModel::F_TwoSided);
 	const bool						use_medium=	as_aero;
 	const bool						use_volume=	as_pressure	||
-		as_volume	;
+												as_volume	;
 	btScalar						volume=0;
 	btScalar						ivolumetp=0;
@@ -2471,30 +2458,30 @@
 void				btSoftBody::PSolve_SContacts(btSoftBody* psb,btScalar,btScalar ti)
 {
-	for(int i=0,ni=psb->m_scontacts.size();i<ni;++i)
-	{
-		const SContact&		c=psb->m_scontacts[i];
-		const btVector3&	nr=c.m_normal;
-		Node&				n=*c.m_node;
-		Face&				f=*c.m_face;
-		const btVector3		p=BaryEval(	f.m_n[0]->m_x,
-			f.m_n[1]->m_x,
-			f.m_n[2]->m_x,
-			c.m_weights);
-		const btVector3		q=BaryEval(	f.m_n[0]->m_q,
-			f.m_n[1]->m_q,
-			f.m_n[2]->m_q,
-			c.m_weights);											
-		const btVector3		vr=(n.m_x-n.m_q)-(p-q);
-		btVector3			corr(0,0,0);
-		if(dot(vr,nr)<0)
-		{
-			const btScalar	j=c.m_margin-(dot(nr,n.m_x)-dot(nr,p));
-			corr+=c.m_normal*j;
-		}
-		corr			-=	ProjectOnPlane(vr,nr)*c.m_friction;
-		n.m_x			+=	corr*c.m_cfm[0];
-		f.m_n[0]->m_x	-=	corr*(c.m_cfm[1]*c.m_weights.x());
-		f.m_n[1]->m_x	-=	corr*(c.m_cfm[1]*c.m_weights.y());
-		f.m_n[2]->m_x	-=	corr*(c.m_cfm[1]*c.m_weights.z());
+for(int i=0,ni=psb->m_scontacts.size();i<ni;++i)
+	{
+	const SContact&		c=psb->m_scontacts[i];
+	const btVector3&	nr=c.m_normal;
+	Node&				n=*c.m_node;
+	Face&				f=*c.m_face;
+	const btVector3		p=BaryEval(	f.m_n[0]->m_x,
+									f.m_n[1]->m_x,
+									f.m_n[2]->m_x,
+									c.m_weights);
+	const btVector3		q=BaryEval(	f.m_n[0]->m_q,
+									f.m_n[1]->m_q,
+									f.m_n[2]->m_q,
+									c.m_weights);											
+	const btVector3		vr=(n.m_x-n.m_q)-(p-q);
+	btVector3			corr(0,0,0);
+	if(dot(vr,nr)<0)
+		{
+		const btScalar	j=c.m_margin-(dot(nr,n.m_x)-dot(nr,p));
+		corr+=c.m_normal*j;
+		}
+	corr			-=	ProjectOnPlane(vr,nr)*c.m_friction;
+	n.m_x			+=	corr*c.m_cfm[0];
+	f.m_n[0]->m_x	-=	corr*(c.m_cfm[1]*c.m_weights.x());
+	f.m_n[1]->m_x	-=	corr*(c.m_cfm[1]*c.m_weights.y());
+	f.m_n[2]->m_x	-=	corr*(c.m_cfm[1]*c.m_weights.z());
 	}
 }
@@ -2523,11 +2510,11 @@
 void				btSoftBody::VSolve_Links(btSoftBody* psb,btScalar kst)
 {
-	for(int i=0,ni=psb->m_links.size();i<ni;++i)
+for(int i=0,ni=psb->m_links.size();i<ni;++i)
 	{			
-		Link&			l=psb->m_links[i];
-		Node**			n=l.m_n;
-		const btScalar	j=-dot(l.m_c3,n[0]->m_v-n[1]->m_v)*l.m_c2*kst;
-		n[0]->m_v+=	l.m_c3*(j*n[0]->m_im);
-		n[1]->m_v-=	l.m_c3*(j*n[1]->m_im);
+	Link&			l=psb->m_links[i];
+	Node**			n=l.m_n;
+	const btScalar	j=-dot(l.m_c3,n[0]->m_v-n[1]->m_v)*l.m_c2*kst;
+	n[0]->m_v+=	l.m_c3*(j*n[0]->m_im);
+	n[1]->m_v-=	l.m_c3*(j*n[1]->m_im);
 	}
 }
@@ -2536,5 +2523,5 @@
 btSoftBody::psolver_t	btSoftBody::getSolver(ePSolver::_ solver)
 {
-	switch(solver)
+switch(solver)
 	{
 	case	ePSolver::Anchors:		return(&btSoftBody::PSolve_Anchors);
@@ -2543,5 +2530,5 @@
 	case	ePSolver::SContacts:	return(&btSoftBody::PSolve_SContacts);	
 	}
-	return(0);
+return(0);
 }
 
@@ -2549,9 +2536,9 @@
 btSoftBody::vsolver_t	btSoftBody::getSolver(eVSolver::_ solver)
 {
-	switch(solver)
+switch(solver)
 	{
 	case	eVSolver::Linear:		return(&btSoftBody::VSolve_Links);
 	}
-	return(0);
+return(0);
 }
 
@@ -2559,35 +2546,35 @@
 void			btSoftBody::defaultCollisionHandler(btCollisionObject* pco)
 {
-	switch(m_cfg.collisions&fCollision::RVSmask)
+switch(m_cfg.collisions&fCollision::RVSmask)
 	{
 	case	fCollision::SDF_RS:
 		{
-			btSoftColliders::CollideSDF_RS	docollide;		
-			btRigidBody*		prb=btRigidBody::upcast(pco);
-			const btTransform	wtr=prb->getInterpolationWorldTransform();
-			const btTransform	ctr=prb->getWorldTransform();
-			const btScalar		timemargin=(wtr.getOrigin()-ctr.getOrigin()).length();
-			const btScalar		basemargin=getCollisionShape()->getMargin();
-			btVector3			mins;
-			btVector3			maxs;
-			ATTRIBUTE_ALIGNED16(btDbvtVolume)		volume;
-			pco->getCollisionShape()->getAabb(	pco->getInterpolationWorldTransform(),
-				mins,
-				maxs);
-			volume=btDbvtVolume::FromMM(mins,maxs);
-			volume.Expand(btVector3(basemargin,basemargin,basemargin));		
-			docollide.psb		=	this;
-			docollide.prb		=	prb;
-			docollide.dynmargin	=	basemargin+timemargin;
-			docollide.stamargin	=	basemargin;
-			btDbvt::collideTV(m_ndbvt.m_root,volume,docollide);
-		}
-		break;
+		btSoftColliders::CollideSDF_RS	docollide;		
+		btRigidBody*		prb=btRigidBody::upcast(pco);
+		const btTransform	wtr=prb->getInterpolationWorldTransform();
+		const btTransform	ctr=prb->getWorldTransform();
+		const btScalar		timemargin=(wtr.getOrigin()-ctr.getOrigin()).length();
+		const btScalar		basemargin=getCollisionShape()->getMargin();
+		btVector3			mins;
+		btVector3			maxs;
+		ATTRIBUTE_ALIGNED16(btDbvtVolume)		volume;
+		pco->getCollisionShape()->getAabb(	pco->getInterpolationWorldTransform(),
+											mins,
+											maxs);
+		volume=btDbvtVolume::FromMM(mins,maxs);
+		volume.Expand(btVector3(basemargin,basemargin,basemargin));		
+		docollide.psb		=	this;
+		docollide.prb		=	prb;
+		docollide.dynmargin	=	basemargin+timemargin;
+		docollide.stamargin	=	basemargin;
+		btDbvt::collideTV(m_ndbvt.m_root,volume,docollide);
+		}
+	break;
 	case	fCollision::CL_RS:
 		{
-			btSoftColliders::CollideCL_RS	collider;
-			collider.Process(this,btRigidBody::upcast(pco));
-		}
-		break;
+		btSoftColliders::CollideCL_RS	collider;
+		collider.Process(this,btRigidBody::upcast(pco));
+		}
+	break;
 	}
 }
@@ -2596,33 +2583,33 @@
 void			btSoftBody::defaultCollisionHandler(btSoftBody* psb)
 {
-	const int cf=m_cfg.collisions&psb->m_cfg.collisions;
-	switch(cf&fCollision::SVSmask)
+const int cf=m_cfg.collisions&psb->m_cfg.collisions;
+switch(cf&fCollision::SVSmask)
 	{
 	case	fCollision::CL_SS:
 		{
-			btSoftColliders::CollideCL_SS	docollide;
-			docollide.Process(this,psb);
-		}
-		break;
+		btSoftColliders::CollideCL_SS	docollide;
+		docollide.Process(this,psb);
+		}
+	break;
 	case	fCollision::VF_SS:
 		{
-			btSoftColliders::CollideVF_SS	docollide;
-			/* common					*/ 
-			docollide.mrg=	getCollisionShape()->getMargin()+
-				psb->getCollisionShape()->getMargin();
-			/* psb0 nodes vs psb1 faces	*/ 
-			docollide.psb[0]=this;
-			docollide.psb[1]=psb;
-			btDbvt::collideTT(	docollide.psb[0]->m_ndbvt.m_root,
-				docollide.psb[1]->m_fdbvt.m_root,
-				docollide);
-			/* psb1 nodes vs psb0 faces	*/ 
-			docollide.psb[0]=psb;
-			docollide.psb[1]=this;
-			btDbvt::collideTT(	docollide.psb[0]->m_ndbvt.m_root,
-				docollide.psb[1]->m_fdbvt.m_root,
-				docollide);
-		}
-		break;
-	}
-}
+		btSoftColliders::CollideVF_SS	docollide;
+		/* common					*/ 
+		docollide.mrg=	getCollisionShape()->getMargin()+
+						psb->getCollisionShape()->getMargin();
+		/* psb0 nodes vs psb1 faces	*/ 
+		docollide.psb[0]=this;
+		docollide.psb[1]=psb;
+		btDbvt::collideTT(	docollide.psb[0]->m_ndbvt.m_root,
+							docollide.psb[1]->m_fdbvt.m_root,
+							docollide);
+		/* psb1 nodes vs psb0 faces	*/ 
+		docollide.psb[0]=psb;
+		docollide.psb[1]=this;
+		btDbvt::collideTT(	docollide.psb[0]->m_ndbvt.m_root,
+							docollide.psb[1]->m_fdbvt.m_root,
+							docollide);
+		}
+	break;
+	}
+}
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftBody.h
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftBody.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftBody.h	(revision 1972)
@@ -63,5 +63,5 @@
 		END
 	};};
-
+	
 	///eVSolver : velocities solvers
 	struct	eVSolver { enum _ {
@@ -69,5 +69,5 @@
 		END
 	};};
-
+	
 	///ePSolver : positions solvers
 	struct	ePSolver { enum _ {
@@ -78,5 +78,5 @@
 		END
 	};};
-
+	
 	///eSolverPresets
 	struct	eSolverPresets { enum _ {
@@ -86,5 +86,5 @@
 		END
 	};};
-
+	
 	///eFeature
 	struct	eFeature { enum _ {
@@ -95,12 +95,12 @@
 		END
 	};};
-
+	
 	typedef btAlignedObjectArray<eVSolver::_>	tVSolverArray;
 	typedef btAlignedObjectArray<ePSolver::_>	tPSolverArray;
-
+	
 	//
 	// Flags
 	//
-
+	
 	///fCollision
 	struct fCollision { enum _ {
@@ -108,5 +108,5 @@
 		SDF_RS	=	0x0001,	///SDF based rigid vs soft
 		CL_RS	=	0x0002, ///Cluster vs convex rigid vs soft
-
+		
 		SVSmask	=	0x00f0,	///Rigid versus soft mask		
 		VF_SS	=	0x0010,	///Vertex vs face soft vs soft handling
@@ -116,5 +116,5 @@
 		END
 	};};
-
+	
 	///fMaterial
 	struct fMaterial { enum _ {
@@ -124,9 +124,9 @@
 		END
 	};};
-
+		
 	//
 	// API Types
 	//
-
+	
 	/* sRayCast		*/ 
 	struct sRayCast
@@ -135,7 +135,7 @@
 		eFeature::_	feature;	/// feature type
 		int			index;		/// feature index
-		btScalar	fraction;		/// time of impact fraction (rayorg+(rayto-rayfrom)*fraction)
-	};
-
+		btScalar	time;		/// time of impact (rayorg+raydir*time)
+	};
+	
 	/* ImplicitFn	*/ 
 	struct	ImplicitFn
@@ -143,5 +143,5 @@
 		virtual btScalar	Eval(const btVector3& x)=0;
 	};
-
+	
 	//
 	// Internal types
@@ -181,5 +181,5 @@
 		int						m_flags;		// Flags
 	};
-
+		
 	/* Feature		*/ 
 	struct	Feature : Element
@@ -297,5 +297,5 @@
 		btScalar					m_matching;
 		bool						m_collide;
-		Cluster() : m_leaf(0),m_ndamping(0),m_ldamping(0),m_adamping(0),m_matching(0) {}
+									Cluster() : m_leaf(0),m_ndamping(0),m_ldamping(0),m_adamping(0),m_matching(0) {}
 	};
 	/* Impulse		*/ 
@@ -308,17 +308,17 @@
 		Impulse() : m_velocity(0,0,0),m_drift(0,0,0),m_asVelocity(0),m_asDrift(0)	{}
 		Impulse						operator -() const
-		{
+			{
 			Impulse i=*this;
 			i.m_velocity=-i.m_velocity;
 			i.m_drift=-i.m_drift;
 			return(i);
-		}
+			}
 		Impulse						operator*(btScalar x) const
-		{
+			{
 			Impulse i=*this;
 			i.m_velocity*=x;
 			i.m_drift*=x;
 			return(i);
-		}
+			}
 	};
 	/* Body			*/ 
@@ -327,88 +327,88 @@
 		Cluster*		m_soft;
 		btRigidBody*				m_rigid;
-		Body() : m_soft(0),m_rigid(0)				{}
-		Body(Cluster* p) : m_soft(p),m_rigid(0)	{}
-		Body(btRigidBody* p) : m_soft(0),m_rigid(p)	{}
+									Body() : m_soft(0),m_rigid(0)				{}
+									Body(Cluster* p) : m_soft(p),m_rigid(0)	{}
+									Body(btRigidBody* p) : m_soft(0),m_rigid(p)	{}
 		void						activate() const
-		{
+			{
 			if(m_rigid) m_rigid->activate();
-		}
+			}
 		const btMatrix3x3&			invWorldInertia() const
-		{
+			{
 			static const btMatrix3x3	iwi(0,0,0,0,0,0,0,0,0);
 			if(m_rigid) return(m_rigid->getInvInertiaTensorWorld());
 			if(m_soft)	return(m_soft->m_invwi);
 			return(iwi);
-		}
+			}
 		btScalar					invMass() const
-		{
+			{
 			if(m_rigid) return(m_rigid->getInvMass());
 			if(m_soft)	return(m_soft->m_imass);
 			return(0);
-		}
+			}
 		const btTransform&			xform() const
-		{
+			{
 			static const btTransform	identity=btTransform::getIdentity();		
 			if(m_rigid) return(m_rigid->getInterpolationWorldTransform());
 			if(m_soft)	return(m_soft->m_framexform);
 			return(identity);
-		}
+			}
 		btVector3					linearVelocity() const
-		{
+			{
 			if(m_rigid) return(m_rigid->getLinearVelocity());
 			if(m_soft)	return(m_soft->m_lv);
 			return(btVector3(0,0,0));
-		}
+			}
 		btVector3					angularVelocity(const btVector3& rpos) const
-		{			
+			{			
 			if(m_rigid) return(cross(m_rigid->getAngularVelocity(),rpos));
 			if(m_soft)	return(cross(m_soft->m_av,rpos));
 			return(btVector3(0,0,0));
-		}
+			}
 		btVector3					angularVelocity() const
-		{			
+			{			
 			if(m_rigid) return(m_rigid->getAngularVelocity());
 			if(m_soft)	return(m_soft->m_av);
 			return(btVector3(0,0,0));
-		}
+			}
 		btVector3					velocity(const btVector3& rpos) const
-		{
+			{
 			return(linearVelocity()+angularVelocity(rpos));
-		}
+			}
 		void						applyVImpulse(const btVector3& impulse,const btVector3& rpos) const
-		{
+			{
 			if(m_rigid)	m_rigid->applyImpulse(impulse,rpos);
 			if(m_soft)	btSoftBody::clusterVImpulse(m_soft,rpos,impulse);
-		}
+			}
 		void						applyDImpulse(const btVector3& impulse,const btVector3& rpos) const
-		{
+			{
 			if(m_rigid)	m_rigid->applyImpulse(impulse,rpos);
 			if(m_soft)	btSoftBody::clusterDImpulse(m_soft,rpos,impulse);
-		}		
+			}		
 		void						applyImpulse(const Impulse& impulse,const btVector3& rpos) const
-		{
+			{
 			if(impulse.m_asVelocity)	applyVImpulse(impulse.m_velocity,rpos);
 			if(impulse.m_asDrift)		applyDImpulse(impulse.m_drift,rpos);
-		}
+			}
 		void						applyVAImpulse(const btVector3& impulse) const
-		{
+			{
 			if(m_rigid)	m_rigid->applyTorqueImpulse(impulse);
 			if(m_soft)	btSoftBody::clusterVAImpulse(m_soft,impulse);
-		}
+			}
 		void						applyDAImpulse(const btVector3& impulse) const
-		{
+			{
 			if(m_rigid)	m_rigid->applyTorqueImpulse(impulse);
 			if(m_soft)	btSoftBody::clusterDAImpulse(m_soft,impulse);
-		}
+			}
 		void						applyAImpulse(const Impulse& impulse) const
-		{
+			{
 			if(impulse.m_asVelocity)	applyVAImpulse(impulse.m_velocity);
 			if(impulse.m_asDrift)		applyDAImpulse(impulse.m_drift);
-		}
+			}
 		void						applyDCImpulse(const btVector3& impulse) const
-		{
+			{
 			if(m_rigid)	m_rigid->applyCentralImpulse(impulse);
 			if(m_soft)	btSoftBody::clusterDCImpulse(m_soft,impulse);
-		}
+			}
 	};
 	/* Joint		*/ 
@@ -421,10 +421,10 @@
 		};};
 		struct Specs
-		{
-			Specs() : erp(1),cfm(1),split(1) {}
+			{
+						Specs() : erp(1),cfm(1),split(1) {}
 			btScalar	erp;
 			btScalar	cfm;
 			btScalar	split;
-		};
+			};
 		Body						m_bodies[2];
 		btVector3					m_refs[2];
@@ -437,5 +437,5 @@
 		bool						m_delete;
 		virtual						~Joint() {}
-		Joint() : m_delete(false) {}
+									Joint() : m_delete(false) {}
 		virtual void				Prepare(btScalar dt,int iterations);
 		virtual void				Solve(btScalar dt,btScalar sor)=0;
@@ -447,7 +447,7 @@
 	{
 		struct Specs : Joint::Specs
-		{
+			{
 			btVector3	position;
-		};		
+			};		
 		btVector3					m_rpos[2];
 		void						Prepare(btScalar dt,int iterations);
@@ -460,15 +460,15 @@
 	{
 		struct IControl
-		{
+			{
 			virtual void			Prepare(AJoint*)				{}
 			virtual btScalar		Speed(AJoint*,btScalar current) { return(current); }
 			static IControl*		Default()						{ static IControl def;return(&def); }
-		};
+			};
 		struct Specs : Joint::Specs
-		{
-			Specs() : icontrol(IControl::Default()) {}
+			{
+						Specs() : icontrol(IControl::Default()) {}
 			btVector3	axis;
 			IControl*	icontrol;
-		};		
+			};		
 		btVector3					m_axis[2];
 		IControl*					m_icontrol;
@@ -533,24 +533,21 @@
 		btScalar				updmrg;			// Update margin
 	};	
-	/// RayFromToCaster takes a ray from, ray to (instead of direction!)
-	struct	RayFromToCaster : btDbvt::ICollide
-	{
-		btVector3			m_rayFrom;
-		btVector3			m_rayTo;
-		btVector3			m_rayNormalizedDirection;
-		btScalar			m_mint;
-		Face*				m_face;
-		int					m_tests;
-		RayFromToCaster(const btVector3& rayFrom,const btVector3& rayTo,btScalar mxt);
+	/* RayCaster	*/ 
+	struct	RayCaster : btDbvt::ICollide
+		{
+		btVector3			o;
+		btVector3			d;
+		btScalar			mint;
+		Face*	face;
+		int					tests;
+								RayCaster(const btVector3& org,const btVector3& dir,btScalar mxt);
 		void					Process(const btDbvtNode* leaf);
-
-		static inline btScalar	rayFromToTriangle(const btVector3& rayFrom,
-			const btVector3& rayTo,
-			const btVector3& rayNormalizedDirection,
-			const btVector3& a,
-			const btVector3& b,
-			const btVector3& c,
-			btScalar maxt=SIMD_INFINITY);
-	};
+		static inline btScalar	rayTriangle(const btVector3& org,
+											const btVector3& dir,
+											const btVector3& a,
+											const btVector3& b,
+											const btVector3& c,
+											btScalar maxt=SIMD_INFINITY);
+		};
 
 	//
@@ -598,13 +595,13 @@
 	btDbvt					m_cdbvt;		// Clusters tree
 	tClusterArray			m_clusters;		// Clusters
-
+		
 	//
 	// Api
 	//
-
+	
 	/* ctor																	*/ 
 	btSoftBody(	btSoftBodyWorldInfo* worldInfo,int node_count,
-		const btVector3* x,
-		const btScalar* m);
+				const btVector3* x,
+				const btScalar* m);
 	/* dtor																	*/ 
 	virtual ~btSoftBody();
@@ -626,28 +623,28 @@
 		int node1) const;
 	bool				checkLink(	const Node* node0,
-		const Node* node1) const;
+									const Node* node1) const;
 	/* Check for existring face												*/ 
 	bool				checkFace(	int node0,
-		int node1,
-		int node2) const;
+									int node1,
+									int node2) const;
 	/* Append material														*/ 
 	Material*			appendMaterial();
 	/* Append note															*/ 
 	void				appendNote(	const char* text,
-		const btVector3& o,
-		const btVector4& c=btVector4(1,0,0,0),
-		Node* n0=0,
-		Node* n1=0,
-		Node* n2=0,
-		Node* n3=0);
+									const btVector3& o,
+									const btVector4& c=btVector4(1,0,0,0),
+									Node* n0=0,
+									Node* n1=0,
+									Node* n2=0,
+									Node* n3=0);
 	void				appendNote(	const char* text,
-		const btVector3& o,
-		Node* feature);
+									const btVector3& o,
+									Node* feature);
 	void				appendNote(	const char* text,
-		const btVector3& o,
-		Link* feature);
+									const btVector3& o,
+									Link* feature);
 	void				appendNote(	const char* text,
-		const btVector3& o,
-		Face* feature);
+									const btVector3& o,
+									Face* feature);
 	/* Append node															*/ 
 	void				appendNode(	const btVector3& x,btScalar m);
@@ -655,20 +652,20 @@
 	void				appendLink(int model=-1,Material* mat=0);
 	void				appendLink(	int node0,
-		int node1,
-		Material* mat=0,
-		bool bcheckexist=false);
+									int node1,
+									Material* mat=0,
+									bool bcheckexist=false);
 	void				appendLink(	Node* node0,
-		Node* node1,
-		Material* mat=0,
-		bool bcheckexist=false);
+									Node* node1,
+									Material* mat=0,
+									bool bcheckexist=false);
 	/* Append face															*/ 
 	void				appendFace(int model=-1,Material* mat=0);
 	void				appendFace(	int node0,
-		int node1,
-		int node2,
-		Material* mat=0);
+									int node1,
+									int node2,
+									Material* mat=0);
 	/* Append anchor														*/ 
 	void				appendAnchor(	int node,
-		btRigidBody* body);
+										btRigidBody* body);
 	/* Append linear joint													*/ 
 	void				appendLinearJoint(const LJoint::Specs& specs,Cluster* body0,Body body1);
@@ -683,5 +680,5 @@
 	/* Add force (or gravity) to a node of the body							*/ 
 	void				addForce(		const btVector3& force,
-		int node);
+										int node);
 	/* Add velocity to the entire body										*/ 
 	void				addVelocity(	const btVector3& velocity);
@@ -692,8 +689,8 @@
 	/* Add velocity to a node of the body									*/ 
 	void				addVelocity(	const btVector3& velocity,
-		int node);
+										int node);
 	/* Set mass																*/ 
 	void				setMass(		int node,
-		btScalar mass);
+										btScalar mass);
 	/* Get mass																*/ 
 	btScalar			getMass(		int node) const;
@@ -702,5 +699,5 @@
 	/* Set total mass (weighted by previous masses)							*/ 
 	void				setTotalMass(	btScalar mass,
-		bool fromfaces=false);
+										bool fromfaces=false);
 	/* Set total density													*/ 
 	void				setTotalDensity(btScalar density);
@@ -715,5 +712,5 @@
 	/* Set current state as pose											*/ 
 	void				setPose(		bool bvolume,
-		bool bframe);
+										bool bframe);
 	/* Return the volume													*/ 
 	btScalar			getVolume() const;
@@ -735,5 +732,5 @@
 	/* Generate bending constraints based on distance in the adjency graph	*/ 
 	int					generateBendingConstraints(	int distance,
-		Material* mat=0);
+													Material* mat=0);
 	/* Randomize constraints to reduce solver bias							*/ 
 	void				randomizeConstraints();
@@ -748,9 +745,9 @@
 	bool				cutLink(int node0,int node1,btScalar position);
 	bool				cutLink(const Node* node0,const Node* node1,btScalar position);
-
-	///Ray casting using rayFrom and rayTo in worldspace, (not direction!)
-	bool				rayTest(const btVector3& rayFrom,
-		const btVector3& rayTo,
-		sRayCast& results);
+	/* Ray casting															*/ 
+	bool				rayCast(const btVector3& org,
+								const btVector3& dir,
+								sRayCast& results,
+								btScalar maxtime=SIMD_INFINITY);
 	/* Solver presets														*/ 
 	void				setSolver(eSolverPresets::_ preset);
@@ -770,9 +767,9 @@
 	void				defaultCollisionHandler(btCollisionObject* pco);
 	void				defaultCollisionHandler(btSoftBody* psb);
-
+		
 	//
 	// Cast
 	//
-
+		
 	static const btSoftBody*	upcast(const btCollisionObject* colObj)
 	{
@@ -802,7 +799,6 @@
 	void				pointersToIndices();
 	void				indicesToPointers(const int* map=0);
-
-	int					rayTest(const btVector3& rayFrom,const btVector3& rayTo,
-		btScalar& mint,eFeature::_& feature,int& index,bool bcountonly) const;
+	int					rayCast(const btVector3& org,const btVector3& dir,
+								btScalar& mint,eFeature::_& feature,int& index,bool bcountonly) const;
 	void				initializeFaceTree();
 	btVector3			evaluateCom() const;
@@ -827,5 +823,5 @@
 	static psolver_t	getSolver(ePSolver::_ solver);
 	static vsolver_t	getSolver(eVSolver::_ solver);
-
+	
 };
 
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.cpp	(revision 1972)
@@ -51,25 +51,25 @@
 
 btSoftBodyTriangleCallback::btSoftBodyTriangleCallback(btDispatcher*  dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped):
-m_dispatcher(dispatcher),
-m_dispatchInfoPtr(0)
+	  m_dispatcher(dispatcher),
+	m_dispatchInfoPtr(0)
 {
 	m_softBody = (btSoftBody*) (isSwapped? body1:body0);
 	m_triBody = isSwapped? body0:body1;
-
-	//
-	// create the manifold from the dispatcher 'manifold pool'
-	//
-	//	  m_manifoldPtr = m_dispatcher->getNewManifold(m_convexBody,m_triBody);
-
+	
+	  //
+	  // create the manifold from the dispatcher 'manifold pool'
+	  //
+//	  m_manifoldPtr = m_dispatcher->getNewManifold(m_convexBody,m_triBody);
+
+  	  clearCache();
+}
+
+btSoftBodyTriangleCallback::~btSoftBodyTriangleCallback()
+{
 	clearCache();
-}
-
-btSoftBodyTriangleCallback::~btSoftBodyTriangleCallback()
-{
-	clearCache();
-	//	m_dispatcher->releaseManifold( m_manifoldPtr );
-
-}
-
+//	m_dispatcher->releaseManifold( m_manifoldPtr );
+  
+}
+  
 
 void	btSoftBodyTriangleCallback::clearCache()
@@ -89,5 +89,5 @@
 void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId, int triangleIndex)
 {
-	//just for debugging purposes
+ 	//just for debugging purposes
 	//printf("triangle %d",m_triangleCount++);
 	btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBody);
@@ -95,5 +95,5 @@
 	ci.m_dispatcher1 = m_dispatcher;
 
-	///debug drawing of the overlapping triangles
+		///debug drawing of the overlapping triangles
 	if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && m_dispatchInfoPtr->m_debugDraw->getDebugMode() > 0)
 	{
@@ -108,5 +108,5 @@
 	btHashKey<btTriIndex> triKey(triIndex.getUid());
 
-
+	
 	btTriIndex* shapeIndex = m_shapeCache[triKey];
 	if (shapeIndex)
@@ -117,11 +117,11 @@
 		//copy over user pointers to temporary shape
 		tm->setUserPointer(ob->getRootCollisionShape()->getUserPointer());
-
+		
 		btCollisionShape* tmpShape = ob->getCollisionShape();
 		ob->internalSetTemporaryCollisionShape( tm );
-
+		
 
 		btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_softBody,m_triBody,0);//m_manifoldPtr);
-
+		
 		colAlgo->processCollision(m_softBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
 		colAlgo->~btCollisionAlgorithm();
@@ -134,34 +134,34 @@
 
 	//btCollisionObject* colObj = static_cast<btCollisionObject*>(m_convexProxy->m_clientObject);
-
-	//	if (m_softBody->getCollisionShape()->getShapeType()==
-	{
-		//		btVector3 other;
+	
+//	if (m_softBody->getCollisionShape()->getShapeType()==
+	{
+//		btVector3 other;
 		btVector3 normal = (triangle[1]-triangle[0]).cross(triangle[2]-triangle[0]);
 		normal.normalize();
 		normal*= BT_SOFTBODY_TRIANGLE_EXTRUSION;
-		//		other=(triangle[0]+triangle[1]+triangle[2])*0.333333f;
-		//		other+=normal*22.f;
+//		other=(triangle[0]+triangle[1]+triangle[2])*0.333333f;
+//		other+=normal*22.f;
 		btVector3	pts[6] = {triangle[0]+normal,
 			triangle[1]+normal,
-			triangle[2]+normal,
-			triangle[0]-normal,
-			triangle[1]-normal,
-			triangle[2]-normal};
+		triangle[2]+normal,
+		triangle[0]-normal,
+		triangle[1]-normal,
+		triangle[2]-normal};
 
 		btConvexHullShape* tm = new btConvexHullShape(&pts[0].getX(),6);
 
 
-		//		btBU_Simplex1to4 tm(triangle[0],triangle[1],triangle[2],other);
-
+//		btBU_Simplex1to4 tm(triangle[0],triangle[1],triangle[2],other);
+		
 		//btTriangleShape tm(triangle[0],triangle[1],triangle[2]);	
-		//	tm.setMargin(m_collisionMarginTriangle);
-
+	//	tm.setMargin(m_collisionMarginTriangle);
+		
 		//copy over user pointers to temporary shape
 		tm->setUserPointer(ob->getRootCollisionShape()->getUserPointer());
-
+		
 		btCollisionShape* tmpShape = ob->getCollisionShape();
 		ob->internalSetTemporaryCollisionShape( tm );
-
+		
 
 		btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_softBody,m_triBody,0);//m_manifoldPtr);
@@ -170,11 +170,11 @@
 
 		//m_resultOut->setShapeIdentifiers(-1,-1,partId,triangleIndex);
-		//	cvxcvxalgo.setShapeIdentifiers(-1,-1,partId,triangleIndex);
-		//		cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
+	//	cvxcvxalgo.setShapeIdentifiers(-1,-1,partId,triangleIndex);
+//		cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
 		colAlgo->processCollision(m_softBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
 		colAlgo->~btCollisionAlgorithm();
 		ci.m_dispatcher1->freeCollisionAlgorithm(colAlgo);
-
-
+		
+		
 		ob->internalSetTemporaryCollisionShape( tmpShape );
 		triIndex.m_childShape = tm;
@@ -183,5 +183,5 @@
 	}
 
-
+	
 
 }
@@ -195,5 +195,5 @@
 	m_resultOut = resultOut;
 
-
+	
 	btVector3	aabbWorldSpaceMin,aabbWorldSpaceMax;
 	m_softBody->getAabb(aabbWorldSpaceMin,aabbWorldSpaceMax);
@@ -218,6 +218,6 @@
 void btSoftBodyConcaveCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
-
-
+	
+	
 	btCollisionObject* convexBody = m_isSwapped ? body1 : body0;
 	btCollisionObject* triBody = m_isSwapped ? body0 : body1;
@@ -229,10 +229,10 @@
 		btCollisionObject*	triOb = triBody;
 		btConcaveShape* concaveShape = static_cast<btConcaveShape*>( triOb->getCollisionShape());
-
-		//	if (convexBody->getCollisionShape()->isConvex())
+		
+	//	if (convexBody->getCollisionShape()->isConvex())
 		{
 			btScalar collisionMarginTriangle = concaveShape->getMargin();
-
-			//			resultOut->setPersistentManifold(m_btSoftBodyTriangleCallback.m_manifoldPtr);
+					
+//			resultOut->setPersistentManifold(m_btSoftBodyTriangleCallback.m_manifoldPtr);
 			m_btSoftBodyTriangleCallback.setTimeStepAndCounters(collisionMarginTriangle,dispatchInfo,resultOut);
 
@@ -240,13 +240,13 @@
 			//m_dispatcher->clearManifold(m_btSoftBodyTriangleCallback.m_manifoldPtr);
 
-			//			m_btSoftBodyTriangleCallback.m_manifoldPtr->setBodies(convexBody,triBody);
+//			m_btSoftBodyTriangleCallback.m_manifoldPtr->setBodies(convexBody,triBody);
 
 
 			concaveShape->processAllTriangles( &m_btSoftBodyTriangleCallback,m_btSoftBodyTriangleCallback.getAabbMin(),m_btSoftBodyTriangleCallback.getAabbMax());
-
-			//	resultOut->refreshContactPoints();
-
-		}
-
+			
+		//	resultOut->refreshContactPoints();
+	
+		}
+	
 	}
 
@@ -288,5 +288,5 @@
 		btScalar	m_ccdSphereRadius;
 		btScalar	m_hitFraction;
-
+	
 
 		LocalTriangleSphereCastCallback(const btTransform& from,const btTransform& to,btScalar ccdSphereRadius,btScalar hitFraction)
@@ -297,6 +297,6 @@
 		{			
 		}
-
-
+		
+		
 		virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
 		{
@@ -328,7 +328,7 @@
 
 
-
-
-
+	
+
+	
 	if (triBody->getCollisionShape()->isConcave())
 	{
@@ -350,10 +350,10 @@
 
 		btConcaveShape* triangleMesh = (btConcaveShape*) concavebody->getCollisionShape();
-
+		
 		if (triangleMesh)
 		{
 			triangleMesh->processAllTriangles(&raycastCallback,rayAabbMin,rayAabbMax);
 		}
-
+	
 
 
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h	(revision 1972)
@@ -36,5 +36,5 @@
 	int m_PartIdTriangleIndex;
 	class btCollisionShape*	m_childShape;
-
+	
 	btTriIndex(int partId,int triangleIndex,btCollisionShape* shape)
 	{
@@ -76,9 +76,9 @@
 
 	btHashMap<btHashKey<btTriIndex>,btTriIndex> m_shapeCache;
-
+	
 public:
-	int	m_triangleCount;
-
-	//	btPersistentManifold*	m_manifoldPtr;
+int	m_triangleCount;
+	
+//	btPersistentManifold*	m_manifoldPtr;
 
 	btSoftBodyTriangleCallback(btDispatcher* dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
@@ -89,5 +89,5 @@
 
 	virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex);
-
+	
 	void clearCache();
 
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyHelpers.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyHelpers.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyHelpers.cpp	(revision 1972)
@@ -23,55 +23,55 @@
 //
 static void				drawVertex(	btIDebugDraw* idraw,
-								   const btVector3& x,btScalar s,const btVector3& c)
-{
-	idraw->drawLine(x-btVector3(s,0,0),x+btVector3(s,0,0),c);
-	idraw->drawLine(x-btVector3(0,s,0),x+btVector3(0,s,0),c);
-	idraw->drawLine(x-btVector3(0,0,s),x+btVector3(0,0,s),c);
-}
+									const btVector3& x,btScalar s,const btVector3& c)
+	{
+		idraw->drawLine(x-btVector3(s,0,0),x+btVector3(s,0,0),c);
+		idraw->drawLine(x-btVector3(0,s,0),x+btVector3(0,s,0),c);
+		idraw->drawLine(x-btVector3(0,0,s),x+btVector3(0,0,s),c);
+	}
 
 //
 static void				drawBox(	btIDebugDraw* idraw,
-								const btVector3& mins,
-								const btVector3& maxs,
-								const btVector3& color)
-{
-	const btVector3	c[]={	btVector3(mins.x(),mins.y(),mins.z()),
-		btVector3(maxs.x(),mins.y(),mins.z()),
-		btVector3(maxs.x(),maxs.y(),mins.z()),
-		btVector3(mins.x(),maxs.y(),mins.z()),
-		btVector3(mins.x(),mins.y(),maxs.z()),
-		btVector3(maxs.x(),mins.y(),maxs.z()),
-		btVector3(maxs.x(),maxs.y(),maxs.z()),
-		btVector3(mins.x(),maxs.y(),maxs.z())};
-	idraw->drawLine(c[0],c[1],color);idraw->drawLine(c[1],c[2],color);
-	idraw->drawLine(c[2],c[3],color);idraw->drawLine(c[3],c[0],color);
-	idraw->drawLine(c[4],c[5],color);idraw->drawLine(c[5],c[6],color);
-	idraw->drawLine(c[6],c[7],color);idraw->drawLine(c[7],c[4],color);
-	idraw->drawLine(c[0],c[4],color);idraw->drawLine(c[1],c[5],color);
-	idraw->drawLine(c[2],c[6],color);idraw->drawLine(c[3],c[7],color);
+									const btVector3& mins,
+									const btVector3& maxs,
+									const btVector3& color)
+{
+const btVector3	c[]={	btVector3(mins.x(),mins.y(),mins.z()),
+						btVector3(maxs.x(),mins.y(),mins.z()),
+						btVector3(maxs.x(),maxs.y(),mins.z()),
+						btVector3(mins.x(),maxs.y(),mins.z()),
+						btVector3(mins.x(),mins.y(),maxs.z()),
+						btVector3(maxs.x(),mins.y(),maxs.z()),
+						btVector3(maxs.x(),maxs.y(),maxs.z()),
+						btVector3(mins.x(),maxs.y(),maxs.z())};
+idraw->drawLine(c[0],c[1],color);idraw->drawLine(c[1],c[2],color);
+idraw->drawLine(c[2],c[3],color);idraw->drawLine(c[3],c[0],color);
+idraw->drawLine(c[4],c[5],color);idraw->drawLine(c[5],c[6],color);
+idraw->drawLine(c[6],c[7],color);idraw->drawLine(c[7],c[4],color);
+idraw->drawLine(c[0],c[4],color);idraw->drawLine(c[1],c[5],color);
+idraw->drawLine(c[2],c[6],color);idraw->drawLine(c[3],c[7],color);
 }
 
 //
 static void				drawTree(	btIDebugDraw* idraw,
-								 const btDbvtNode* node,
-								 int depth,
-								 const btVector3& ncolor,
-								 const btVector3& lcolor,
-								 int mindepth,
-								 int maxdepth)
-{
-	if(node)
-	{
-		if(node->isinternal()&&((depth<maxdepth)||(maxdepth<0)))
-		{
-			drawTree(idraw,node->childs[0],depth+1,ncolor,lcolor,mindepth,maxdepth);
-			drawTree(idraw,node->childs[1],depth+1,ncolor,lcolor,mindepth,maxdepth);
-		}
-		if(depth>=mindepth)
-		{
-			const btScalar	scl=(btScalar)(node->isinternal()?1:1);
-			const btVector3	mi=node->volume.Center()-node->volume.Extents()*scl;
-			const btVector3	mx=node->volume.Center()+node->volume.Extents()*scl;
-			drawBox(idraw,mi,mx,node->isleaf()?lcolor:ncolor);
+									const btDbvtNode* node,
+									int depth,
+									const btVector3& ncolor,
+									const btVector3& lcolor,
+									int mindepth,
+									int maxdepth)
+{
+if(node)
+	{
+	if(node->isinternal()&&((depth<maxdepth)||(maxdepth<0)))
+		{
+		drawTree(idraw,node->childs[0],depth+1,ncolor,lcolor,mindepth,maxdepth);
+		drawTree(idraw,node->childs[1],depth+1,ncolor,lcolor,mindepth,maxdepth);
+		}
+	if(depth>=mindepth)
+		{
+		const btScalar	scl=(btScalar)(node->isinternal()?1:1);
+		const btVector3	mi=node->volume.Center()-node->volume.Extents()*scl;
+		const btVector3	mx=node->volume.Center()+node->volume.Extents()*scl;
+		drawBox(idraw,mi,mx,node->isleaf()?lcolor:ncolor);
 		}
 	}
@@ -82,14 +82,14 @@
 static inline T				sum(const btAlignedObjectArray<T>& items)
 {
-	T	v;
-	if(items.size())
-	{
-		v=items[0];
-		for(int i=1,ni=items.size();i<ni;++i)
-		{
-			v+=items[i];
-		}
-	}
-	return(v);
+T	v;
+if(items.size())
+	{
+	v=items[0];
+	for(int i=1,ni=items.size();i<ni;++i)
+		{
+		v+=items[i];
+		}
+	}
+return(v);
 }
 
@@ -98,7 +98,7 @@
 static inline void			add(btAlignedObjectArray<T>& items,const Q& value)
 {
-	for(int i=0,ni=items.size();i<ni;++i)
-	{
-		items[i]+=value;
+for(int i=0,ni=items.size();i<ni;++i)
+	{
+	items[i]+=value;
 	}
 }
@@ -108,7 +108,7 @@
 static inline void			mul(btAlignedObjectArray<T>& items,const Q& value)
 {
-	for(int i=0,ni=items.size();i<ni;++i)
-	{
-		items[i]*=value;
+for(int i=0,ni=items.size();i<ni;++i)
+	{
+	items[i]*=value;
 	}
 }
@@ -118,6 +118,6 @@
 static inline T				average(const btAlignedObjectArray<T>& items)
 {
-	const btScalar	n=(btScalar)(items.size()>0?items.size():1);
-	return(sum(items)/n);
+const btScalar	n=(btScalar)(items.size()>0?items.size():1);
+return(sum(items)/n);
 }
 
@@ -137,12 +137,12 @@
 #if 0
 static btVector3		stresscolor(btScalar stress)
-{
+	{
 	static const btVector3	spectrum[]=	{	btVector3(1,0,1),
-		btVector3(0,0,1),
-		btVector3(0,1,1),
-		btVector3(0,1,0),
-		btVector3(1,1,0),
-		btVector3(1,0,0),
-		btVector3(1,0,0)};
+											btVector3(0,0,1),
+											btVector3(0,1,1),
+											btVector3(0,1,0),
+											btVector3(1,1,0),
+											btVector3(1,0,0),
+											btVector3(1,0,0)};
 	static const int		ncolors=sizeof(spectrum)/sizeof(spectrum[0])-1;
 	static const btScalar	one=1;
@@ -151,11 +151,11 @@
 	const btScalar			frc=stress-sel;
 	return(spectrum[sel]+(spectrum[sel+1]-spectrum[sel])*frc);
-}
+	}
 #endif
 
 //
 void			btSoftBodyHelpers::Draw(	btSoftBody* psb,
-										btIDebugDraw* idraw,
-										int drawflags)
+					 btIDebugDraw* idraw,
+					 int drawflags)
 {
 	const btScalar		scl=(btScalar)0.1;
@@ -252,27 +252,27 @@
 			const btVector3			c=(x[0]+x[1]+x[2])/3;
 			idraw->drawTriangle((x[0]-c)*scl+c,
-				(x[1]-c)*scl+c,
-				(x[2]-c)*scl+c,
-				col,alp);
+								(x[1]-c)*scl+c,
+								(x[2]-c)*scl+c,
+								col,alp);
 		}	
 	}
 	/* Clusters	*/ 
 	if(0!=(drawflags&fDrawFlags::Clusters))
-	{
+		{
 		srand(1806);
 		for(i=0;i<psb->m_clusters.size();++i)
-		{
+			{
 			if(psb->m_clusters[i]->m_collide)
-			{
+				{
 				btVector3						color(	rand()/(btScalar)RAND_MAX,
-					rand()/(btScalar)RAND_MAX,
-					rand()/(btScalar)RAND_MAX);
+														rand()/(btScalar)RAND_MAX,
+														rand()/(btScalar)RAND_MAX);
 				color=color.normalized()*0.75;
 				btAlignedObjectArray<btVector3>	vertices;
 				vertices.resize(psb->m_clusters[i]->m_nodes.size());
 				for(j=0,nj=vertices.size();j<nj;++j)
-				{				
+					{				
 					vertices[j]=psb->m_clusters[i]->m_nodes[j]->m_x;
-				}
+					}
 				HullDesc		hdsc(QF_TRIANGLES,vertices.size(),&vertices[0]);
 				HullResult		hres;
@@ -285,23 +285,23 @@
 				add(hres.m_OutputVertices,center);
 				for(j=0;j<(int)hres.mNumFaces;++j)
-				{
+					{
 					const int idx[]={hres.m_Indices[j*3+0],hres.m_Indices[j*3+1],hres.m_Indices[j*3+2]};
 					idraw->drawTriangle(hres.m_OutputVertices[idx[0]],
-						hres.m_OutputVertices[idx[1]],
-						hres.m_OutputVertices[idx[2]],
-						color,1);
+										hres.m_OutputVertices[idx[1]],
+										hres.m_OutputVertices[idx[2]],
+										color,1);
+					}
+				hlib.ReleaseResult(hres);
 				}
-				hlib.ReleaseResult(hres);
-			}
 			/* Velocities	*/ 
-#if 0
+			#if 0
 			for(int j=0;j<psb->m_clusters[i].m_nodes.size();++j)
-			{
+				{
 				const btSoftBody::Cluster&	c=psb->m_clusters[i];
 				const btVector3				r=c.m_nodes[j]->m_x-c.m_com;
 				const btVector3				v=c.m_lv+cross(c.m_av,r);
 				idraw->drawLine(c.m_nodes[j]->m_x,c.m_nodes[j]->m_x+v,btVector3(1,0,0));
-			}
-#endif
+				}
+			#endif
 			/* Frame		*/ 
 			btSoftBody::Cluster& c=*psb->m_clusters[i];
@@ -309,6 +309,6 @@
 			idraw->drawLine(c.m_com,c.m_framexform*btVector3(0,10,0),btVector3(0,1,0));
 			idraw->drawLine(c.m_com,c.m_framexform*btVector3(0,0,10),btVector3(0,0,1));
-		}
-	}
+			}
+		}
 	/* Notes	*/ 
 	if(0!=(drawflags&fDrawFlags::Notes))
@@ -319,7 +319,7 @@
 			btVector3				p=n.m_offset;
 			for(int j=0;j<n.m_rank;++j)
-			{
+				{
 				p+=n.m_nodes[j]->m_x*n.m_coords[j];
-			}
+				}
 			idraw->draw3dText(p,n.m_text);
 		}
@@ -334,31 +334,31 @@
 	if(0!=(drawflags&fDrawFlags::Joints))
 	{
-		for(i=0;i<psb->m_joints.size();++i)
-		{
-			const btSoftBody::Joint*	pj=psb->m_joints[i];
-			switch(pj->Type())
+	for(i=0;i<psb->m_joints.size();++i)
+		{
+		const btSoftBody::Joint*	pj=psb->m_joints[i];
+		switch(pj->Type())
 			{
 			case	btSoftBody::Joint::eType::Linear:
 				{
-					const btSoftBody::LJoint*	pjl=(const btSoftBody::LJoint*)pj;
-					const btVector3	a0=pj->m_bodies[0].xform()*pjl->m_refs[0];
-					const btVector3	a1=pj->m_bodies[1].xform()*pjl->m_refs[1];
-					idraw->drawLine(pj->m_bodies[0].xform().getOrigin(),a0,btVector3(1,1,0));
-					idraw->drawLine(pj->m_bodies[1].xform().getOrigin(),a1,btVector3(0,1,1));
-					drawVertex(idraw,a0,0.25,btVector3(1,1,0));
-					drawVertex(idraw,a1,0.25,btVector3(0,1,1));
+				const btSoftBody::LJoint*	pjl=(const btSoftBody::LJoint*)pj;
+				const btVector3	a0=pj->m_bodies[0].xform()*pjl->m_refs[0];
+				const btVector3	a1=pj->m_bodies[1].xform()*pjl->m_refs[1];
+				idraw->drawLine(pj->m_bodies[0].xform().getOrigin(),a0,btVector3(1,1,0));
+				idraw->drawLine(pj->m_bodies[1].xform().getOrigin(),a1,btVector3(0,1,1));
+				drawVertex(idraw,a0,0.25,btVector3(1,1,0));
+				drawVertex(idraw,a1,0.25,btVector3(0,1,1));
 				}
-				break;
+			break;
 			case	btSoftBody::Joint::eType::Angular:
 				{
-					const btSoftBody::AJoint*	pja=(const btSoftBody::AJoint*)pj;
-					const btVector3	o0=pj->m_bodies[0].xform().getOrigin();
-					const btVector3	o1=pj->m_bodies[1].xform().getOrigin();
-					const btVector3	a0=pj->m_bodies[0].xform().getBasis()*pj->m_refs[0];
-					const btVector3	a1=pj->m_bodies[1].xform().getBasis()*pj->m_refs[1];
-					idraw->drawLine(o0,o0+a0*10,btVector3(1,1,0));
-					idraw->drawLine(o0,o0+a1*10,btVector3(1,1,0));
-					idraw->drawLine(o1,o1+a0*10,btVector3(0,1,1));
-					idraw->drawLine(o1,o1+a1*10,btVector3(0,1,1));
+				const btSoftBody::AJoint*	pja=(const btSoftBody::AJoint*)pj;
+				const btVector3	o0=pj->m_bodies[0].xform().getOrigin();
+				const btVector3	o1=pj->m_bodies[1].xform().getOrigin();
+				const btVector3	a0=pj->m_bodies[0].xform().getBasis()*pj->m_refs[0];
+				const btVector3	a1=pj->m_bodies[1].xform().getBasis()*pj->m_refs[1];
+				idraw->drawLine(o0,o0+a0*10,btVector3(1,1,0));
+				idraw->drawLine(o0,o0+a1*10,btVector3(1,1,0));
+				idraw->drawLine(o1,o1+a0*10,btVector3(0,1,1));
+				idraw->drawLine(o1,o1+a1*10,btVector3(0,1,1));
 				}
 			}		
@@ -369,8 +369,8 @@
 //
 void			btSoftBodyHelpers::DrawInfos(		btSoftBody* psb,
-											 btIDebugDraw* idraw,
-											 bool masses,
-											 bool areas,
-											 bool /*stress*/)
+						  btIDebugDraw* idraw,
+						  bool masses,
+						  bool areas,
+						  bool /*stress*/)
 {
 	for(int i=0;i<psb->m_nodes.size();++i)
@@ -395,32 +395,32 @@
 //
 void			btSoftBodyHelpers::DrawNodeTree(	btSoftBody* psb,
-												btIDebugDraw* idraw,
-												int mindepth,
-												int maxdepth)
-{
-	drawTree(idraw,psb->m_ndbvt.m_root,0,btVector3(1,0,1),btVector3(1,1,1),mindepth,maxdepth);
+													btIDebugDraw* idraw,
+													int mindepth,
+													int maxdepth)
+{
+drawTree(idraw,psb->m_ndbvt.m_root,0,btVector3(1,0,1),btVector3(1,1,1),mindepth,maxdepth);
 }
 
 //
 void			btSoftBodyHelpers::DrawFaceTree(	btSoftBody* psb,
-												btIDebugDraw* idraw,
-												int mindepth,
-												int maxdepth)
-{
-	drawTree(idraw,psb->m_fdbvt.m_root,0,btVector3(0,1,0),btVector3(1,0,0),mindepth,maxdepth);
+													btIDebugDraw* idraw,
+													int mindepth,
+													int maxdepth)
+{
+drawTree(idraw,psb->m_fdbvt.m_root,0,btVector3(0,1,0),btVector3(1,0,0),mindepth,maxdepth);
 }
 
 //
 void			btSoftBodyHelpers::DrawClusterTree(	btSoftBody* psb,
-												   btIDebugDraw* idraw,
-												   int mindepth,
-												   int maxdepth)
-{
-	drawTree(idraw,psb->m_cdbvt.m_root,0,btVector3(0,1,1),btVector3(1,0,0),mindepth,maxdepth);
+													btIDebugDraw* idraw,
+													int mindepth,
+													int maxdepth)
+{
+drawTree(idraw,psb->m_cdbvt.m_root,0,btVector3(0,1,1),btVector3(1,0,0),mindepth,maxdepth);
 }
 
 //
 void			btSoftBodyHelpers::DrawFrame(		btSoftBody* psb,
-											 btIDebugDraw* idraw)
+						  btIDebugDraw* idraw)
 {
 	if(psb->m_pose.m_bframe)
@@ -446,7 +446,7 @@
 //
 btSoftBody*		btSoftBodyHelpers::CreateRope(	btSoftBodyWorldInfo& worldInfo, const btVector3& from,
-											  const btVector3& to,
-											  int res,
-											  int fixeds)
+						   const btVector3& to,
+						   int res,
+						   int fixeds)
 {
 	/* Create nodes	*/ 
@@ -478,11 +478,11 @@
 //
 btSoftBody*		btSoftBodyHelpers::CreatePatch(btSoftBodyWorldInfo& worldInfo,const btVector3& corner00,
-											   const btVector3& corner10,
-											   const btVector3& corner01,
-											   const btVector3& corner11,
-											   int resx,
-											   int resy,
-											   int fixeds,
-											   bool gendiags)
+							const btVector3& corner10,
+							const btVector3& corner01,
+							const btVector3& corner11,
+							int resx,
+							int resy,
+							int fixeds,
+							bool gendiags)
 {
 #define IDX(_x_,_y_)	((_y_)*rx+(_x_))
@@ -554,211 +554,7 @@
 
 //
-btSoftBody*		btSoftBodyHelpers::CreatePatchUV(btSoftBodyWorldInfo& worldInfo,
-												 const btVector3& corner00,
-												 const btVector3& corner10,
-												 const btVector3& corner01,
-												 const btVector3& corner11,
-												 int resx,
-												 int resy,
-												 int fixeds,
-												 bool gendiags,
-												 float* tex_coords)
-{
-
-	/*
-	*
-	*  corners:
-	*
-	*  [0][0]     corner00 ------- corner01   [resx][0]
-	*                |                |
-	*                |                |
-	*  [0][resy]  corner10 -------- corner11  [resx][resy]
-	*
-	*
-	*
-	*
-	*
-	*
-	*   "fixedgs" map:
-	*
-	*  corner00     -->   +1
-	*  corner01     -->   +2
-	*  corner10     -->   +4
-	*  corner11     -->   +8
-	*  upper middle -->  +16
-	*  left middle  -->  +32
-	*  right middle -->  +64
-	*  lower middle --> +128
-	*  center       --> +256
-	*
-	*
-	*   tex_coords size   (resx-1)*(resy-1)*12
-	*
-	*
-	*
-	*     SINGLE QUAD INTERNALS
-	*
-	*  1) btSoftBody's nodes and links,
-	*     diagonal link is optional ("gendiags")
-	*
-	*
-	*    node00 ------ node01
-	*      | .              
-	*      |   .            
-	*      |     .          
-	*      |       .        
-	*      |         .      
-	*    node10        node11
-	*
-	*
-	*
-	*   2) Faces:
-	*      two triangles,
-	*      UV Coordinates (hier example for single quad)
-	*      
-	*     (0,1)          (0,1)  (1,1)
-	*     1 |\            3 \-----| 2
-	*       | \              \    |
-	*       |  \              \   |
-	*       |   \              \  |
-	*       |    \              \ |
-	*     2 |-----\ 3            \| 1
-	*     (0,0)    (1,0)       (1,0)
-	*
-	*
-	*
-	*
-	*
-	*
-	*/
-
-#define IDX(_x_,_y_)	((_y_)*rx+(_x_))
-	/* Create nodes		*/ 
-	if((resx<2)||(resy<2)) return(0);
-	const int	rx=resx;
-	const int	ry=resy;
-	const int	tot=rx*ry;
-	btVector3*	x=new btVector3[tot];
-	btScalar*	m=new btScalar[tot];
-
-	for(int iy=0;iy<ry;++iy)
-	{
-		const btScalar	ty=iy/(btScalar)(ry-1);
-		const btVector3	py0=lerp(corner00,corner01,ty);
-		const btVector3	py1=lerp(corner10,corner11,ty);
-		for(int ix=0;ix<rx;++ix)
-		{
-			const btScalar	tx=ix/(btScalar)(rx-1);
-			x[IDX(ix,iy)]=lerp(py0,py1,tx);
-			m[IDX(ix,iy)]=1;
-		}
-	}
-	btSoftBody*	psb=new btSoftBody(&worldInfo,tot,x,m);
-	if(fixeds&1)		psb->setMass(IDX(0,0),0);
-	if(fixeds&2)		psb->setMass(IDX(rx-1,0),0);
-	if(fixeds&4)		psb->setMass(IDX(0,ry-1),0);
-	if(fixeds&8)		psb->setMass(IDX(rx-1,ry-1),0);
-	if(fixeds&16)		psb->setMass(IDX((rx-1)/2,0),0);
-	if(fixeds&32)		psb->setMass(IDX(0,(ry-1)/2),0);
-	if(fixeds&64)		psb->setMass(IDX(rx-1,(ry-1)/2),0);
-	if(fixeds&128)		psb->setMass(IDX((rx-1)/2,ry-1),0);
-	if(fixeds&256)		psb->setMass(IDX((rx-1)/2,(ry-1)/2),0);
-	delete[] x;
-	delete[] m;
-
-
-	int z = 0;
-	/* Create links	and faces	*/ 
-	for(int iy=0;iy<ry;++iy)
-	{
-		for(int ix=0;ix<rx;++ix)
-		{
-			const bool	mdx=(ix+1)<rx;
-			const bool	mdy=(iy+1)<ry;
-
-			int node00=IDX(ix,iy);
-			int node01=IDX(ix+1,iy);
-			int node10=IDX(ix,iy+1);
-			int node11=IDX(ix+1,iy+1);
-
-			if(mdx) psb->appendLink(node00,node01);
-			if(mdy) psb->appendLink(node00,node10);
-			if(mdx&&mdy)
-			{
-				psb->appendFace(node00,node10,node11);
-				if (tex_coords) {
-					tex_coords[z+0]=CalculateUV(resx,resy,ix,iy,0);
-					tex_coords[z+1]=CalculateUV(resx,resy,ix,iy,1);
-					tex_coords[z+2]=CalculateUV(resx,resy,ix,iy,0);
-					tex_coords[z+3]=CalculateUV(resx,resy,ix,iy,2);
-					tex_coords[z+4]=CalculateUV(resx,resy,ix,iy,3);
-					tex_coords[z+5]=CalculateUV(resx,resy,ix,iy,2);
-				}
-				psb->appendFace(node11,node01,node00);
-				if (tex_coords) {
-					tex_coords[z+6 ]=CalculateUV(resx,resy,ix,iy,3);
-					tex_coords[z+7 ]=CalculateUV(resx,resy,ix,iy,2);
-					tex_coords[z+8 ]=CalculateUV(resx,resy,ix,iy,3);
-					tex_coords[z+9 ]=CalculateUV(resx,resy,ix,iy,1);
-					tex_coords[z+10]=CalculateUV(resx,resy,ix,iy,0);
-					tex_coords[z+11]=CalculateUV(resx,resy,ix,iy,1);
-				}
-				if (gendiags) psb->appendLink(node00,node11);
-				z += 12;
-			}
-		}
-	}
-	/* Finished	*/ 
-#undef IDX
-	return(psb);
-}
-
-float   btSoftBodyHelpers::CalculateUV(int resx,int resy,int ix,int iy,int id)
-{
-
-	/*
-	*
-	*
-	*    node00 --- node01
-	*      |          |
-	*    node10 --- node11
-	*
-	*
-	*   ID map:
-	*
-	*   node00 s --> 0
-	*   node00 t --> 1
-	*
-	*   node01 s --> 3
-	*   node01 t --> 1
-	*
-	*   node10 s --> 0
-	*   node10 t --> 2
-	*
-	*   node11 s --> 3
-	*   node11 t --> 2
-	*
-	*
-	*/
-
-	float tc=0.0f;
-	if (id == 0) {
-		tc = (1.0f/((resx-1))*ix);
-	}
-	else if (id==1) {
-		tc = (1.0f/((resy-1))*(resy-1-iy));
-	}
-	else if (id==2) {
-		tc = (1.0f/((resy-1))*(resy-1-iy-1));
-	}
-	else if (id==3) {
-		tc = (1.0f/((resx-1))*(ix+1));
-	}
-	return tc;
-}
-//
 btSoftBody*		btSoftBodyHelpers::CreateEllipsoid(btSoftBodyWorldInfo& worldInfo,const btVector3& center,
-												   const btVector3& radius,
-												   int res)
+								const btVector3& radius,
+								int res)
 {
 	struct	Hammersley
@@ -791,6 +587,6 @@
 //
 btSoftBody*		btSoftBodyHelpers::CreateFromTriMesh(btSoftBodyWorldInfo& worldInfo,const btScalar*	vertices,
-													 const int* triangles,
-													 int ntriangles)
+								  const int* triangles,
+								  int ntriangles)
 {
 	int		maxidx=0;
@@ -833,5 +629,5 @@
 //
 btSoftBody*		btSoftBodyHelpers::CreateFromConvexHull(btSoftBodyWorldInfo& worldInfo,	const btVector3* vertices,
-														int nvertices)
+									 int nvertices)
 {
 	HullDesc		hdsc(QF_TRIANGLES,nvertices,vertices);
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyHelpers.h
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyHelpers.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyHelpers.h	(revision 1972)
@@ -47,72 +47,60 @@
 	/* Draw body															*/ 
 	static void				Draw(		btSoftBody* psb,
-		btIDebugDraw* idraw,
-		int drawflags=fDrawFlags::Std);
+										btIDebugDraw* idraw,
+										int drawflags=fDrawFlags::Std);
 	/* Draw body infos														*/ 
 	static	void			DrawInfos(	btSoftBody* psb,
-		btIDebugDraw* idraw,
-		bool masses,
-		bool areas,
-		bool stress);
+										btIDebugDraw* idraw,
+										bool masses,
+										bool areas,
+										bool stress);
 	/* Draw node tree														*/ 
 	static void				DrawNodeTree(	btSoftBody* psb,
-		btIDebugDraw* idraw,
-		int mindepth=0,
-		int maxdepth=-1);
+											btIDebugDraw* idraw,
+											int mindepth=0,
+											int maxdepth=-1);
 	/* Draw face tree														*/ 
 	static void				DrawFaceTree(	btSoftBody* psb,
-		btIDebugDraw* idraw,
-		int mindepth=0,
-		int maxdepth=-1);
+											btIDebugDraw* idraw,
+											int mindepth=0,
+											int maxdepth=-1);
 	/* Draw cluster tree													*/ 
 	static void				DrawClusterTree(btSoftBody* psb,
-		btIDebugDraw* idraw,
-		int mindepth=0,
-		int maxdepth=-1);
+											btIDebugDraw* idraw,
+											int mindepth=0,
+											int maxdepth=-1);
 	/* Draw rigid frame														*/ 
 	static	void			DrawFrame(		btSoftBody* psb,
-		btIDebugDraw* idraw);
+											btIDebugDraw* idraw);
 	/* Create a rope														*/ 
 	static	btSoftBody*		CreateRope( btSoftBodyWorldInfo& worldInfo,
-		const btVector3& from,
-		const btVector3& to,
-		int res,
-		int fixeds);
+										const btVector3& from,
+										const btVector3& to,
+										int res,
+										int fixeds);
 	/* Create a patch														*/ 
 	static	btSoftBody*		CreatePatch(btSoftBodyWorldInfo& worldInfo,
-		const btVector3& corner00,
-		const btVector3& corner10,
-		const btVector3& corner01,
-		const btVector3& corner11,
-		int resx,
-		int resy,
-		int fixeds,
-		bool gendiags);
-	/* Create a patch with UV Texture Coordinates	*/ 
-	static	btSoftBody*		CreatePatchUV(btSoftBodyWorldInfo& worldInfo,
-		const btVector3& corner00,
-		const btVector3& corner10,
-		const btVector3& corner01,
-		const btVector3& corner11,
-		int resx,
-		int resy,
-		int fixeds,
-		bool gendiags,
-		float* tex_coords=0);
-	static	float	CalculateUV(int resx,int resy,int ix,int iy,int id);
+										const btVector3& corner00,
+										const btVector3& corner10,
+										const btVector3& corner01,
+										const btVector3& corner11,
+										int resx,
+										int resy,
+										int fixeds,
+										bool gendiags);
 	/* Create an ellipsoid													*/ 
 	static	btSoftBody*		CreateEllipsoid(btSoftBodyWorldInfo& worldInfo,
-		const btVector3& center,
-		const btVector3& radius,
-		int res);	
+											const btVector3& center,
+											const btVector3& radius,
+											int res);	
 	/* Create from trimesh													*/ 
 	static	btSoftBody*		CreateFromTriMesh(	btSoftBodyWorldInfo& worldInfo,
-		const btScalar*	vertices,
-		const int* triangles,
-		int ntriangles);
+												const btScalar*	vertices,
+												const int* triangles,
+												int ntriangles);
 	/* Create from convex-hull												*/ 
 	static	btSoftBody*		CreateFromConvexHull(	btSoftBodyWorldInfo& worldInfo,
-		const btVector3* vertices,
-		int nvertices);
+													const btVector3* vertices,
+													int nvertices);
 };
 
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyInternals.h
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyInternals.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyInternals.h	(revision 1972)
@@ -32,12 +32,12 @@
 struct btSymMatrix
 {
-	btSymMatrix() : dim(0)					{}
-	btSymMatrix(int n,const T& init=T())	{ resize(n,init); }
-	void					resize(int n,const T& init=T())			{ dim=n;store.resize((n*(n+1))/2,init); }
-	int						index(int c,int r) const				{ if(c>r) btSwap(c,r);btAssert(r<dim);return((r*(r+1))/2+c); }
-	T&						operator()(int c,int r)					{ return(store[index(c,r)]); }
-	const T&				operator()(int c,int r) const			{ return(store[index(c,r)]); }
-	btAlignedObjectArray<T>	store;
-	int						dim;
+						btSymMatrix() : dim(0)					{}
+						btSymMatrix(int n,const T& init=T())	{ resize(n,init); }
+void					resize(int n,const T& init=T())			{ dim=n;store.resize((n*(n+1))/2,init); }
+int						index(int c,int r) const				{ if(c>r) btSwap(c,r);btAssert(r<dim);return((r*(r+1))/2+c); }
+T&						operator()(int c,int r)					{ return(store[index(c,r)]); }
+const T&				operator()(int c,int r) const			{ return(store[index(c,r)]); }
+btAlignedObjectArray<T>	store;
+int						dim;
 };	
 
@@ -49,5 +49,5 @@
 public:
 	btSoftBody*						m_body;
-
+	
 	btSoftBodyCollisionShape(btSoftBody* backptr)
 	{
@@ -70,24 +70,24 @@
 	virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
 	{
-		/* t should be identity, but better be safe than...fast? */ 
-		const btVector3	mins=m_body->m_bounds[0];
-		const btVector3	maxs=m_body->m_bounds[1];
-		const btVector3	crns[]={t*btVector3(mins.x(),mins.y(),mins.z()),
-			t*btVector3(maxs.x(),mins.y(),mins.z()),
-			t*btVector3(maxs.x(),maxs.y(),mins.z()),
-			t*btVector3(mins.x(),maxs.y(),mins.z()),
-			t*btVector3(mins.x(),mins.y(),maxs.z()),
-			t*btVector3(maxs.x(),mins.y(),maxs.z()),
-			t*btVector3(maxs.x(),maxs.y(),maxs.z()),
-			t*btVector3(mins.x(),maxs.y(),maxs.z())};
-		aabbMin=aabbMax=crns[0];
-		for(int i=1;i<8;++i)
-		{
-			aabbMin.setMin(crns[i]);
-			aabbMax.setMax(crns[i]);
-		}
-	}
-
-
+	/* t should be identity, but better be safe than...fast? */ 
+	const btVector3	mins=m_body->m_bounds[0];
+	const btVector3	maxs=m_body->m_bounds[1];
+	const btVector3	crns[]={t*btVector3(mins.x(),mins.y(),mins.z()),
+							t*btVector3(maxs.x(),mins.y(),mins.z()),
+							t*btVector3(maxs.x(),maxs.y(),mins.z()),
+							t*btVector3(mins.x(),maxs.y(),mins.z()),
+							t*btVector3(mins.x(),mins.y(),maxs.z()),
+							t*btVector3(maxs.x(),mins.y(),maxs.z()),
+							t*btVector3(maxs.x(),maxs.y(),maxs.z()),
+							t*btVector3(mins.x(),maxs.y(),maxs.z())};
+	aabbMin=aabbMax=crns[0];
+	for(int i=1;i<8;++i)
+		{
+		aabbMin.setMin(crns[i]);
+		aabbMax.setMax(crns[i]);
+		}
+	}
+
+	
 	virtual void	setLocalScaling(const btVector3& /*scaling*/)
 	{		
@@ -96,6 +96,6 @@
 	virtual const btVector3& getLocalScaling() const
 	{
-		static const btVector3 dummy(1,1,1);
-		return dummy;
+	static const btVector3 dummy(1,1,1);
+	return dummy;
 	}
 	virtual void	calculateLocalInertia(btScalar /*mass*/,btVector3& /*inertia*/) const
@@ -120,22 +120,22 @@
 
 	btSoftClusterCollisionShape (const btSoftBody::Cluster* cluster) : m_cluster(cluster) { setMargin(0); }
-
-
+	
+	
 	virtual btVector3	localGetSupportingVertex(const btVector3& vec) const
-	{
+		{
 		btSoftBody::Node* const *						n=&m_cluster->m_nodes[0];
 		btScalar										d=dot(vec,n[0]->m_x);
 		int												j=0;
 		for(int i=1,ni=m_cluster->m_nodes.size();i<ni;++i)
-		{
+			{
 			const btScalar	k=dot(vec,n[i]->m_x);
 			if(k>d) { d=k;j=i; }
-		}
+			}
 		return(n[j]->m_x);
-	}
+		}
 	virtual btVector3	localGetSupportingVertexWithoutMargin(const btVector3& vec)const
-	{
+		{
 		return(localGetSupportingVertex(vec));
-	}
+		}
 	//notice that the vectors should be unit length
 	virtual void	batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
@@ -150,5 +150,5 @@
 
 	virtual int	getShapeType() const { return SOFTBODY_SHAPE_PROXYTYPE; }
-
+	
 	//debugging
 	virtual const char*	getName()const {return "SOFTCLUSTER";}
@@ -172,6 +172,6 @@
 static inline void			ZeroInitialize(T& value)
 {
-	static const T	zerodummy;
-	value=zerodummy;
+static const T	zerodummy;
+value=zerodummy;
 }
 //
@@ -193,21 +193,21 @@
 //
 static inline btMatrix3x3	Lerp(	const btMatrix3x3& a,
-								 const btMatrix3x3& b,
-								 btScalar t)
-{
-	btMatrix3x3	r;
-	r[0]=Lerp(a[0],b[0],t);
-	r[1]=Lerp(a[1],b[1],t);
-	r[2]=Lerp(a[2],b[2],t);
-	return(r);
+									const btMatrix3x3& b,
+									btScalar t)
+{
+btMatrix3x3	r;
+r[0]=Lerp(a[0],b[0],t);
+r[1]=Lerp(a[1],b[1],t);
+r[2]=Lerp(a[2],b[2],t);
+return(r);
 }
 //
 static inline btVector3		Clamp(const btVector3& v,btScalar maxlength)
 {
-	const btScalar sql=v.length2();
-	if(sql>(maxlength*maxlength))
-		return((v*maxlength)/btSqrt(sql));
+const btScalar sql=v.length2();
+if(sql>(maxlength*maxlength))
+	return((v*maxlength)/btSqrt(sql));
 	else
-		return(v);
+	return(v);
 }
 //
@@ -234,6 +234,6 @@
 static inline btScalar		ClusterMetric(const btVector3& x,const btVector3& y)
 {
-	const btVector3	d=x-y;
-	return(btFabs(d[0])+btFabs(d[1])+btFabs(d[2]));
+const btVector3	d=x-y;
+return(btFabs(d[0])+btFabs(d[1])+btFabs(d[2]));
 }
 //
@@ -272,5 +272,5 @@
 //
 static inline btMatrix3x3	Add(const btMatrix3x3& a,
-								const btMatrix3x3& b)
+	const btMatrix3x3& b)
 {
 	btMatrix3x3	r;
@@ -280,5 +280,5 @@
 //
 static inline btMatrix3x3	Sub(const btMatrix3x3& a,
-								const btMatrix3x3& b)
+	const btMatrix3x3& b)
 {
 	btMatrix3x3	r;
@@ -288,5 +288,5 @@
 //
 static inline btMatrix3x3	Mul(const btMatrix3x3& a,
-								btScalar b)
+	btScalar b)
 {
 	btMatrix3x3	r;
@@ -297,7 +297,7 @@
 static inline void			Orthogonalize(btMatrix3x3& m)
 {
-	m[2]=cross(m[0],m[1]).normalized();
-	m[1]=cross(m[2],m[0]).normalized();
-	m[0]=cross(m[1],m[2]).normalized();
+m[2]=cross(m[0],m[1]).normalized();
+m[1]=cross(m[2],m[0]).normalized();
+m[0]=cross(m[1],m[2]).normalized();
 }
 //
@@ -310,8 +310,8 @@
 //
 static inline btMatrix3x3	ImpulseMatrix(	btScalar dt,
-										  btScalar ima,
-										  btScalar imb,
-										  const btMatrix3x3& iwi,
-										  const btVector3& r)
+	btScalar ima,
+	btScalar imb,
+	const btMatrix3x3& iwi,
+	const btVector3& r)
 {
 	return(Diagonal(1/dt)*Add(Diagonal(ima),MassMatrix(imb,iwi,r)).inverse());
@@ -320,19 +320,19 @@
 //
 static inline btMatrix3x3	ImpulseMatrix(	btScalar ima,const btMatrix3x3& iia,const btVector3& ra,
-										  btScalar imb,const btMatrix3x3& iib,const btVector3& rb)	
-{
-	return(Add(MassMatrix(ima,iia,ra),MassMatrix(imb,iib,rb)).inverse());
+											btScalar imb,const btMatrix3x3& iib,const btVector3& rb)	
+{
+return(Add(MassMatrix(ima,iia,ra),MassMatrix(imb,iib,rb)).inverse());
 }
 
 //
 static inline btMatrix3x3	AngularImpulseMatrix(	const btMatrix3x3& iia,
-												 const btMatrix3x3& iib)
-{
-	return(Add(iia,iib).inverse());
+													const btMatrix3x3& iib)
+{
+return(Add(iia,iib).inverse());
 }
 
 //
 static inline btVector3		ProjectOnAxis(	const btVector3& v,
-										  const btVector3& a)
+	const btVector3& a)
 {
 	return(a*dot(v,a));
@@ -340,5 +340,5 @@
 //
 static inline btVector3		ProjectOnPlane(	const btVector3& v,
-										   const btVector3& a)
+	const btVector3& a)
 {
 	return(v-ProjectOnAxis(v,a));
@@ -347,51 +347,51 @@
 //
 static inline void			ProjectOrigin(	const btVector3& a,
-										  const btVector3& b,
-										  btVector3& prj,
-										  btScalar& sqd)
-{
-	const btVector3	d=b-a;
-	const btScalar	m2=d.length2();
-	if(m2>SIMD_EPSILON)
+											const btVector3& b,
+											btVector3& prj,
+											btScalar& sqd)
+{
+const btVector3	d=b-a;
+const btScalar	m2=d.length2();
+if(m2>SIMD_EPSILON)
 	{	
-		const btScalar	t=Clamp<btScalar>(-dot(a,d)/m2,0,1);
-		const btVector3	p=a+d*t;
-		const btScalar	l2=p.length2();
-		if(l2<sqd)
-		{
+	const btScalar	t=Clamp<btScalar>(-dot(a,d)/m2,0,1);
+	const btVector3	p=a+d*t;
+	const btScalar	l2=p.length2();
+	if(l2<sqd)
+		{
+		prj=p;
+		sqd=l2;
+		}
+	}
+}
+//
+static inline void			ProjectOrigin(	const btVector3& a,
+											const btVector3& b,
+											const btVector3& c,
+											btVector3& prj,
+											btScalar& sqd)
+{
+const btVector3&	q=cross(b-a,c-a);
+const btScalar		m2=q.length2();
+if(m2>SIMD_EPSILON)
+	{
+	const btVector3	n=q/btSqrt(m2);
+	const btScalar	k=dot(a,n);
+	const btScalar	k2=k*k;
+	if(k2<sqd)
+		{
+		const btVector3	p=n*k;
+		if(	(dot(cross(a-p,b-p),q)>0)&&
+			(dot(cross(b-p,c-p),q)>0)&&
+			(dot(cross(c-p,a-p),q)>0))
+			{			
 			prj=p;
-			sqd=l2;
-		}
-	}
-}
-//
-static inline void			ProjectOrigin(	const btVector3& a,
-										  const btVector3& b,
-										  const btVector3& c,
-										  btVector3& prj,
-										  btScalar& sqd)
-{
-	const btVector3&	q=cross(b-a,c-a);
-	const btScalar		m2=q.length2();
-	if(m2>SIMD_EPSILON)
-	{
-		const btVector3	n=q/btSqrt(m2);
-		const btScalar	k=dot(a,n);
-		const btScalar	k2=k*k;
-		if(k2<sqd)
-		{
-			const btVector3	p=n*k;
-			if(	(dot(cross(a-p,b-p),q)>0)&&
-				(dot(cross(b-p,c-p),q)>0)&&
-				(dot(cross(c-p,a-p),q)>0))
-			{			
-				prj=p;
-				sqd=k2;
+			sqd=k2;
 			}
 			else
 			{
-				ProjectOrigin(a,b,prj,sqd);
-				ProjectOrigin(b,c,prj,sqd);
-				ProjectOrigin(c,a,prj,sqd);
+			ProjectOrigin(a,b,prj,sqd);
+			ProjectOrigin(b,c,prj,sqd);
+			ProjectOrigin(c,a,prj,sqd);
 			}
 		}
@@ -402,7 +402,7 @@
 template <typename T>
 static inline T				BaryEval(		const T& a,
-									 const T& b,
-									 const T& c,
-									 const btVector3& coord)
+											const T& b,
+											const T& c,
+											const btVector3& coord)
 {
 	return(a*coord.x()+b*coord.y()+c*coord.z());
@@ -410,43 +410,43 @@
 //
 static inline btVector3		BaryCoord(	const btVector3& a,
-									  const btVector3& b,
-									  const btVector3& c,
-									  const btVector3& p)
-{
-	const btScalar	w[]={	cross(a-p,b-p).length(),
-		cross(b-p,c-p).length(),
-		cross(c-p,a-p).length()};
-	const btScalar	isum=1/(w[0]+w[1]+w[2]);
-	return(btVector3(w[1]*isum,w[2]*isum,w[0]*isum));
+										const btVector3& b,
+										const btVector3& c,
+										const btVector3& p)
+{
+const btScalar	w[]={	cross(a-p,b-p).length(),
+						cross(b-p,c-p).length(),
+						cross(c-p,a-p).length()};
+const btScalar	isum=1/(w[0]+w[1]+w[2]);
+return(btVector3(w[1]*isum,w[2]*isum,w[0]*isum));
 }
 
 //
 static btScalar				ImplicitSolve(	btSoftBody::ImplicitFn* fn,
-										  const btVector3& a,
-										  const btVector3& b,
-										  const btScalar accuracy,
-										  const int maxiterations=256)
-{
-	btScalar	span[2]={0,1};
-	btScalar	values[2]={fn->Eval(a),fn->Eval(b)};
-	if(values[0]>values[1])
-	{
-		btSwap(span[0],span[1]);
-		btSwap(values[0],values[1]);
-	}
-	if(values[0]>-accuracy) return(-1);
-	if(values[1]<+accuracy) return(-1);
-	for(int i=0;i<maxiterations;++i)
-	{
-		const btScalar	t=Lerp(span[0],span[1],values[0]/(values[0]-values[1]));
-		const btScalar	v=fn->Eval(Lerp(a,b,t));
-		if((t<=0)||(t>=1))		break;
-		if(btFabs(v)<accuracy)	return(t);
-		if(v<0)
+											const btVector3& a,
+											const btVector3& b,
+											const btScalar accuracy,
+											const int maxiterations=256)
+{
+btScalar	span[2]={0,1};
+btScalar	values[2]={fn->Eval(a),fn->Eval(b)};
+if(values[0]>values[1])
+	{
+	btSwap(span[0],span[1]);
+	btSwap(values[0],values[1]);
+	}
+if(values[0]>-accuracy) return(-1);
+if(values[1]<+accuracy) return(-1);
+for(int i=0;i<maxiterations;++i)
+	{
+	const btScalar	t=Lerp(span[0],span[1],values[0]/(values[0]-values[1]));
+	const btScalar	v=fn->Eval(Lerp(a,b,t));
+	if((t<=0)||(t>=1))		break;
+	if(btFabs(v)<accuracy)	return(t);
+	if(v<0)
 		{ span[0]=t;values[0]=v; }
 		else
 		{ span[1]=t;values[1]=v; }
 	}
-	return(-1);
+return(-1);
 }
 
@@ -463,12 +463,12 @@
 //
 static inline btDbvtVolume	VolumeOf(	const btSoftBody::Face& f,
-									 btScalar margin)
-{
-	const btVector3*	pts[]={	&f.m_n[0]->m_x,
-		&f.m_n[1]->m_x,
-		&f.m_n[2]->m_x};
-	btDbvtVolume		vol=btDbvtVolume::FromPoints(pts,3);
-	vol.Expand(btVector3(margin,margin,margin));
-	return(vol);
+										btScalar margin)
+{
+const btVector3*	pts[]={	&f.m_n[0]->m_x,
+							&f.m_n[1]->m_x,
+							&f.m_n[2]->m_x};
+btDbvtVolume		vol=btDbvtVolume::FromPoints(pts,3);
+vol.Expand(btVector3(margin,margin,margin));
+return(vol);
 }
 
@@ -476,11 +476,11 @@
 static inline btVector3			CenterOf(	const btSoftBody::Face& f)
 {
-	return((f.m_n[0]->m_x+f.m_n[1]->m_x+f.m_n[2]->m_x)/3);
+return((f.m_n[0]->m_x+f.m_n[1]->m_x+f.m_n[2]->m_x)/3);
 }
 
 //
 static inline btScalar			AreaOf(		const btVector3& x0,
-									   const btVector3& x1,
-									   const btVector3& x2)
+											const btVector3& x1,
+											const btVector3& x2)
 {
 	const btVector3	a=x1-x0;
@@ -493,7 +493,7 @@
 //
 static inline btScalar		VolumeOf(	const btVector3& x0,
-									 const btVector3& x1,
-									 const btVector3& x2,
-									 const btVector3& x3)
+										const btVector3& x1,
+										const btVector3& x2,
+										const btVector3& x3)
 {
 	const btVector3	a=x1-x0;
@@ -505,6 +505,6 @@
 //
 static void					EvaluateMedium(	const btSoftBodyWorldInfo* wfi,
-										   const btVector3& x,
-										   btSoftBody::sMedium& medium)
+											const btVector3& x,
+											btSoftBody::sMedium& medium)
 {
 	medium.m_velocity	=	btVector3(0,0,0);
@@ -524,6 +524,6 @@
 //
 static inline void			ApplyClampedForce(	btSoftBody::Node& n,
-											  const btVector3& f,
-											  btScalar dt)
+												const btVector3& f,
+												btScalar dt)
 {
 	const btScalar	dtim=dt*n.m_im;
@@ -540,11 +540,11 @@
 //
 static inline int		MatchEdge(	const btSoftBody::Node* a,
-								  const btSoftBody::Node* b,
-								  const btSoftBody::Node* ma,
-								  const btSoftBody::Node* mb)
-{
-	if((a==ma)&&(b==mb)) return(0);
-	if((a==mb)&&(b==ma)) return(1);
-	return(-1);
+									const btSoftBody::Node* b,
+									const btSoftBody::Node* ma,
+									const btSoftBody::Node* mb)
+{
+if((a==ma)&&(b==mb)) return(0);
+if((a==mb)&&(b==ma)) return(1);
+return(-1);
 }
 
@@ -556,54 +556,54 @@
 struct	btEigen
 {
-	static int			system(btMatrix3x3& a,btMatrix3x3* vectors,btVector3* values=0)
-	{
-		static const int		maxiterations=16;
-		static const btScalar	accuracy=(btScalar)0.0001;
-		btMatrix3x3&			v=*vectors;
-		int						iterations=0;
-		vectors->setIdentity();
-		do	{
-			int				p=0,q=1;
-			if(btFabs(a[p][q])<btFabs(a[0][2])) { p=0;q=2; }
-			if(btFabs(a[p][q])<btFabs(a[1][2])) { p=1;q=2; }
-			if(btFabs(a[p][q])>accuracy)
+static int			system(btMatrix3x3& a,btMatrix3x3* vectors,btVector3* values=0)
+	{
+	static const int		maxiterations=16;
+	static const btScalar	accuracy=(btScalar)0.0001;
+	btMatrix3x3&			v=*vectors;
+	int						iterations=0;
+	vectors->setIdentity();
+	do	{
+		int				p=0,q=1;
+		if(btFabs(a[p][q])<btFabs(a[0][2])) { p=0;q=2; }
+		if(btFabs(a[p][q])<btFabs(a[1][2])) { p=1;q=2; }
+		if(btFabs(a[p][q])>accuracy)
 			{
-				const btScalar	w=(a[q][q]-a[p][p])/(2*a[p][q]);
-				const btScalar	z=btFabs(w);
-				const btScalar	t=w/(z*(btSqrt(1+w*w)+z));
-				if(t==t)/* [WARNING] let hope that one does not get thrown aways by some compilers... */ 
+			const btScalar	w=(a[q][q]-a[p][p])/(2*a[p][q]);
+			const btScalar	z=btFabs(w);
+			const btScalar	t=w/(z*(btSqrt(1+w*w)+z));
+			if(t==t)/* [WARNING] let hope that one does not get thrown aways by some compilers... */ 
 				{
-					const btScalar	c=1/btSqrt(t*t+1);
-					const btScalar	s=c*t;
-					mulPQ(a,c,s,p,q);
-					mulTPQ(a,c,s,p,q);
-					mulPQ(v,c,s,p,q);
+				const btScalar	c=1/btSqrt(t*t+1);
+				const btScalar	s=c*t;
+				mulPQ(a,c,s,p,q);
+				mulTPQ(a,c,s,p,q);
+				mulPQ(v,c,s,p,q);
 				} else break;
 			} else break;
 		} while((++iterations)<maxiterations);
-		if(values)
-		{
-			*values=btVector3(a[0][0],a[1][1],a[2][2]);
-		}
-		return(iterations);
+	if(values)
+		{
+		*values=btVector3(a[0][0],a[1][1],a[2][2]);
+		}
+	return(iterations);
 	}
 private:
-	static inline void	mulTPQ(btMatrix3x3& a,btScalar c,btScalar s,int p,int q)
-	{
-		const btScalar	m[2][3]={	{a[p][0],a[p][1],a[p][2]},
-		{a[q][0],a[q][1],a[q][2]}};
-		int i;
-
-		for(i=0;i<3;++i) a[p][i]=c*m[0][i]-s*m[1][i];
-		for(i=0;i<3;++i) a[q][i]=c*m[1][i]+s*m[0][i];
-	}
-	static inline void	mulPQ(btMatrix3x3& a,btScalar c,btScalar s,int p,int q)
-	{
-		const btScalar	m[2][3]={	{a[0][p],a[1][p],a[2][p]},
-		{a[0][q],a[1][q],a[2][q]}};
-		int i;
-
-		for(i=0;i<3;++i) a[i][p]=c*m[0][i]-s*m[1][i];
-		for(i=0;i<3;++i) a[i][q]=c*m[1][i]+s*m[0][i];
+static inline void	mulTPQ(btMatrix3x3& a,btScalar c,btScalar s,int p,int q)
+	{
+	const btScalar	m[2][3]={	{a[p][0],a[p][1],a[p][2]},
+								{a[q][0],a[q][1],a[q][2]}};
+	int i;
+
+	for(i=0;i<3;++i) a[p][i]=c*m[0][i]-s*m[1][i];
+	for(i=0;i<3;++i) a[q][i]=c*m[1][i]+s*m[0][i];
+	}
+static inline void	mulPQ(btMatrix3x3& a,btScalar c,btScalar s,int p,int q)
+	{
+	const btScalar	m[2][3]={	{a[0][p],a[1][p],a[2][p]},
+								{a[0][q],a[1][q],a[2][q]}};
+	int i;
+
+	for(i=0;i<3;++i) a[i][p]=c*m[0][i]-s*m[1][i];
+	for(i=0;i<3;++i) a[i][q]=c*m[1][i]+s*m[0][i];
 	}
 };
@@ -640,5 +640,5 @@
 		s.setIdentity();
 	}
-	return(i);
+return(i);
 }
 
@@ -653,52 +653,52 @@
 	struct	ClusterBase : btDbvt::ICollide
 	{
-		btScalar			erp;
-		btScalar			idt;
-		btScalar			margin;
-		btScalar			friction;
-		btScalar			threshold;
-		ClusterBase()
-		{
-			erp			=(btScalar)1;
-			idt			=0;
-			margin		=0;
-			friction	=0;
-			threshold	=(btScalar)0;
-		}
-		bool				SolveContact(	const btGjkEpaSolver2::sResults& res,
-			btSoftBody::Body ba,btSoftBody::Body bb,
-			btSoftBody::CJoint& joint)
-		{
-			if(res.distance<margin)
+	btScalar			erp;
+	btScalar			idt;
+	btScalar			margin;
+	btScalar			friction;
+	btScalar			threshold;
+					ClusterBase()
+		{
+		erp			=(btScalar)1;
+		idt			=0;
+		margin		=0;
+		friction	=0;
+		threshold	=(btScalar)0;
+		}
+	bool				SolveContact(	const btGjkEpaSolver2::sResults& res,
+										btSoftBody::Body ba,btSoftBody::Body bb,
+										btSoftBody::CJoint& joint)
+		{
+		if(res.distance<margin)
 			{
-				const btVector3		ra=res.witnesses[0]-ba.xform().getOrigin();
-				const btVector3		rb=res.witnesses[1]-bb.xform().getOrigin();
-				const btVector3		va=ba.velocity(ra);
-				const btVector3		vb=bb.velocity(rb);
-				const btVector3		vrel=va-vb;
-				const btScalar		rvac=dot(vrel,res.normal);
-				const btScalar		depth=res.distance-margin;
-				const btVector3		iv=res.normal*rvac;
-				const btVector3		fv=vrel-iv;
-				joint.m_bodies[0]	=	ba;
-				joint.m_bodies[1]	=	bb;
-				joint.m_refs[0]		=	ra*ba.xform().getBasis();
-				joint.m_refs[1]		=	rb*bb.xform().getBasis();
-				joint.m_rpos[0]		=	ra;
-				joint.m_rpos[1]		=	rb;
-				joint.m_cfm			=	1;
-				joint.m_erp			=	1;
-				joint.m_life		=	0;
-				joint.m_maxlife		=	0;
-				joint.m_split		=	1;
-				joint.m_drift		=	depth*res.normal;
-				joint.m_normal		=	res.normal;
-				joint.m_delete		=	false;
-				joint.m_friction	=	fv.length2()<(-rvac*friction)?1:friction;
-				joint.m_massmatrix	=	ImpulseMatrix(	ba.invMass(),ba.invWorldInertia(),joint.m_rpos[0],
-					bb.invMass(),bb.invWorldInertia(),joint.m_rpos[1]);
-				return(true);
+			const btVector3		ra=res.witnesses[0]-ba.xform().getOrigin();
+			const btVector3		rb=res.witnesses[1]-bb.xform().getOrigin();
+			const btVector3		va=ba.velocity(ra);
+			const btVector3		vb=bb.velocity(rb);
+			const btVector3		vrel=va-vb;
+			const btScalar		rvac=dot(vrel,res.normal);
+			const btScalar		depth=res.distance-margin;
+			const btVector3		iv=res.normal*rvac;
+			const btVector3		fv=vrel-iv;
+			joint.m_bodies[0]	=	ba;
+			joint.m_bodies[1]	=	bb;
+			joint.m_refs[0]		=	ra*ba.xform().getBasis();
+			joint.m_refs[1]		=	rb*bb.xform().getBasis();
+			joint.m_rpos[0]		=	ra;
+			joint.m_rpos[1]		=	rb;
+			joint.m_cfm			=	1;
+			joint.m_erp			=	1;
+			joint.m_life		=	0;
+			joint.m_maxlife		=	0;
+			joint.m_split		=	1;
+			joint.m_drift		=	depth*res.normal;
+			joint.m_normal		=	res.normal;
+			joint.m_delete		=	false;
+			joint.m_friction	=	fv.length2()<(-rvac*friction)?1:friction;
+			joint.m_massmatrix	=	ImpulseMatrix(	ba.invMass(),ba.invWorldInertia(),joint.m_rpos[0],
+													bb.invMass(),bb.invWorldInertia(),joint.m_rpos[1]);
+			return(true);
 			}
-			return(false);
+		return(false);
 		}
 	};
@@ -708,50 +708,50 @@
 	struct	CollideCL_RS : ClusterBase
 	{
-		btSoftBody*		psb;
-		btRigidBody*	prb;
-		void		Process(const btDbvtNode* leaf)
-		{
-			btSoftBody::Cluster*		cluster=(btSoftBody::Cluster*)leaf->data;
-			btSoftClusterCollisionShape	cshape(cluster);
-			const btConvexShape*		rshape=(const btConvexShape*)prb->getCollisionShape();
-			btGjkEpaSolver2::sResults	res;		
-			if(btGjkEpaSolver2::SignedDistance(	&cshape,btTransform::getIdentity(),
-				rshape,prb->getInterpolationWorldTransform(),
-				btVector3(1,0,0),res))
+	btSoftBody*		psb;
+	btRigidBody*	prb;
+	void		Process(const btDbvtNode* leaf)
+		{
+		btSoftBody::Cluster*		cluster=(btSoftBody::Cluster*)leaf->data;
+		btSoftClusterCollisionShape	cshape(cluster);
+		const btConvexShape*		rshape=(const btConvexShape*)prb->getCollisionShape();
+		btGjkEpaSolver2::sResults	res;		
+		if(btGjkEpaSolver2::SignedDistance(	&cshape,btTransform::getIdentity(),
+											rshape,prb->getInterpolationWorldTransform(),
+											btVector3(1,0,0),res))
 			{
-				btSoftBody::CJoint	joint;
-				if(SolveContact(res,cluster,prb,joint))
+			btSoftBody::CJoint	joint;
+			if(SolveContact(res,cluster,prb,joint))
 				{
-					btSoftBody::CJoint*	pj=new(btAlignedAlloc(sizeof(btSoftBody::CJoint),16)) btSoftBody::CJoint();
-					*pj=joint;psb->m_joints.push_back(pj);
-					if(prb->isStaticOrKinematicObject())
+				btSoftBody::CJoint*	pj=new(btAlignedAlloc(sizeof(btSoftBody::CJoint),16)) btSoftBody::CJoint();
+				*pj=joint;psb->m_joints.push_back(pj);
+				if(prb->isStaticOrKinematicObject())
 					{
-						pj->m_erp	*=	psb->m_cfg.kSKHR_CL;
-						pj->m_split	*=	psb->m_cfg.kSK_SPLT_CL;
+					pj->m_erp	*=	psb->m_cfg.kSKHR_CL;
+					pj->m_split	*=	psb->m_cfg.kSK_SPLT_CL;
 					}
 					else
 					{
-						pj->m_erp	*=	psb->m_cfg.kSRHR_CL;
-						pj->m_split	*=	psb->m_cfg.kSR_SPLT_CL;
+					pj->m_erp	*=	psb->m_cfg.kSRHR_CL;
+					pj->m_split	*=	psb->m_cfg.kSR_SPLT_CL;
 					}
 				}
 			}
 		}
-		void		Process(btSoftBody* ps,btRigidBody* pr)
-		{
-			psb			=	ps;
-			prb			=	pr;
-			idt			=	ps->m_sst.isdt;
-			margin		=	ps->getCollisionShape()->getMargin()+
-				pr->getCollisionShape()->getMargin();
-			friction	=	btMin(psb->m_cfg.kDF,prb->getFriction());
-			btVector3			mins;
-			btVector3			maxs;
-
-			ATTRIBUTE_ALIGNED16(btDbvtVolume)		volume;
-			pr->getCollisionShape()->getAabb(pr->getInterpolationWorldTransform(),mins,maxs);
-			volume=btDbvtVolume::FromMM(mins,maxs);
-			volume.Expand(btVector3(1,1,1)*margin);
-			btDbvt::collideTV(ps->m_cdbvt.m_root,volume,*this);
+	void		Process(btSoftBody* ps,btRigidBody* pr)
+		{
+		psb			=	ps;
+		prb			=	pr;
+		idt			=	ps->m_sst.isdt;
+		margin		=	ps->getCollisionShape()->getMargin()+
+						pr->getCollisionShape()->getMargin();
+		friction	=	btMin(psb->m_cfg.kDF,prb->getFriction());
+		btVector3			mins;
+		btVector3			maxs;
+		
+		ATTRIBUTE_ALIGNED16(btDbvtVolume)		volume;
+		pr->getCollisionShape()->getAabb(pr->getInterpolationWorldTransform(),mins,maxs);
+		volume=btDbvtVolume::FromMM(mins,maxs);
+		volume.Expand(btVector3(1,1,1)*margin);
+		btDbvt::collideTV(ps->m_cdbvt.m_root,volume,*this);
 		}	
 	};
@@ -761,34 +761,34 @@
 	struct	CollideCL_SS : ClusterBase
 	{
-		btSoftBody*	bodies[2];
-		void		Process(const btDbvtNode* la,const btDbvtNode* lb)
-		{
-			btSoftBody::Cluster*		cla=(btSoftBody::Cluster*)la->data;
-			btSoftBody::Cluster*		clb=(btSoftBody::Cluster*)lb->data;
-			btSoftClusterCollisionShape	csa(cla);
-			btSoftClusterCollisionShape	csb(clb);
-			btGjkEpaSolver2::sResults	res;		
-			if(btGjkEpaSolver2::SignedDistance(	&csa,btTransform::getIdentity(),
-				&csb,btTransform::getIdentity(),
-				cla->m_com-clb->m_com,res))
+	btSoftBody*	bodies[2];
+	void		Process(const btDbvtNode* la,const btDbvtNode* lb)
+		{
+		btSoftBody::Cluster*		cla=(btSoftBody::Cluster*)la->data;
+		btSoftBody::Cluster*		clb=(btSoftBody::Cluster*)lb->data;
+		btSoftClusterCollisionShape	csa(cla);
+		btSoftClusterCollisionShape	csb(clb);
+		btGjkEpaSolver2::sResults	res;		
+		if(btGjkEpaSolver2::SignedDistance(	&csa,btTransform::getIdentity(),
+											&csb,btTransform::getIdentity(),
+											cla->m_com-clb->m_com,res))
 			{
-				btSoftBody::CJoint	joint;
-				if(SolveContact(res,cla,clb,joint))
+			btSoftBody::CJoint	joint;
+			if(SolveContact(res,cla,clb,joint))
 				{
-					btSoftBody::CJoint*	pj=new(btAlignedAlloc(sizeof(btSoftBody::CJoint),16)) btSoftBody::CJoint();
-					*pj=joint;bodies[0]->m_joints.push_back(pj);
-					pj->m_erp	*=	btMax(bodies[0]->m_cfg.kSSHR_CL,bodies[1]->m_cfg.kSSHR_CL);
-					pj->m_split	*=	(bodies[0]->m_cfg.kSS_SPLT_CL+bodies[1]->m_cfg.kSS_SPLT_CL)/2;
+				btSoftBody::CJoint*	pj=new(btAlignedAlloc(sizeof(btSoftBody::CJoint),16)) btSoftBody::CJoint();
+				*pj=joint;bodies[0]->m_joints.push_back(pj);
+				pj->m_erp	*=	btMax(bodies[0]->m_cfg.kSSHR_CL,bodies[1]->m_cfg.kSSHR_CL);
+				pj->m_split	*=	(bodies[0]->m_cfg.kSS_SPLT_CL+bodies[1]->m_cfg.kSS_SPLT_CL)/2;
 				}
 			}
 		}
-		void		Process(btSoftBody* psa,btSoftBody* psb)
-		{
-			idt			=	psa->m_sst.isdt;
-			margin		=	(psa->getCollisionShape()->getMargin()+psb->getCollisionShape()->getMargin())/2;
-			friction	=	btMin(psa->m_cfg.kDF,psb->m_cfg.kDF);
-			bodies[0]	=	psa;
-			bodies[1]	=	psb;
-			btDbvt::collideTT(psa->m_cdbvt.m_root,psb->m_cdbvt.m_root,*this);
+	void		Process(btSoftBody* psa,btSoftBody* psb)
+		{
+		idt			=	psa->m_sst.isdt;
+		margin		=	(psa->getCollisionShape()->getMargin()+psb->getCollisionShape()->getMargin())/2;
+		friction	=	btMin(psa->m_cfg.kDF,psb->m_cfg.kDF);
+		bodies[0]	=	psa;
+		bodies[1]	=	psb;
+		btDbvt::collideTT(psa->m_cdbvt.m_root,psb->m_cdbvt.m_root,*this);
 		}	
 	};
@@ -798,45 +798,45 @@
 	struct	CollideSDF_RS : btDbvt::ICollide
 	{
-		void		Process(const btDbvtNode* leaf)
-		{
-			btSoftBody::Node*	node=(btSoftBody::Node*)leaf->data;
-			DoNode(*node);
-		}
-		void		DoNode(btSoftBody::Node& n) const
-		{
-			const btScalar			m=n.m_im>0?dynmargin:stamargin;
-			btSoftBody::RContact	c;
-			if(	(!n.m_battach)&&
-				psb->checkContact(prb,n.m_x,m,c.m_cti))
+	void		Process(const btDbvtNode* leaf)
+		{
+		btSoftBody::Node*	node=(btSoftBody::Node*)leaf->data;
+		DoNode(*node);
+		}
+	void		DoNode(btSoftBody::Node& n) const
+		{
+		const btScalar			m=n.m_im>0?dynmargin:stamargin;
+		btSoftBody::RContact	c;
+		if(	(!n.m_battach)&&
+			psb->checkContact(prb,n.m_x,m,c.m_cti))
 			{
-				const btScalar	ima=n.m_im;
-				const btScalar	imb=prb->getInvMass();
-				const btScalar	ms=ima+imb;
-				if(ms>0)
+			const btScalar	ima=n.m_im;
+			const btScalar	imb=prb->getInvMass();
+			const btScalar	ms=ima+imb;
+			if(ms>0)
 				{
-					const btTransform&	wtr=prb->getInterpolationWorldTransform();
-					const btMatrix3x3&	iwi=prb->getInvInertiaTensorWorld();
-					const btVector3		ra=n.m_x-wtr.getOrigin();
-					const btVector3		va=prb->getVelocityInLocalPoint(ra)*psb->m_sst.sdt;
-					const btVector3		vb=n.m_x-n.m_q;	
-					const btVector3		vr=vb-va;
-					const btScalar		dn=dot(vr,c.m_cti.m_normal);
-					const btVector3		fv=vr-c.m_cti.m_normal*dn;
-					const btScalar		fc=psb->m_cfg.kDF*prb->getFriction();
-					c.m_node	=	&n;
-					c.m_c0		=	ImpulseMatrix(psb->m_sst.sdt,ima,imb,iwi,ra);
-					c.m_c1		=	ra;
-					c.m_c2		=	ima*psb->m_sst.sdt;
-					c.m_c3		=	fv.length2()<(btFabs(dn)*fc)?0:1-fc;
-					c.m_c4		=	prb->isStaticOrKinematicObject()?psb->m_cfg.kKHR:psb->m_cfg.kCHR;
-					psb->m_rcontacts.push_back(c);
-					prb->activate();
+				const btTransform&	wtr=prb->getInterpolationWorldTransform();
+				const btMatrix3x3&	iwi=prb->getInvInertiaTensorWorld();
+				const btVector3		ra=n.m_x-wtr.getOrigin();
+				const btVector3		va=prb->getVelocityInLocalPoint(ra)*psb->m_sst.sdt;
+				const btVector3		vb=n.m_x-n.m_q;	
+				const btVector3		vr=vb-va;
+				const btScalar		dn=dot(vr,c.m_cti.m_normal);
+				const btVector3		fv=vr-c.m_cti.m_normal*dn;
+				const btScalar		fc=psb->m_cfg.kDF*prb->getFriction();
+				c.m_node	=	&n;
+				c.m_c0		=	ImpulseMatrix(psb->m_sst.sdt,ima,imb,iwi,ra);
+				c.m_c1		=	ra;
+				c.m_c2		=	ima*psb->m_sst.sdt;
+				c.m_c3		=	fv.length2()<(btFabs(dn)*fc)?0:1-fc;
+				c.m_c4		=	prb->isStaticOrKinematicObject()?psb->m_cfg.kKHR:psb->m_cfg.kCHR;
+				psb->m_rcontacts.push_back(c);
+				prb->activate();
 				}
 			}
 		}
-		btSoftBody*		psb;
-		btRigidBody*	prb;
-		btScalar		dynmargin;
-		btScalar		stamargin;
+	btSoftBody*		psb;
+	btRigidBody*	prb;
+	btScalar		dynmargin;
+	btScalar		stamargin;
 	};
 	//
@@ -845,47 +845,47 @@
 	struct	CollideVF_SS : btDbvt::ICollide
 	{
-		void		Process(const btDbvtNode* lnode,
-			const btDbvtNode* lface)
-		{
-			btSoftBody::Node*	node=(btSoftBody::Node*)lnode->data;
-			btSoftBody::Face*	face=(btSoftBody::Face*)lface->data;
-			btVector3			o=node->m_x;
-			btVector3			p;
-			btScalar			d=SIMD_INFINITY;
-			ProjectOrigin(	face->m_n[0]->m_x-o,
-				face->m_n[1]->m_x-o,
-				face->m_n[2]->m_x-o,
-				p,d);
-			const btScalar	m=mrg+(o-node->m_q).length()*2;
-			if(d<(m*m))
+	void		Process(const btDbvtNode* lnode,
+						const btDbvtNode* lface)
+		{
+		btSoftBody::Node*	node=(btSoftBody::Node*)lnode->data;
+		btSoftBody::Face*	face=(btSoftBody::Face*)lface->data;
+		btVector3			o=node->m_x;
+		btVector3			p;
+		btScalar			d=SIMD_INFINITY;
+		ProjectOrigin(	face->m_n[0]->m_x-o,
+						face->m_n[1]->m_x-o,
+						face->m_n[2]->m_x-o,
+						p,d);
+		const btScalar	m=mrg+(o-node->m_q).length()*2;
+		if(d<(m*m))
 			{
-				const btSoftBody::Node*	n[]={face->m_n[0],face->m_n[1],face->m_n[2]};
-				const btVector3			w=BaryCoord(n[0]->m_x,n[1]->m_x,n[2]->m_x,p+o);
-				const btScalar			ma=node->m_im;
-				btScalar				mb=BaryEval(n[0]->m_im,n[1]->m_im,n[2]->m_im,w);
-				if(	(n[0]->m_im<=0)||
-					(n[1]->m_im<=0)||
-					(n[2]->m_im<=0))
+			const btSoftBody::Node*	n[]={face->m_n[0],face->m_n[1],face->m_n[2]};
+			const btVector3			w=BaryCoord(n[0]->m_x,n[1]->m_x,n[2]->m_x,p+o);
+			const btScalar			ma=node->m_im;
+			btScalar				mb=BaryEval(n[0]->m_im,n[1]->m_im,n[2]->m_im,w);
+			if(	(n[0]->m_im<=0)||
+				(n[1]->m_im<=0)||
+				(n[2]->m_im<=0))
 				{
-					mb=0;
+				mb=0;
 				}
-				const btScalar	ms=ma+mb;
-				if(ms>0)
+			const btScalar	ms=ma+mb;
+			if(ms>0)
 				{
-					btSoftBody::SContact	c;
-					c.m_normal		=	p/-btSqrt(d);
-					c.m_margin		=	m;
-					c.m_node		=	node;
-					c.m_face		=	face;
-					c.m_weights		=	w;
-					c.m_friction	=	btMax(psb[0]->m_cfg.kDF,psb[1]->m_cfg.kDF);
-					c.m_cfm[0]		=	ma/ms*psb[0]->m_cfg.kSHR;
-					c.m_cfm[1]		=	mb/ms*psb[1]->m_cfg.kSHR;
-					psb[0]->m_scontacts.push_back(c);
+				btSoftBody::SContact	c;
+				c.m_normal		=	p/-btSqrt(d);
+				c.m_margin		=	m;
+				c.m_node		=	node;
+				c.m_face		=	face;
+				c.m_weights		=	w;
+				c.m_friction	=	btMax(psb[0]->m_cfg.kDF,psb[1]->m_cfg.kDF);
+				c.m_cfm[0]		=	ma/ms*psb[0]->m_cfg.kSHR;
+				c.m_cfm[1]		=	mb/ms*psb[1]->m_cfg.kSHR;
+				psb[0]->m_scontacts.push_back(c);
 				}
 			}	
 		}
-		btSoftBody*		psb[2];
-		btScalar		mrg;
+	btSoftBody*		psb[2];
+	btScalar		mrg;
 	};
 };
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.cpp	(revision 1972)
@@ -30,8 +30,8 @@
 	mem = btAlignedAlloc(sizeof(btSoftSoftCollisionAlgorithm::CreateFunc),16);
 	m_softSoftCreateFunc = new(mem) btSoftSoftCollisionAlgorithm::CreateFunc;
-
+	
 	mem = btAlignedAlloc(sizeof(btSoftRigidCollisionAlgorithm::CreateFunc),16);
 	m_softRigidConvexCreateFunc = new(mem) btSoftRigidCollisionAlgorithm::CreateFunc;
-
+	
 	mem = btAlignedAlloc(sizeof(btSoftRigidCollisionAlgorithm::CreateFunc),16);
 	m_swappedSoftRigidConvexCreateFunc = new(mem) btSoftRigidCollisionAlgorithm::CreateFunc;
@@ -41,5 +41,5 @@
 	mem = btAlignedAlloc(sizeof(btSoftBodyConcaveCollisionAlgorithm::CreateFunc),16);
 	m_softRigidConcaveCreateFunc = new(mem) btSoftBodyConcaveCollisionAlgorithm::CreateFunc;
-
+	
 	mem = btAlignedAlloc(sizeof(btSoftBodyConcaveCollisionAlgorithm::CreateFunc),16);
 	m_swappedSoftRigidConcaveCreateFunc = new(mem) btSoftBodyConcaveCollisionAlgorithm::SwappedCreateFunc;
@@ -48,11 +48,11 @@
 
 	//replace pool by a new one, with potential larger size
-
+	
 	if (m_ownsCollisionAlgorithmPool && m_collisionAlgorithmPool)
 	{
 		int curElemSize = m_collisionAlgorithmPool->getElementSize();
 		///calculate maximum element size, big enough to fit any collision algorithm in the memory pool
-
-
+		
+		
 		int maxSize0 = sizeof(btSoftSoftCollisionAlgorithm);
 		int maxSize1 = sizeof(btSoftRigidCollisionAlgorithm);
@@ -93,5 +93,5 @@
 #endif
 }
-
+	
 ///creation of soft-soft and soft-rigid, and otherwise fallback to base class implementation
 btCollisionAlgorithmCreateFunc* btSoftBodyRigidBodyCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1)
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h	(revision 1972)
@@ -33,5 +33,5 @@
 	btCollisionAlgorithmCreateFunc*	m_softRigidConcaveCreateFunc;
 	btCollisionAlgorithmCreateFunc*	m_swappedSoftRigidConcaveCreateFunc;
-
+	
 public:
 
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftRigidCollisionAlgorithm.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftRigidCollisionAlgorithm.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftRigidCollisionAlgorithm.cpp	(revision 1972)
@@ -36,11 +36,11 @@
 btSoftRigidCollisionAlgorithm::~btSoftRigidCollisionAlgorithm()
 {
-
+	
 	//m_softBody->m_overlappingRigidBodies.remove(m_rigidCollisionObject);
 
 	/*if (m_ownManifold)
 	{
-	if (m_manifoldPtr)
-	m_dispatcher->releaseManifold(m_manifoldPtr);
+		if (m_manifoldPtr)
+			m_dispatcher->releaseManifold(m_manifoldPtr);
 	}
 	*/
@@ -59,5 +59,5 @@
 	btSoftBody* softBody =  m_isSwapped? (btSoftBody*)body1 : (btSoftBody*)body0;
 	btCollisionObject* rigidCollisionObject = m_isSwapped? body0 : body1;
-
+	
 	softBody->defaultCollisionHandler(rigidCollisionObject);
 
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftRigidCollisionAlgorithm.h
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftRigidCollisionAlgorithm.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftRigidCollisionAlgorithm.h	(revision 1972)
@@ -29,6 +29,6 @@
 class btSoftRigidCollisionAlgorithm : public btCollisionAlgorithm
 {
-	//	bool	m_ownManifold;
-	//	btPersistentManifold*	m_manifoldPtr;
+//	bool	m_ownManifold;
+//	btPersistentManifold*	m_manifoldPtr;
 
 	btSoftBody*				m_softBody;
@@ -37,5 +37,5 @@
 	///for rigid versus soft (instead of soft versus rigid), we use this swapped boolean
 	bool	m_isSwapped;
-
+	
 public:
 
@@ -53,5 +53,5 @@
 	}
 
-
+	
 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
 	{
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftRigidDynamicsWorld.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftRigidDynamicsWorld.cpp	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftRigidDynamicsWorld.cpp	(revision 1972)
@@ -29,15 +29,15 @@
 :btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration)
 {
-	m_drawFlags			=	fDrawFlags::Std;
-	m_drawNodeTree		=	true;
-	m_drawFaceTree		=	false;
-	m_drawClusterTree	=	false;
-	m_sbi.m_broadphase = pairCache;
-	m_sbi.m_dispatcher = dispatcher;
-	m_sbi.m_sparsesdf.Initialize();
-	m_sbi.m_sparsesdf.Reset();
+m_drawFlags			=	fDrawFlags::Std;
+m_drawNodeTree		=	true;
+m_drawFaceTree		=	false;
+m_drawClusterTree	=	false;
+m_sbi.m_broadphase = pairCache;
+m_sbi.m_dispatcher = dispatcher;
+m_sbi.m_sparsesdf.Initialize();
+m_sbi.m_sparsesdf.Reset();
 
 }
-
+		
 btSoftRigidDynamicsWorld::~btSoftRigidDynamicsWorld()
 {
@@ -56,5 +56,5 @@
 	}
 }
-
+		
 void	btSoftRigidDynamicsWorld::internalSingleStepSimulation( btScalar timeStep)
 {
@@ -72,5 +72,5 @@
 {
 	BT_PROFILE("updateSoftBodies");
-
+	
 	for ( int i=0;i<m_softBodies.size();i++)
 	{
@@ -83,10 +83,10 @@
 {
 	BT_PROFILE("solveSoftConstraints");
-
+	
 	if(m_softBodies.size())
-	{
+		{
 		btSoftBody::solveClusters(m_softBodies);
-	}
-
+		}
+	
 	for(int i=0;i<m_softBodies.size();++i)
 	{
@@ -101,6 +101,6 @@
 
 	btCollisionWorld::addCollisionObject(body,
-		btBroadphaseProxy::DefaultFilter,
-		btBroadphaseProxy::AllFilter);
+					btBroadphaseProxy::DefaultFilter,
+					btBroadphaseProxy::AllFilter);
 
 }
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftRigidDynamicsWorld.h
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftRigidDynamicsWorld.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftRigidDynamicsWorld.h	(revision 1972)
@@ -24,5 +24,5 @@
 class btSoftRigidDynamicsWorld : public btDiscreteDynamicsWorld
 {
-
+	
 	btSoftBodyArray	m_softBodies;
 	int				m_drawFlags;
@@ -33,7 +33,7 @@
 
 protected:
-
+	
 	virtual void	predictUnconstraintMotion(btScalar timeStep);
-
+	
 	virtual void	internalSingleStepSimulation( btScalar timeStep);
 
@@ -44,15 +44,15 @@
 
 public:
-
+	
 	btSoftRigidDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration);
 
 	virtual ~btSoftRigidDynamicsWorld();
-
+	
 	virtual void	debugDrawWorld();
-
+			
 	void	addSoftBody(btSoftBody* body);
 
 	void	removeSoftBody(btSoftBody* body);
-
+	
 	int		getDrawFlags() const { return(m_drawFlags); }
 	void	setDrawFlags(int f)	{ m_drawFlags=f; }
@@ -67,5 +67,5 @@
 	}
 
-
+			
 	btSoftBodyArray& getSoftBodyArray()
 	{
@@ -77,5 +77,5 @@
 		return m_softBodies;
 	}
-
+		
 };
 
Index: code/branches/physics/src/bullet/BulletSoftBody/btSoftSoftCollisionAlgorithm.h
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSoftSoftCollisionAlgorithm.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSoftSoftCollisionAlgorithm.h	(revision 1972)
@@ -34,5 +34,5 @@
 	btSoftBody*	m_softBody1;
 
-
+	
 public:
 	btSoftSoftCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
Index: code/branches/physics/src/bullet/BulletSoftBody/btSparseSDF.h
===================================================================
--- code/branches/physics/src/bullet/BulletSoftBody/btSparseSDF.h	(revision 1971)
+++ code/branches/physics/src/bullet/BulletSoftBody/btSparseSDF.h	(revision 1972)
@@ -24,9 +24,9 @@
 template <const int DWORDLEN>
 unsigned int HsiehHash(const void* pdata)
-{
+	{
 	const unsigned short*	data=(const unsigned short*)pdata;
 	unsigned				hash=DWORDLEN<<2,tmp;
 	for(int i=0;i<DWORDLEN;++i)
-	{
+		{
 		hash	+=	data[0];
 		tmp		=	(data[1]<<11)^hash;
@@ -34,25 +34,25 @@
 		data	+=	2;
 		hash	+=	hash>>11;
-	}
+		}
 	hash^=hash<<3;hash+=hash>>5;
 	hash^=hash<<4;hash+=hash>>17;
 	hash^=hash<<25;hash+=hash>>6;
 	return(hash);
-}
+	}
 
 template <const int CELLSIZE>
 struct	btSparseSdf
-{
+	{
 	//
 	// Inner types
 	//
 	struct IntFrac
-	{
+		{
 		int					b;
 		int					i;
 		btScalar			f;
-	};
+		};
 	struct	Cell
-	{
+		{
 		btScalar			d[CELLSIZE+1][CELLSIZE+1][CELLSIZE+1];
 		int					c[3];
@@ -61,9 +61,9 @@
 		btCollisionShape*	pclient;
 		Cell*				next;
-	};
+		};
 	//
 	// Fields
 	//
-
+	
 	btAlignedObjectArray<Cell*>		cells;	
 	btScalar						voxelsz;
@@ -72,29 +72,29 @@
 	int								nprobes;
 	int								nqueries;	
-
+	
 	//
 	// Methods
 	//
-
+	
 	//
 	void					Initialize(int hashsize=2383)
-	{
+		{
 		cells.resize(hashsize,0);
 		Reset();		
-	}
+		}
 	//
 	void					Reset()
-	{
+		{
 		for(int i=0,ni=cells.size();i<ni;++i)
-		{
+			{
 			Cell*	pc=cells[i];
 			cells[i]=0;
 			while(pc)
-			{
+				{
 				Cell*	pn=pc->next;
 				delete pc;
 				pc=pn;
-			}
-		}
+				}
+			}
 		voxelsz		=0.25;
 		puid		=0;
@@ -102,59 +102,59 @@
 		nprobes		=1;
 		nqueries	=1;
-	}
+		}
 	//
 	void					GarbageCollect(int lifetime=256)
-	{
+		{
 		const int life=puid-lifetime;
 		for(int i=0;i<cells.size();++i)
-		{
+			{
 			Cell*&	root=cells[i];
 			Cell*	pp=0;
 			Cell*	pc=root;
 			while(pc)
-			{
+				{
 				Cell*	pn=pc->next;
 				if(pc->puid<life)
-				{
+					{
 					if(pp) pp->next=pn; else root=pn;
 					delete pc;pc=pp;--ncells;
+					}
+				pp=pc;pc=pn;
 				}
-				pp=pc;pc=pn;
-			}
-		}
+			}
 		//printf("GC[%d]: %d cells, PpQ: %f\r\n",puid,ncells,nprobes/(btScalar)nqueries);
 		nqueries=1;
 		nprobes=1;
 		++puid;	/* TODO: Reset puid's when int range limit is reached	*/ 
-		/* else setup a priority list...						*/ 
-	}
+				/* else setup a priority list...						*/ 
+		}
 	//
 	int						RemoveReferences(btCollisionShape* pcs)
-	{
+		{
 		int	refcount=0;
 		for(int i=0;i<cells.size();++i)
-		{
+			{
 			Cell*&	root=cells[i];
 			Cell*	pp=0;
 			Cell*	pc=root;
 			while(pc)
-			{
+				{
 				Cell*	pn=pc->next;
 				if(pc->pclient==pcs)
-				{
+					{
 					if(pp) pp->next=pn; else root=pn;
 					delete pc;pc=pp;++refcount;
+					}
+				pp=pc;pc=pn;
 				}
-				pp=pc;pc=pn;
-			}
-		}
+			}
 		return(refcount);
-	}
+		}
 	//
 	btScalar				Evaluate(	const btVector3& x,
-		btCollisionShape* shape,
-		btVector3& normal,
-		btScalar margin)
-	{
+										btCollisionShape* shape,
+										btVector3& normal,
+										btScalar margin)
+		{
 		/* Lookup cell			*/ 
 		const btVector3	scx=x/voxelsz;
@@ -167,5 +167,5 @@
 		++nqueries;
 		while(c)
-		{
+			{
 			++nprobes;
 			if(	(c->hash==h)	&&
@@ -174,10 +174,10 @@
 				(c->c[2]==iz.b)	&&
 				(c->pclient==shape))
-			{ break; }
-			else
-			{ c=c->next; }
-		}
+				{ break; }
+				else
+				{ c=c->next; }
+			}
 		if(!c)
-		{
+			{
 			++nprobes;		
 			++ncells;
@@ -188,80 +188,80 @@
 			c->c[0]=ix.b;c->c[1]=iy.b;c->c[2]=iz.b;
 			BuildCell(*c);
-		}
+			}
 		c->puid=puid;
 		/* Extract infos		*/ 
 		const int		o[]={	ix.i,iy.i,iz.i};
 		const btScalar	d[]={	c->d[o[0]+0][o[1]+0][o[2]+0],
-			c->d[o[0]+1][o[1]+0][o[2]+0],
-			c->d[o[0]+1][o[1]+1][o[2]+0],
-			c->d[o[0]+0][o[1]+1][o[2]+0],
-			c->d[o[0]+0][o[1]+0][o[2]+1],
-			c->d[o[0]+1][o[1]+0][o[2]+1],
-			c->d[o[0]+1][o[1]+1][o[2]+1],
-			c->d[o[0]+0][o[1]+1][o[2]+1]};
+								c->d[o[0]+1][o[1]+0][o[2]+0],
+								c->d[o[0]+1][o[1]+1][o[2]+0],
+								c->d[o[0]+0][o[1]+1][o[2]+0],
+								c->d[o[0]+0][o[1]+0][o[2]+1],
+								c->d[o[0]+1][o[1]+0][o[2]+1],
+								c->d[o[0]+1][o[1]+1][o[2]+1],
+								c->d[o[0]+0][o[1]+1][o[2]+1]};
 		/* Normal	*/ 
-#if 1
+		#if 1
 		const btScalar	gx[]={	d[1]-d[0],d[2]-d[3],
-			d[5]-d[4],d[6]-d[7]};
+								d[5]-d[4],d[6]-d[7]};
 		const btScalar	gy[]={	d[3]-d[0],d[2]-d[1],
-			d[7]-d[4],d[6]-d[5]};
+								d[7]-d[4],d[6]-d[5]};
 		const btScalar	gz[]={	d[4]-d[0],d[5]-d[1],
-			d[7]-d[3],d[6]-d[2]};
+								d[7]-d[3],d[6]-d[2]};
 		normal.setX(Lerp(	Lerp(gx[0],gx[1],iy.f),
-			Lerp(gx[2],gx[3],iy.f),iz.f));
+							Lerp(gx[2],gx[3],iy.f),iz.f));
 		normal.setY(Lerp(	Lerp(gy[0],gy[1],ix.f),
-			Lerp(gy[2],gy[3],ix.f),iz.f));
+							Lerp(gy[2],gy[3],ix.f),iz.f));
 		normal.setZ(Lerp(	Lerp(gz[0],gz[1],ix.f),
-			Lerp(gz[2],gz[3],ix.f),iy.f));
+							Lerp(gz[2],gz[3],ix.f),iy.f));
 		normal		=	normal.normalized();
-#else
+		#else
 		normal		=	btVector3(d[1]-d[0],d[3]-d[0],d[4]-d[0]).normalized();
-#endif
+		#endif
 		/* Distance	*/ 
 		const btScalar	d0=Lerp(Lerp(d[0],d[1],ix.f),
-			Lerp(d[3],d[2],ix.f),iy.f);
+								Lerp(d[3],d[2],ix.f),iy.f);
 		const btScalar	d1=Lerp(Lerp(d[4],d[5],ix.f),
-			Lerp(d[7],d[6],ix.f),iy.f);
+								Lerp(d[7],d[6],ix.f),iy.f);
 		return(Lerp(d0,d1,iz.f)-margin);
-	}
+		}
 	//
 	void					BuildCell(Cell& c)
-	{
+		{
 		const btVector3	org=btVector3(	(btScalar)c.c[0],
-			(btScalar)c.c[1],
-			(btScalar)c.c[2])	*
-			CELLSIZE*voxelsz;
+										(btScalar)c.c[1],
+										(btScalar)c.c[2])	*
+										CELLSIZE*voxelsz;
 		for(int k=0;k<=CELLSIZE;++k)
-		{
+			{
 			const btScalar	z=voxelsz*k+org.z();
 			for(int j=0;j<=CELLSIZE;++j)
-			{
+				{
 				const btScalar	y=voxelsz*j+org.y();
 				for(int i=0;i<=CELLSIZE;++i)
-				{
+					{
 					const btScalar	x=voxelsz*i+org.x();
 					c.d[i][j][k]=DistanceToShape(	btVector3(x,y,z),
-						c.pclient);
+													c.pclient);
+					}
 				}
 			}
 		}
-	}
 	//
 	static inline btScalar	DistanceToShape(const btVector3& x,
-		btCollisionShape* shape)
-	{
+											btCollisionShape* shape)
+		{
 		btTransform	unit;
 		unit.setIdentity();
 		if(shape->isConvex())
-		{
+			{
 			btGjkEpaSolver2::sResults	res;
 			btConvexShape*				csh=static_cast<btConvexShape*>(shape);
 			return(btGjkEpaSolver2::SignedDistance(x,0,csh,unit,res));
-		}
+			}
 		return(0);
-	}
+		}
 	//
 	static inline IntFrac	Decompose(btScalar x)
-	{
+		{
 		/* That one need a lot of improvements...	*/
 		/* Remove test, faster floor...				*/ 
@@ -273,16 +273,16 @@
 		r.i=(int)k;r.f=k-r.i;r.b-=o;
 		return(r);
-	}
+		}
 	//
 	static inline btScalar	Lerp(btScalar a,btScalar b,btScalar t)
-	{
+		{
 		return(a+(b-a)*t);
-	}
-
-
+		}
+
+	
 
 	//
 	static inline unsigned int	Hash(int x,int y,int z,btCollisionShape* shape)
-	{
+		{
 		struct btS
 		{ 
@@ -292,15 +292,15 @@
 
 		btS myset;
-
+		
 		myset.x=x;myset.y=y;myset.z=z;myset.p=shape;
 		const void* ptr = &myset;
 
 		unsigned int result = HsiehHash<sizeof(btS)/4> (ptr);
-
+		
 
 		return result;
-	}
+		}
 };
-
+	
 
 #endif
Index: code/branches/physics/src/bullet/CMakeLists.txt
===================================================================
--- code/branches/physics/src/bullet/CMakeLists.txt	(revision 1971)
+++ code/branches/physics/src/bullet/CMakeLists.txt	(revision 1972)
@@ -1,5 +1,6 @@
-if (CMAKE_SIZEOF_VOID_P MATCHES "8")
-  SUBDIRS( BulletSoftBody BulletCollision BulletDynamics LinearMath )
-else (CMAKE_SIZEOF_VOID_P MATCHES "8")
-  SUBDIRS( BulletMultiThreaded BulletSoftBody BulletCollision BulletDynamics LinearMath )
-endif (CMAKE_SIZEOF_VOID_P MATCHES "8")
+INCLUDE_DIRECTORIES(.)
+
+ADD_SUBDIRECTORY(BulletSoftBody)
+ADD_SUBDIRECTORY(BulletCollision)
+ADD_SUBDIRECTORY(BulletDynamics)
+ADD_SUBDIRECTORY(BulletLinearMath)
Index: code/branches/physics/src/bullet/ChangeLog
===================================================================
--- code/branches/physics/src/bullet/ChangeLog	(revision 1971)
+++ code/branches/physics/src/bullet/ChangeLog	(revision 1972)
@@ -5,6 +5,4 @@
 See http://code.google.com/p/bullet/source/list for more complete log in Subversion
 
-2008 October 10
-	- Moved aabb to btBroadphaseProxy, improves rayTest dramatically. Further raytest improvements using the broadphase acceleration structures are planned
 
 2008 October 3
Index: code/branches/physics/src/bullet/LinearMath/btScalar.h
===================================================================
--- code/branches/physics/src/bullet/LinearMath/btScalar.h	(revision 1971)
+++ code/branches/physics/src/bullet/LinearMath/btScalar.h	(revision 1972)
@@ -25,5 +25,5 @@
 #include <float.h>
 
-#define BT_BULLET_VERSION 273
+#define BT_BULLET_VERSION 272
 
 inline int	btGetVersion()
