allow toggling convex hull simplification at run-time in order to expected convex hull creation work

This commit is contained in:
Irlan 2018-05-12 21:56:11 -03:00
parent df304a5bb8
commit 569a555bde
2 changed files with 108 additions and 112 deletions

View File

@ -44,7 +44,9 @@ struct b3QHull : public b3Hull
// Create a convex hull from an array of points.
// If the creation has failed then this convex hull is not modified.
void Set(const b3Vec3* points, u32 count);
// Use the flag simplify to tell the convex hull creation code to simplify the convex hull after
// construction.
void Set(const b3Vec3* points, u32 count, bool simplify = true);
// Set this hull as a cylinder located at the origin.
void SetAsCylinder(float32 radius = 1.0f, float32 height = 1.0f);

View File

@ -21,10 +21,6 @@
#define B3_NULL_HULL_FEATURE 0xFF
// Enables or disables convex hull simplification.
// This can speed up collision detection and stability significantly.
#define B3_SIMPLIFY_HULL 1
// Used to map pointers to indices
// If more performance is required then a use hash-map
template<class T, u32 N>
@ -142,7 +138,7 @@ static b3Vec3 b3ComputeCentroid(b3QHull* hull)
return centroid;
}
void b3QHull::Set(const b3Vec3* points, u32 count)
void b3QHull::Set(const b3Vec3* points, u32 count, bool simplify)
{
B3_ASSERT(count >= 4);
@ -178,9 +174,10 @@ void b3QHull::Set(const b3Vec3* points, u32 count)
}
// Create a convex hull.
qhHull hull;
#if B3_SIMPLIFY_HULL == 1
if (simplify == true)
{
qhHull primary;
primary.Construct(ps, psCount);
b3Free(ps);
@ -286,20 +283,17 @@ void b3QHull::Set(const b3Vec3* points, u32 count)
return;
}
qhHull hull;
hull.Construct(pvs, pvCount);
b3Free(pvs);
// Translate the hull back to the origin
hull.Translate(s);
#else
qhHull hull;
}
else
{
hull.Construct(ps, psCount);
b3Free(ps);
#endif
}
if (hull.GetVertexList().count > B3_MAX_HULL_VERTICES)
{
@ -464,7 +458,7 @@ void b3QHull::SetAsCylinder(float32 radius, float32 height)
}
// Set
Set(vs, count);
Set(vs, count, false);
}
void b3QHull::SetAsCone(float32 radius, float32 height)
@ -499,5 +493,5 @@ void b3QHull::SetAsCone(float32 radius, float32 height)
vs[count++].Set(0.0f, height, 0.0f);
// Set
Set(vs, count);
Set(vs, count, false);
}