refactoring

This commit is contained in:
Irlan
2018-04-25 22:00:20 -03:00
parent 4f27966147
commit 534448ea60
3 changed files with 120 additions and 105 deletions

View File

@ -59,7 +59,9 @@ struct qhFace
u32 GetVertexCount() const;
u32 GetEdgeCount() const;
qhHalfEdge* FindTwin(const qhVertex* tail, const qhVertex* head) const;
qhHalfEdge* FindHalfEdge(const qhVertex* v1, const qhVertex* v2) const;
void ComputeCenterAndPlane();
};
@ -117,6 +119,7 @@ public:
void Draw() const;
private:
bool BuildInitialHull(const b3Vec3* vertices, u32 count);
qhFace* AddFace(qhVertex* v1, qhVertex* v2, qhVertex* v3);
qhVertex* FindEyeVertex() const;
void AddVertex(qhVertex* v);
@ -124,13 +127,12 @@ private:
void FindHorizon(qhVertex* eye);
void AddNewFaces(qhVertex* eye);
void AddNewFace(qhVertex* v1, qhVertex* v2, qhVertex* v3);
void MergeFaces();
bool MergeFace(qhFace* face);
qhFace* CreateTriangle(qhVertex* v1, qhVertex* v2, qhVertex* v3);
qhHalfEdge* CreateAdjoiningTriangle(qhVertex* v, qhHalfEdge* he);
qhHalfEdge* FindTwin(const qhVertex* tail, const qhVertex* head) const;
qhHalfEdge* FindHalfEdge(const qhVertex* v1, const qhVertex* v2) const;
// Coplanarity tolerance
float32 m_tolerance;

View File

@ -66,15 +66,12 @@ inline u32 qhFace::GetEdgeCount() const
return count;
}
inline qhHalfEdge* qhFace::FindTwin(const qhVertex* tail, const qhVertex* head) const
inline qhHalfEdge* qhFace::FindHalfEdge(const qhVertex* v1, const qhVertex* v2) const
{
qhHalfEdge* e = edge;
do
{
qhVertex* tail2 = e->tail;
qhVertex* head2 = e->next->tail;
if (tail2 == tail && head2 == head)
if (e->tail == v1 && e->next->tail == v2)
{
return e;
}
@ -137,7 +134,7 @@ constexpr u32 qhGetBufferSize(u32 pointCount)
u32 E = 3 * V - 6;
u32 HE = 2 * E;
u32 F = 2 * V - 4;
size += V * sizeof(qhVertex);
size += HE * sizeof(qhHalfEdge);
size += F * sizeof(qhFace);
@ -148,11 +145,11 @@ constexpr u32 qhGetBufferSize(u32 pointCount)
// Horizon
size += HE * sizeof(qhHalfEdge*);
// New Faces
// One face per horizon edge
size += HE * sizeof(qhFace*);
return size;
}
@ -206,17 +203,15 @@ inline void qhHull::FreeFace(qhFace* f)
m_freeFaces = f;
}
inline qhHalfEdge* qhHull::FindTwin(const qhVertex* tail, const qhVertex* head) const
inline qhHalfEdge* qhHull::FindHalfEdge(const qhVertex* v1, const qhVertex* v2) const
{
qhFace* face = m_faceList.head;
while (face)
for (qhFace* face = m_faceList.head; face != NULL; face = face->next)
{
qhHalfEdge* e = face->FindTwin(tail, head);
qhHalfEdge* e = face->FindHalfEdge(v1, v2);
if (e)
{
return e;
}
face = face->next;
}
return NULL;
}