Index: code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp	(revision 1963)
+++ 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 1963)
+++ 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 1963)
+++ 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 1963)
+++ 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 1963)
+++ 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 1963)
+++ 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 1963)
+++ 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 1963)
+++ 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 1963)
+++ 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 1963)
+++ 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 1963)
+++ 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 1963)
+++ 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 1963)
+++ 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 1963)
+++ 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()
