erase dep, constexpr, cleanup
This commit is contained in:
@ -58,8 +58,8 @@ struct qhFace
|
||||
b3Vec3 center;
|
||||
b3Plane plane;
|
||||
|
||||
u32 VertexCount() const;
|
||||
u32 EdgeCount() const;
|
||||
u32 GetVertexCount() const;
|
||||
u32 GetEdgeCount() const;
|
||||
qhHalfEdge* FindTwin(const qhVertex* tail, const qhVertex* head) const;
|
||||
void ComputeCenterAndPlane();
|
||||
};
|
||||
@ -89,12 +89,8 @@ struct qhVertex
|
||||
qhFace* conflictFace;
|
||||
};
|
||||
|
||||
// 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.
|
||||
u32 qhGetMemorySize(u32 V);
|
||||
|
||||
// A convex hull builder. Given a list of points constructs its convex hull.
|
||||
// A convex hull builder.
|
||||
// Given a list of points constructs its convex hull.
|
||||
// The output convex hull might contain polygonal faces and not only triangles.
|
||||
// Coplanar face merging is necessary for stable physics simulation.
|
||||
class qhHull
|
||||
@ -102,18 +98,23 @@ class qhHull
|
||||
public:
|
||||
qhHull();
|
||||
~qhHull();
|
||||
|
||||
// Entry point of qhHull.
|
||||
// Construct this hull given a memory buffer and a list of points.
|
||||
// Use qhGetMemorySize to see how many free bytes should be available in the buffer.
|
||||
void Construct(void* memory, const b3Array<b3Vec3>& vertices);
|
||||
|
||||
// Get the list of faces in this hull.
|
||||
const qhList<qhFace>& GetFaceList() const;
|
||||
|
||||
// Construct this hull given a memory buffer and an array of points.
|
||||
// Use qhGetBufferCapacity to get the buffer capacity from the point array size.
|
||||
void Construct(void* buffer, const b3Vec3* vertices, u32 vertexCount);
|
||||
|
||||
// Get the number of iterations this algorithm ran.
|
||||
u32 GetIterations() const;
|
||||
|
||||
// Get the list of faces in this convex hull.
|
||||
const qhList<qhFace>& GetFaceList() const;
|
||||
|
||||
// Get the number of unique edges in this convex hull.
|
||||
// u32 GetEdgeCount() const;
|
||||
|
||||
// Get the number of unique vertices in this convex hull.
|
||||
// u32 GetVertexCount() const;
|
||||
|
||||
// Validate this hull.
|
||||
void Validate() const;
|
||||
void Validate(const qhFace* face) const;
|
||||
@ -122,7 +123,7 @@ public:
|
||||
// Draw this hull.
|
||||
void Draw() const;
|
||||
private:
|
||||
bool BuildInitialHull(const b3Array<b3Vec3>& vertices);
|
||||
bool BuildInitialHull(const b3Vec3* vertices, u32 count);
|
||||
|
||||
qhVertex* NextVertex();
|
||||
|
||||
@ -146,13 +147,13 @@ private:
|
||||
|
||||
// Coplanarity tolerance
|
||||
float32 m_tolerance;
|
||||
|
||||
|
||||
// Number of Quickhull iterations
|
||||
u32 m_iteration;
|
||||
|
||||
// List of faces
|
||||
qhList<qhFace> m_faceList;
|
||||
|
||||
// Number of Quickhull iterations
|
||||
u32 m_iteration;
|
||||
|
||||
// Memory
|
||||
qhVertex* AllocateVertex();
|
||||
void FreeVertex(qhVertex* p);
|
||||
|
@ -1,5 +1,7 @@
|
||||
// qhHull.h
|
||||
|
||||
// Lists
|
||||
|
||||
template<class T>
|
||||
inline void qhList<T>::PushFront(T* link)
|
||||
{
|
||||
@ -38,7 +40,9 @@ inline T* qhList<T>::Remove(T* link)
|
||||
return next;
|
||||
}
|
||||
|
||||
inline u32 qhFace::VertexCount() const
|
||||
// qhFace
|
||||
|
||||
inline u32 qhFace::GetVertexCount() const
|
||||
{
|
||||
u32 count = 0;
|
||||
qhHalfEdge* e = edge;
|
||||
@ -50,7 +54,7 @@ inline u32 qhFace::VertexCount() const
|
||||
return count;
|
||||
}
|
||||
|
||||
inline u32 qhFace::EdgeCount() const
|
||||
inline u32 qhFace::GetEdgeCount() const
|
||||
{
|
||||
u32 count = 0;
|
||||
qhHalfEdge* e = edge;
|
||||
@ -81,7 +85,7 @@ inline qhHalfEdge* qhFace::FindTwin(const qhVertex* tail, const qhVertex* head)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline b3Vec3 b3Newell(const b3Vec3& a, const b3Vec3& b)
|
||||
static inline b3Vec3 b3Newell(const b3Vec3& a, const b3Vec3& b)
|
||||
{
|
||||
return b3Vec3((a.y - b.y) * (a.z + b.z), (a.z - b.z) * (a.x + b.x), (a.x - b.x) * (a.y + b.y));
|
||||
}
|
||||
@ -116,29 +120,21 @@ inline void qhFace::ComputeCenterAndPlane()
|
||||
center = c;
|
||||
}
|
||||
|
||||
inline qhHalfEdge* qhHull::FindTwin(const qhVertex* tail, const qhVertex* head) const
|
||||
{
|
||||
qhFace* face = m_faceList.head;
|
||||
while (face)
|
||||
{
|
||||
qhHalfEdge* e = face->FindTwin(tail, head);
|
||||
if (e)
|
||||
{
|
||||
return e;
|
||||
}
|
||||
face = face->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
// qhHull
|
||||
|
||||
inline u32 qhGetMemorySize(u32 V)
|
||||
// Given a number of points return the required memory size in
|
||||
// bytes for constructing the convex hull of those points.
|
||||
// This function uses constant expression (C++11). Therefore, you can evaluate
|
||||
// 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)
|
||||
{
|
||||
u32 V = pointCount;
|
||||
u32 E = 3 * V - 6;
|
||||
u32 HE = 2 * E;
|
||||
u32 F = 2 * V - 4;
|
||||
|
||||
// V - E + F = 2
|
||||
|
||||
HE *= 2;
|
||||
F *= 2;
|
||||
|
||||
@ -149,16 +145,16 @@ inline u32 qhGetMemorySize(u32 V)
|
||||
return size;
|
||||
}
|
||||
|
||||
inline const qhList<qhFace>& qhHull::GetFaceList() const
|
||||
{
|
||||
return m_faceList;
|
||||
}
|
||||
|
||||
inline u32 qhHull::GetIterations() const
|
||||
{
|
||||
return m_iteration;
|
||||
}
|
||||
|
||||
inline const qhList<qhFace>& qhHull::GetFaceList() const
|
||||
{
|
||||
return m_faceList;
|
||||
}
|
||||
|
||||
inline qhVertex* qhHull::AllocateVertex()
|
||||
{
|
||||
qhVertex* v = m_freeVertices;
|
||||
@ -197,4 +193,19 @@ inline void qhHull::FreeFace(qhFace* f)
|
||||
f->state = qhFace::e_deleted;
|
||||
f->freeNext = m_freeFaces;
|
||||
m_freeFaces = f;
|
||||
}
|
||||
|
||||
inline qhHalfEdge* qhHull::FindTwin(const qhVertex* tail, const qhVertex* head) const
|
||||
{
|
||||
qhFace* face = m_faceList.head;
|
||||
while (face)
|
||||
{
|
||||
qhHalfEdge* e = face->FindTwin(tail, head);
|
||||
if (e)
|
||||
{
|
||||
return e;
|
||||
}
|
||||
face = face->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
Reference in New Issue
Block a user