allow toggling convex hull simplification at run-time in order to expected convex hull creation work
This commit is contained in:
		| @@ -44,7 +44,9 @@ struct b3QHull : public b3Hull | |||||||
|  |  | ||||||
| 	// Create a convex hull from an array of points. | 	// Create a convex hull from an array of points. | ||||||
| 	// If the creation has failed then this convex hull is not modified. | 	// 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. | 	// Set this hull as a cylinder located at the origin. | ||||||
| 	void SetAsCylinder(float32 radius = 1.0f, float32 height = 1.0f); | 	void SetAsCylinder(float32 radius = 1.0f, float32 height = 1.0f); | ||||||
|   | |||||||
| @@ -21,10 +21,6 @@ | |||||||
|  |  | ||||||
| #define B3_NULL_HULL_FEATURE 0xFF | #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  | // Used to map pointers to indices  | ||||||
| // If more performance is required then a use hash-map | // If more performance is required then a use hash-map | ||||||
| template<class T, u32 N> | template<class T, u32 N> | ||||||
| @@ -142,13 +138,13 @@ static b3Vec3 b3ComputeCentroid(b3QHull* hull) | |||||||
| 	return centroid; | 	return centroid; | ||||||
| } | } | ||||||
|  |  | ||||||
| void b3QHull::Set(const b3Vec3* points, u32 count) | void b3QHull::Set(const b3Vec3* points, u32 count, bool simplify) | ||||||
| { | { | ||||||
| 	B3_ASSERT(count >= 4); | 	B3_ASSERT(count >= 4); | ||||||
|  |  | ||||||
| 	// Copy points into local buffer, perform welding. | 	// Copy points into local buffer, perform welding. | ||||||
| 	u32 psCount = 0; | 	u32 psCount = 0; | ||||||
| 	b3Vec3* ps = (b3Vec3*) b3Alloc(count * sizeof(b3Vec3)); | 	b3Vec3* ps = (b3Vec3*)b3Alloc(count * sizeof(b3Vec3)); | ||||||
| 	for (u32 i = 0; i < count; ++i) | 	for (u32 i = 0; i < count; ++i) | ||||||
| 	{ | 	{ | ||||||
| 		b3Vec3 p = points[i]; | 		b3Vec3 p = points[i]; | ||||||
| @@ -178,9 +174,10 @@ void b3QHull::Set(const b3Vec3* points, u32 count) | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Create a convex hull. | 	// Create a convex hull. | ||||||
|  | 	qhHull hull; | ||||||
|  |  | ||||||
| #if B3_SIMPLIFY_HULL == 1 | 	if (simplify == true) | ||||||
| 	 | 	{ | ||||||
| 		qhHull primary; | 		qhHull primary; | ||||||
| 		primary.Construct(ps, psCount); | 		primary.Construct(ps, psCount); | ||||||
| 		b3Free(ps); | 		b3Free(ps); | ||||||
| @@ -286,20 +283,17 @@ void b3QHull::Set(const b3Vec3* points, u32 count) | |||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 	qhHull hull; |  | ||||||
| 		hull.Construct(pvs, pvCount); | 		hull.Construct(pvs, pvCount); | ||||||
| 		b3Free(pvs); | 		b3Free(pvs); | ||||||
|  |  | ||||||
| 		// Translate the hull back to the origin | 		// Translate the hull back to the origin | ||||||
| 		hull.Translate(s); | 		hull.Translate(s); | ||||||
|  | 	} | ||||||
| #else | 	else | ||||||
| 	 | 	{ | ||||||
| 	qhHull hull; |  | ||||||
| 		hull.Construct(ps, psCount); | 		hull.Construct(ps, psCount); | ||||||
| 		b3Free(ps); | 		b3Free(ps); | ||||||
|  | 	} | ||||||
| #endif |  | ||||||
|  |  | ||||||
| 	if (hull.GetVertexList().count > B3_MAX_HULL_VERTICES) | 	if (hull.GetVertexList().count > B3_MAX_HULL_VERTICES) | ||||||
| 	{ | 	{ | ||||||
| @@ -464,7 +458,7 @@ void b3QHull::SetAsCylinder(float32 radius, float32 height) | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Set | 	// Set | ||||||
| 	Set(vs, count); | 	Set(vs, count, false); | ||||||
| } | } | ||||||
|  |  | ||||||
| void b3QHull::SetAsCone(float32 radius, float32 height) | 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); | 	vs[count++].Set(0.0f, height, 0.0f); | ||||||
|  |  | ||||||
| 	// Set | 	// Set | ||||||
| 	Set(vs, count); | 	Set(vs, count, false); | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user