15#if defined(_WIN32) || defined(__i386__)
16#define BT_USE_SSE_IN_API
31btPolyhedralConvexShape::~btPolyhedralConvexShape()
35 m_polyhedron->~btConvexPolyhedron();
44 *m_polyhedron = polyhedron;
53bool btPolyhedralConvexShape::initializePolyhedralFeatures(
int shiftVerticesByMargin)
57 m_polyhedron->~btConvexPolyhedron();
74 if (shiftVerticesByMargin)
80 for (
int p = 0; p < planeEquations.
size(); p++)
92 conv.compute(&tmpVertices[0].
getX(),
sizeof(
btVector3), tmpVertices.
size(), 0.f, 0.f);
96 conv.compute(&orgVertices[0].
getX(),
sizeof(
btVector3), orgVertices.
size(), 0.f, 0.f);
99#ifndef BT_RECONSTRUCT_FACES
105 m_polyhedron->m_vertices[p] = conv.
vertices[p];
109 for (
int j = 0; j < conv.
faces.
size(); j++)
126 edges[numEdges++] = newEdge;
138 btVector3 faceNormal = edges[0].cross(edges[1]);
139 faceNormal.normalize();
151 combinedFace.
m_plane[0] = faceNormal.getX();
152 combinedFace.
m_plane[1] = faceNormal.getY();
153 combinedFace.
m_plane[2] = faceNormal.getZ();
154 combinedFace.
m_plane[3] = -planeEq;
156 m_polyhedron->m_faces.push_back(combinedFace);
163 faceNormals.
resize(numFaces);
167 tmpFaces.
resize(numFaces);
173 m_polyhedron->m_vertices[p] = convexUtil->
vertices[p];
176 for (
int i = 0;
i < numFaces;
i++)
178 int face = convexUtil->
faces[
i];
198 edges[numEdges++] = newEdge;
201 }
while (edge != firstEdge);
207 faceNormals[
i] = edges[0].cross(edges[1]);
208 faceNormals[
i].normalize();
209 tmpFaces[
i].m_plane[0] = faceNormals[
i].getX();
210 tmpFaces[
i].m_plane[1] = faceNormals[
i].getY();
211 tmpFaces[
i].m_plane[2] = faceNormals[
i].getZ();
212 tmpFaces[
i].m_plane[3] = planeEq;
217 faceNormals[
i].setZero();
220 for (
int v = 0;
v < tmpFaces[
i].m_indices.
size();
v++)
222 btScalar eq = m_polyhedron->m_vertices[tmpFaces[
i].m_indices[
v]].dot(faceNormals[
i]);
228 tmpFaces[
i].m_plane[3] = -planeEq;
233 btScalar faceWeldThreshold = 0.999f;
235 for (
int i = 0;
i < tmpFaces.
size();
i++)
238 while (todoFaces.
size())
241 int refFace = todoFaces[todoFaces.
size() - 1];
244 btFace& faceA = tmpFaces[refFace];
248 for (
int j = todoFaces.
size() - 1; j >= 0; j--)
250 int i = todoFaces[j];
253 if (faceNormalA.dot(faceNormalB) > faceWeldThreshold)
260 bool did_merge =
false;
261 if (coplanarFaceGroup.
size() > 1)
268 for (
int i = 0;
i < coplanarFaceGroup.
size();
i++)
272 btFace& face = tmpFaces[coplanarFaceGroup[
i]];
274 averageFaceNormal += faceNormal;
278 btVector3 pt = m_polyhedron->m_vertices[orgIndex];
282 for (
int i = 0;
i < orgpoints.
size();
i++)
285 if (orgpoints[
i].m_orgIndex == orgIndex)
297 for (
int i = 0;
i < 4;
i++)
298 combinedFace.
m_plane[
i] = tmpFaces[coplanarFaceGroup[0]].m_plane[
i];
302 averageFaceNormal.normalize();
305 for (
int i = 0;
i < hull.
size();
i++)
308 for (
int k = 0; k < orgpoints.
size(); k++)
310 if (orgpoints[k].m_orgIndex == hull[
i].m_orgIndex)
312 orgpoints[k].m_orgIndex = -1;
319 bool reject_merge =
false;
321 for (
int i = 0;
i < orgpoints.
size();
i++)
323 if (orgpoints[
i].m_orgIndex == -1)
326 for (
int j = 0; j < tmpFaces.
size(); j++)
328 btFace& face = tmpFaces[j];
330 bool is_in_current_group =
false;
331 for (
int k = 0; k < coplanarFaceGroup.
size(); k++)
333 if (coplanarFaceGroup[k] == j)
335 is_in_current_group =
true;
339 if (is_in_current_group)
362 m_polyhedron->m_faces.push_back(combinedFace);
367 for (
int i = 0;
i < coplanarFaceGroup.
size();
i++)
369 btFace face = tmpFaces[coplanarFaceGroup[
i]];
377 m_polyhedron->initialize();
383#define MIN(_a, _b) ((_a) < (_b) ? (_a) : (_b))
386btVector3 btPolyhedralConvexShape::localGetSupportingVertexWithoutMargin(
const btVector3& vec0)
const
397 vec.setValue(1, 0, 0);
412 for (
i = 0;
i < inner_count;
i++)
414 i = (int)vec.maxDot(temp, inner_count, newDot);
426void btPolyhedralConvexShape::batchedUnitVectorGetSupportingVertexWithoutMargin(
const btVector3* vectors,
btVector3* supportVerticesOut,
int numVectors)
const
434 for (
i = 0;
i < numVectors;
i++)
439 for (
int j = 0; j < numVectors; j++)
447 for (
i = 0;
i < inner_count;
i++)
449 i = (int)vec.maxDot(temp, inner_count, newDot);
450 if (newDot > supportVerticesOut[j][3])
452 supportVerticesOut[j] = temp[
i];
453 supportVerticesOut[j][3] = newDot;
461void btPolyhedralConvexShape::calculateLocalInertia(
btScalar mass,
btVector3& inertia)
const
471 getAabb(ident, aabbMin, aabbMax);
482 inertia = scaledmass * (
btVector3(y2 + z2, x2 + z2, x2 + y2));
488 btConvexInternalShape::setLocalScaling(scaling);
494 m_localAabbMin(1, 1, 1),
495 m_localAabbMax(-1, -1, -1),
496 m_isLocalAabbValid(
false)
507 m_isLocalAabbValid =
true;
530 for (
int i = 0;
i < 3; ++
i)
532 m_localAabbMax[
i] = _supporting[
i][
i];
533 m_localAabbMin[
i] = _supporting[
i + 3][
i];
538 for (
int i = 0;
i < 3;
i++)
543 m_localAabbMax[
i] = tmp[
i];
546 m_localAabbMin[
i] = tmp[
i];
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define btAlignedFree(ptr)
#define btAlignedAlloc(size, alignment)
virtual btVector3 localGetSupportingVertex(const btVector3 &vec) const
virtual int getNumVertices() const
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb's default implementation is brute force, expected derived classes to implement a fast dedicat...
virtual void getVertex(int i, btVector3 &vtx) const
virtual btScalar getMargin() const =0
void GrahamScanConvexHull2D(btAlignedObjectArray< GrahamVector3 > &originalPoints, btAlignedObjectArray< GrahamVector3 > &hull, const btVector3 &normalAxis)
btPolyhedralConvexShape()
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const
SIMD_FORCE_INLINE const btScalar & getX() const
Return the x value.
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
SIMD_FORCE_INLINE btScalar btSqrt(btScalar y)
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 long maxDot(const btVector3 *array, long array_count, btScalar &dotOut) const
returns index of maximum dot product between this and vectors in array[]
SIMD_FORCE_INLINE T & expand(const T &fillValue=T())
SIMD_FORCE_INLINE int size() const
return the number of elements in the array
SIMD_FORCE_INLINE void pop_back()
void remove(const T &key)
SIMD_FORCE_INLINE void resize(int newsize, const T &fillData=T())
SIMD_FORCE_INLINE void push_back(const T &_Val)
const Edge * getNextEdgeOfFace() const
int getSourceVertex() const
int getTargetVertex() const
btAlignedObjectArray< btVector3 > vertices
btAlignedObjectArray< int > faces
btAlignedObjectArray< Edge > edges
static void getVerticesFromPlaneEquations(const btAlignedObjectArray< btVector3 > &planeEquations, btAlignedObjectArray< btVector3 > &verticesOut)
static void getPlaneEquationsFromVertices(btAlignedObjectArray< btVector3 > &vertices, btAlignedObjectArray< btVector3 > &planeEquationsOut)
btPolyhedralConvexAabbCachingShape()
virtual void setLocalScaling(const btVector3 &scaling)
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
void getNonvirtualAabb(const btTransform &trans, btVector3 &aabbMin, btVector3 &aabbMax, btScalar margin) const
btAlignedObjectArray< int > m_indices