21 #if defined(DEBUG) || defined(_DEBUG) 25 #include <spu_printf.h> 26 #define printf spu_printf 31 #ifdef BT_USE_DOUBLE_PRECISION 32 #define REL_ERROR2 btScalar(1.0e-12) 35 #define REL_ERROR2 btScalar(1.0e-6) 42 m_penetrationDepthSolver(penetrationDepthSolver),
43 m_simplexSolver(simplexSolver),
44 m_minkowskiA(objectA),
45 m_minkowskiB(objectB),
46 m_shapeTypeA(objectA->getShapeType()),
47 m_shapeTypeB(objectB->getShapeType()),
48 m_marginA(objectA->getMargin()),
49 m_marginB(objectB->getMargin()),
50 m_ignoreMargin(false),
52 m_catchDegeneracies(1),
53 m_fixContactNormalDirection(1)
91 supAworld = localTransA(pInA);
92 supBworld = localTransB(qInB);
100 aMinb = supAworld - supBworld;
350 double u, v, w, p, q, r;
351 double s, t, dist, dist2;
365 s = (q * r - w * p) / (w * v - r * r);
366 t = (-s * r - q) / w;
573 int B_on_ACD, C_on_ADB, D_on_ABC;
574 int AB_O, AC_O, AD_O;
630 if (AB_O && AC_O && AD_O)
700 localTransA.
getOrigin() -= positionOffset;
701 localTransB.
getOrigin() -= positionOffset;
717 int gGjkMaxIter = 1000;
720 bool isValid =
false;
721 bool checkSimplex =
false;
722 bool checkPenetration =
true;
728 btScalar margin = marginA + marginB;
762 for (
int iterations = 0; iterations < gGjkMaxIter; iterations++)
791 if (do_simplex_res == 1)
796 else if (do_simplex_res == -1)
877 btScalar f0 = squaredDistance - delta;
914 btScalar previousSquaredDistance = squaredDistance;
915 squaredDistance = newCachedSeparatingAxis.
length2();
917 if (squaredDistance > previousSquaredDistance)
921 squaredDistance = previousSquaredDistance;
922 checkSimplex =
false;
930 if (previousSquaredDistance - squaredDistance <=
SIMD_EPSILON * previousSquaredDistance)
944 #if defined(DEBUG) || defined(_DEBUG) 946 printf(
"btGjkPairDetector maxIter exceeded:%i\n",
m_curIter);
947 printf(
"sepAxis=(%f,%f,%f), squaredDistance = %f, shapeTypeA=%i,shapeTypeB=%i\n",
993 distance = ((
btScalar(1.) / rlen) - margin);
995 orgNormalInB = normalInB;
1006 bool catchDegeneratePenetrationCase =
1010 if ((checkPenetration && (!isValid || catchDegeneratePenetrationCase)) || (status == 0))
1025 localTransA, localTransB,
1033 btVector3 tmpNormalInB = tmpPointOnB - tmpPointOnA;
1041 if (lenSqr > (SIMD_EPSILON * SIMD_EPSILON))
1043 tmpNormalInB /=
btSqrt(lenSqr);
1047 if (!isValid || (distance2 < distance))
1049 distance = distance2;
1050 pointOnA = tmpPointOnA;
1051 pointOnB = tmpPointOnB;
1052 normalInB = tmpNormalInB;
1076 btScalar distance2 = (tmpPointOnA - tmpPointOnB).
length() - margin;
1078 if (!isValid || (distance2 < distance))
1080 distance = distance2;
1081 pointOnA = tmpPointOnA;
1082 pointOnB = tmpPointOnB;
1128 d2 = orgNormalInB.
dot(w) - margin;
1142 d1 = (-normalInB).
dot(w) - margin;
1155 d0 = normalInB.
dot(w) - margin;
1166 if (d2 > d0 && d2 > d1 && d2 > distance)
1168 normalInB = orgNormalInB;
1176 pointOnB + positionOffset,
btConvexPenetrationDepthSolver * m_penetrationDepthSolver
btVector3 m_cachedSeparatingAxis
btSimplexSolverInterface * m_simplexSolver
void btVec3Scale(btVector3 *d, btScalar k)
btGjkPairDetector(const btConvexShape *objectA, const btConvexShape *objectB, btSimplexSolverInterface *simplexSolver, btConvexPenetrationDepthSolver *penetrationDepthSolver)
btScalar length(const btQuaternion &q)
Return the length of a quaternion.
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
btScalar m_cachedSeparatingDistance
void btSimplexSet(btSimplex *s, size_t pos, const btSupportVector *a)
btScalar gGjkEpaPenetrationTolerance
ConvexPenetrationDepthSolver provides an interface for penetration depth calculation.
static int btDoSimplex(btSimplex *simplex, btVector3 *dir)
btScalar length2() const
Return the length of the vector squared.
static btVector3 ccd_vec3_origin(0, 0, 0)
btScalar btVec3PointSegmentDist2(const btVector3 *P, const btVector3 *x0, const btVector3 *b, btVector3 *witness)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
btScalar btSqrt(btScalar y)
static int btDoSimplex3(btSimplex *simplex, btVector3 *dir)
const btSupportVector * btSimplexPoint(const btSimplex *s, int idx)
int ccdEq(btScalar _a, btScalar _b)
void ccdVec3Add(btVector3 *v, const btVector3 *w)
int btVec3Eq(const btVector3 *a, const btVector3 *b)
const btScalar & getY() const
Return the y value.
btVector3 v1
Support point in obj1.
void btVec3Cross(btVector3 *d, const btVector3 *a, const btVector3 *b)
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
static int btDoSimplex4(btSimplex *simplex, btVector3 *dir)
The btConvexShape is an abstract shape interface, implemented by all convex shapes such as btBoxShape...
const btScalar & getZ() const
Return the z value.
virtual bool calcPenDepth(btSimplexSolverInterface &simplexSolver, const btConvexShape *convexA, const btConvexShape *convexB, const btTransform &transA, const btTransform &transB, btVector3 &v, btVector3 &pa, btVector3 &pb, class btIDebugDraw *debugDraw)=0
void btSimplexSetSize(btSimplex *s, int size)
void btSimplexInit(btSimplex *s)
#define btSimplexSolverInterface
const btScalar & x() const
Return the x value.
btScalar dot(const btVector3 &v) const
Return the dot product.
int m_fixContactNormalDirection
void btSupportCopy(btSupportVector *d, const btSupportVector *s)
const btScalar & y() const
Return the y value.
const btScalar & z() const
Return the z value.
void btSimplexAdd(btSimplex *s, const btSupportVector *v)
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations...
int last
index of last added point
const btConvexShape * m_minkowskiB
void btTripleCross(const btVector3 *a, const btVector3 *b, const btVector3 *c, btVector3 *d)
btVector3 v2
Support point in obj2.
void btVec3Sub2(btVector3 *d, const btVector3 *v, const btVector3 *w)
btScalar ccdVec3Dist2(const btVector3 *a, const btVector3 *b)
btVector3 can be used to represent 3D points and vectors.
btScalar ccdVec3Z(const btVector3 *v)
btScalar btVec3PointTriDist2(const btVector3 *P, const btVector3 *x0, const btVector3 *B, const btVector3 *C, btVector3 *witness)
btVector3 v
Support point in minkowski sum.
virtual void addContactPoint(const btVector3 &normalOnBInWorld, const btVector3 &pointInWorld, btScalar depth)=0
void ccdVec3Sub(btVector3 *v, const btVector3 *w)
int btSimplexSize(const btSimplex *s)
bool btFuzzyZero(btScalar x)
int ccdSign(btScalar val)
const btSupportVector * ccdSimplexLast(const btSimplex *s)
btScalar dot(const btQuaternion &q1, const btQuaternion &q2)
Calculate the dot product between two quaternions.
btScalar ccdVec3Y(const btVector3 *v)
btVector3 localGetSupportVertexWithoutMarginNonVirtual(const btVector3 &vec) const
void btVec3Copy(btVector3 *v, const btVector3 *w)
const btConvexShape * m_minkowskiA
const btScalar & getX() const
Return the x value.
btScalar ccdVec3X(const btVector3 *v)
btScalar btVec3Dot(const btVector3 *a, const btVector3 *b)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
virtual void getClosestPoints(const ClosestPointInput &input, Result &output, class btIDebugDraw *debugDraw, bool swapResults=false)
static void btComputeSupport(const btConvexShape *convexA, const btTransform &localTransA, const btConvexShape *convexB, const btTransform &localTransB, const btVector3 &dir, bool check2d, btVector3 &supAworld, btVector3 &supBworld, btVector3 &aMinb)
static int btDoSimplex2(btSimplex *simplex, btVector3 *dir)
void getClosestPointsNonVirtual(const ClosestPointInput &input, Result &output, class btIDebugDraw *debugDraw)
btScalar btFabs(btScalar x)