switch hull indices to 32-bit indices
This commit is contained in:
@@ -19,41 +19,24 @@
|
||||
#include <bounce/collision/shapes/qhull.h>
|
||||
#include <bounce/quickhull/qh_hull.h>
|
||||
|
||||
#define B3_NULL_HULL_FEATURE 0xFF
|
||||
|
||||
// Used to map pointers to indices
|
||||
// If more performance is required then a use hash-map
|
||||
template<class T, u32 N>
|
||||
template <class T>
|
||||
struct b3UniqueStackArray
|
||||
{
|
||||
b3UniqueStackArray()
|
||||
u32 PushBack(const T& e)
|
||||
{
|
||||
count = 0;
|
||||
}
|
||||
|
||||
// Return value index if added
|
||||
// Return N if the array is full
|
||||
u32 PushBack(const T& value)
|
||||
{
|
||||
for (u32 i = 0; i < count; ++i)
|
||||
for (u32 i = 0; i < elements.Count(); ++i)
|
||||
{
|
||||
if (values[i] == value)
|
||||
if (elements[i] == e)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == N)
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
values[count++] = value;
|
||||
return count - 1;
|
||||
elements.PushBack(e);
|
||||
return elements.Count() - 1;
|
||||
}
|
||||
|
||||
T values[N];
|
||||
u32 count;
|
||||
b3StackArray<T, 256> elements;
|
||||
};
|
||||
|
||||
//
|
||||
@@ -287,22 +270,9 @@ void b3QHull::Set(const b3Vec3* points, u32 count, bool simplify)
|
||||
b3Free(ps);
|
||||
}
|
||||
|
||||
if (hull.GetVertexList().count > B3_MAX_HULL_VERTICES)
|
||||
{
|
||||
// Vertex excess
|
||||
return;
|
||||
}
|
||||
|
||||
if (hull.GetFaceList().count > B3_MAX_HULL_FACES)
|
||||
{
|
||||
// Face excess
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the constructed hull into a run-time hull.
|
||||
b3UniqueStackArray<qhVertex*, B3_MAX_HULL_VERTICES> vs;
|
||||
b3UniqueStackArray<qhHalfEdge*, B3_MAX_HULL_EDGES> es;
|
||||
u32 fs_count = 0;
|
||||
b3UniqueStackArray<qhVertex*> vs;
|
||||
b3UniqueStackArray<qhHalfEdge*> es;
|
||||
|
||||
// Add vertices to the map
|
||||
for (qhVertex* vertex = hull.GetVertexList().head; vertex != NULL; vertex = vertex->next)
|
||||
@@ -310,13 +280,9 @@ void b3QHull::Set(const b3Vec3* points, u32 count, bool simplify)
|
||||
vs.PushBack(vertex);
|
||||
}
|
||||
|
||||
// Add faces and half-edges to the map
|
||||
// Add half-edges to the map
|
||||
for (qhFace* face = hull.GetFaceList().head; face != NULL; face = face->next)
|
||||
{
|
||||
// Add face
|
||||
B3_ASSERT(fs_count < B3_MAX_HULL_FACES);
|
||||
++fs_count;
|
||||
|
||||
// Add half-edges
|
||||
qhHalfEdge* begin = face->edge;
|
||||
qhHalfEdge* edge = begin;
|
||||
@@ -324,59 +290,54 @@ void b3QHull::Set(const b3Vec3* points, u32 count, bool simplify)
|
||||
{
|
||||
// Add half-edge
|
||||
u32 iedge = es.PushBack(edge);
|
||||
if (iedge == B3_MAX_HULL_EDGES)
|
||||
{
|
||||
// Half-edge excess
|
||||
return;
|
||||
}
|
||||
|
||||
// Add half-edge just after its twin
|
||||
u32 itwin = es.PushBack(edge->twin);
|
||||
if (itwin == B3_MAX_HULL_EDGES)
|
||||
{
|
||||
// Half-edge excess
|
||||
return;
|
||||
}
|
||||
|
||||
edge = edge->next;
|
||||
} while (edge != begin);
|
||||
}
|
||||
|
||||
hullVertices.Resize(hull.GetVertexList().count);
|
||||
hullEdges.Resize(es.elements.Count());
|
||||
hullFaces.Resize(hull.GetFaceList().count);
|
||||
hullPlanes.Resize(hull.GetFaceList().count);
|
||||
|
||||
// Build and link the features
|
||||
u32 iface = 0;
|
||||
for (qhFace* face = hull.GetFaceList().head; face != NULL; face = face->next)
|
||||
{
|
||||
// Build and link the half-edges
|
||||
b3Face* hface = faces + iface;
|
||||
b3Face* hface = hullFaces.Get(iface);
|
||||
|
||||
planes[iface] = face->plane;
|
||||
hullPlanes[iface] = face->plane;
|
||||
|
||||
qhHalfEdge* begin = face->edge;
|
||||
hface->edge = (u8)es.PushBack(begin);
|
||||
hface->edge = es.PushBack(begin);
|
||||
|
||||
qhHalfEdge* edge = begin;
|
||||
do
|
||||
{
|
||||
qhVertex* v = edge->tail;
|
||||
u8 iv = (u8)vs.PushBack(v);
|
||||
vertices[iv] = v->position;
|
||||
u32 iv = vs.PushBack(v);
|
||||
hullVertices[iv] = v->position;
|
||||
|
||||
u8 iedge = (u8)es.PushBack(edge);
|
||||
b3HalfEdge* hedge = edges + iedge;
|
||||
hedge->face = u8(iface);
|
||||
u32 iedge = es.PushBack(edge);
|
||||
b3HalfEdge* hedge = hullEdges.Get(iedge);
|
||||
hedge->face = iface;
|
||||
hedge->origin = iv;
|
||||
|
||||
qhHalfEdge* twin = edge->twin;
|
||||
u8 itwin = (u8)es.PushBack(twin);
|
||||
b3HalfEdge* htwin = edges + itwin;
|
||||
u32 itwin = es.PushBack(twin);
|
||||
b3HalfEdge* htwin = hullEdges.Get(itwin);
|
||||
htwin->twin = iedge;
|
||||
|
||||
hedge->twin = itwin;
|
||||
|
||||
qhHalfEdge* next = edge->next;
|
||||
u8 inext = (u8)es.PushBack(next);
|
||||
u32 inext = es.PushBack(next);
|
||||
|
||||
edges[iedge].next = inext;
|
||||
hullEdges[iedge].next = inext;
|
||||
|
||||
edge = next;
|
||||
} while (edge != begin);
|
||||
@@ -384,14 +345,9 @@ void b3QHull::Set(const b3Vec3* points, u32 count, bool simplify)
|
||||
++iface;
|
||||
}
|
||||
|
||||
B3_ASSERT(vs.count <= B3_MAX_HULL_VERTICES);
|
||||
vertexCount = vs.count;
|
||||
|
||||
B3_ASSERT(es.count <= B3_MAX_HULL_EDGES);
|
||||
edgeCount = es.count;
|
||||
|
||||
B3_ASSERT(fs_count <= B3_MAX_HULL_FACES);
|
||||
faceCount = fs_count;
|
||||
vertexCount = hullVertices.Count();
|
||||
edgeCount = hullEdges.Count();
|
||||
faceCount = hullFaces.Count();
|
||||
|
||||
// Validate
|
||||
Validate();
|
||||
|
@@ -85,7 +85,6 @@ static void b3BuildEdgeContact(b3Manifold& manifold,
|
||||
manifold.points[0].localNormal1 = b3MulT(xf1.rotation, N);
|
||||
manifold.points[0].localPoint1 = b3MulT(xf1, c1);
|
||||
manifold.points[0].localPoint2 = b3MulT(xf2, c2);
|
||||
manifold.points[0].triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key = b3MakeKey(pair);
|
||||
}
|
||||
|
||||
@@ -131,7 +130,6 @@ static void b3BuildFaceContact(b3Manifold& manifold,
|
||||
mp->localNormal1 = b3MulT(xf1.rotation, n1);
|
||||
mp->localPoint1 = b3MulT(xf1, c1);
|
||||
mp->localPoint2 = b3MulT(xf2, c2);
|
||||
mp->triangleKey = B3_NULL_TRIANGLE;
|
||||
mp->key = b3MakeKey(clipEdge1[i].pair);
|
||||
|
||||
++pointCount;
|
||||
@@ -193,9 +191,10 @@ void b3CollideCapsuleAndHull(b3Manifold& manifold,
|
||||
manifold.points[0].localNormal1 = b3MulT(xf1.rotation, N1);
|
||||
manifold.points[0].localPoint1 = b3MulT(xf1, gjk.point1);
|
||||
manifold.points[0].localPoint2 = b3MulT(xf2, gjk.point2);
|
||||
manifold.points[0].triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key = 0;
|
||||
|
||||
manifold.points[0].key.triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key.key1 = 0;
|
||||
manifold.points[0].key.key2 = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -233,13 +233,11 @@ void b3CollideCapsuleAndCapsule(b3Manifold& manifold,
|
||||
manifold.points[0].localNormal1 = b3MulT(xf1.rotation, n1);
|
||||
manifold.points[0].localPoint1 = b3MulT(xf1, clipEdge1[0].position);
|
||||
manifold.points[0].localPoint2 = b3MulT(xf2, cp1);
|
||||
manifold.points[0].triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key = b3MakeKey(clipEdge1[0].pair);
|
||||
|
||||
manifold.points[1].localNormal1 = b3MulT(xf1.rotation, n2);
|
||||
manifold.points[1].localPoint1 = b3MulT(xf1, clipEdge1[1].position);
|
||||
manifold.points[1].localPoint2 = b3MulT(xf2, cp2);
|
||||
manifold.points[1].triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[1].key = b3MakeKey(clipEdge1[1].pair);
|
||||
|
||||
return;
|
||||
@@ -253,8 +251,9 @@ void b3CollideCapsuleAndCapsule(b3Manifold& manifold,
|
||||
manifold.points[0].localNormal1 = b3MulT(xf1.rotation, normal);
|
||||
manifold.points[0].localPoint1 = b3MulT(xf1, point1);
|
||||
manifold.points[0].localPoint2 = b3MulT(xf2, point2);
|
||||
manifold.points[0].triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key = 0;
|
||||
manifold.points[0].key.triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key.key1 = 0;
|
||||
manifold.points[0].key.key2 = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
@@ -87,7 +87,6 @@ void b3BuildEdgeContact(b3Manifold& manifold,
|
||||
manifold.points[0].localNormal1 = b3MulT(xf1.rotation, N);
|
||||
manifold.points[0].localPoint1 = b3MulT(xf1, c1);
|
||||
manifold.points[0].localPoint2 = b3MulT(xf2, c2);
|
||||
manifold.points[0].triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key = b3MakeKey(pair);
|
||||
}
|
||||
|
||||
@@ -190,7 +189,6 @@ void b3BuildFaceContact(b3Manifold& manifold,
|
||||
mp->localNormal1 = b3MulT(xf2.rotation, s_normal);
|
||||
mp->localPoint1 = b3MulT(xf2, v2.position);
|
||||
mp->localPoint2 = b3MulT(xf1, v1);
|
||||
mp->triangleKey = B3_NULL_TRIANGLE;
|
||||
mp->key = b3MakeKey(pair);
|
||||
}
|
||||
else
|
||||
@@ -198,7 +196,6 @@ void b3BuildFaceContact(b3Manifold& manifold,
|
||||
mp->localNormal1 = b3MulT(xf1.rotation, normal);
|
||||
mp->localPoint1 = b3MulT(xf1, v1);
|
||||
mp->localPoint2 = b3MulT(xf2, v2.position);
|
||||
mp->triangleKey = B3_NULL_TRIANGLE;
|
||||
mp->key = b3MakeKey(v2.pair);
|
||||
}
|
||||
}
|
||||
|
@@ -106,7 +106,6 @@ static void b3RebuildEdgeContact(b3Manifold& manifold,
|
||||
manifold.points[0].localNormal1 = b3MulT(xf1.rotation, N);
|
||||
manifold.points[0].localPoint1 = b3MulT(xf1, c1);
|
||||
manifold.points[0].localPoint2 = b3MulT(xf2, c2);
|
||||
manifold.points[0].triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key = b3MakeKey(pair);
|
||||
}
|
||||
}
|
||||
|
@@ -59,8 +59,9 @@ void b3CollideSphereAndCapsule(b3Manifold& manifold,
|
||||
manifold.points[0].localNormal1 = b3MulT(xf1.rotation, n);
|
||||
manifold.points[0].localPoint1 = s1->m_center;
|
||||
manifold.points[0].localPoint2 = s2->m_centers[0];
|
||||
manifold.points[0].triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key = 0;
|
||||
manifold.points[0].key.triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key.key1 = 0;
|
||||
manifold.points[0].key.key2 = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -87,8 +88,9 @@ void b3CollideSphereAndCapsule(b3Manifold& manifold,
|
||||
manifold.points[0].localNormal1 = b3MulT(xf1.rotation, n);
|
||||
manifold.points[0].localPoint1 = s1->m_center;
|
||||
manifold.points[0].localPoint2 = s2->m_centers[1];
|
||||
manifold.points[0].triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key = 0;
|
||||
manifold.points[0].key.triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key.key1 = 0;
|
||||
manifold.points[0].key.key2 = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -126,6 +128,7 @@ void b3CollideSphereAndCapsule(b3Manifold& manifold,
|
||||
manifold.points[0].localNormal1 = b3MulT(xf1.rotation, n);
|
||||
manifold.points[0].localPoint1 = s1->m_center;
|
||||
manifold.points[0].localPoint2 = b3MulT(xf2, P);
|
||||
manifold.points[0].triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key = 2;
|
||||
}
|
||||
manifold.points[0].key.triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key.key1 = 0;
|
||||
manifold.points[0].key.key2 = 0;
|
||||
}
|
@@ -52,8 +52,9 @@ void b3CollideSphereAndHull(b3Manifold& manifold,
|
||||
manifold.points[0].localNormal1 = b3MulT(xf1.rotation, normal);
|
||||
manifold.points[0].localPoint1 = s1->m_center;
|
||||
manifold.points[0].localPoint2 = b3MulT(xf2, c2);
|
||||
manifold.points[0].triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key = 0;
|
||||
manifold.points[0].key.triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key.key1 = 0;
|
||||
manifold.points[0].key.key2 = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -80,6 +81,7 @@ void b3CollideSphereAndHull(b3Manifold& manifold,
|
||||
manifold.points[0].localNormal1 = b3MulT(xf1.rotation, n1);
|
||||
manifold.points[0].localPoint1 = s1->m_center;
|
||||
manifold.points[0].localPoint2 = b3MulT(xf2, c2);
|
||||
manifold.points[0].triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key = 1;
|
||||
manifold.points[0].key.triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key.key1 = 0;
|
||||
manifold.points[0].key.key2 = 0;
|
||||
}
|
@@ -50,6 +50,7 @@ void b3CollideSphereAndSphere(b3Manifold& manifold,
|
||||
manifold.points[0].localNormal1 = b3MulT(xf1.rotation, normal);
|
||||
manifold.points[0].localPoint1 = s1->m_center;
|
||||
manifold.points[0].localPoint2 = s2->m_center;
|
||||
manifold.points[0].triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key = 0;
|
||||
manifold.points[0].key.triangleKey = B3_NULL_TRIANGLE;
|
||||
manifold.points[0].key.key1 = 0;
|
||||
manifold.points[0].key.key2 = 0;
|
||||
}
|
@@ -36,16 +36,18 @@ void b3Manifold::Initialize(const b3Manifold& oldManifold)
|
||||
tangentImpulse = oldManifold.tangentImpulse;
|
||||
motorImpulse = oldManifold.motorImpulse;
|
||||
|
||||
for (u32 i = 0; i < oldManifold.pointCount; ++i)
|
||||
for (u32 i = 0; i < pointCount; ++i)
|
||||
{
|
||||
const b3ManifoldPoint* p1 = oldManifold.points + i;
|
||||
for (u32 j = 0; j < pointCount; ++j)
|
||||
b3ManifoldPoint* p1 = points + i;
|
||||
|
||||
for (u32 j = 0; j < oldManifold.pointCount; ++j)
|
||||
{
|
||||
b3ManifoldPoint* p2 = points + j;
|
||||
if (p2->triangleKey == p1->triangleKey && p2->key == p1->key)
|
||||
const b3ManifoldPoint* p2 = oldManifold.points + j;
|
||||
|
||||
if (p2->key == p1->key)
|
||||
{
|
||||
p2->normalImpulse = p1->normalImpulse;
|
||||
p2->persisting = 1;
|
||||
p1->normalImpulse = p2->normalImpulse;
|
||||
p1->persisting = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -259,7 +259,7 @@ void b3MeshContact::Collide()
|
||||
|
||||
for (u32 j = 0; j < manifold->pointCount; ++j)
|
||||
{
|
||||
manifold->points[j].triangleKey = triangleIndex;
|
||||
manifold->points[j].key.triangleKey = triangleIndex;
|
||||
}
|
||||
|
||||
++tempCount;
|
||||
|
Reference in New Issue
Block a user