Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h	(revision 2430)
@@ -22,5 +22,4 @@
 #include "btSimplexSolverInterface.h"
 class btConvexShape;
-#include "LinearMath/btPoint3.h"
 class btTransform;
 
@@ -34,5 +33,5 @@
 		const btConvexShape* convexA,const btConvexShape* convexB,
 					const btTransform& transA,const btTransform& transB,
-				btVector3& v, btPoint3& pa, btPoint3& pb,
+				btVector3& v, btVector3& pa, btVector3& pb,
 				class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc
 				) = 0;
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa.cpp	(revision 2192)
+++ 	(revision )
@@ -1,628 +1,0 @@
-/*
-Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
-
-This software is provided 'as-is', without any express or implied warranty.
-In no event will the authors be held liable for any damages arising from the
-use of this software.
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it
-freely,
-subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not
-claim that you wrote the original software. If you use this software in a
-product, an acknowledgment in the product documentation would be appreciated
-but is not required.
-2. Altered source versions must be plainly marked as such, and must not be
-misrepresented as being the original software.
-3. This notice may not be removed or altered from any source distribution.
-*/
-
-/*
-GJK-EPA collision solver by Nathanael Presson
-Nov.2006
-*/
-
-#include "btGjkEpa.h"
-#include <string.h> //for memset
-#include "LinearMath/btStackAlloc.h"
-
-#if defined(DEBUG) || defined (_DEBUG)
-#include <stdio.h> //for debug printf
-#ifdef __SPU__
-#include <spu_printf.h>
-#define printf spu_printf
-#endif //__SPU__
-#endif
-
-namespace gjkepa_impl
-{
-
-//
-// Port. typedefs
-//
-
-typedef	btScalar		F;
-typedef bool			Z;
-typedef int				I;
-typedef unsigned int	U;
-typedef unsigned char	U1;
-typedef unsigned short	U2;
-
-typedef btVector3		Vector3;
-typedef btMatrix3x3		Rotation;
-
-//
-// Config
-//
-
-#if 0
-#define BTLOCALSUPPORT	localGetSupportingVertexWithoutMargin
-#else
-#define BTLOCALSUPPORT	localGetSupportingVertex
-#endif
-
-//
-// Const
-//
-
-
-#define cstInf				SIMD_INFINITY
-#define cstPi				SIMD_PI
-#define	cst2Pi				SIMD_2_PI
-#define GJK_maxiterations	(128)
-#define GJK_hashsize		(1<<6)
-#define GJK_hashmask		(GJK_hashsize-1)
-#define GJK_insimplex_eps	F(0.0001)
-#define GJK_sqinsimplex_eps	(GJK_insimplex_eps*GJK_insimplex_eps)
-#define EPA_maxiterations	256
-#define	EPA_inface_eps		F(0.01)
-#define EPA_accuracy		F(0.001)
-
-//
-// Utils
-//
-
-static inline F								Abs(F v)					{ return(v<0?-v:v); }
-static inline F								Sign(F v)					{ return(F(v<0?-1:1)); }
-template <typename T> static inline void	Swap(T& a,T& b)				{ T 
-t(a);a=b;b=t; }
-template <typename T> static inline T		Min(const T& a,const T& b)	{ 
-return(a<b?a:b); }
-template <typename T> static inline T		Max(const T& a,const T& b)	{ 
-return(a>b?a:b); }
-static inline void							ClearMemory(void* p,U sz)	{ memset(p,0,(size_t)sz); 
-}
-#if 0
-template <typename T> static inline void	Raise(const T& object)		{
-throw(object); }
-#else
-template <typename T> static inline void	Raise(const T&)				{}
-#endif
-
-
-
-//
-// GJK
-//
-struct	GJK
-	{
-	struct Mkv
-		{
-		Vector3	w;		/* Minkowski vertice	*/
-		Vector3	r;		/* Ray					*/
-		};
-	struct He
-		{
-		Vector3	v;
-		He*		n;
-		};
-	btStackAlloc*				sa;
-	btBlock*		sablock;
-	He*						table[GJK_hashsize];
-	Rotation				wrotations[2];
-	Vector3					positions[2];
-	const btConvexShape*	shapes[2];
-	Mkv						simplex[5];
-	Vector3					ray;
-	U						order;
-	U						iterations;
-	F						margin;
-	Z						failed;
-	//
-					GJK(btStackAlloc* psa,
-						const Rotation& wrot0,const Vector3& pos0,const btConvexShape* shape0,
-						const Rotation& wrot1,const Vector3& pos1,const btConvexShape* shape1,
-						F pmargin=0)
-		{
-		wrotations[0]=wrot0;positions[0]=pos0;shapes[0]=shape0;
-		wrotations[1]=wrot1;positions[1]=pos1;shapes[1]=shape1;
-		sa		=psa;
-		sablock	=sa->beginBlock();
-		margin	=pmargin;
-		failed	=false;
-		}
-	//
-					~GJK()
-		{
-		sa->endBlock(sablock);
-		}
-	// vdh : very dumm hash
-	static inline U	Hash(const Vector3& v)
-		{
-		//this doesn't compile under GCC 3.3.5, so add the ()...
-		//const U	h(U(v[0]*15461)^U(v[1]*83003)^U(v[2]*15473));
-		//return(((*((const U*)&h))*169639)&GJK_hashmask);
-	    const U h((U)(v[0]*15461)^(U)(v[1]*83003)^(U)(v[2]*15473));
-	    return(((*((const U*)&h))*169639)&GJK_hashmask);
-		}
-	//
-	inline Vector3	LocalSupport(const Vector3& d,U i) const
-		{
-		return(wrotations[i]*shapes[i]->BTLOCALSUPPORT(d*wrotations[i])+positions[i]);
-		}
-	//
-	inline void		Support(const Vector3& d,Mkv& v) const
-		{
-		v.r	=	d;
-		v.w	=	LocalSupport(d,0)-LocalSupport(-d,1)+d*margin;
-		}
-	#define SPX(_i_)	simplex[_i_]
-	#define SPXW(_i_)	simplex[_i_].w
-	//
-	inline Z		FetchSupport()
-		{
-		const U			h(Hash(ray));
-		He*				e = (He*)(table[h]);
-		while(e) { if(e->v==ray) { --order;return(false); } else e=e->n; }
-		e=(He*)sa->allocate(sizeof(He));e->v=ray;e->n=table[h];table[h]=e;
-		Support(ray,simplex[++order]);
-		return(ray.dot(SPXW(order))>0);
-		}
-	//
-	inline Z		SolveSimplex2(const Vector3& ao,const Vector3& ab)
-		{
-		if(ab.dot(ao)>=0)
-			{
-			const Vector3	cabo(cross(ab,ao));
-			if(cabo.length2()>GJK_sqinsimplex_eps)
-				{ ray=cross(cabo,ab); }
-				else
-				{ return(true); }
-			}
-			else
-			{ order=0;SPX(0)=SPX(1);ray=ao;	}
-		return(false);
-		}
-	//
-	inline Z		SolveSimplex3(const Vector3& ao,const Vector3& ab,const Vector3& 
-ac)
-		{
-		return(SolveSimplex3a(ao,ab,ac,cross(ab,ac)));
-		}
-	//
-	inline Z		SolveSimplex3a(const Vector3& ao,const Vector3& ab,const Vector3& 
-ac,const Vector3& cabc)
-		{
-				if((cross(cabc,ab)).dot(ao)<-GJK_insimplex_eps)
-			{ order=1;SPX(0)=SPX(1);SPX(1)=SPX(2);return(SolveSimplex2(ao,ab));	}
-		else	if((cross(cabc,ac)).dot(ao)>+GJK_insimplex_eps)
-			{ order=1;SPX(1)=SPX(2);return(SolveSimplex2(ao,ac)); }
-		else
-			{
-			const F			d(cabc.dot(ao));
-			if(Abs(d)>GJK_insimplex_eps)
-				{
-				if(d>0)
-					{ ray=cabc; }
-					else
-					{ ray=-cabc;Swap(SPX(0),SPX(1)); }
-				return(false);
-				} else return(true);
-			}
-		}
-	//
-	inline Z		SolveSimplex4(const Vector3& ao,const Vector3& ab,const Vector3& 
-ac,const Vector3& ad)
-		{
-		Vector3			crs;
-				if((crs=cross(ab,ac)).dot(ao)>GJK_insimplex_eps)
-			{ 
-order=2;SPX(0)=SPX(1);SPX(1)=SPX(2);SPX(2)=SPX(3);return(SolveSimplex3a(ao,ab,ac,crs)); 
-}
-		else	if((crs=cross(ac,ad)).dot(ao)>GJK_insimplex_eps)
-			{ order=2;SPX(2)=SPX(3);return(SolveSimplex3a(ao,ac,ad,crs)); }
-		else	if((crs=cross(ad,ab)).dot(ao)>GJK_insimplex_eps)
-			{ 
-order=2;SPX(1)=SPX(0);SPX(0)=SPX(2);SPX(2)=SPX(3);return(SolveSimplex3a(ao,ad,ab,crs)); 
-}
-		else	return(true);
-		}
-	//
-	inline Z		SearchOrigin(const Vector3& initray=Vector3(1,0,0))
-		{
-		iterations	=	0;
-		order		=	(U)-1;
-		failed		=	false;
-		ray			=	initray.normalized();
-		ClearMemory(table,sizeof(void*)*GJK_hashsize);
-		FetchSupport();
-		ray			=	-SPXW(0);
-		for(;iterations<GJK_maxiterations;++iterations)
-			{
-			const F		rl(ray.length());
-			ray/=rl>0?rl:1;
-			if(FetchSupport())
-				{
-				Z	found(false);
-				switch(order)
-					{
-					case	1:	found=SolveSimplex2(-SPXW(1),SPXW(0)-SPXW(1));break;
-					case	2:	found=SolveSimplex3(-SPXW(2),SPXW(1)-SPXW(2),SPXW(0)-SPXW(2));break;
-					case	3:	found=SolveSimplex4(-SPXW(3),SPXW(2)-SPXW(3),SPXW(1)-SPXW(3),SPXW(0)-SPXW(3));break;
-					}
-				if(found) return(true);
-				} else return(false);
-			}
-		failed=true;
-		return(false);
-		}
-	//
-	inline Z		EncloseOrigin()
-		{
-		switch(order)
-			{
-			/* Point		*/
-			case	0:	break;
-			/* Line			*/
-			case	1:
-				{
-				const Vector3	ab(SPXW(1)-SPXW(0));
-				const Vector3	b[]={	cross(ab,Vector3(1,0,0)),
-										cross(ab,Vector3(0,1,0)),
-										cross(ab,Vector3(0,0,1))};
-				const F			m[]={b[0].length2(),b[1].length2(),b[2].length2()};
-				const Rotation	r(btQuaternion(ab.normalized(),cst2Pi/3));
-				Vector3			w(b[m[0]>m[1]?m[0]>m[2]?0:2:m[1]>m[2]?1:2]);
-				Support(w.normalized(),simplex[4]);w=r*w;
-				Support(w.normalized(),simplex[2]);w=r*w;
-				Support(w.normalized(),simplex[3]);w=r*w;
-				order=4;
-				return(true);
-				}
-			break;
-			/* Triangle		*/
-			case	2:
-				{
-				const 
-Vector3	n(cross((SPXW(1)-SPXW(0)),(SPXW(2)-SPXW(0))).normalized());
-				Support( n,simplex[3]);
-				Support(-n,simplex[4]);
-				order=4;
-				return(true);
-				}
-			break;
-			/* Tetrahedron	*/
-			case	3:	return(true);
-			/* Hexahedron	*/
-			case	4:	return(true);
-			}
-		return(false);
-		}
-	#undef SPX
-	#undef SPXW
-	};
-
-//
-// EPA
-//
-struct	EPA
-	{
-	//
-	struct Face
-		{
-		const GJK::Mkv*	v[3];
-		Face*			f[3];
-		U				e[3];
-		Vector3			n;
-		F				d;
-		U				mark;
-		Face*			prev;
-		Face*			next;
-		Face()			{}
-		};
-	//
-	GJK*			gjk;
-	btStackAlloc*		sa;
-	Face*			root;
-	U				nfaces;
-	U				iterations;
-	Vector3			features[2][3];
-	Vector3			nearest[2];
-	Vector3			normal;
-	F				depth;
-	Z				failed;
-	//
-					EPA(GJK* pgjk)
-		{
-		gjk		=	pgjk;
-		sa		=	pgjk->sa;
-		}
-	//
-					~EPA()
-		{
-		}
-	//
-	inline Vector3	GetCoordinates(const Face* face) const
-		{
-		const Vector3	o(face->n*-face->d);
-		const F			a[]={	cross(face->v[0]->w-o,face->v[1]->w-o).length(),
-								cross(face->v[1]->w-o,face->v[2]->w-o).length(),
-								cross(face->v[2]->w-o,face->v[0]->w-o).length()};
-		const F			sm(a[0]+a[1]+a[2]);
-		return(Vector3(a[1],a[2],a[0])/(sm>0?sm:1));
-		}
-	//
-	inline Face*	FindBest() const
-		{
-		Face*	bf = 0;
-		if(root)
-			{
-			Face*	cf = root;
-			F		bd(cstInf);
-			do	{
-				if(cf->d<bd) { bd=cf->d;bf=cf; }
-				} while(0!=(cf=cf->next));
-			}
-		return(bf);
-		}
-	//
-	inline Z		Set(Face* f,const GJK::Mkv* a,const GJK::Mkv* b,const GJK::Mkv*
-c) const
-		{
-		const Vector3	nrm(cross(b->w-a->w,c->w-a->w));
-		const F			len(nrm.length());
-		const Z			valid(	(cross(a->w,b->w).dot(nrm)>=-EPA_inface_eps)&&
-								(cross(b->w,c->w).dot(nrm)>=-EPA_inface_eps)&&
-								(cross(c->w,a->w).dot(nrm)>=-EPA_inface_eps));
-		f->v[0]	=	a;
-		f->v[1]	=	b;
-		f->v[2]	=	c;
-		f->mark	=	0;
-		f->n	=	nrm/(len>0?len:cstInf);
-		f->d	=	Max<F>(0,-f->n.dot(a->w));
-		return(valid);
-		}
-	//
-	inline Face*	NewFace(const GJK::Mkv* a,const GJK::Mkv* b,const GJK::Mkv* c)
-		{
-		Face*	pf = (Face*)sa->allocate(sizeof(Face));
-		if(Set(pf,a,b,c))
-			{
-			if(root) root->prev=pf;
-			pf->prev=0;
-			pf->next=root;
-			root	=pf;
-			++nfaces;
-			}
-			else
-			{
-			pf->prev=pf->next=0;
-			}
-		return(pf);
-		}
-	//
-	inline void		Detach(Face* face)
-		{
-		if(face->prev||face->next)
-			{
-			--nfaces;
-			if(face==root)
-				{ root=face->next;root->prev=0; }
-				else
-				{
-				if(face->next==0)
-					{ face->prev->next=0; }
-					else
-					{ face->prev->next=face->next;face->next->prev=face->prev; }
-				}
-			face->prev=face->next=0;
-			}
-		}
-	//
-	inline void		Link(Face* f0,U e0,Face* f1,U e1) const
-		{
-		f0->f[e0]=f1;f1->e[e1]=e0;
-		f1->f[e1]=f0;f0->e[e0]=e1;
-		}
-	//
-	GJK::Mkv*		Support(const Vector3& w) const
-		{
-		GJK::Mkv*		v =(GJK::Mkv*)sa->allocate(sizeof(GJK::Mkv));
-		gjk->Support(w,*v);
-		return(v);
-		}
-	//
-	U				BuildHorizon(U markid,const GJK::Mkv* w,Face& f,U e,Face*& cf,Face*& 
-ff)
-		{
-		static const U	mod3[]={0,1,2,0,1};
-		U				ne(0);
-		if(f.mark!=markid)
-			{
-			const U	e1(mod3[e+1]);
-			if((f.n.dot(w->w)+f.d)>0)
-				{
-				Face*	nf = NewFace(f.v[e1],f.v[e],w);
-				Link(nf,0,&f,e);
-				if(cf) Link(cf,1,nf,2); else ff=nf;
-				cf=nf;ne=1;
-				}
-				else
-				{
-				const U	e2(mod3[e+2]);
-				Detach(&f);
-				f.mark	=	markid;
-				ne		+=	BuildHorizon(markid,w,*f.f[e1],f.e[e1],cf,ff);
-				ne		+=	BuildHorizon(markid,w,*f.f[e2],f.e[e2],cf,ff);
-				}
-			}
-		return(ne);
-		}
-	//
-	inline F		EvaluatePD(F accuracy=EPA_accuracy)
-		{
-		btBlock*	sablock = sa->beginBlock();
-		Face*				bestface = 0;
-		U					markid(1);
-		depth		=	-cstInf;
-		normal		=	Vector3(0,0,0);
-		root		=	0;
-		nfaces		=	0;
-		iterations	=	0;
-		failed		=	false;
-		/* Prepare hull		*/
-		if(gjk->EncloseOrigin())
-			{
-			const U*		pfidx = 0;
-			U				nfidx= 0;
-			const U*		peidx = 0;
-			U				neidx = 0;
-			GJK::Mkv*		basemkv[5];
-			Face*			basefaces[6];
-			switch(gjk->order)
-				{
-				/* Tetrahedron		*/
-				case	3:	{
-							static const U	fidx[4][3]={{2,1,0},{3,0,1},{3,1,2},{3,2,0}};
-							static const 
-U	eidx[6][4]={{0,0,2,1},{0,1,1,1},{0,2,3,1},{1,0,3,2},{2,0,1,2},{3,0,2,2}};
-							pfidx=(const U*)fidx;nfidx=4;peidx=(const U*)eidx;neidx=6;
-							}	break;
-				/* Hexahedron		*/
-				case	4:	{
-							static const 
-U	fidx[6][3]={{2,0,4},{4,1,2},{1,4,0},{0,3,1},{0,2,3},{1,3,2}};
-							static const 
-U	eidx[9][4]={{0,0,4,0},{0,1,2,1},{0,2,1,2},{1,1,5,2},{1,0,2,0},{2,2,3,2},{3,1,5,0},{3,0,4,2},{5,1,4,1}};
-							pfidx=(const U*)fidx;nfidx=6;peidx=(const U*)eidx;neidx=9;
-							}	break;
-				}
-			U i;
-
-			for( i=0;i<=gjk->order;++i)		{ 
-basemkv[i]=(GJK::Mkv*)sa->allocate(sizeof(GJK::Mkv));*basemkv[i]=gjk->simplex[i]; 
-}
-			for( i=0;i<nfidx;++i,pfidx+=3)		{ 
-basefaces[i]=NewFace(basemkv[pfidx[0]],basemkv[pfidx[1]],basemkv[pfidx[2]]); 
-}
-			for( i=0;i<neidx;++i,peidx+=4)		{ 
-Link(basefaces[peidx[0]],peidx[1],basefaces[peidx[2]],peidx[3]); }
-			}
-		if(0==nfaces)
-			{
-			sa->endBlock(sablock);
-			return(depth);
-			}
-		/* Expand hull		*/
-		for(;iterations<EPA_maxiterations;++iterations)
-			{
-			Face*		bf = FindBest();
-			if(bf)
-				{
-				GJK::Mkv*	w = Support(-bf->n);
-				const F		d(bf->n.dot(w->w)+bf->d);
-				bestface	=	bf;
-				if(d<-accuracy)
-					{
-					Face*	cf =0;
-					Face*	ff =0;
-					U		nf = 0;
-					Detach(bf);
-					bf->mark=++markid;
-					for(U i=0;i<3;++i)	{ 
-nf+=BuildHorizon(markid,w,*bf->f[i],bf->e[i],cf,ff); }
-					if(nf<=2)			{ break; }
-					Link(cf,1,ff,2);
-					} else break;
-				} else break;
-			}
-		/* Extract contact	*/
-		if(bestface)
-			{
-			const Vector3	b(GetCoordinates(bestface));
-			normal			=	bestface->n;
-			depth			=	Max<F>(0,bestface->d);
-			for(U i=0;i<2;++i)
-				{
-				const F	s(F(i?-1:1));
-				for(U j=0;j<3;++j)
-					{
-					features[i][j]=gjk->LocalSupport(s*bestface->v[j]->r,i);
-					}
-				}
-			nearest[0]		=	features[0][0]*b.x()+features[0][1]*b.y()+features[0][2]*b.z();
-			nearest[1]		=	features[1][0]*b.x()+features[1][1]*b.y()+features[1][2]*b.z();
-			} else failed=true;
-		sa->endBlock(sablock);
-		return(depth);
-		}
-	};
-}
-
-//
-// Api
-//
-
-using namespace	gjkepa_impl;
-
-
-
-//
-bool	btGjkEpaSolver::Collide(const btConvexShape *shape0,const btTransform &wtrs0,
-								const btConvexShape *shape1,const btTransform &wtrs1,
-								btScalar	radialmargin,
-								btStackAlloc* stackAlloc,
-								sResults&	results)
-{
-	
-
-/* Initialize					*/
-results.witnesses[0]	=
-results.witnesses[1]	=
-results.normal			=	Vector3(0,0,0);
-results.depth			=	0;
-results.status			=	sResults::Separated;
-results.epa_iterations	=	0;
-results.gjk_iterations	=	0;
-/* Use GJK to locate origin		*/
-GJK			gjk(stackAlloc,
-				wtrs0.getBasis(),wtrs0.getOrigin(),shape0,
-				wtrs1.getBasis(),wtrs1.getOrigin(),shape1,
-				radialmargin+EPA_accuracy);
-const Z		collide(gjk.SearchOrigin());
-results.gjk_iterations	=	static_cast<int>(gjk.iterations+1);
-if(collide)
-	{
-	/* Then EPA for penetration depth	*/
-	EPA			epa(&gjk);
-	const F		pd(epa.EvaluatePD());
-	results.epa_iterations	=	static_cast<int>(epa.iterations+1);
-	if(pd>0)
-		{
-		results.status			=	sResults::Penetrating;
-		results.normal			=	epa.normal;
-		results.depth			=	pd;
-		results.witnesses[0]	=	epa.nearest[0];
-		results.witnesses[1]	=	epa.nearest[1];
-		return(true);
-		} else { if(epa.failed) results.status=sResults::EPA_Failed; }
-	} else { if(gjk.failed) results.status=sResults::GJK_Failed; }
-return(false);
-}
-
-
-
-
-
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa.h	(revision 2192)
+++ 	(revision )
@@ -1,53 +1,0 @@
-/*
-Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
-
-This software is provided 'as-is', without any express or implied warranty.
-In no event will the authors be held liable for any damages arising from the use of this software.
-Permission is granted to anyone to use this software for any purpose, 
-including commercial applications, and to alter it and redistribute it freely, 
-subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
-2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-3. This notice may not be removed or altered from any source distribution.
-*/
-
-/*
-GJK-EPA collision solver by Nathanael Presson
-Nov.2006
-*/
-
-
-#ifndef _05E48D53_04E0_49ad_BB0A_D74FE62E7366_
-#define _05E48D53_04E0_49ad_BB0A_D74FE62E7366_
-#include "BulletCollision/CollisionShapes/btConvexShape.h"
-
-class btStackAlloc;
-
-///btGjkEpaSolver contributed under zlib by Nathanael Presson
-struct	btGjkEpaSolver
-{
-struct	sResults
-	{
-	enum eStatus
-		{
-		Separated,		/* Shapes doesnt penetrate												*/ 
-		Penetrating,	/* Shapes are penetrating												*/ 
-		GJK_Failed,		/* GJK phase fail, no big issue, shapes are probably just 'touching'	*/ 
-		EPA_Failed		/* EPA phase fail, bigger problem, need to save parameters, and debug	*/ 
-		}		status;
-	btVector3	witnesses[2];
-	btVector3	normal;
-	btScalar	depth;
-	int	epa_iterations;
-	int	gjk_iterations;
-	};
-static bool	Collide(const btConvexShape* shape0,const btTransform& wtrs0,
-					const btConvexShape* shape1,const btTransform& wtrs1,
-					btScalar	radialmargin,
-					btStackAlloc* stackAlloc,
-					sResults&	results);
-};
-
-#endif
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp	(revision 2430)
@@ -38,5 +38,5 @@
 {
 
-// Config
+	// Config
 
 	/* GJK	*/ 
@@ -59,709 +59,709 @@
 
 
-// Shorthands
-typedef unsigned int	U;
-typedef unsigned char	U1;
-
-// MinkowskiDiff
-struct	MinkowskiDiff
+	// Shorthands
+	typedef unsigned int	U;
+	typedef unsigned char	U1;
+
+	// MinkowskiDiff
+	struct	MinkowskiDiff
 	{
-	const btConvexShape*	m_shapes[2];
-	btMatrix3x3				m_toshape1;
-	btTransform				m_toshape0;
-	btVector3				(btConvexShape::*Ls)(const btVector3&) const;
-	void					EnableMargin(bool enable)
-		{
-		if(enable)
-			Ls=&btConvexShape::localGetSupportVertexNonVirtual;
+		const btConvexShape*	m_shapes[2];
+		btMatrix3x3				m_toshape1;
+		btTransform				m_toshape0;
+		btVector3				(btConvexShape::*Ls)(const btVector3&) const;
+		void					EnableMargin(bool enable)
+		{
+			if(enable)
+				Ls=&btConvexShape::localGetSupportVertexNonVirtual;
 			else
-			Ls=&btConvexShape::localGetSupportVertexWithoutMarginNonVirtual;
+				Ls=&btConvexShape::localGetSupportVertexWithoutMarginNonVirtual;
 		}	
-	inline btVector3		Support0(const btVector3& d) const
-		{
-		return(((m_shapes[0])->*(Ls))(d));
+		inline btVector3		Support0(const btVector3& d) const
+		{
+			return(((m_shapes[0])->*(Ls))(d));
 		}
-	inline btVector3		Support1(const btVector3& d) const
-		{
-		return(m_toshape0*((m_shapes[1])->*(Ls))(m_toshape1*d));
+		inline btVector3		Support1(const btVector3& d) const
+		{
+			return(m_toshape0*((m_shapes[1])->*(Ls))(m_toshape1*d));
 		}
-	inline btVector3		Support(const btVector3& d) const
-		{
-		return(Support0(d)-Support1(-d));
+		inline btVector3		Support(const btVector3& d) const
+		{
+			return(Support0(d)-Support1(-d));
 		}
-	btVector3				Support(const btVector3& d,U index) const
-		{
-		if(index)
-			return(Support1(d));
+		btVector3				Support(const btVector3& d,U index) const
+		{
+			if(index)
+				return(Support1(d));
 			else
-			return(Support0(d));
+				return(Support0(d));
 		}
 	};
 
-typedef	MinkowskiDiff	tShape;
-
-
-// GJK
-struct	GJK
-{
-/* Types		*/ 
-struct	sSV
+	typedef	MinkowskiDiff	tShape;
+
+
+	// GJK
+	struct	GJK
 	{
-	btVector3	d,w;
-	};
-struct	sSimplex
-	{
-	sSV*		c[4];
-	btScalar	p[4];
-	U			rank;
-	};
-struct	eStatus	{ enum _ {
-	Valid,
-	Inside,
-	Failed		};};
-/* Fields		*/ 
-tShape			m_shape;
-btVector3		m_ray;
-btScalar		m_distance;
-sSimplex		m_simplices[2];
-sSV				m_store[4];
-sSV*			m_free[4];
-U				m_nfree;
-U				m_current;
-sSimplex*		m_simplex;
-eStatus::_		m_status;
-/* Methods		*/ 
-					GJK()
-	{
-	Initialize();
-	}
-void				Initialize()
-	{
-	m_ray		=	btVector3(0,0,0);
-	m_nfree		=	0;
-	m_status	=	eStatus::Failed;
-	m_current	=	0;
-	m_distance	=	0;
-	}
-eStatus::_			Evaluate(const tShape& shapearg,const btVector3& guess)
-	{
-	U			iterations=0;
-	btScalar	sqdist=0;
-	btScalar	alpha=0;
-	btVector3	lastw[4];
-	U			clastw=0;
-	/* Initialize solver		*/ 
-	m_free[0]			=	&m_store[0];
-	m_free[1]			=	&m_store[1];
-	m_free[2]			=	&m_store[2];
-	m_free[3]			=	&m_store[3];
-	m_nfree				=	4;
-	m_current			=	0;
-	m_status			=	eStatus::Valid;
-	m_shape				=	shapearg;
-	m_distance			=	0;
-	/* Initialize simplex		*/ 
-	m_simplices[0].rank	=	0;
-	m_ray				=	guess;
-	const btScalar	sqrl=	m_ray.length2();
-	appendvertice(m_simplices[0],sqrl>0?-m_ray:btVector3(1,0,0));
-	m_simplices[0].p[0]	=	1;
-	m_ray				=	m_simplices[0].c[0]->w;	
-	sqdist				=	sqrl;
-	lastw[0]			=
-	lastw[1]			=
-	lastw[2]			=
-	lastw[3]			=	m_ray;
-	/* Loop						*/ 
-	do	{
-		const U		next=1-m_current;
-		sSimplex&	cs=m_simplices[m_current];
-		sSimplex&	ns=m_simplices[next];
-		/* Check zero							*/ 
-		const btScalar	rl=m_ray.length();
-		if(rl<GJK_MIN_DISTANCE)
-			{/* Touching or inside				*/ 
-			m_status=eStatus::Inside;
-			break;
-			}
-		/* Append new vertice in -'v' direction	*/ 
-		appendvertice(cs,-m_ray);
-		const btVector3&	w=cs.c[cs.rank-1]->w;
-		bool				found=false;
-		for(U i=0;i<4;++i)
-			{
-			if((w-lastw[i]).length2()<GJK_DUPLICATED_EPS)
-				{ found=true;break; }
-			}
-		if(found)
-			{/* Return old simplex				*/ 
-			removevertice(m_simplices[m_current]);
-			break;
-			}
-			else
-			{/* Update lastw					*/ 
-			lastw[clastw=(clastw+1)&3]=w;
-			}
-		/* Check for termination				*/ 
-		const btScalar	omega=dot(m_ray,w)/rl;
-		alpha=btMax(omega,alpha);
-		if(((rl-alpha)-(GJK_ACCURARY*rl))<=0)
-			{/* Return old simplex				*/ 
-			removevertice(m_simplices[m_current]);
-			break;
-			}		
-		/* Reduce simplex						*/ 
-		btScalar	weights[4];
-		U			mask=0;
-		switch(cs.rank)
-			{
-			case	2:	sqdist=projectorigin(	cs.c[0]->w,
-												cs.c[1]->w,
-												weights,mask);break;
-			case	3:	sqdist=projectorigin(	cs.c[0]->w,
-												cs.c[1]->w,
-												cs.c[2]->w,
-												weights,mask);break;
-			case	4:	sqdist=projectorigin(	cs.c[0]->w,
-												cs.c[1]->w,
-												cs.c[2]->w,
-												cs.c[3]->w,
-												weights,mask);break;
-			}
-		if(sqdist>=0)
-			{/* Valid	*/ 
-			ns.rank		=	0;
-			m_ray		=	btVector3(0,0,0);
-			m_current	=	next;
-			for(U i=0,ni=cs.rank;i<ni;++i)
-				{
-				if(mask&(1<<i))
-					{
-					ns.c[ns.rank]		=	cs.c[i];
-					ns.p[ns.rank++]		=	weights[i];
-					m_ray				+=	cs.c[i]->w*weights[i];
+		/* Types		*/ 
+		struct	sSV
+		{
+			btVector3	d,w;
+		};
+		struct	sSimplex
+		{
+			sSV*		c[4];
+			btScalar	p[4];
+			U			rank;
+		};
+		struct	eStatus	{ enum _ {
+			Valid,
+			Inside,
+			Failed		};};
+			/* Fields		*/ 
+			tShape			m_shape;
+			btVector3		m_ray;
+			btScalar		m_distance;
+			sSimplex		m_simplices[2];
+			sSV				m_store[4];
+			sSV*			m_free[4];
+			U				m_nfree;
+			U				m_current;
+			sSimplex*		m_simplex;
+			eStatus::_		m_status;
+			/* Methods		*/ 
+			GJK()
+			{
+				Initialize();
+			}
+			void				Initialize()
+			{
+				m_ray		=	btVector3(0,0,0);
+				m_nfree		=	0;
+				m_status	=	eStatus::Failed;
+				m_current	=	0;
+				m_distance	=	0;
+			}
+			eStatus::_			Evaluate(const tShape& shapearg,const btVector3& guess)
+			{
+				U			iterations=0;
+				btScalar	sqdist=0;
+				btScalar	alpha=0;
+				btVector3	lastw[4];
+				U			clastw=0;
+				/* Initialize solver		*/ 
+				m_free[0]			=	&m_store[0];
+				m_free[1]			=	&m_store[1];
+				m_free[2]			=	&m_store[2];
+				m_free[3]			=	&m_store[3];
+				m_nfree				=	4;
+				m_current			=	0;
+				m_status			=	eStatus::Valid;
+				m_shape				=	shapearg;
+				m_distance			=	0;
+				/* Initialize simplex		*/ 
+				m_simplices[0].rank	=	0;
+				m_ray				=	guess;
+				const btScalar	sqrl=	m_ray.length2();
+				appendvertice(m_simplices[0],sqrl>0?-m_ray:btVector3(1,0,0));
+				m_simplices[0].p[0]	=	1;
+				m_ray				=	m_simplices[0].c[0]->w;	
+				sqdist				=	sqrl;
+				lastw[0]			=
+					lastw[1]			=
+					lastw[2]			=
+					lastw[3]			=	m_ray;
+				/* Loop						*/ 
+				do	{
+					const U		next=1-m_current;
+					sSimplex&	cs=m_simplices[m_current];
+					sSimplex&	ns=m_simplices[next];
+					/* Check zero							*/ 
+					const btScalar	rl=m_ray.length();
+					if(rl<GJK_MIN_DISTANCE)
+					{/* Touching or inside				*/ 
+						m_status=eStatus::Inside;
+						break;
+					}
+					/* Append new vertice in -'v' direction	*/ 
+					appendvertice(cs,-m_ray);
+					const btVector3&	w=cs.c[cs.rank-1]->w;
+					bool				found=false;
+					for(U i=0;i<4;++i)
+					{
+						if((w-lastw[i]).length2()<GJK_DUPLICATED_EPS)
+						{ found=true;break; }
+					}
+					if(found)
+					{/* Return old simplex				*/ 
+						removevertice(m_simplices[m_current]);
+						break;
 					}
 					else
-					{
-					m_free[m_nfree++]	=	cs.c[i];
-					}
-				}
-			if(mask==15) m_status=eStatus::Inside;
-			}
-			else
-			{/* Return old simplex				*/ 
-			removevertice(m_simplices[m_current]);
-			break;
-			}
-		m_status=((++iterations)<GJK_MAX_ITERATIONS)?m_status:eStatus::Failed;
-		} while(m_status==eStatus::Valid);
-	m_simplex=&m_simplices[m_current];
-	switch(m_status)
-		{
-		case	eStatus::Valid:		m_distance=m_ray.length();break;
-		case	eStatus::Inside:	m_distance=0;break;
-		}	
-	return(m_status);
-	}
-bool					EncloseOrigin()
-	{
-	switch(m_simplex->rank)
-		{
-		case	1:
-			{
-			for(U i=0;i<3;++i)
-				{
-				btVector3		axis=btVector3(0,0,0);
-				axis[i]=1;
-				appendvertice(*m_simplex, axis);
-				if(EncloseOrigin())	return(true);
-				removevertice(*m_simplex);
-				appendvertice(*m_simplex,-axis);
-				if(EncloseOrigin())	return(true);
-				removevertice(*m_simplex);
-				}
-			}
-		break;
-		case	2:
-			{
-			const btVector3	d=m_simplex->c[1]->w-m_simplex->c[0]->w;
-			for(U i=0;i<3;++i)
-				{
-				btVector3		axis=btVector3(0,0,0);
-				axis[i]=1;
-				const btVector3	p=cross(d,axis);
-				if(p.length2()>0)
-					{
-					appendvertice(*m_simplex, p);
-					if(EncloseOrigin())	return(true);
-					removevertice(*m_simplex);
-					appendvertice(*m_simplex,-p);
-					if(EncloseOrigin())	return(true);
-					removevertice(*m_simplex);
-					}
-				}
-			}
-		break;
-		case	3:
-			{
-			const btVector3	n=cross(m_simplex->c[1]->w-m_simplex->c[0]->w,
-									m_simplex->c[2]->w-m_simplex->c[0]->w);
-			if(n.length2()>0)
-				{
-				appendvertice(*m_simplex,n);
-				if(EncloseOrigin())	return(true);
-				removevertice(*m_simplex);
-				appendvertice(*m_simplex,-n);
-				if(EncloseOrigin())	return(true);
-				removevertice(*m_simplex);
-				}
-			}
-		break;
-		case	4:
-			{
-			if(btFabs(det(	m_simplex->c[0]->w-m_simplex->c[3]->w,
+					{/* Update lastw					*/ 
+						lastw[clastw=(clastw+1)&3]=w;
+					}
+					/* Check for termination				*/ 
+					const btScalar	omega=dot(m_ray,w)/rl;
+					alpha=btMax(omega,alpha);
+					if(((rl-alpha)-(GJK_ACCURARY*rl))<=0)
+					{/* Return old simplex				*/ 
+						removevertice(m_simplices[m_current]);
+						break;
+					}		
+					/* Reduce simplex						*/ 
+					btScalar	weights[4];
+					U			mask=0;
+					switch(cs.rank)
+					{
+					case	2:	sqdist=projectorigin(	cs.c[0]->w,
+									cs.c[1]->w,
+									weights,mask);break;
+					case	3:	sqdist=projectorigin(	cs.c[0]->w,
+									cs.c[1]->w,
+									cs.c[2]->w,
+									weights,mask);break;
+					case	4:	sqdist=projectorigin(	cs.c[0]->w,
+									cs.c[1]->w,
+									cs.c[2]->w,
+									cs.c[3]->w,
+									weights,mask);break;
+					}
+					if(sqdist>=0)
+					{/* Valid	*/ 
+						ns.rank		=	0;
+						m_ray		=	btVector3(0,0,0);
+						m_current	=	next;
+						for(U i=0,ni=cs.rank;i<ni;++i)
+						{
+							if(mask&(1<<i))
+							{
+								ns.c[ns.rank]		=	cs.c[i];
+								ns.p[ns.rank++]		=	weights[i];
+								m_ray				+=	cs.c[i]->w*weights[i];
+							}
+							else
+							{
+								m_free[m_nfree++]	=	cs.c[i];
+							}
+						}
+						if(mask==15) m_status=eStatus::Inside;
+					}
+					else
+					{/* Return old simplex				*/ 
+						removevertice(m_simplices[m_current]);
+						break;
+					}
+					m_status=((++iterations)<GJK_MAX_ITERATIONS)?m_status:eStatus::Failed;
+				} while(m_status==eStatus::Valid);
+				m_simplex=&m_simplices[m_current];
+				switch(m_status)
+				{
+				case	eStatus::Valid:		m_distance=m_ray.length();break;
+				case	eStatus::Inside:	m_distance=0;break;
+				}	
+				return(m_status);
+			}
+			bool					EncloseOrigin()
+			{
+				switch(m_simplex->rank)
+				{
+				case	1:
+					{
+						for(U i=0;i<3;++i)
+						{
+							btVector3		axis=btVector3(0,0,0);
+							axis[i]=1;
+							appendvertice(*m_simplex, axis);
+							if(EncloseOrigin())	return(true);
+							removevertice(*m_simplex);
+							appendvertice(*m_simplex,-axis);
+							if(EncloseOrigin())	return(true);
+							removevertice(*m_simplex);
+						}
+					}
+					break;
+				case	2:
+					{
+						const btVector3	d=m_simplex->c[1]->w-m_simplex->c[0]->w;
+						for(U i=0;i<3;++i)
+						{
+							btVector3		axis=btVector3(0,0,0);
+							axis[i]=1;
+							const btVector3	p=cross(d,axis);
+							if(p.length2()>0)
+							{
+								appendvertice(*m_simplex, p);
+								if(EncloseOrigin())	return(true);
+								removevertice(*m_simplex);
+								appendvertice(*m_simplex,-p);
+								if(EncloseOrigin())	return(true);
+								removevertice(*m_simplex);
+							}
+						}
+					}
+					break;
+				case	3:
+					{
+						const btVector3	n=cross(m_simplex->c[1]->w-m_simplex->c[0]->w,
+							m_simplex->c[2]->w-m_simplex->c[0]->w);
+						if(n.length2()>0)
+						{
+							appendvertice(*m_simplex,n);
+							if(EncloseOrigin())	return(true);
+							removevertice(*m_simplex);
+							appendvertice(*m_simplex,-n);
+							if(EncloseOrigin())	return(true);
+							removevertice(*m_simplex);
+						}
+					}
+					break;
+				case	4:
+					{
+						if(btFabs(det(	m_simplex->c[0]->w-m_simplex->c[3]->w,
 							m_simplex->c[1]->w-m_simplex->c[3]->w,
 							m_simplex->c[2]->w-m_simplex->c[3]->w))>0)
-				return(true);
-			}
-		break;
-		}
-	return(false);
-	}
-/* Internals	*/ 
-void				getsupport(const btVector3& d,sSV& sv) const
-	{
-	sv.d	=	d/d.length();
-	sv.w	=	m_shape.Support(sv.d);
-	}
-void				removevertice(sSimplex& simplex)
-	{
-	m_free[m_nfree++]=simplex.c[--simplex.rank];
-	}
-void				appendvertice(sSimplex& simplex,const btVector3& v)
-	{
-	simplex.p[simplex.rank]=0;
-	simplex.c[simplex.rank]=m_free[--m_nfree];
-	getsupport(v,*simplex.c[simplex.rank++]);
-	}
-static btScalar		det(const btVector3& a,const btVector3& b,const btVector3& c)
-	{
-	return(	a.y()*b.z()*c.x()+a.z()*b.x()*c.y()-
-			a.x()*b.z()*c.y()-a.y()*b.x()*c.z()+
-			a.x()*b.y()*c.z()-a.z()*b.y()*c.x());
-	}
-static btScalar		projectorigin(	const btVector3& a,
-									const btVector3& b,
-									btScalar* w,U& m)
-	{
-	const btVector3	d=b-a;
-	const btScalar	l=d.length2();
-	if(l>GJK_SIMPLEX2_EPS)
-		{
-		const btScalar	t(l>0?-dot(a,d)/l:0);
-		if(t>=1)		{ w[0]=0;w[1]=1;m=2;return(b.length2()); }
-		else if(t<=0)	{ w[0]=1;w[1]=0;m=1;return(a.length2()); }
-		else			{ w[0]=1-(w[1]=t);m=3;return((a+d*t).length2()); }
-		}
-	return(-1);
-	}
-static btScalar		projectorigin(	const btVector3& a,
-									const btVector3& b,
-									const btVector3& c,
-									btScalar* w,U& m)
-	{
-	static const U		imd3[]={1,2,0};
-	const btVector3*	vt[]={&a,&b,&c};
-	const btVector3		dl[]={a-b,b-c,c-a};
-	const btVector3		n=cross(dl[0],dl[1]);
-	const btScalar		l=n.length2();
-	if(l>GJK_SIMPLEX3_EPS)
-		{
-		btScalar	mindist=-1;
-		btScalar	subw[2];
-		U			subm;
-		for(U i=0;i<3;++i)
-			{
-			if(dot(*vt[i],cross(dl[i],n))>0)
-				{
-				const U			j=imd3[i];
-				const btScalar	subd(projectorigin(*vt[i],*vt[j],subw,subm));
-				if((mindist<0)||(subd<mindist))
-					{
-					mindist		=	subd;
-					m			=	static_cast<U>(((subm&1)?1<<i:0)+((subm&2)?1<<j:0));
-					w[i]		=	subw[0];
-					w[j]		=	subw[1];
-					w[imd3[j]]	=	0;				
-					}
+							return(true);
+					}
+					break;
 				}
-			}
-		if(mindist<0)
-			{
-			const btScalar	d=dot(a,n);	
-			const btScalar	s=btSqrt(l);
-			const btVector3	p=n*(d/l);
-			mindist	=	p.length2();
-			m		=	7;
-			w[0]	=	(cross(dl[1],b-p)).length()/s;
-			w[1]	=	(cross(dl[2],c-p)).length()/s;
-			w[2]	=	1-(w[0]+w[1]);
-			}
-		return(mindist);
-		}
-	return(-1);
-	}
-static btScalar		projectorigin(	const btVector3& a,
-									const btVector3& b,
-									const btVector3& c,
-									const btVector3& d,
-									btScalar* w,U& m)
-	{
-	static const U		imd3[]={1,2,0};
-	const btVector3*	vt[]={&a,&b,&c,&d};
-	const btVector3		dl[]={a-d,b-d,c-d};
-	const btScalar		vl=det(dl[0],dl[1],dl[2]);
-	const bool			ng=(vl*dot(a,cross(b-c,a-b)))<=0;
-	if(ng&&(btFabs(vl)>GJK_SIMPLEX4_EPS))
-		{
-		btScalar	mindist=-1;
-		btScalar	subw[3];
-		U			subm;
-		for(U i=0;i<3;++i)
-			{
-			const U			j=imd3[i];
-			const btScalar	s=vl*dot(d,cross(dl[i],dl[j]));
-			if(s>0)
-				{
-				const btScalar	subd=projectorigin(*vt[i],*vt[j],d,subw,subm);
-				if((mindist<0)||(subd<mindist))
-					{
-					mindist		=	subd;
-					m			=	static_cast<U>((subm&1?1<<i:0)+
+				return(false);
+			}
+			/* Internals	*/ 
+			void				getsupport(const btVector3& d,sSV& sv) const
+			{
+				sv.d	=	d/d.length();
+				sv.w	=	m_shape.Support(sv.d);
+			}
+			void				removevertice(sSimplex& simplex)
+			{
+				m_free[m_nfree++]=simplex.c[--simplex.rank];
+			}
+			void				appendvertice(sSimplex& simplex,const btVector3& v)
+			{
+				simplex.p[simplex.rank]=0;
+				simplex.c[simplex.rank]=m_free[--m_nfree];
+				getsupport(v,*simplex.c[simplex.rank++]);
+			}
+			static btScalar		det(const btVector3& a,const btVector3& b,const btVector3& c)
+			{
+				return(	a.y()*b.z()*c.x()+a.z()*b.x()*c.y()-
+					a.x()*b.z()*c.y()-a.y()*b.x()*c.z()+
+					a.x()*b.y()*c.z()-a.z()*b.y()*c.x());
+			}
+			static btScalar		projectorigin(	const btVector3& a,
+				const btVector3& b,
+				btScalar* w,U& m)
+			{
+				const btVector3	d=b-a;
+				const btScalar	l=d.length2();
+				if(l>GJK_SIMPLEX2_EPS)
+				{
+					const btScalar	t(l>0?-dot(a,d)/l:0);
+					if(t>=1)		{ w[0]=0;w[1]=1;m=2;return(b.length2()); }
+					else if(t<=0)	{ w[0]=1;w[1]=0;m=1;return(a.length2()); }
+					else			{ w[0]=1-(w[1]=t);m=3;return((a+d*t).length2()); }
+				}
+				return(-1);
+			}
+			static btScalar		projectorigin(	const btVector3& a,
+				const btVector3& b,
+				const btVector3& c,
+				btScalar* w,U& m)
+			{
+				static const U		imd3[]={1,2,0};
+				const btVector3*	vt[]={&a,&b,&c};
+				const btVector3		dl[]={a-b,b-c,c-a};
+				const btVector3		n=cross(dl[0],dl[1]);
+				const btScalar		l=n.length2();
+				if(l>GJK_SIMPLEX3_EPS)
+				{
+					btScalar	mindist=-1;
+					btScalar	subw[2];
+					U			subm;
+					for(U i=0;i<3;++i)
+					{
+						if(dot(*vt[i],cross(dl[i],n))>0)
+						{
+							const U			j=imd3[i];
+							const btScalar	subd(projectorigin(*vt[i],*vt[j],subw,subm));
+							if((mindist<0)||(subd<mindist))
+							{
+								mindist		=	subd;
+								m			=	static_cast<U>(((subm&1)?1<<i:0)+((subm&2)?1<<j:0));
+								w[i]		=	subw[0];
+								w[j]		=	subw[1];
+								w[imd3[j]]	=	0;				
+							}
+						}
+					}
+					if(mindist<0)
+					{
+						const btScalar	d=dot(a,n);	
+						const btScalar	s=btSqrt(l);
+						const btVector3	p=n*(d/l);
+						mindist	=	p.length2();
+						m		=	7;
+						w[0]	=	(cross(dl[1],b-p)).length()/s;
+						w[1]	=	(cross(dl[2],c-p)).length()/s;
+						w[2]	=	1-(w[0]+w[1]);
+					}
+					return(mindist);
+				}
+				return(-1);
+			}
+			static btScalar		projectorigin(	const btVector3& a,
+				const btVector3& b,
+				const btVector3& c,
+				const btVector3& d,
+				btScalar* w,U& m)
+			{
+				static const U		imd3[]={1,2,0};
+				const btVector3*	vt[]={&a,&b,&c,&d};
+				const btVector3		dl[]={a-d,b-d,c-d};
+				const btScalar		vl=det(dl[0],dl[1],dl[2]);
+				const bool			ng=(vl*dot(a,cross(b-c,a-b)))<=0;
+				if(ng&&(btFabs(vl)>GJK_SIMPLEX4_EPS))
+				{
+					btScalar	mindist=-1;
+					btScalar	subw[3];
+					U			subm;
+					for(U i=0;i<3;++i)
+					{
+						const U			j=imd3[i];
+						const btScalar	s=vl*dot(d,cross(dl[i],dl[j]));
+						if(s>0)
+						{
+							const btScalar	subd=projectorigin(*vt[i],*vt[j],d,subw,subm);
+							if((mindist<0)||(subd<mindist))
+							{
+								mindist		=	subd;
+								m			=	static_cast<U>((subm&1?1<<i:0)+
 									(subm&2?1<<j:0)+
 									(subm&4?8:0));
-					w[i]		=	subw[0];
-					w[j]		=	subw[1];
-					w[imd3[j]]	=	0;
-					w[3]		=	subw[2];
-					}
+								w[i]		=	subw[0];
+								w[j]		=	subw[1];
+								w[imd3[j]]	=	0;
+								w[3]		=	subw[2];
+							}
+						}
+					}
+					if(mindist<0)
+					{
+						mindist	=	0;
+						m		=	15;
+						w[0]	=	det(c,b,d)/vl;
+						w[1]	=	det(a,c,d)/vl;
+						w[2]	=	det(b,a,d)/vl;
+						w[3]	=	1-(w[0]+w[1]+w[2]);
+					}
+					return(mindist);
 				}
-			}
-		if(mindist<0)
-			{
-			mindist	=	0;
-			m		=	15;
-			w[0]	=	det(c,b,d)/vl;
-			w[1]	=	det(a,c,d)/vl;
-			w[2]	=	det(b,a,d)/vl;
-			w[3]	=	1-(w[0]+w[1]+w[2]);
-			}
-		return(mindist);
-		}
-	return(-1);
-	}
-};
-
-// EPA
-struct	EPA
-{
-/* Types		*/ 
-typedef	GJK::sSV	sSV;
-struct	sFace
+				return(-1);
+			}
+	};
+
+	// EPA
+	struct	EPA
 	{
-	btVector3	n;
-	btScalar	d;
-	btScalar	p;
-	sSV*		c[3];
-	sFace*		f[3];
-	sFace*		l[2];
-	U1			e[3];
-	U1			pass;
-	};
-struct	sList
-	{
-	sFace*		root;
-	U			count;
-				sList() : root(0),count(0)	{}
-	};
-struct	sHorizon
-	{
-	sFace*		cf;
-	sFace*		ff;
-	U			nf;
-				sHorizon() : cf(0),ff(0),nf(0)	{}
-	};
-struct	eStatus { enum _ {
-	Valid,
-	Touching,
-	Degenerated,
-	NonConvex,
-	InvalidHull,		
-	OutOfFaces,
-	OutOfVertices,
-	AccuraryReached,
-	FallBack,
-	Failed		};};
-/* Fields		*/ 
-eStatus::_		m_status;
-GJK::sSimplex	m_result;
-btVector3		m_normal;
-btScalar		m_depth;
-sSV				m_sv_store[EPA_MAX_VERTICES];
-sFace			m_fc_store[EPA_MAX_FACES];
-U				m_nextsv;
-sList			m_hull;
-sList			m_stock;
-/* Methods		*/ 
-					EPA()
-	{
-	Initialize();	
-	}
-
-
-					static inline void		bind(sFace* fa,U ea,sFace* fb,U eb)
-	{
-	fa->e[ea]=(U1)eb;fa->f[ea]=fb;
-	fb->e[eb]=(U1)ea;fb->f[eb]=fa;
-	}
-static inline void		append(sList& list,sFace* face)
-	{
-	face->l[0]	=	0;
-	face->l[1]	=	list.root;
-	if(list.root) list.root->l[0]=face;
-	list.root	=	face;
-	++list.count;
-	}
-static inline void		remove(sList& list,sFace* face)
-	{
-	if(face->l[1]) face->l[1]->l[0]=face->l[0];
-	if(face->l[0]) face->l[0]->l[1]=face->l[1];
-	if(face==list.root) list.root=face->l[1];
-	--list.count;
-	}
-
-
-void				Initialize()
-	{
-	m_status	=	eStatus::Failed;
-	m_normal	=	btVector3(0,0,0);
-	m_depth		=	0;
-	m_nextsv	=	0;
-	for(U i=0;i<EPA_MAX_FACES;++i)
-		{
-		append(m_stock,&m_fc_store[EPA_MAX_FACES-i-1]);
-		}
-	}
-eStatus::_			Evaluate(GJK& gjk,const btVector3& guess)
-	{
-	GJK::sSimplex&	simplex=*gjk.m_simplex;
-	if((simplex.rank>1)&&gjk.EncloseOrigin())
-		{
-
-		/* Clean up				*/ 
-		while(m_hull.root)
-			{
-			sFace*	f = m_hull.root;
-			remove(m_hull,f);
-			append(m_stock,f);
-			}
-		m_status	=	eStatus::Valid;
-		m_nextsv	=	0;
-		/* Orient simplex		*/ 
-		if(gjk.det(	simplex.c[0]->w-simplex.c[3]->w,
-					simplex.c[1]->w-simplex.c[3]->w,
-					simplex.c[2]->w-simplex.c[3]->w)<0)
-			{
-			btSwap(simplex.c[0],simplex.c[1]);
-			btSwap(simplex.p[0],simplex.p[1]);
-			}
-		/* Build initial hull	*/ 
-		sFace*	tetra[]={newface(simplex.c[0],simplex.c[1],simplex.c[2],true),
+		/* Types		*/ 
+		typedef	GJK::sSV	sSV;
+		struct	sFace
+		{
+			btVector3	n;
+			btScalar	d;
+			btScalar	p;
+			sSV*		c[3];
+			sFace*		f[3];
+			sFace*		l[2];
+			U1			e[3];
+			U1			pass;
+		};
+		struct	sList
+		{
+			sFace*		root;
+			U			count;
+			sList() : root(0),count(0)	{}
+		};
+		struct	sHorizon
+		{
+			sFace*		cf;
+			sFace*		ff;
+			U			nf;
+			sHorizon() : cf(0),ff(0),nf(0)	{}
+		};
+		struct	eStatus { enum _ {
+			Valid,
+			Touching,
+			Degenerated,
+			NonConvex,
+			InvalidHull,		
+			OutOfFaces,
+			OutOfVertices,
+			AccuraryReached,
+			FallBack,
+			Failed		};};
+			/* Fields		*/ 
+			eStatus::_		m_status;
+			GJK::sSimplex	m_result;
+			btVector3		m_normal;
+			btScalar		m_depth;
+			sSV				m_sv_store[EPA_MAX_VERTICES];
+			sFace			m_fc_store[EPA_MAX_FACES];
+			U				m_nextsv;
+			sList			m_hull;
+			sList			m_stock;
+			/* Methods		*/ 
+			EPA()
+			{
+				Initialize();	
+			}
+
+
+			static inline void		bind(sFace* fa,U ea,sFace* fb,U eb)
+			{
+				fa->e[ea]=(U1)eb;fa->f[ea]=fb;
+				fb->e[eb]=(U1)ea;fb->f[eb]=fa;
+			}
+			static inline void		append(sList& list,sFace* face)
+			{
+				face->l[0]	=	0;
+				face->l[1]	=	list.root;
+				if(list.root) list.root->l[0]=face;
+				list.root	=	face;
+				++list.count;
+			}
+			static inline void		remove(sList& list,sFace* face)
+			{
+				if(face->l[1]) face->l[1]->l[0]=face->l[0];
+				if(face->l[0]) face->l[0]->l[1]=face->l[1];
+				if(face==list.root) list.root=face->l[1];
+				--list.count;
+			}
+
+
+			void				Initialize()
+			{
+				m_status	=	eStatus::Failed;
+				m_normal	=	btVector3(0,0,0);
+				m_depth		=	0;
+				m_nextsv	=	0;
+				for(U i=0;i<EPA_MAX_FACES;++i)
+				{
+					append(m_stock,&m_fc_store[EPA_MAX_FACES-i-1]);
+				}
+			}
+			eStatus::_			Evaluate(GJK& gjk,const btVector3& guess)
+			{
+				GJK::sSimplex&	simplex=*gjk.m_simplex;
+				if((simplex.rank>1)&&gjk.EncloseOrigin())
+				{
+
+					/* Clean up				*/ 
+					while(m_hull.root)
+					{
+						sFace*	f = m_hull.root;
+						remove(m_hull,f);
+						append(m_stock,f);
+					}
+					m_status	=	eStatus::Valid;
+					m_nextsv	=	0;
+					/* Orient simplex		*/ 
+					if(gjk.det(	simplex.c[0]->w-simplex.c[3]->w,
+						simplex.c[1]->w-simplex.c[3]->w,
+						simplex.c[2]->w-simplex.c[3]->w)<0)
+					{
+						btSwap(simplex.c[0],simplex.c[1]);
+						btSwap(simplex.p[0],simplex.p[1]);
+					}
+					/* Build initial hull	*/ 
+					sFace*	tetra[]={newface(simplex.c[0],simplex.c[1],simplex.c[2],true),
 						newface(simplex.c[1],simplex.c[0],simplex.c[3],true),
 						newface(simplex.c[2],simplex.c[1],simplex.c[3],true),
 						newface(simplex.c[0],simplex.c[2],simplex.c[3],true)};
-		if(m_hull.count==4)
-			{
-			sFace*		best=findbest();
-			sFace		outer=*best;
-			U			pass=0;
-			U			iterations=0;
-			bind(tetra[0],0,tetra[1],0);
-			bind(tetra[0],1,tetra[2],0);
-			bind(tetra[0],2,tetra[3],0);
-			bind(tetra[1],1,tetra[3],2);
-			bind(tetra[1],2,tetra[2],1);
-			bind(tetra[2],2,tetra[3],1);
-			m_status=eStatus::Valid;
-			for(;iterations<EPA_MAX_ITERATIONS;++iterations)
-				{
-				if(m_nextsv<EPA_MAX_VERTICES)
-					{	
-					sHorizon		horizon;
-					sSV*			w=&m_sv_store[m_nextsv++];
-					bool			valid=true;					
-					best->pass	=	(U1)(++pass);
-					gjk.getsupport(best->n,*w);
-					const btScalar	wdist=dot(best->n,w->w)-best->d;
-					if(wdist>EPA_ACCURACY)
+					if(m_hull.count==4)
+					{
+						sFace*		best=findbest();
+						sFace		outer=*best;
+						U			pass=0;
+						U			iterations=0;
+						bind(tetra[0],0,tetra[1],0);
+						bind(tetra[0],1,tetra[2],0);
+						bind(tetra[0],2,tetra[3],0);
+						bind(tetra[1],1,tetra[3],2);
+						bind(tetra[1],2,tetra[2],1);
+						bind(tetra[2],2,tetra[3],1);
+						m_status=eStatus::Valid;
+						for(;iterations<EPA_MAX_ITERATIONS;++iterations)
 						{
-						for(U j=0;(j<3)&&valid;++j)
-							{
-							valid&=expand(	pass,w,
+							if(m_nextsv<EPA_MAX_VERTICES)
+							{	
+								sHorizon		horizon;
+								sSV*			w=&m_sv_store[m_nextsv++];
+								bool			valid=true;					
+								best->pass	=	(U1)(++pass);
+								gjk.getsupport(best->n,*w);
+								const btScalar	wdist=dot(best->n,w->w)-best->d;
+								if(wdist>EPA_ACCURACY)
+								{
+									for(U j=0;(j<3)&&valid;++j)
+									{
+										valid&=expand(	pass,w,
 											best->f[j],best->e[j],
 											horizon);
-							}
-						if(valid&&(horizon.nf>=3))
-							{
-							bind(horizon.cf,1,horizon.ff,2);
-							remove(m_hull,best);
-							append(m_stock,best);
-							best=findbest();
-							if(best->p>=outer.p) outer=*best;
-							} else { m_status=eStatus::InvalidHull;break; }
-						} else { m_status=eStatus::AccuraryReached;break; }
-					} else { m_status=eStatus::OutOfVertices;break; }
+									}
+									if(valid&&(horizon.nf>=3))
+									{
+										bind(horizon.cf,1,horizon.ff,2);
+										remove(m_hull,best);
+										append(m_stock,best);
+										best=findbest();
+										if(best->p>=outer.p) outer=*best;
+									} else { m_status=eStatus::InvalidHull;break; }
+								} else { m_status=eStatus::AccuraryReached;break; }
+							} else { m_status=eStatus::OutOfVertices;break; }
+						}
+						const btVector3	projection=outer.n*outer.d;
+						m_normal	=	outer.n;
+						m_depth		=	outer.d;
+						m_result.rank	=	3;
+						m_result.c[0]	=	outer.c[0];
+						m_result.c[1]	=	outer.c[1];
+						m_result.c[2]	=	outer.c[2];
+						m_result.p[0]	=	cross(	outer.c[1]->w-projection,
+							outer.c[2]->w-projection).length();
+						m_result.p[1]	=	cross(	outer.c[2]->w-projection,
+							outer.c[0]->w-projection).length();
+						m_result.p[2]	=	cross(	outer.c[0]->w-projection,
+							outer.c[1]->w-projection).length();
+						const btScalar	sum=m_result.p[0]+m_result.p[1]+m_result.p[2];
+						m_result.p[0]	/=	sum;
+						m_result.p[1]	/=	sum;
+						m_result.p[2]	/=	sum;
+						return(m_status);
+					}
 				}
-			const btVector3	projection=outer.n*outer.d;
-			m_normal	=	outer.n;
-			m_depth		=	outer.d;
-			m_result.rank	=	3;
-			m_result.c[0]	=	outer.c[0];
-			m_result.c[1]	=	outer.c[1];
-			m_result.c[2]	=	outer.c[2];
-			m_result.p[0]	=	cross(	outer.c[1]->w-projection,
-										outer.c[2]->w-projection).length();
-			m_result.p[1]	=	cross(	outer.c[2]->w-projection,
-										outer.c[0]->w-projection).length();
-			m_result.p[2]	=	cross(	outer.c[0]->w-projection,
-										outer.c[1]->w-projection).length();
-			const btScalar	sum=m_result.p[0]+m_result.p[1]+m_result.p[2];
-			m_result.p[0]	/=	sum;
-			m_result.p[1]	/=	sum;
-			m_result.p[2]	/=	sum;
-			return(m_status);
-			}
-		}
-	/* Fallback		*/ 
-	m_status	=	eStatus::FallBack;
-	m_normal	=	-guess;
-	const btScalar	nl=m_normal.length();
-	if(nl>0)
-		m_normal	=	m_normal/nl;
-		else
-		m_normal	=	btVector3(1,0,0);
-	m_depth	=	0;
-	m_result.rank=1;
-	m_result.c[0]=simplex.c[0];
-	m_result.p[0]=1;	
-	return(m_status);
+				/* Fallback		*/ 
+				m_status	=	eStatus::FallBack;
+				m_normal	=	-guess;
+				const btScalar	nl=m_normal.length();
+				if(nl>0)
+					m_normal	=	m_normal/nl;
+				else
+					m_normal	=	btVector3(1,0,0);
+				m_depth	=	0;
+				m_result.rank=1;
+				m_result.c[0]=simplex.c[0];
+				m_result.p[0]=1;	
+				return(m_status);
+			}
+			sFace*				newface(sSV* a,sSV* b,sSV* c,bool forced)
+			{
+				if(m_stock.root)
+				{
+					sFace*	face=m_stock.root;
+					remove(m_stock,face);
+					append(m_hull,face);
+					face->pass	=	0;
+					face->c[0]	=	a;
+					face->c[1]	=	b;
+					face->c[2]	=	c;
+					face->n		=	cross(b->w-a->w,c->w-a->w);
+					const btScalar	l=face->n.length();
+					const bool		v=l>EPA_ACCURACY;
+					face->p		=	btMin(btMin(
+						dot(a->w,cross(face->n,a->w-b->w)),
+						dot(b->w,cross(face->n,b->w-c->w))),
+						dot(c->w,cross(face->n,c->w-a->w)))	/
+						(v?l:1);
+					face->p		=	face->p>=-EPA_INSIDE_EPS?0:face->p;
+					if(v)
+					{
+						face->d		=	dot(a->w,face->n)/l;
+						face->n		/=	l;
+						if(forced||(face->d>=-EPA_PLANE_EPS))
+						{
+							return(face);
+						} else m_status=eStatus::NonConvex;
+					} else m_status=eStatus::Degenerated;
+					remove(m_hull,face);
+					append(m_stock,face);
+					return(0);
+				}
+				m_status=m_stock.root?eStatus::OutOfVertices:eStatus::OutOfFaces;
+				return(0);
+			}
+			sFace*				findbest()
+			{
+				sFace*		minf=m_hull.root;
+				btScalar	mind=minf->d*minf->d;
+				btScalar	maxp=minf->p;
+				for(sFace* f=minf->l[1];f;f=f->l[1])
+				{
+					const btScalar	sqd=f->d*f->d;
+					if((f->p>=maxp)&&(sqd<mind))
+					{
+						minf=f;
+						mind=sqd;
+						maxp=f->p;
+					}
+				}
+				return(minf);
+			}
+			bool				expand(U pass,sSV* w,sFace* f,U e,sHorizon& horizon)
+			{
+				static const U	i1m3[]={1,2,0};
+				static const U	i2m3[]={2,0,1};
+				if(f->pass!=pass)
+				{
+					const U	e1=i1m3[e];
+					if((dot(f->n,w->w)-f->d)<-EPA_PLANE_EPS)
+					{
+						sFace*	nf=newface(f->c[e1],f->c[e],w,false);
+						if(nf)
+						{
+							bind(nf,0,f,e);
+							if(horizon.cf) bind(horizon.cf,1,nf,2); else horizon.ff=nf;
+							horizon.cf=nf;
+							++horizon.nf;
+							return(true);
+						}
+					}
+					else
+					{
+						const U	e2=i2m3[e];
+						f->pass		=	(U1)pass;
+						if(	expand(pass,w,f->f[e1],f->e[e1],horizon)&&
+							expand(pass,w,f->f[e2],f->e[e2],horizon))
+						{
+							remove(m_hull,f);
+							append(m_stock,f);
+							return(true);
+						}
+					}
+				}
+				return(false);
+			}
+
+	};
+
+	//
+	static void	Initialize(	const btConvexShape* shape0,const btTransform& wtrs0,
+		const btConvexShape* shape1,const btTransform& wtrs1,
+		btGjkEpaSolver2::sResults& results,
+		tShape& shape,
+		bool withmargins)
+	{
+		/* Results		*/ 
+		results.witnesses[0]	=
+			results.witnesses[1]	=	btVector3(0,0,0);
+		results.status			=	btGjkEpaSolver2::sResults::Separated;
+		/* Shape		*/ 
+		shape.m_shapes[0]		=	shape0;
+		shape.m_shapes[1]		=	shape1;
+		shape.m_toshape1		=	wtrs1.getBasis().transposeTimes(wtrs0.getBasis());
+		shape.m_toshape0		=	wtrs0.inverseTimes(wtrs1);
+		shape.EnableMargin(withmargins);
 	}
-sFace*				newface(sSV* a,sSV* b,sSV* c,bool forced)
-	{
-	if(m_stock.root)
-		{
-		sFace*	face=m_stock.root;
-		remove(m_stock,face);
-		append(m_hull,face);
-		face->pass	=	0;
-		face->c[0]	=	a;
-		face->c[1]	=	b;
-		face->c[2]	=	c;
-		face->n		=	cross(b->w-a->w,c->w-a->w);
-		const btScalar	l=face->n.length();
-		const bool		v=l>EPA_ACCURACY;
-		face->p		=	btMin(btMin(
-							dot(a->w,cross(face->n,a->w-b->w)),
-							dot(b->w,cross(face->n,b->w-c->w))),
-							dot(c->w,cross(face->n,c->w-a->w)))	/
-							(v?l:1);
-		face->p		=	face->p>=-EPA_INSIDE_EPS?0:face->p;
-		if(v)
-			{
-			face->d		=	dot(a->w,face->n)/l;
-			face->n		/=	l;
-			if(forced||(face->d>=-EPA_PLANE_EPS))
-				{
-				return(face);
-				} else m_status=eStatus::NonConvex;
-			} else m_status=eStatus::Degenerated;
-		remove(m_hull,face);
-		append(m_stock,face);
-		return(0);
-		}
-	m_status=m_stock.root?eStatus::OutOfVertices:eStatus::OutOfFaces;
-	return(0);
-	}
-sFace*				findbest()
-	{
-	sFace*		minf=m_hull.root;
-	btScalar	mind=minf->d*minf->d;
-	btScalar	maxp=minf->p;
-	for(sFace* f=minf->l[1];f;f=f->l[1])
-		{
-		const btScalar	sqd=f->d*f->d;
-		if((f->p>=maxp)&&(sqd<mind))
-			{
-			minf=f;
-			mind=sqd;
-			maxp=f->p;
-			}
-		}
-	return(minf);
-	}
-bool				expand(U pass,sSV* w,sFace* f,U e,sHorizon& horizon)
-	{
-	static const U	i1m3[]={1,2,0};
-	static const U	i2m3[]={2,0,1};
-	if(f->pass!=pass)
-		{
-		const U	e1=i1m3[e];
-		if((dot(f->n,w->w)-f->d)<-EPA_PLANE_EPS)
-			{
-			sFace*	nf=newface(f->c[e1],f->c[e],w,false);
-			if(nf)
-				{
-				bind(nf,0,f,e);
-				if(horizon.cf) bind(horizon.cf,1,nf,2); else horizon.ff=nf;
-				horizon.cf=nf;
-				++horizon.nf;
-				return(true);
-				}
-			}
-			else
-			{
-			const U	e2=i2m3[e];
-			f->pass		=	(U1)pass;
-			if(	expand(pass,w,f->f[e1],f->e[e1],horizon)&&
-				expand(pass,w,f->f[e2],f->e[e2],horizon))
-				{
-				remove(m_hull,f);
-				append(m_stock,f);
-				return(true);
-				}
-			}
-		}
-	return(false);
-	}
-
-};
-
-//
-static void	Initialize(	const btConvexShape* shape0,const btTransform& wtrs0,
-						const btConvexShape* shape1,const btTransform& wtrs1,
-						btGjkEpaSolver2::sResults& results,
-						tShape& shape,
-						bool withmargins)
-{
-/* Results		*/ 
-results.witnesses[0]	=
-results.witnesses[1]	=	btVector3(0,0,0);
-results.status			=	btGjkEpaSolver2::sResults::Separated;
-/* Shape		*/ 
-shape.m_shapes[0]		=	shape0;
-shape.m_shapes[1]		=	shape1;
-shape.m_toshape1		=	wtrs1.getBasis().transposeTimes(wtrs0.getBasis());
-shape.m_toshape0		=	wtrs0.inverseTimes(wtrs1);
-shape.EnableMargin(withmargins);
-}
 
 }
@@ -776,42 +776,42 @@
 int			btGjkEpaSolver2::StackSizeRequirement()
 {
-return(sizeof(GJK)+sizeof(EPA));
+	return(sizeof(GJK)+sizeof(EPA));
 }
 
 //
 bool		btGjkEpaSolver2::Distance(	const btConvexShape*	shape0,
-										const btTransform&		wtrs0,
-										const btConvexShape*	shape1,
-										const btTransform&		wtrs1,
-										const btVector3&		guess,
-										sResults&				results)
+									  const btTransform&		wtrs0,
+									  const btConvexShape*	shape1,
+									  const btTransform&		wtrs1,
+									  const btVector3&		guess,
+									  sResults&				results)
 {
-tShape			shape;
-Initialize(shape0,wtrs0,shape1,wtrs1,results,shape,false);
-GJK				gjk;
-GJK::eStatus::_	gjk_status=gjk.Evaluate(shape,guess);
-if(gjk_status==GJK::eStatus::Valid)
+	tShape			shape;
+	Initialize(shape0,wtrs0,shape1,wtrs1,results,shape,false);
+	GJK				gjk;
+	GJK::eStatus::_	gjk_status=gjk.Evaluate(shape,guess);
+	if(gjk_status==GJK::eStatus::Valid)
 	{
-	btVector3	w0=btVector3(0,0,0);
-	btVector3	w1=btVector3(0,0,0);
-	for(U i=0;i<gjk.m_simplex->rank;++i)
-		{
-		const btScalar	p=gjk.m_simplex->p[i];
-		w0+=shape.Support( gjk.m_simplex->c[i]->d,0)*p;
-		w1+=shape.Support(-gjk.m_simplex->c[i]->d,1)*p;
+		btVector3	w0=btVector3(0,0,0);
+		btVector3	w1=btVector3(0,0,0);
+		for(U i=0;i<gjk.m_simplex->rank;++i)
+		{
+			const btScalar	p=gjk.m_simplex->p[i];
+			w0+=shape.Support( gjk.m_simplex->c[i]->d,0)*p;
+			w1+=shape.Support(-gjk.m_simplex->c[i]->d,1)*p;
 		}
-	results.witnesses[0]	=	wtrs0*w0;
-	results.witnesses[1]	=	wtrs0*w1;
-	results.normal			=	w0-w1;
-	results.distance		=	results.normal.length();
-	results.normal			/=	results.distance>GJK_MIN_DISTANCE?results.distance:1;
-	return(true);
+		results.witnesses[0]	=	wtrs0*w0;
+		results.witnesses[1]	=	wtrs0*w1;
+		results.normal			=	w0-w1;
+		results.distance		=	results.normal.length();
+		results.normal			/=	results.distance>GJK_MIN_DISTANCE?results.distance:1;
+		return(true);
 	}
 	else
 	{
-	results.status	=	gjk_status==GJK::eStatus::Inside?
-							sResults::Penetrating	:
-							sResults::GJK_Failed	;
-	return(false);
+		results.status	=	gjk_status==GJK::eStatus::Inside?
+			sResults::Penetrating	:
+		sResults::GJK_Failed	;
+		return(false);
 	}
 }
@@ -819,42 +819,42 @@
 //
 bool	btGjkEpaSolver2::Penetration(	const btConvexShape*	shape0,
-										const btTransform&		wtrs0,
-										const btConvexShape*	shape1,
-										const btTransform&		wtrs1,
-										const btVector3&		guess,
-										sResults&				results,
-										bool					usemargins)
+									 const btTransform&		wtrs0,
+									 const btConvexShape*	shape1,
+									 const btTransform&		wtrs1,
+									 const btVector3&		guess,
+									 sResults&				results,
+									 bool					usemargins)
 {
-tShape			shape;
-Initialize(shape0,wtrs0,shape1,wtrs1,results,shape,usemargins);
-GJK				gjk;	
-GJK::eStatus::_	gjk_status=gjk.Evaluate(shape,-guess);
-switch(gjk_status)
+	tShape			shape;
+	Initialize(shape0,wtrs0,shape1,wtrs1,results,shape,usemargins);
+	GJK				gjk;	
+	GJK::eStatus::_	gjk_status=gjk.Evaluate(shape,-guess);
+	switch(gjk_status)
 	{
 	case	GJK::eStatus::Inside:
 		{
-		EPA				epa;
-		EPA::eStatus::_	epa_status=epa.Evaluate(gjk,-guess);
-		if(epa_status!=EPA::eStatus::Failed)
-			{
-			btVector3	w0=btVector3(0,0,0);
-			for(U i=0;i<epa.m_result.rank;++i)
-				{
-				w0+=shape.Support(epa.m_result.c[i]->d,0)*epa.m_result.p[i];
+			EPA				epa;
+			EPA::eStatus::_	epa_status=epa.Evaluate(gjk,-guess);
+			if(epa_status!=EPA::eStatus::Failed)
+			{
+				btVector3	w0=btVector3(0,0,0);
+				for(U i=0;i<epa.m_result.rank;++i)
+				{
+					w0+=shape.Support(epa.m_result.c[i]->d,0)*epa.m_result.p[i];
 				}
-			results.status			=	sResults::Penetrating;
-			results.witnesses[0]	=	wtrs0*w0;
-			results.witnesses[1]	=	wtrs0*(w0-epa.m_normal*epa.m_depth);
-			results.normal			=	-epa.m_normal;
-			results.distance		=	-epa.m_depth;
-			return(true);
+				results.status			=	sResults::Penetrating;
+				results.witnesses[0]	=	wtrs0*w0;
+				results.witnesses[1]	=	wtrs0*(w0-epa.m_normal*epa.m_depth);
+				results.normal			=	-epa.m_normal;
+				results.distance		=	-epa.m_depth;
+				return(true);
 			} else results.status=sResults::EPA_Failed;
 		}
-	break;
+		break;
 	case	GJK::eStatus::Failed:
-	results.status=sResults::GJK_Failed;
-	break;
+		results.status=sResults::GJK_Failed;
+		break;
 	}
-return(false);
+	return(false);
 }
 
@@ -866,47 +866,47 @@
 											sResults& results)
 {
-tShape			shape;
-btSphereShape	shape1(margin);
-btTransform		wtrs1(btQuaternion(0,0,0,1),position);
-Initialize(shape0,wtrs0,&shape1,wtrs1,results,shape,false);
-GJK				gjk;	
-GJK::eStatus::_	gjk_status=gjk.Evaluate(shape,btVector3(1,1,1));
-if(gjk_status==GJK::eStatus::Valid)
+	tShape			shape;
+	btSphereShape	shape1(margin);
+	btTransform		wtrs1(btQuaternion(0,0,0,1),position);
+	Initialize(shape0,wtrs0,&shape1,wtrs1,results,shape,false);
+	GJK				gjk;	
+	GJK::eStatus::_	gjk_status=gjk.Evaluate(shape,btVector3(1,1,1));
+	if(gjk_status==GJK::eStatus::Valid)
 	{
-	btVector3	w0=btVector3(0,0,0);
-	btVector3	w1=btVector3(0,0,0);
-	for(U i=0;i<gjk.m_simplex->rank;++i)
-		{
-		const btScalar	p=gjk.m_simplex->p[i];
-		w0+=shape.Support( gjk.m_simplex->c[i]->d,0)*p;
-		w1+=shape.Support(-gjk.m_simplex->c[i]->d,1)*p;
+		btVector3	w0=btVector3(0,0,0);
+		btVector3	w1=btVector3(0,0,0);
+		for(U i=0;i<gjk.m_simplex->rank;++i)
+		{
+			const btScalar	p=gjk.m_simplex->p[i];
+			w0+=shape.Support( gjk.m_simplex->c[i]->d,0)*p;
+			w1+=shape.Support(-gjk.m_simplex->c[i]->d,1)*p;
 		}
-	results.witnesses[0]	=	wtrs0*w0;
-	results.witnesses[1]	=	wtrs0*w1;
-	const btVector3	delta=	results.witnesses[1]-
-							results.witnesses[0];
-	const btScalar	margin=	shape0->getMargin()+
-							shape1.getMargin();
-	const btScalar	length=	delta.length();	
-	results.normal			=	delta/length;
-	results.witnesses[0]	+=	results.normal*margin;
-	return(length-margin);
+		results.witnesses[0]	=	wtrs0*w0;
+		results.witnesses[1]	=	wtrs0*w1;
+		const btVector3	delta=	results.witnesses[1]-
+			results.witnesses[0];
+		const btScalar	margin=	shape0->getMarginNonVirtual()+
+			shape1.getMarginNonVirtual();
+		const btScalar	length=	delta.length();	
+		results.normal			=	delta/length;
+		results.witnesses[0]	+=	results.normal*margin;
+		return(length-margin);
 	}
 	else
 	{
-	if(gjk_status==GJK::eStatus::Inside)
-		{
-		if(Penetration(shape0,wtrs0,&shape1,wtrs1,gjk.m_ray,results))
-			{
-			const btVector3	delta=	results.witnesses[0]-
-									results.witnesses[1];
-			const btScalar	length=	delta.length();
-			if (length >= SIMD_EPSILON)
-				results.normal	=	delta/length;			
-			return(-length);
+		if(gjk_status==GJK::eStatus::Inside)
+		{
+			if(Penetration(shape0,wtrs0,&shape1,wtrs1,gjk.m_ray,results))
+			{
+				const btVector3	delta=	results.witnesses[0]-
+					results.witnesses[1];
+				const btScalar	length=	delta.length();
+				if (length >= SIMD_EPSILON)
+					results.normal	=	delta/length;			
+				return(-length);
 			}
 		}	
 	}
-return(SIMD_INFINITY);
+	return(SIMD_INFINITY);
 }
 
@@ -919,8 +919,8 @@
 										sResults&				results)
 {
-if(!Distance(shape0,wtrs0,shape1,wtrs1,guess,results))
-	return(Penetration(shape0,wtrs0,shape1,wtrs1,guess,results,false));
+	if(!Distance(shape0,wtrs0,shape1,wtrs1,guess,results))
+		return(Penetration(shape0,wtrs0,shape1,wtrs1,guess,results,false));
 	else
-	return(true);
+		return(true);
 }
 
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.cpp	(revision 2430)
@@ -19,11 +19,4 @@
 #include "btGjkEpaPenetrationDepthSolver.h"
 
-#ifndef __SPU__
-//#define USE_ORIGINAL_GJK 1
-#endif
-
-#ifdef USE_ORIGINAL_GJK
-#include "BulletCollision/NarrowPhaseCollision/btGjkEpa.h"
-#endif
 
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
@@ -32,5 +25,5 @@
 											  const btConvexShape* pConvexA, const btConvexShape* pConvexB,
 											  const btTransform& transformA, const btTransform& transformB,
-											  btVector3& v, btPoint3& wWitnessOnA, btPoint3& wWitnessOnB,
+											  btVector3& v, btVector3& wWitnessOnA, btVector3& wWitnessOnB,
 											  class btIDebugDraw* debugDraw, btStackAlloc* stackAlloc )
 {
@@ -42,11 +35,4 @@
 	const btScalar				radialmargin(btScalar(0.));
 	
-//#define USE_ORIGINAL_GJK 1
-#ifdef USE_ORIGINAL_GJK
-	btGjkEpaSolver::sResults	results;
-	if(btGjkEpaSolver::Collide(	pConvexA,transformA,
-								pConvexB,transformB,
-								radialmargin,stackAlloc,results))
-#else
 	btVector3	guessVector(transformA.getOrigin()-transformB.getOrigin());
 	btGjkEpaSolver2::sResults	results;
@@ -55,5 +41,4 @@
 								guessVector,results))
 	
-#endif
 		{
 	//	debugDraw->drawLine(results.witnesses[1],results.witnesses[1]+results.normal,btVector3(255,0,0));
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h	(revision 2430)
@@ -29,5 +29,5 @@
 									  const btConvexShape* pConvexA, const btConvexShape* pConvexB,
 									  const btTransform& transformA, const btTransform& transformB,
-									  btVector3& v, btPoint3& wWitnessOnA, btPoint3& wWitnessOnB,
+									  btVector3& v, btVector3& wWitnessOnA, btVector3& wWitnessOnB,
 									  class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc );
 
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp	(revision 2430)
@@ -22,5 +22,5 @@
 
 #if defined(DEBUG) || defined (_DEBUG)
-#define TEST_NON_VIRTUAL 1
+//#define TEST_NON_VIRTUAL 1
 #include <stdio.h> //for debug printf
 #ifdef __SPU__
@@ -54,4 +54,6 @@
 void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults)
 {
+	m_cachedSeparatingDistance = 0.f;
+
 	btScalar distance=btScalar(0.);
 	btVector3	normalInB(btScalar(0.),btScalar(0.),btScalar(0.));
@@ -63,15 +65,19 @@
 	localTransB.getOrigin() -= positionOffset;
 
-
+#ifdef __SPU__
 	btScalar marginA = m_minkowskiA->getMarginNonVirtual();
 	btScalar marginB = m_minkowskiB->getMarginNonVirtual();
-
+#else
+	btScalar marginA = m_minkowskiA->getMargin();
+	btScalar marginB = m_minkowskiB->getMargin();
 #ifdef TEST_NON_VIRTUAL
-	btScalar marginAv = m_minkowskiA->getMargin();
-	btScalar marginBv = m_minkowskiB->getMargin();
-
+	btScalar marginAv = m_minkowskiA->getMarginNonVirtual();
+	btScalar marginBv = m_minkowskiB->getMarginNonVirtual();
 	btAssert(marginA == marginAv);
 	btAssert(marginB == marginBv);
 #endif //TEST_NON_VIRTUAL
+#endif
+	
+
 
 	gNumGjkChecks++;
@@ -118,17 +124,20 @@
 			btVector3 seperatingAxisInB = m_cachedSeparatingAxis* input.m_transformB.getBasis();
 
+#ifdef __SPU__
+			btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA);
+			btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB);
+#else
+			btVector3 pInA = m_minkowskiA->localGetSupportingVertexWithoutMargin(seperatingAxisInA);
+			btVector3 qInB = m_minkowskiB->localGetSupportingVertexWithoutMargin(seperatingAxisInB);
 #ifdef TEST_NON_VIRTUAL
 			btVector3 pInAv = m_minkowskiA->localGetSupportingVertexWithoutMargin(seperatingAxisInA);
 			btVector3 qInBv = m_minkowskiB->localGetSupportingVertexWithoutMargin(seperatingAxisInB);
-#endif 
-			btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA);
-			btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB);
-#ifdef TEST_NON_VIRTUAL
 			btAssert((pInAv-pInA).length() < 0.0001);
 			btAssert((qInBv-qInB).length() < 0.0001);
 #endif //
-
-			btPoint3  pWorld = localTransA(pInA);	
-			btPoint3  qWorld = localTransB(qInB);
+#endif //__SPU__
+
+			btVector3  pWorld = localTransA(pInA);	
+			btVector3  qWorld = localTransB(qInB);
 
 #ifdef DEBUG_SPU_COLLISION_DETECTION
@@ -332,4 +341,7 @@
 		spu_printf("output 1\n");
 #endif
+		m_cachedSeparatingAxis = normalInB;
+		m_cachedSeparatingDistance = distance;
+
 		output.addContactPoint(
 			normalInB,
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h	(revision 2430)
@@ -21,5 +21,4 @@
 
 #include "btDiscreteCollisionDetectorInterface.h"
-#include "LinearMath/btPoint3.h"
 #include "BulletCollision/CollisionShapes/btCollisionMargin.h"
 
@@ -39,4 +38,5 @@
 	const btConvexShape* m_minkowskiB;
 	bool		m_ignoreMargin;
+	btScalar	m_cachedSeparatingDistance;
 	
 
@@ -69,4 +69,13 @@
 	}
 
+	const btVector3& getCachedSeparatingAxis() const
+	{
+		return m_cachedSeparatingAxis;
+	}
+	btScalar	getCachedSeparatingDistance() const
+	{
+		return m_cachedSeparatingDistance;
+	}
+
 	void	setPenetrationDepthSolver(btConvexPenetrationDepthSolver*	penetrationDepthSolver)
 	{
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h	(revision 2430)
@@ -33,4 +33,6 @@
 				m_appliedImpulse(0.f),
 				m_lateralFrictionInitialized(false),
+				m_appliedImpulseLateral1(0.f),
+				m_appliedImpulseLateral2(0.f),
 				m_lifeTime(0)
 			{
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp	(revision 2430)
@@ -71,5 +71,5 @@
 												   const btConvexShape* convexA,const btConvexShape* convexB,
 												   const btTransform& transA,const btTransform& transB,
-												   btVector3& v, btPoint3& pa, btPoint3& pb,
+												   btVector3& v, btVector3& pa, btVector3& pb,
 												   class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc
 												   )
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h	(revision 2430)
@@ -28,5 +28,5 @@
 	const btConvexShape* convexA,const btConvexShape* convexB,
 				const btTransform& transA,const btTransform& transB,
-			btVector3& v, btPoint3& pa, btPoint3& pb,
+			btVector3& v, btVector3& pa, btVector3& pb,
 			class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc
 			);
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp	(revision 2430)
@@ -17,5 +17,5 @@
 #include "btPersistentManifold.h"
 #include "LinearMath/btTransform.h"
-#include <assert.h>
+
 
 btScalar					gContactBreakingThreshold = btScalar(0.02);
@@ -67,5 +67,5 @@
 			}
 		}
-		assert(occurance<=0);
+		btAssert(occurance<=0);
 #endif //DEBUG_PERSISTENCY
 
@@ -165,5 +165,5 @@
 int btPersistentManifold::addManifoldPoint(const btManifoldPoint& newPoint)
 {
-	assert(validContactDistance(newPoint));
+	btAssert(validContactDistance(newPoint));
 
 	int insertIndex = getNumContacts();
@@ -191,5 +191,5 @@
 btScalar	btPersistentManifold::getContactBreakingThreshold() const
 {
-	return gContactBreakingThreshold;
+	return m_contactBreakingThreshold;
 }
 
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h	(revision 2430)
@@ -25,5 +25,5 @@
 struct btCollisionResult;
 
-///contact breaking and merging threshold
+///maximum contact breaking and merging threshold
 extern btScalar gContactBreakingThreshold;
 
@@ -55,4 +55,6 @@
 	int	m_cachedPoints;
 
+	btScalar	m_contactBreakingThreshold;
+
 	
 	/// sort cached points so most isolated points come first
@@ -69,8 +71,9 @@
 	btPersistentManifold();
 
-	btPersistentManifold(void* body0,void* body1,int bla)
-		: m_body0(body0),m_body1(body1),m_cachedPoints(0)
+	btPersistentManifold(void* body0,void* body1,int , btScalar contactBreakingThreshold)
+		: m_body0(body0),m_body1(body1),m_cachedPoints(0),
+		m_contactBreakingThreshold(contactBreakingThreshold)
 	{
-		(void)bla;
+		
 	}
 
@@ -107,5 +110,5 @@
 	}
 
-	/// todo: get this margin from the current physics / collision environment
+	///@todo: get this margin from the current physics / collision environment
 	btScalar	getContactBreakingThreshold() const;
 	
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h	(revision 2430)
@@ -20,5 +20,4 @@
 
 #include "LinearMath/btVector3.h"
-#include "LinearMath/btPoint3.h"
 
 #define NO_VIRTUAL_INTERFACE 1
@@ -38,5 +37,5 @@
 	virtual void reset() = 0;
 
-	virtual void addVertex(const btVector3& w, const btPoint3& p, const btPoint3& q) = 0;
+	virtual void addVertex(const btVector3& w, const btVector3& p, const btVector3& q) = 0;
 	
 	virtual bool closest(btVector3& v) = 0;
@@ -46,5 +45,5 @@
 	virtual bool fullSimplex() const = 0;
 
-	virtual int getSimplex(btPoint3 *pBuf, btPoint3 *qBuf, btVector3 *yBuf) const = 0;
+	virtual int getSimplex(btVector3 *pBuf, btVector3 *qBuf, btVector3 *yBuf) const = 0;
 
 	virtual bool inSimplex(const btVector3& w) = 0;
@@ -54,5 +53,5 @@
 	virtual bool emptySimplex() const = 0;
 
-	virtual void compute_points(btPoint3& p1, btPoint3& p2) = 0;
+	virtual void compute_points(btVector3& p1, btVector3& p2) = 0;
 
 	virtual int numVertices() const =0;
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp	(revision 2430)
@@ -78,5 +78,5 @@
 
 	//add a vertex
-void btVoronoiSimplexSolver::addVertex(const btVector3& w, const btPoint3& p, const btPoint3& q)
+void btVoronoiSimplexSolver::addVertex(const btVector3& w, const btVector3& p, const btVector3& q)
 {
 	m_lastW = w;
@@ -268,5 +268,5 @@
 
 	//return the current simplex
-int btVoronoiSimplexSolver::getSimplex(btPoint3 *pBuf, btPoint3 *qBuf, btVector3 *yBuf) const
+int btVoronoiSimplexSolver::getSimplex(btVector3 *pBuf, btVector3 *qBuf, btVector3 *yBuf) const
 {
 	int i;
@@ -315,5 +315,5 @@
 }
 
-void btVoronoiSimplexSolver::compute_points(btPoint3& p1, btPoint3& p2) 
+void btVoronoiSimplexSolver::compute_points(btVector3& p1, btVector3& p2) 
 {
 	updateClosestVectorAndPoints();
@@ -326,5 +326,5 @@
 
 
-bool	btVoronoiSimplexSolver::closestPtPointTriangle(const btPoint3& p, const btPoint3& a, const btPoint3& b, const btPoint3& c,btSubSimplexClosestResult& result)
+bool	btVoronoiSimplexSolver::closestPtPointTriangle(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c,btSubSimplexClosestResult& result)
 {
 	result.m_usedVertices.reset();
@@ -426,5 +426,5 @@
 
 /// Test if point p and d lie on opposite sides of plane through abc
-int btVoronoiSimplexSolver::pointOutsideOfPlane(const btPoint3& p, const btPoint3& a, const btPoint3& b, const btPoint3& c, const btPoint3& d)
+int btVoronoiSimplexSolver::pointOutsideOfPlane(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d)
 {
 	btVector3 normal = (b-a).cross(c-a);
@@ -453,5 +453,5 @@
 
 
-bool	btVoronoiSimplexSolver::closestPtPointTetrahedron(const btPoint3& p, const btPoint3& a, const btPoint3& b, const btPoint3& c, const btPoint3& d, btSubSimplexClosestResult& finalResult)
+bool	btVoronoiSimplexSolver::closestPtPointTetrahedron(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d, btSubSimplexClosestResult& finalResult)
 {
 	btSubSimplexClosestResult tempResult;
@@ -487,5 +487,5 @@
 	{
         closestPtPointTriangle(p, a, b, c,tempResult);
-		btPoint3 q = tempResult.m_closestPointOnSimplex;
+		btVector3 q = tempResult.m_closestPointOnSimplex;
 		
         btScalar sqDist = (q - p).dot( q - p);
@@ -514,5 +514,5 @@
 	{
         closestPtPointTriangle(p, a, c, d,tempResult);
-		btPoint3 q = tempResult.m_closestPointOnSimplex;
+		btVector3 q = tempResult.m_closestPointOnSimplex;
 		//convert result bitmask!
 
@@ -542,5 +542,5 @@
 	{
 		closestPtPointTriangle(p, a, d, b,tempResult);
-		btPoint3 q = tempResult.m_closestPointOnSimplex;
+		btVector3 q = tempResult.m_closestPointOnSimplex;
 		//convert result bitmask!
 
@@ -570,5 +570,5 @@
 	{
         closestPtPointTriangle(p, b, d, c,tempResult);
-		btPoint3 q = tempResult.m_closestPointOnSimplex;
+		btVector3 q = tempResult.m_closestPointOnSimplex;
 		//convert result bitmask!
         btScalar sqDist = (q - p).dot( q - p);
Index: code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h
===================================================================
--- code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h	(revision 2192)
+++ code/branches/physics/src/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h	(revision 2430)
@@ -51,5 +51,5 @@
 struct	btSubSimplexClosestResult
 {
-	btPoint3	m_closestPointOnSimplex;
+	btVector3	m_closestPointOnSimplex;
 	//MASK for m_usedVertices
 	//stores the simplex vertex-usage, using the MASK, 
@@ -98,11 +98,11 @@
 
 	btVector3	m_simplexVectorW[VORONOI_SIMPLEX_MAX_VERTS];
-	btPoint3	m_simplexPointsP[VORONOI_SIMPLEX_MAX_VERTS];
-	btPoint3	m_simplexPointsQ[VORONOI_SIMPLEX_MAX_VERTS];
+	btVector3	m_simplexPointsP[VORONOI_SIMPLEX_MAX_VERTS];
+	btVector3	m_simplexPointsQ[VORONOI_SIMPLEX_MAX_VERTS];
 
 	
 
-	btPoint3	m_cachedP1;
-	btPoint3	m_cachedP2;
+	btVector3	m_cachedP1;
+	btVector3	m_cachedP2;
 	btVector3	m_cachedV;
 	btVector3	m_lastW;
@@ -117,7 +117,7 @@
 	bool	updateClosestVectorAndPoints();
 
-	bool	closestPtPointTetrahedron(const btPoint3& p, const btPoint3& a, const btPoint3& b, const btPoint3& c, const btPoint3& d, btSubSimplexClosestResult& finalResult);
-	int		pointOutsideOfPlane(const btPoint3& p, const btPoint3& a, const btPoint3& b, const btPoint3& c, const btPoint3& d);
-	bool	closestPtPointTriangle(const btPoint3& p, const btPoint3& a, const btPoint3& b, const btPoint3& c,btSubSimplexClosestResult& result);
+	bool	closestPtPointTetrahedron(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d, btSubSimplexClosestResult& finalResult);
+	int		pointOutsideOfPlane(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d);
+	bool	closestPtPointTriangle(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c,btSubSimplexClosestResult& result);
 
 public:
@@ -125,5 +125,5 @@
 	 void reset();
 
-	 void addVertex(const btVector3& w, const btPoint3& p, const btPoint3& q);
+	 void addVertex(const btVector3& w, const btVector3& p, const btVector3& q);
 
 
@@ -137,5 +137,5 @@
 	 }
 
-	 int getSimplex(btPoint3 *pBuf, btPoint3 *qBuf, btVector3 *yBuf) const;
+	 int getSimplex(btVector3 *pBuf, btVector3 *qBuf, btVector3 *yBuf) const;
 
 	 bool inSimplex(const btVector3& w);
@@ -145,5 +145,5 @@
 	 bool emptySimplex() const ;
 
-	 void compute_points(btPoint3& p1, btPoint3& p2) ;
+	 void compute_points(btVector3& p1, btVector3& p2) ;
 
 	 int numVertices() const 
