rollback function def
This commit is contained in:
parent
4f2ec314c2
commit
77a193267f
@ -118,11 +118,11 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool BuildInitialHull(const b3Vec3* vertices, u32 count);
|
bool BuildInitialHull(const b3Vec3* vertices, u32 count);
|
||||||
|
|
||||||
qhVertex* NextVertex();
|
qhVertex* FindEyeVertex() const;
|
||||||
void AddVertex(qhVertex* v);
|
void AddVertex(qhVertex* v);
|
||||||
|
|
||||||
void FindHorizon(qhVertex* eye);
|
void FindHorizon(qhVertex* eye);
|
||||||
void FindHorizon(qhVertex* eye, qhHalfEdge* edge);
|
void FindHorizon(qhVertex* eye, qhFace* face, qhHalfEdge* begin);
|
||||||
|
|
||||||
void AddNewFaces(qhVertex* eye);
|
void AddNewFaces(qhVertex* eye);
|
||||||
void MergeFaces();
|
void MergeFaces();
|
||||||
@ -137,7 +137,7 @@ private:
|
|||||||
float32 m_tolerance;
|
float32 m_tolerance;
|
||||||
|
|
||||||
// Number of Quickhull iterations
|
// Number of Quickhull iterations
|
||||||
u32 m_iteration;
|
u32 m_iterations;
|
||||||
|
|
||||||
// List of faces
|
// List of faces
|
||||||
qhList<qhFace> m_faceList;
|
qhList<qhFace> m_faceList;
|
||||||
|
@ -158,7 +158,7 @@ constexpr u32 qhGetBufferSize(u32 pointCount)
|
|||||||
|
|
||||||
inline u32 qhHull::GetIterations() const
|
inline u32 qhHull::GetIterations() const
|
||||||
{
|
{
|
||||||
return m_iteration;
|
return m_iterations;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const qhList<qhFace>& qhHull::GetFaceList() const
|
inline const qhList<qhFace>& qhHull::GetFaceList() const
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <bounce/quickhull/qh_hull.h>
|
#include <bounce/quickhull/qh_hull.h>
|
||||||
#include <bounce/common/template/array.h>
|
#include <bounce/common/template/array.h>
|
||||||
#include <bounce/common/template/stack.h>
|
#include <bounce/common/template/stack.h>
|
||||||
|
#include <bounce/common/template/queue.h>
|
||||||
#include <bounce/common/draw.h>
|
#include <bounce/common/draw.h>
|
||||||
|
|
||||||
static float32 qhFindAABB(u32 iMin[3], u32 iMax[3], const b3Vec3* vertices, u32 count)
|
static float32 qhFindAABB(u32 iMin[3], u32 iMax[3], const b3Vec3* vertices, u32 count)
|
||||||
@ -108,19 +109,19 @@ void qhHull::Construct(void* memory, const b3Vec3* vs, u32 count)
|
|||||||
|
|
||||||
m_faceList.head = NULL;
|
m_faceList.head = NULL;
|
||||||
m_faceList.count = 0;
|
m_faceList.count = 0;
|
||||||
m_iteration = 0;
|
m_iterations = 0;
|
||||||
|
|
||||||
if (!BuildInitialHull(vs, count))
|
if (!BuildInitialHull(vs, count))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qhVertex* eye = NextVertex();
|
qhVertex* eye = FindEyeVertex();
|
||||||
while (eye)
|
while (eye)
|
||||||
{
|
{
|
||||||
AddVertex(eye);
|
AddVertex(eye);
|
||||||
eye = NextVertex();
|
eye = FindEyeVertex();
|
||||||
++m_iteration;
|
++m_iterations;
|
||||||
}
|
}
|
||||||
|
|
||||||
Validate();
|
Validate();
|
||||||
@ -323,17 +324,15 @@ bool qhHull::BuildInitialHull(const b3Vec3* vertices, u32 vertexCount)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
qhVertex* qhHull::NextVertex()
|
qhVertex* qhHull::FindEyeVertex() const
|
||||||
{
|
{
|
||||||
// Find the point furthest from the current hull.
|
// Find the point furthest from the current hull.
|
||||||
float32 d0 = m_tolerance;
|
float32 d0 = m_tolerance;
|
||||||
qhVertex* v0 = NULL;
|
qhVertex* v0 = NULL;
|
||||||
|
|
||||||
qhFace* f = m_faceList.head;
|
for (qhFace* f = m_faceList.head; f != NULL; f = f->next)
|
||||||
while (f)
|
|
||||||
{
|
{
|
||||||
qhVertex* v = f->conflictList.head;
|
for (qhVertex* v = f->conflictList.head; v != NULL; v = v->next)
|
||||||
while (v)
|
|
||||||
{
|
{
|
||||||
float32 d = b3Distance(v->position, f->plane);
|
float32 d = b3Distance(v->position, f->plane);
|
||||||
if (d > d0)
|
if (d > d0)
|
||||||
@ -341,11 +340,7 @@ qhVertex* qhHull::NextVertex()
|
|||||||
d0 = d;
|
d0 = d;
|
||||||
v0 = v;
|
v0 = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
v = v->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
f = f->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return v0;
|
return v0;
|
||||||
@ -368,27 +363,29 @@ void qhHull::FindHorizon(qhVertex* eye)
|
|||||||
|
|
||||||
// Find the horizon
|
// Find the horizon
|
||||||
m_horizonCount = 0;
|
m_horizonCount = 0;
|
||||||
FindHorizon(eye, eye->conflictFace->edge);
|
FindHorizon(eye, eye->conflictFace, eye->conflictFace->edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
void qhHull::FindHorizon(qhVertex* eye, qhHalfEdge* begin)
|
void qhHull::FindHorizon(qhVertex* eye, qhFace* face, qhHalfEdge* begin)
|
||||||
{
|
{
|
||||||
// Mark face as visible/visited.
|
// Mark the face
|
||||||
qhFace* face = begin->face;
|
|
||||||
face->state = qhFace::e_visible;
|
face->state = qhFace::e_visible;
|
||||||
|
|
||||||
|
//
|
||||||
qhHalfEdge* edge = begin;
|
qhHalfEdge* edge = begin;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
qhHalfEdge* adjEdge = edge->twin;
|
qhHalfEdge* twin = edge->twin;
|
||||||
qhFace* adjFace = adjEdge->face;
|
qhFace* other = twin->face;
|
||||||
|
|
||||||
if (adjFace->state == qhFace::e_invisible)
|
if (other->state == qhFace::e_invisible)
|
||||||
{
|
{
|
||||||
if (b3Distance(eye->position, adjFace->plane) > m_tolerance)
|
// Is the other face invisible?
|
||||||
|
if (b3Distance(eye->position, other->plane) > m_tolerance)
|
||||||
{
|
{
|
||||||
FindHorizon(eye, adjEdge);
|
// Recurse starting from the twin edge for
|
||||||
|
// ensuring CCW horizon order
|
||||||
|
FindHorizon(eye, other, twin);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -397,7 +394,6 @@ void qhHull::FindHorizon(qhVertex* eye, qhHalfEdge* begin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
edge = edge->next;
|
edge = edge->next;
|
||||||
|
|
||||||
} while (edge != begin);
|
} while (edge != begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user