diff --git a/include/bounce/quickhull/qh_hull.h b/include/bounce/quickhull/qh_hull.h index c72ab7b..90a3d8e 100644 --- a/include/bounce/quickhull/qh_hull.h +++ b/include/bounce/quickhull/qh_hull.h @@ -32,7 +32,6 @@ struct qhList u32 count; }; -// Half-edge data structure definition used by qhHull. struct qhHalfEdge; struct qhVertex; @@ -90,16 +89,6 @@ struct qhVertex qhFace* conflictFace; }; -// todo -// Snapshots of the algorithm for debug drawing. -struct qhDraw -{ - //DrawIteration* iter; // current iteration - //b3Array iterations; -}; - -class b3Draw; - // Given a number of points return the required memory size in bytes for constructing the // convex hull of those points. Use this function before allocating the memory buffer passed // as argument to Construct. @@ -119,15 +108,23 @@ public: // Use qhGetMemorySize to see how many free bytes should be available in the buffer. void Construct(void* memory, const b3Array& vertices); - // Output of qhHull. - // todo - // Output a cleaner data structure. Maybe similar to b3Hull but storing larger hulls? - qhList m_faceList; // convex hull - u32 m_iteration; // number of quickhull iterations + // Get the list of faces in this hull. + const qhList& GetFaceList() const + { + return m_faceList; + } + + // Get the number of iterations this algorithm ran. + u32 GetIterations() const + { + return m_iteration; + } + // Return if this hull is valid. bool IsConsistent() const; - void Draw(b3Draw* draw) const; + // Draw this hull. + void Draw() const; private: bool BuildInitialHull(const b3Array& vertices); @@ -154,6 +151,12 @@ private: // Coplanarity tolerance float32 m_tolerance; + // List of faces + qhList m_faceList; // list of faces + + // Number of Quickhull iterations + u32 m_iteration; + // Memory qhVertex* AllocateVertex(); void FreeVertex(qhVertex* p); @@ -167,6 +170,7 @@ private: qhVertex* m_freeVertices; qhHalfEdge* m_freeEdges; qhFace* m_freeFaces; + }; #include diff --git a/src/bounce/quickhull/qh_hull.cpp b/src/bounce/quickhull/qh_hull.cpp index 42179b2..6411850 100644 --- a/src/bounce/quickhull/qh_hull.cpp +++ b/src/bounce/quickhull/qh_hull.cpp @@ -20,7 +20,7 @@ #include #include -float32 qhFindAABB(u32 iMin[3], u32 iMax[3], const b3Array& vertices) +static float32 qhFindAABB(u32 iMin[3], u32 iMax[3], const b3Array& vertices) { b3Vec3 min(B3_MAX_FLOAT, B3_MAX_FLOAT, B3_MAX_FLOAT); iMin[0] = 0; @@ -65,6 +65,8 @@ qhHull::~qhHull() void qhHull::Construct(void* memory, const b3Array& vs) { + // Euler's formula + // V - E + F = 2 u32 V = vs.Count(); u32 E = 3 * V - 6; u32 HE = 2 * E; @@ -73,9 +75,6 @@ void qhHull::Construct(void* memory, const b3Array& vs) HE *= 2; F *= 2; - // Euler's formula - // V - E + F = 2 - m_freeVertices = NULL; qhVertex* vertices = (qhVertex*)memory; for (u32 i = 0; i < V; ++i) @@ -739,7 +738,7 @@ bool qhHull::IsConsistent() const return true; } -void qhHull::Draw(b3Draw* draw) const +void qhHull::Draw() const { qhFace* face = m_faceList.head; while (face) @@ -757,17 +756,17 @@ void qhHull::Draw(b3Draw* draw) const edge = edge->next; } while (edge != begin); - draw->DrawSolidPolygon(n, vs.Begin(), vs.Count(), b3Color(1.0f, 1.0f, 1.0f, 0.5f)); + b3Draw_draw->DrawSolidPolygon(n, vs.Begin(), vs.Count(), b3Color(1.0f, 1.0f, 1.0f, 0.5f)); qhVertex* v = face->conflictList.head; while (v) { - draw->DrawPoint(v->position, 4.0f, b3Color(1.0f, 1.0f, 0.0f)); - draw->DrawSegment(c, v->position, b3Color(1.0f, 1.0f, 0.0f)); + b3Draw_draw->DrawPoint(v->position, 4.0f, b3Color(1.0f, 1.0f, 0.0f)); + b3Draw_draw->DrawSegment(c, v->position, b3Color(1.0f, 1.0f, 0.0f)); v = v->next; } - draw->DrawSegment(c, c + n, b3Color(1.0f, 1.0f, 1.0f)); + b3Draw_draw->DrawSegment(c, c + n, b3Color(1.0f, 1.0f, 1.0f)); face = face->next; }