remove quickhull array dependency (except for drawing)

This commit is contained in:
Irlan
2018-04-20 23:37:59 -03:00
parent bd4ca5d143
commit 4ebe826eea
4 changed files with 200 additions and 187 deletions

View File

@ -20,7 +20,6 @@
#define QH_HULL_H
#include <bounce/common/geometry.h>
#include <bounce/common/template/array.h>
template<class T>
struct qhList
@ -100,7 +99,7 @@ public:
~qhHull();
// Construct this hull given a memory buffer and an array of points.
// Use qhGetBufferCapacity to get the buffer capacity from the point array size.
// Use qhGetBufferSize to get the buffer size given the number of points.
void Construct(void* buffer, const b3Vec3* vertices, u32 vertexCount);
// Get the number of iterations this algorithm ran.
@ -128,21 +127,18 @@ private:
qhVertex* NextVertex();
void AddVertex(qhVertex* v);
void BuildHorizon(b3Array<qhHalfEdge*>& horizon, qhVertex* eye);
void BuildHorizon(b3Array<qhHalfEdge*>& horizon, qhVertex* eye, qhHalfEdge* e0, qhFace* f);
void BuildHorizon(qhVertex* eye);
void BuildHorizon(qhVertex* eye, qhHalfEdge* e0, qhFace* f);
void AddNewFaces(qhVertex* eye);
void MergeFaces();
bool MergeFace(qhFace* face);
qhFace* AddTriangle(qhVertex* v1, qhVertex* v2, qhVertex* v3);
qhHalfEdge* AddAdjoiningTriangle(qhVertex* v, qhHalfEdge* he);
void AddNewFaces(b3Array<qhFace*>& newFaces, qhVertex* eye, const b3Array<qhHalfEdge*>& horizon);
bool MergeFace(qhFace* face);
void MergeFaces(b3Array<qhFace*>& newFaces);
qhHalfEdge* FindTwin(const qhVertex* tail, const qhVertex* head) const;
// Coplanarity tolerance
@ -163,10 +159,16 @@ private:
qhFace* AllocateFace();
void FreeFace(qhFace* p);
qhVertex* m_freeVertices;
qhHalfEdge* m_freeEdges;
qhFace* m_freeFaces;
qhHalfEdge** m_horizon;
u32 m_horizonCount;
qhFace** m_newFaces;
u32 m_newFaceCount;
};
#include <bounce/quickhull/qh_hull.inl>

View File

@ -128,20 +128,31 @@ inline void qhFace::ComputeCenterAndPlane()
// its value at compile-time. That is particularly usefull when you want to
// create a stack buffer from a constant number of vertices.
// Due to the constexpr specifier, this function is automatically inlined.
constexpr u32 qhGetBufferCapacity(u32 pointCount)
constexpr u32 qhGetBufferSize(u32 pointCount)
{
u32 size = 0;
// Hull using Euler's Formula
u32 V = pointCount;
u32 E = 3 * V - 6;
u32 HE = 2 * E;
u32 F = 2 * V - 4;
HE *= 2;
F *= 2;
u32 size = 0;
size += V * sizeof(qhVertex);
size += HE * sizeof(qhHalfEdge);
size += F * sizeof(qhFace);
// Extra
size += HE * sizeof(qhHalfEdge);
size += F * sizeof(qhFace);
// Horizon
size += HE * sizeof(qhHalfEdge*);
// New Faces
// One face per horizon edge
size += HE * sizeof(qhFace*);
return size;
}