55#if defined(DEBUG) || defined (_DEBUG)
58#include <spu_printf.h>
59#define printf spu_printf
68#define GJK_MAX_ITERATIONS 128
69#define GJK_ACCURARY ((btScalar)0.0001)
70#define GJK_MIN_DISTANCE ((btScalar)0.0001)
71#define GJK_DUPLICATED_EPS ((btScalar)0.0001)
72#define GJK_SIMPLEX2_EPS ((btScalar)0.0)
73#define GJK_SIMPLEX3_EPS ((btScalar)0.0)
74#define GJK_SIMPLEX4_EPS ((btScalar)0.0)
77#define EPA_MAX_VERTICES 64
78#define EPA_MAX_FACES (EPA_MAX_VERTICES*2)
79#define EPA_MAX_ITERATIONS 255
80#define EPA_ACCURACY ((btScalar)0.0001)
81#define EPA_FALLBACK (10*EPA_ACCURACY)
82#define EPA_PLANE_EPS ((btScalar)0.00001)
83#define EPA_INSIDE_EPS ((btScalar)0.01)
87 typedef unsigned int U;
88 typedef unsigned char U1;
91 template <
typename btConvexTemplate>
144 template <
typename btConvexTemplate>
234 {
found=
true;
break; }
392 return( a.
y()*b.
z()*c.
x()+a.
z()*b.
x()*c.
y()-
393 a.
x()*b.
z()*c.
y()-a.
y()*b.
x()*c.
z()+
394 a.
x()*b.
y()*c.
z()-a.
z()*b.
y()*c.
x());
405 if(
t>=1) { w[0]=0;w[1]=1;
m=2;
return(b.
length2()); }
406 else if(
t<=0) { w[0]=1;w[1]=0;
m=1;
return(a.
length2()); }
407 else { w[0]=1-(w[1]=
t);
m=3;
return((a+d*
t).length2()); }
416 static const U imd3[]={1,2,0};
435 m =
static_cast<U>(((
subm&1)?1<<i:0)+((
subm&2)?1<<
j:0));
451 w[2] = 1-(w[0]+w[1]);
463 static const U imd3[]={1,2,0};
483 m =
static_cast<U>((
subm&1?1<<i:0)+
497 w[0] =
det(c,b,d)/
vl;
498 w[1] =
det(a,c,d)/
vl;
499 w[2] =
det(b,a,d)/
vl;
500 w[3] = 1-(w[0]+w[1]+w[2]);
525template <
typename btConvexTemplate>
579 face->
l[1] =
list.root;
586 if(face->
l[1]) face->
l[1]->
l[0]=face->
l[0];
587 if(face->
l[0]) face->
l[0]->
l[1]=face->
l[1];
588 if(face==
list.root)
list.root=face->
l[1];
652 best->pass = (
U1)(++pass);
806 static const U i1m3[]={1,2,0};
807 static const U i2m3[]={2,0,1};
841 template <
typename btConvexTemplate>
852 shape.m_toshape1 = b.getWorldTransform().getBasis().transposeTimes(a.getWorldTransform().getBasis());
853 shape.m_toshape0 = a.getWorldTransform().inverseTimes(b.getWorldTransform());
865template <
typename btConvexTemplate>
878 for(
U i=0;i<
gjk.m_simplex->rank;++i)
881 w0+=
shape.Support(
gjk.m_simplex->c[i]->d,0)*p;
882 w1+=
shape.Support(-
gjk.m_simplex->c[i]->d,1)*p;
884 results.witnesses[0] = a.getWorldTransform()*
w0;
885 results.witnesses[1] = a.getWorldTransform()*
w1;
901template <
typename btConvexTemplate>
920 for(
U i=0;i<
epa.m_result.rank;++i)
925 results.witnesses[0] = a.getWorldTransform()*
w0;
926 results.witnesses[1] = a.getWorldTransform()*(
w0-
epa.m_normal*
epa.m_depth);
992template <
typename btConvexTemplate,
typename btDistanceInfoTemplate>
1016#undef GJK_MAX_ITERATIONS
1018#undef GJK_MIN_DISTANCE
1019#undef GJK_DUPLICATED_EPS
1020#undef GJK_SIMPLEX2_EPS
1021#undef GJK_SIMPLEX3_EPS
1022#undef GJK_SIMPLEX4_EPS
1024#undef EPA_MAX_VERTICES
1026#undef EPA_MAX_ITERATIONS
1030#undef EPA_INSIDE_EPS
int btComputeGjkDistance(const btConvexTemplate &a, const btConvexTemplate &b, const btGjkCollisionDescription &colDesc, btDistanceInfoTemplate *distInfo)
static void Initialize(const btConvexTemplate &a, const btConvexTemplate &b, btGjkEpaSolver3::sResults &results, MinkowskiDiff< btConvexTemplate > &shape)
#define GJK_DUPLICATED_EPS
bool btGjkEpaSolver3_Penetration(const btConvexTemplate &a, const btConvexTemplate &b, const btVector3 &guess, btGjkEpaSolver3::sResults &results)
#define GJK_MAX_ITERATIONS
bool btGjkEpaSolver3_Distance(const btConvexTemplate &a, const btConvexTemplate &b, const btVector3 &guess, btGjkEpaSolver3::sResults &results)
#define EPA_MAX_ITERATIONS
const T & btMax(const T &a, const T &b)
btScalar length(const btQuaternion &q)
Return the length of a quaternion.
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
btScalar btSqrt(btScalar y)
btScalar btFabs(btScalar x)
static T sum(const btAlignedObjectArray< T > &items)
btScalar btDot(const btVector3 &v1, const btVector3 &v2)
Return the dot product between two vectors.
btVector3 btCross(const btVector3 &v1, const btVector3 &v2)
Return the cross product of two vectors.
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
btVector3 can be used to represent 3D points and vectors.
const btScalar & w() const
Return the w value.
const btScalar & z() const
Return the z value.
btScalar length() const
Return the length of the vector.
btScalar length2() const
Return the length of the vector squared.
const btScalar & x() const
Return the x value.
const btScalar & y() const
Return the y value.
GJK< btConvexTemplate >::sSV * c[3]
bool getedgedist(sFace *face, typename GJK< btConvexTemplate >::sSV *a, typename GJK< btConvexTemplate >::sSV *b, btScalar &dist)
bool expand(U pass, typename GJK< btConvexTemplate >::sSV *w, sFace *f, U e, sHorizon &horizon)
static void append(sList &list, sFace *face)
sFace * newface(typename GJK< btConvexTemplate >::sSV *a, typename GJK< btConvexTemplate >::sSV *b, typename GJK< btConvexTemplate >::sSV *c, bool forced)
GJK< btConvexTemplate >::sSimplex m_result
GJK< btConvexTemplate >::sSV m_sv_store[EPA_MAX_VERTICES]
static void remove(sList &list, sFace *face)
eEpaStatus Evaluate(GJK< btConvexTemplate > &gjk, const btVector3 &guess)
static void bind(sFace *fa, U ea, sFace *fb, U eb)
sFace m_fc_store[EPA_MAX_FACES]
eGjkStatus Evaluate(const MinkowskiDiff< btConvexTemplate > &shapearg, const btVector3 &guess)
void getsupport(const btVector3 &d, sSV &sv) const
MinkowskiDiff< btConvexTemplate > m_shape
static btScalar projectorigin(const btVector3 &a, const btVector3 &b, const btVector3 &c, const btVector3 &d, btScalar *w, U &m)
static btScalar projectorigin(const btVector3 &a, const btVector3 &b, btScalar *w, U &m)
static btScalar det(const btVector3 &a, const btVector3 &b, const btVector3 &c)
GJK(const btConvexTemplate &a, const btConvexTemplate &b)
static btScalar projectorigin(const btVector3 &a, const btVector3 &b, const btVector3 &c, btScalar *w, U &m)
void removevertice(sSimplex &simplex)
void appendvertice(sSimplex &simplex, const btVector3 &v)
btVector3 Support1(const btVector3 &d) const
btVector3 Support0(const btVector3 &d) const
void EnableMargin(bool enable)
btVector3 Support(const btVector3 &d) const
btVector3 Support(const btVector3 &d, U index) const
MinkowskiDiff(const btConvexTemplate &a, const btConvexTemplate &b)
const btConvexTemplate * m_convexBPtr
const btConvexTemplate * m_convexAPtr
enum btGjkEpaSolver3::sResults::eStatus status