29 #if defined(DEBUG) || defined(_DEBUG)
32 #include <spu_printf.h>
33 #define printf spu_printf
42 #define GJK_MAX_ITERATIONS 128
44 #ifdef BT_USE_DOUBLE_PRECISION
45 #define GJK_ACCURACY ((btScalar)1e-12)
46 #define GJK_MIN_DISTANCE ((btScalar)1e-12)
47 #define GJK_DUPLICATED_EPS ((btScalar)1e-12)
49 #define GJK_ACCURACY ((btScalar)0.0001)
50 #define GJK_MIN_DISTANCE ((btScalar)0.0001)
51 #define GJK_DUPLICATED_EPS ((btScalar)0.0001)
54 #define GJK_SIMPLEX2_EPS ((btScalar)0.0)
55 #define GJK_SIMPLEX3_EPS ((btScalar)0.0)
56 #define GJK_SIMPLEX4_EPS ((btScalar)0.0)
59 #define EPA_MAX_VERTICES 128
60 #define EPA_MAX_ITERATIONS 255
62 #ifdef BT_USE_DOUBLE_PRECISION
63 #define EPA_ACCURACY ((btScalar)1e-12)
64 #define EPA_PLANE_EPS ((btScalar)1e-14)
65 #define EPA_INSIDE_EPS ((btScalar)1e-9)
67 #define EPA_ACCURACY ((btScalar)0.0001)
68 #define EPA_PLANE_EPS ((btScalar)0.00001)
69 #define EPA_INSIDE_EPS ((btScalar)0.01)
72 #define EPA_FALLBACK (10 * EPA_ACCURACY)
73 #define EPA_MAX_FACES (EPA_MAX_VERTICES * 2)
76 typedef unsigned int U;
77 typedef unsigned char U1;
97 m_enableMargin = enable;
103 return m_shapes[0]->localGetSupportVertexNonVirtual(d);
107 return m_shapes[0]->localGetSupportVertexWithoutMarginNonVirtual(d);
247 for (
U i = 0; i < 4; ++i)
262 lastw[clastw = (clastw + 1) & 3] =
w;
266 alpha =
btMax(omega, alpha);
301 for (
U i = 0, ni = cs.
rank; i < ni; ++i)
306 ns.
p[ns.
rank++] = weights[i];
307 m_ray += cs.
c[i]->
w * weights[i];
344 for (
U i = 0; i < 3; ++i)
360 for (
U i = 0; i < 3; ++i)
406 sv.
d = d / d.length();
415 simplex.
p[simplex.
rank] = 0;
421 return (
a.y() *
b.z() *
c.x() +
a.z() *
b.x() *
c.y() -
422 a.x() *
b.z() *
c.y() -
a.y() *
b.x() *
c.z() +
423 a.x() *
b.y() *
c.z() -
a.z() *
b.y() *
c.x());
439 return (
b.length2());
446 return (
a.length2());
450 w[0] = 1 - (
w[1] =
t);
452 return ((
a + d *
t).length2());
462 static const U imd3[] = {1, 2, 0};
472 for (
U i = 0; i < 3; ++i)
478 if ((mindist < 0) || (subd < mindist))
481 m =
static_cast<U>(((subm & 1) ? 1 << i : 0) + ((subm & 2) ? 1 << j : 0));
493 mindist = p.length2();
497 w[2] = 1 - (
w[0] +
w[1]);
509 static const U imd3[] = {1, 2, 0};
519 for (
U i = 0; i < 3; ++i)
526 if ((mindist < 0) || (subd < mindist))
529 m =
static_cast<U>((subm & 1 ? 1 << i : 0) +
530 (subm & 2 ? 1 << j : 0) +
546 w[3] = 1 - (
w[0] +
w[1] +
w[2]);
624 face->
l[1] = list.
root;
631 if (face->
l[1]) face->
l[1]->
l[0] = face->
l[0];
632 if (face->
l[0]) face->
l[0]->
l[1] = face->
l[1];
633 if (face == list.
root) list.
root = face->
l[1];
663 if (gjk.
det(simplex.
c[0]->
w - simplex.
c[3]->
w,
664 simplex.
c[1]->
w - simplex.
c[3]->
w,
665 simplex.
c[2]->
w - simplex.
c[3]->
w) < 0)
671 sFace* tetra[] = {
newface(simplex.
c[0], simplex.
c[1], simplex.
c[2],
true),
672 newface(simplex.
c[1], simplex.
c[0], simplex.
c[3],
true),
673 newface(simplex.
c[2], simplex.
c[1], simplex.
c[3],
true),
674 newface(simplex.
c[0], simplex.
c[2], simplex.
c[3],
true)};
681 bind(tetra[0], 0, tetra[1], 0);
682 bind(tetra[0], 1, tetra[2], 0);
683 bind(tetra[0], 2, tetra[3], 0);
684 bind(tetra[1], 1, tetra[3], 2);
685 bind(tetra[1], 2, tetra[2], 1);
686 bind(tetra[2], 2, tetra[3], 1);
695 best->
pass = (
U1)(++pass);
700 for (
U j = 0; (j < 3) && valid; ++j)
703 best->
f[j], best->
e[j],
706 if (valid && (horizon.
nf >= 3))
740 outer.
c[2]->
w - projection)
743 outer.
c[0]->
w - projection)
746 outer.
c[1]->
w - projection)
779 const btScalar ba_l2 = ba.length2();
786 dist =
a->w.length();
788 else if (b_dot_ba < 0)
791 dist =
b->w.length();
853 for (
sFace* f = minf->
l[1]; f; f = f->
l[1])
866 static const U i1m3[] = {1, 2, 0};
867 static const U i2m3[] = {2, 0, 1};
870 const U e1 = i1m3[
e];
878 bind(horizon.
cf, 1, nf, 2);
888 const U e2 = i2m3[
e];
890 if (
expand(pass,
w, f->
f[e1], f->
e[e1], horizon) &&
891 expand(pass,
w, f->
f[e2], f->
e[e2], horizon))
917 shape.
m_toshape1 = wtrs1.getBasis().transposeTimes(wtrs0.getBasis());
933 return (
sizeof(
GJK) +
sizeof(
EPA));
945 Initialize(shape0, wtrs0, shape1, wtrs1, results, shape,
false);
982 Initialize(shape0, wtrs0, shape1, wtrs1, results, shape, usemargins);
998 results.
status = sResults::Penetrating;
1006 results.
status = sResults::EPA_Failed;
1010 results.
status = sResults::GJK_Failed;
1030 Initialize(shape0, wtrs0, &shape1, wtrs1, results, shape,
false);
1047 const btScalar margin = shape0->getMarginNonVirtual() +
1048 shape1.getMarginNonVirtual();
1059 if (Penetration(shape0, wtrs0, &shape1, wtrs1, gjk.
m_ray, results))
1081 if (!Distance(shape0, wtrs0, shape1, wtrs1, guess, results))
1082 return (Penetration(shape0, wtrs0, shape1, wtrs1, guess, results,
false));
1090 #undef GJK_MAX_ITERATIONS
1092 #undef GJK_MIN_DISTANCE
1093 #undef GJK_DUPLICATED_EPS
1094 #undef GJK_SIMPLEX2_EPS
1095 #undef GJK_SIMPLEX3_EPS
1096 #undef GJK_SIMPLEX4_EPS
1098 #undef EPA_MAX_VERTICES
1099 #undef EPA_MAX_FACES
1100 #undef EPA_MAX_ITERATIONS
1103 #undef EPA_PLANE_EPS
1104 #undef EPA_INSIDE_EPS
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
btConvexShape()
not supported on IBM SDK, until we fix the alignment of btVector3
btVector3 localGetSupportVertexNonVirtual(const btVector3 &vec) const
btVector3 localGetSupportVertexWithoutMarginNonVirtual(const btVector3 &vec) const
#define GJK_DUPLICATED_EPS
#define GJK_MAX_ITERATIONS
#define EPA_MAX_ITERATIONS
btMatrix3x3
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
SIMD_FORCE_INLINE const T & btMax(const T &a, const T &b)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
SIMD_FORCE_INLINE btScalar btFabs(btScalar x)
SIMD_FORCE_INLINE btScalar btSqrt(btScalar y)
SIMD_FORCE_INLINE void btSwap(T &a, T &b)
static T sum(const btAlignedObjectArray< T > &items)
btSphereShape(btScalar radius)
SIMD_FORCE_INLINE btScalar length2() const
Return the length of the vector squared.
SIMD_FORCE_INLINE btScalar btDot(const btVector3 &v1, const btVector3 &v2)
Return the dot product between two vectors.
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
SIMD_FORCE_INLINE btVector3 btCross(const btVector3 &v1, const btVector3 &v2)
Return the cross product of two vectors.
The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatr...
BLI_INLINE float fb(float length, float L)
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
T length(const vec_base< T, Size > &a)
static void Initialize(const btConvexShape *shape0, const btTransform &wtrs0, const btConvexShape *shape1, const btTransform &wtrs1, btGjkEpaSolver2::sResults &results, tShape &shape, bool withmargins)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
enum btGjkEpaSolver2::sResults::eStatus status
static btScalar SignedDistance(const btVector3 &position, btScalar margin, const btConvexShape *shape, const btTransform &wtrs, sResults &results)
static bool Penetration(const btConvexShape *shape0, const btTransform &wtrs0, const btConvexShape *shape1, const btTransform &wtrs1, const btVector3 &guess, sResults &results, bool usemargins=true)
static bool Distance(const btConvexShape *shape0, const btTransform &wtrs0, const btConvexShape *shape1, const btTransform &wtrs1, const btVector3 &guess, sResults &results)
static int StackSizeRequirement()
bool expand(U pass, sSV *w, sFace *f, U e, sHorizon &horizon)
static void remove(sList &list, sFace *face)
sSV m_sv_store[EPA_MAX_VERTICES]
eStatus::_ Evaluate(GJK &gjk, const btVector3 &guess)
sFace m_fc_store[EPA_MAX_FACES]
static void append(sList &list, sFace *face)
sFace * newface(sSV *a, sSV *b, sSV *c, bool forced)
static void bind(sFace *fa, U ea, sFace *fb, U eb)
bool getedgedist(sFace *face, sSV *a, sSV *b, btScalar &dist)
void removevertice(sSimplex &simplex)
void getsupport(const btVector3 &d, sSV &sv) const
static btScalar det(const btVector3 &a, const btVector3 &b, const btVector3 &c)
void appendvertice(sSimplex &simplex, const btVector3 &v)
static btScalar projectorigin(const btVector3 &a, const btVector3 &b, const btVector3 &c, btScalar *w, U &m)
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)
eStatus::_ Evaluate(const tShape &shapearg, const btVector3 &guess)
btVector3 Support0(const btVector3 &d) const
void EnableMargin(bool enable)
const btConvexShape * m_shapes[2]
btVector3 Support1(const btVector3 &d) const
btVector3 Support(const btVector3 &d, U index) const
btVector3(btConvexShape::* Ls)(const btVector3 &) const
btVector3 Support(const btVector3 &d) const