21#ifndef BT_MPR_PENETRATION_H
22#define BT_MPR_PENETRATION_H
59#define BT_MPR_SQRT sqrtf
61#define BT_MPR_SQRT sqrt
63#define BT_MPR_FMIN(x, y) ((x) < (y) ? (x) : (y))
64#define BT_MPR_FABS fabs
66#define BT_MPR_TOLERANCE 1E-6f
67#define BT_MPR_MAX_ITERATIONS 1000
97 printf(
"portal[%d].v = %f,%f,%f, v1=%f,%f,%f, v2=%f,%f,%f\n", index, portal->
ps[index].
v.
x(), portal->
ps[index].
v.
y(), portal->
ps[index].
v.
z(),
98 portal->
ps[index].
v1.
x(), portal->
ps[index].
v1.
y(), portal->
ps[index].
v1.
z(),
99 portal->
ps[index].
v2.
x(), portal->
ps[index].
v2.
y(), portal->
ps[index].
v2.
z());
151 return ab < FLT_EPSILON * b;
155 return ab < FLT_EPSILON * a;
164template <
typename btConvexTemplate>
167 center->
v1 = a.getObjectCenterInWorld();
168 center->
v2 = b.getObjectCenterInWorld();
169 center->
v = center->
v1 - center->
v2;
245 float dv1, dv2, dv3, dv4;
246 float dot1, dot2, dot3;
307template <
typename btConvexTemplate>
308inline void btMprSupport(
const btConvexTemplate &a,
const btConvexTemplate &b,
312 btVector3 separatingAxisInA = dir * a.getWorldTransform().getBasis();
313 btVector3 separatingAxisInB = -dir * b.getWorldTransform().getBasis();
315 btVector3 pInA = a.getLocalSupportWithMargin(separatingAxisInA);
316 btVector3 qInB = b.getLocalSupportWithMargin(separatingAxisInB);
318 supp->
v1 = a.getWorldTransform()(pInA);
319 supp->
v2 = b.getWorldTransform()(qInB);
320 supp->
v = supp->
v1 - supp->
v2;
323template <
typename btConvexTemplate>
460template <
typename btConvexTemplate>
504 float b[4],
sum, inv;
526 sum = b[0] + b[1] + b[2] + b[3];
542 sum = b[1] + b[2] + b[3];
549 for (i = 0; i < 4; i++)
561#ifdef MPR_AVERAGE_CONTACT_POSITIONS
615 else if (t > 1.f ||
btMprEq(t, 1.f))
657 float u, v, w, p, q, r;
658 float s, t, dist, dist2;
679 s = (q * r - w * p) / div;
680 t = (-s * r - q) / w;
699 dist += 2.f * s * t * r;
729template <
typename btConvexTemplate>
730static void btFindPenetr(
const btConvexTemplate &a,
const btConvexTemplate &b,
737 unsigned long iterations;
784#ifdef MPR_AVERAGE_CONTACT_POSITIONS
799#ifdef MPR_AVERAGE_CONTACT_POSITIONS
812template <
typename btConvexTemplate>
835 btFindPenetr(a, b, colDesc, &portal, depthOut, dirOut, posOut);
865template <
typename btConvexTemplate,
typename btMprDistanceTemplate>
874 distInfo->m_distance = -depth;
875 distInfo->m_pointOnB = pos;
876 distInfo->m_normalBtoA = -dir;
877 distInfo->m_pointOnA = pos - distInfo->m_distance * dir;
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void btMprSupport(const btConvexTemplate &a, const btConvexTemplate &b, const btMprCollisionDescription &colDesc, const btVector3 &dir, btMprSupport_t *supp)
float _btMprVec3PointSegmentDist2(const btVector3 *P, const btVector3 *x0, const btVector3 *b, btVector3 *witness)
int portalEncapsulesOrigin(const btMprSimplex_t *portal, const btVector3 *dir)
void btMprVec3Scale(btVector3 *d, float k)
float btMprVec3PointTriDist2(const btVector3 *P, const btVector3 *x0, const btVector3 *B, const btVector3 *C, btVector3 *witness)
void btFindOrigin(const btConvexTemplate &a, const btConvexTemplate &b, const btMprCollisionDescription &colDesc, btMprSupport_t *center)
int btMprIsZero(float val)
static void btFindPenetr(const btConvexTemplate &a, const btConvexTemplate &b, const btMprCollisionDescription &colDesc, btMprSimplex_t *portal, float *depth, btVector3 *pdir, btVector3 *pos)
static void btFindPenetrTouch(btMprSimplex_t *portal, float *depth, btVector3 *dir, btVector3 *pos)
static void btFindPos(const btMprSimplex_t *portal, btVector3 *pos)
static int btRefinePortal(const btConvexTemplate &a, const btConvexTemplate &b, const btMprCollisionDescription &colDesc, btMprSimplex_t *portal)
void btMprSupportCopy(btMprSupport_t *d, const btMprSupport_t *s)
void btMprSimplexSetSize(btMprSimplex_t *s, int size)
#define BT_MPR_FMIN(x, y)
const btMprSupport_t * btMprSimplexPoint(const btMprSimplex_t *s, int idx)
int btComputeMprPenetration(const btConvexTemplate &a, const btConvexTemplate &b, const btMprCollisionDescription &colDesc, btMprDistanceTemplate *distInfo)
int btMprPenetration(const btConvexTemplate &a, const btConvexTemplate &b, const btMprCollisionDescription &colDesc, float *depthOut, btVector3 *dirOut, btVector3 *posOut)
void btMprVec3Add(btVector3 *v, const btVector3 *w)
void btMprSimplexSwap(btMprSimplex_t *s, size_t pos1, size_t pos2)
float btMprVec3Dist2(const btVector3 *a, const btVector3 *b)
int portalReachTolerance(const btMprSimplex_t *portal, const btMprSupport_t *v4, const btVector3 *dir)
int portalCanEncapsuleOrigin(const btMprSimplex_t *portal, const btMprSupport_t *v4, const btVector3 *dir)
static int btDiscoverPortal(const btConvexTemplate &a, const btConvexTemplate &b, const btMprCollisionDescription &colDesc, btMprSimplex_t *portal)
void btMprSimplexSet(btMprSimplex_t *s, size_t pos, const btMprSupport_t *a)
void btMprVec3Sub2(btVector3 *d, const btVector3 *v, const btVector3 *w)
void btMprVec3Normalize(btVector3 *d)
float btMprVec3Len2(const btVector3 *v)
float btMprVec3Dot(const btVector3 *a, const btVector3 *b)
btMprSupport_t * btMprSimplexPointW(btMprSimplex_t *s, int idx)
void btPortalDir(const btMprSimplex_t *portal, btVector3 *dir)
static void btFindPenetrSegment(btMprSimplex_t *portal, float *depth, btVector3 *dir, btVector3 *pos)
void btMprVec3Set(btVector3 *v, float x, float y, float z)
int btMprSimplexSize(const btMprSimplex_t *s)
void btMprVec3Copy(btVector3 *v, const btVector3 *w)
int btMprVec3Eq(const btVector3 *a, const btVector3 *b)
void btExpandPortal(btMprSimplex_t *portal, const btMprSupport_t *v4)
void btMprVec3Cross(btVector3 *d, const btVector3 *a, const btVector3 *b)
#define BT_MPR_MAX_ITERATIONS
int btMprEq(float _a, float _b)
btScalar dot(const btQuaternion &q1, const btQuaternion &q2)
Calculate the dot product between two quaternions.
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
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.
btVector3 can be used to represent 3D points and vectors.
const btScalar & z() const
Return the z value.
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
const btScalar & x() const
Return the x value.
const btScalar & y() const
Return the y value.
int last
index of last added point
btVector3 v2
Support point in obj2.
btVector3 v1
Support point in obj1.
btVector3 v
Support point in minkowski sum.
btScalar m_maximumDistanceSquared
btMprCollisionDescription()
virtual ~btMprCollisionDescription()