30 int3(
int _x,
int _y,
int _z)
74 potentialVertex += n3n1;
75 potentialVertex += n1n2;
76 potentialVertex *= quotient;
93 return p0 + (dif * t);
139#define SPLIT (OVER | UNDER)
140#define PAPERWIDTH (btScalar(0.001))
149 edges.resize(edges_size);
207 for (
int i = 0; i < count; i++)
210 if (m == -1 ||
btDot(p[i], dir) >
btDot(p[m], dir))
239 if (allow[m] == 3)
return m;
248 if (ma == m && mb == m)
253 if (ma != -1 && ma != mb)
261 if (mc == m && md == m)
281 for (
int i = 0; i < 3; i++)
283 if (a[i] != b[i])
return 0;
292 return (
btDot(n, p - vertices[t[0]]) > epsilon);
297 for (
int i = 0; i < 3; i++)
299 int i1 = (i + 1) % 3;
300 if (t[i] == a && t[i1] == b)
return 1;
307 return (t[0] == v || t[1] == v || t[2] == v);
313 for (i = 0; i < 3; i++)
315 int i1 = (i + 1) % 3;
316 if (
hasedge(a, b[i1], b[i]))
return 1;
338 int &
neib(
int a,
int b);
345 for (i = 0; i < 3; i++)
347 int i1 = (i + 1) % 3;
348 int i2 = (i + 2) % 3;
349 if ((*
this)[i] == a && (*this)[i1] == b)
return n[i2];
350 if ((*
this)[i] == b && (*this)[i1] == a)
return n[i2];
358 for (i = 0; i < 3; i++)
360 int i1 = (i + 1) % 3;
361 int i2 = (i + 2) % 3;
385 for (i = 0; i < 3; i++)
387 int i1 = (i + 1) % 3;
388 int i2 = (i + 2) % 3;
426 ta->
n =
int3(t0->
n[0], n + 1, n + 2);
427 m_tris[t0->
n[0]]->neib(t[1], t[2]) = n + 0;
429 tb->
n =
int3(t0->
n[1], n + 2, n + 0);
430 m_tris[t0->
n[1]]->neib(t[2], t[0]) = n + 1;
432 tc->
n =
int3(t0->
n[2], n + 0, n + 1);
433 m_tris[t0->
n[2]]->neib(t[0], t[1]) = n + 2;
454 return (t->
rise > epsilon) ? t : NULL;
461 int p0 =
maxdirsterid(verts, verts_count, basis[0], allow);
462 int p1 =
maxdirsterid(verts, verts_count, -basis[0], allow);
463 basis[0] = verts[p0] - verts[p1];
464 if (p0 == p1 || basis[0] ==
btVector3(0, 0, 0))
465 return int4(-1, -1, -1, -1);
477 int p2 =
maxdirsterid(verts, verts_count, basis[1], allow);
478 if (p2 == p0 || p2 == p1)
480 p2 =
maxdirsterid(verts, verts_count, -basis[1], allow);
482 if (p2 == p0 || p2 == p1)
483 return int4(-1, -1, -1, -1);
484 basis[1] = verts[p2] - verts[p0];
486 int p3 =
maxdirsterid(verts, verts_count, basis[2], allow);
487 if (p3 == p0 || p3 == p1 || p3 == p2) p3 =
maxdirsterid(verts, verts_count, -basis[2], allow);
488 if (p3 == p0 || p3 == p1 || p3 == p2)
489 return int4(-1, -1, -1, -1);
490 btAssert(!(p0 == p1 || p0 == p2 || p0 == p3 || p1 == p2 || p1 == p3 || p2 == p3));
491 if (
btDot(verts[p3] - verts[p0],
btCross(verts[p1] - verts[p0], verts[p2] - verts[p0])) < 0)
495 return int4(p0, p1, p2, p3);
500 if (verts_count < 4)
return 0;
501 if (vlimit == 0) vlimit = 1000000000;
505 isextreme.
reserve(verts_count);
509 for (j = 0; j < verts_count; j++)
513 bmin.setMin(verts[j]);
520 if (p.
x == -1)
return 0;
522 btVector3 center = (verts[p[0]] + verts[p[1]] + verts[p[2]] + verts[p[3]]) /
btScalar(4.0);
524 t0->
n =
int3(2, 3, 1);
526 t1->
n =
int3(3, 2, 0);
528 t2->
n =
int3(0, 1, 3);
530 t3->
n =
int3(1, 0, 2);
531 isextreme[p[0]] = isextreme[p[1]] = isextreme[p[2]] = isextreme[p[3]] = 1;
548 while (vlimit > 0 && ((te =
extrudable(epsilon)) != 0))
573 if (
above(verts, nt, center,
btScalar(0.01) * epsilon) ||
btCross(verts[nt[1]] - verts[nt[0]], verts[nt[2]] - verts[nt[1]]).
length() < epsilon * epsilon *
btScalar(0.1))
588 if (t->
vmax >= 0)
break;
591 if (isextreme[t->
vmax])
616 for (
int j = 0; j < 3; j++)
621 tris_count = ts.
size() / 3;
624 for (i = 0; i < ts.
size(); i++)
626 tris_out[i] =
static_cast<unsigned int>(ts[i]);
637 if (!ret)
return false;
638 result.
mIndexCount = (
unsigned int)(tris_count * 3);
641 result.
mVcount = (
unsigned int)vcount;
677 unsigned int vcount = desc.
mVcount;
678 if (vcount < 8) vcount = 8;
681 vertexSource.
resize(
static_cast<int>(vcount));
685 unsigned int ovcount;
693 for (
unsigned int i = 0; i < ovcount; i++)
695 btVector3 &v = vertexSource[
static_cast<int>(i)];
728 const unsigned int *source = &hr.
m_Indices[0];
729 unsigned int *dest = &result.
m_Indices[0];
731 for (
unsigned int i = 0; i < hr.
mFaceCount; i++)
757 const unsigned int *source = &hr.
m_Indices[0];
758 unsigned int *dest = &result.
m_Indices[0];
759 for (
unsigned int i = 0; i < hr.
mFaceCount; i++)
819 return dx * dx + dy * dy + dz * dz;
825 unsigned int &vcount,
830 if (svcount == 0)
return false;
834#define EPSILON btScalar(0.000001)
838 btScalar recip[3] = {0.f, 0.f, 0.f};
847 btScalar bmin[3] = {FLT_MAX, FLT_MAX, FLT_MAX};
848 btScalar bmax[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX};
850 const char *vtx = (
const char *)svertices;
854 for (
unsigned int i = 0; i < svcount; i++)
860 for (
int j = 0; j < 3; j++)
862 if (p[j] < bmin[j]) bmin[j] = p[j];
863 if (p[j] > bmax[j]) bmax[j] = p[j];
874 center[0] = dx *
btScalar(0.5) + bmin[0];
875 center[1] = dy *
btScalar(0.5) + bmin[1];
876 center[2] = dz *
btScalar(0.5) + bmin[2];
882 if (dx >
EPSILON && dx < len) len = dx;
883 if (dy >
EPSILON && dy < len) len = dy;
884 if (dz >
EPSILON && dz < len) len = dz;
906 addPoint(vcount, vertices, x1, y1, z1);
907 addPoint(vcount, vertices, x2, y1, z1);
908 addPoint(vcount, vertices, x2, y2, z1);
909 addPoint(vcount, vertices, x1, y2, z1);
910 addPoint(vcount, vertices, x1, y1, z2);
911 addPoint(vcount, vertices, x2, y1, z2);
912 addPoint(vcount, vertices, x2, y2, z2);
913 addPoint(vcount, vertices, x1, y2, z2);
929 center[0] *= recip[0];
930 center[1] *= recip[1];
931 center[2] *= recip[2];
935 vtx = (
const char *)svertices;
937 for (
unsigned int i = 0; i < svcount; i++)
957 for (j = 0; j < vcount; j++)
970 if (dx < normalepsilon && dy < normalepsilon && dz < normalepsilon)
1005 btScalar bmin[3] = {FLT_MAX, FLT_MAX, FLT_MAX};
1006 btScalar bmax[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX};
1008 for (
unsigned int i = 0; i < vcount; i++)
1011 for (
int j = 0; j < 3; j++)
1013 if (p[j] < bmin[j]) bmin[j] = p[j];
1014 if (p[j] > bmax[j]) bmax[j] = p[j];
1030 if (dx >=
EPSILON && dx < len) len = dx;
1031 if (dy >=
EPSILON && dy < len) len = dy;
1032 if (dz >=
EPSILON && dz < len) len = dz;
1056 addPoint(vcount, vertices, x1, y1, z1);
1057 addPoint(vcount, vertices, x2, y1, z1);
1058 addPoint(vcount, vertices, x2, y2, z1);
1059 addPoint(vcount, vertices, x1, y2, z1);
1060 addPoint(vcount, vertices, x1, y1, z2);
1061 addPoint(vcount, vertices, x2, y1, z2);
1062 addPoint(vcount, vertices, x2, y2, z2);
1063 addPoint(vcount, vertices, x1, y2, z2);
1084 usedIndices.
resize(
static_cast<int>(vcount));
1085 memset(&usedIndices[0], 0,
sizeof(
unsigned int) * vcount);
1089 for (i = 0; i < int(indexcount); i++)
1091 unsigned int v = indices[i];
1095 if (usedIndices[
static_cast<int>(v)])
1097 indices[i] = usedIndices[
static_cast<int>(v)] - 1;
1101 indices[i] = ocount;
1103 overts[ocount][0] = verts[v][0];
1104 overts[ocount][1] = verts[v][1];
1105 overts[ocount][2] = verts[v][2];
1109 if (tmpIndices[k] ==
int(v))
1115 btAssert(ocount >= 0 && ocount <= vcount);
1117 usedIndices[
static_cast<int>(v)] = ocount;
#define btAlignedFree(ptr)
#define btAlignedAlloc(size, alignment)
ConvexH::HalfEdge HalfEdge
btVector3 ThreePlaneIntersection(const btPlane &p0, const btPlane &p1, const btPlane &p2)
btScalar DistanceBetweenLines(const btVector3 &ustart, const btVector3 &udir, const btVector3 &vstart, const btVector3 &vdir, btVector3 *upoint=NULL, btVector3 *vpoint=NULL)
int maxdirsterid(const T *p, int count, const T &dir, btAlignedObjectArray< int > &allow)
btVector3 PlaneLineIntersection(const btPlane &plane, const btVector3 &p0, const btVector3 &p1)
static void addPoint(unsigned int &vcount, btVector3 *p, btScalar x, btScalar y, btScalar z)
int operator==(const btPlane &a, const btPlane &b)
void ReleaseHull(PHullResult &result)
int hasvert(const int3 &t, int v)
btPlane PlaneFlip(const btPlane &plane)
btVector3 NormalOf(const btVector3 *vert, const int n)
int coplanar(const btPlane &a, const btPlane &b)
btVector3 PlaneProject(const btPlane &plane, const btVector3 &point)
int maxdirfiltered(const T *p, int count, const T &dir, btAlignedObjectArray< int > &allow)
btVector3 TriNormal(const btVector3 &v0, const btVector3 &v1, const btVector3 &v2)
int SplitTest(ConvexH &convex, const btPlane &plane)
int hasedge(const int3 &t, int a, int b)
int above(btVector3 *vertices, const int3 &t, const btVector3 &p, btScalar epsilon)
btScalar planetestepsilon
int PlaneTest(const btPlane &p, const btVector3 &v)
btScalar GetDist(btScalar px, btScalar py, btScalar pz, const btScalar *p2)
int shareedge(const int3 &a, const int3 &b)
btVector3 orth(const btVector3 &v)
btScalar length(const btQuaternion &q)
Return the length of a quaternion.
#define SIMD_RADS_PER_DEG
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
btScalar btSin(btScalar x)
btScalar btFabs(btScalar x)
btScalar btCos(btScalar x)
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.
btAlignedObjectArray< HalfEdge > edges
btAlignedObjectArray< btPlane > facets
btAlignedObjectArray< btVector3 > vertices
bool HasHullFlag(HullFlag flag) const
unsigned int mMaxVertices
const btVector3 * mVertices
unsigned int mVertexStride
btHullTriangle * extrudable(btScalar epsilon)
class btHullTriangle * allocateTriangle(int a, int b, int c)
bool ComputeHull(unsigned int vcount, const btVector3 *vertices, PHullResult &result, unsigned int vlimit)
HullError ReleaseResult(HullResult &result)
void BringOutYourDead(const btVector3 *verts, unsigned int vcount, btVector3 *overts, unsigned int &ocount, unsigned int *indices, unsigned indexcount)
HullError CreateConvexHull(const HullDesc &desc, HullResult &result)
void deAllocateTriangle(btHullTriangle *)
int calchull(btVector3 *verts, int verts_count, TUIntArray &tris_out, int &tris_count, int vlimit)
btAlignedObjectArray< int > m_vertexIndexMapping
void b2bfix(btHullTriangle *s, btHullTriangle *t)
void removeb2b(btHullTriangle *s, btHullTriangle *t)
btAlignedObjectArray< class btHullTriangle * > m_tris
void checkit(btHullTriangle *t)
void extrude(class btHullTriangle *t0, int v)
int calchullgen(btVector3 *verts, int verts_count, int vlimit)
int4 FindSimplex(btVector3 *verts, int verts_count, btAlignedObjectArray< int > &allow)
bool CleanupVertices(unsigned int svcount, const btVector3 *svertices, unsigned int stride, unsigned int &vcount, btVector3 *vertices, btScalar normalepsilon, btVector3 &scale)
btAlignedObjectArray< btVector3 > m_OutputVertices
btAlignedObjectArray< unsigned int > m_Indices
unsigned int mNumOutputVertices
int size() const
return the number of elements in the array
void resize(int newsize, const T &fillData=T())
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0),...
void push_back(const T &_Val)
btHullTriangle(int a, int b, int c)
btVector3 can be used to represent 3D points and vectors.
const btScalar & getZ() const
Return the z value.
void setMax(const btVector3 &other)
Set each element to the max of the current values and the values of another btVector3.
btScalar length() const
Return the length of the vector.
btVector3 cross(const btVector3 &v) const
Return the cross product between this and another vector.
btScalar dot(const btVector3 &v) const
Return the dot product.
btVector3 normalized() const
Return a normalized version of this vector.
const btScalar & getY() const
Return the y value.
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
const btScalar & getX() const
Return the x value.
int3(int _x, int _y, int _z)
const int & operator[](int i) const