- Added b3BodyDef::safetyFactor for CCD tuning
- #155
- #153
- #148 
- #149
This commit is contained in:
Erin Catto 2026-09-16 15:46:31 -07:00 • committed by GitHub
commit 954cf879e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
46 changed files with 1944 additions and 318 deletions

View file

@ -171,6 +171,10 @@ B3_API b3Version b3GetVersion( void );
/// @return true if the library was built with BOX3D_DOUBLE_PRECISION (large world mode)
B3_API bool b3IsDoublePrecision( void );
/// @return the value of B3_MAX_MANIFOLD_POINTS the library was compiled with. Useful for
/// an ABI test.
B3_API int b3GetMaxManifoldPoints( void );
/**@}*/
//! @cond

View file

@ -691,6 +691,12 @@ B3_API void b3Body_SetSleepThreshold( b3BodyId bodyId, float sleepThreshold );
/// Get the sleep threshold, usually in meters per second.
B3_API float b3Body_GetSleepThreshold( b3BodyId bodyId );
/// Set the continuous collision safety factor. Smaller is safer but can lead to hitching. Recommended range [0.01, 0.5]. Non-dimensional.
B3_API void b3Body_SetSafetyFactor( b3BodyId bodyId, float safetyFactor );
/// Get the continuous collision safety factor. Non-dimensional.
B3_API float b3Body_GetSafetyFactor( b3BodyId bodyId );
/// Returns true if this body is enabled
B3_API bool b3Body_IsEnabled( b3BodyId bodyId );

View file

@ -221,7 +221,8 @@ B3_API b3HullData* b3CreateCone( float height, float radius1, float radius2, int
/// Create a rock shaped hull.
B3_API b3HullData* b3CreateRock( float radius );
/// Create a generic convex hull.
/// Create a generic convex hull. This can fail if B3_MAX_HULL_VERTICES, B3_MAX_HULL_FACES,
/// or B3_MAX_HULL_EDGES is exceeded.
B3_API b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCount );
/// Deep clone a hull.
@ -647,6 +648,21 @@ B3_API void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b
B3_API void b3CollideTriangleAndSphere( b3LocalManifold* manifold, int capacity, const b3Vec3* triangleA,
const b3Sphere* sphereB );
/// This is used for computing 2D hulls in service of contact manifold simplification.
/// Placed here for testing. Internal.
typedef struct b3Point2D
{
b3Vec2 p; // 2D point
float separation; // separation of the associated contact point
int originalIndex; // original index of the associated contact point
} b3Point2D;
/// Compute a 2D hull. Used internally for contact manifold simplification. Here for testing.
B3_API int b3Hull2D( b3Point2D* pts, int count, b3Point2D* hull );
/// Simplify a 2D hull. Used internally for contact manifold simplification. Here for testing.
B3_API int b3SimplifyHull2D( b3Point2D* hull, int count, int target );
/**@}*/ // collision
/**

View file

@ -76,7 +76,9 @@ B3_API float b3GetStallThreshold( void );
#define B3_MAX_ROTATION ( 0.25f * B3_PI )
/// @warning modifying this can have a significant impact on performance and stability
#ifndef B3_SPECULATIVE_DISTANCE
#define B3_SPECULATIVE_DISTANCE ( 4.0f * B3_LINEAR_SLOP )
#endif
/// The rest offset is used for mesh contact to reduce ghost collisions and assist with CCD.
/// The rest offset adjusts the contact point separation value, making the solver push the shapes
@ -104,7 +106,14 @@ B3_API float b3GetStallThreshold( void );
#define B3_TIME_TO_SLEEP 0.5f
/// The maximum number of contact points between two touching shapes.
/// The default and minimum is 4 and this case uses a fast approximate hull to reduce the
/// point count. A larger value builds a 2D convex hull of the candidate points and then
/// simplifies it to the target by dropping the vertices that contribute the least area.
/// Useful for testing, but I don't recommend shipping with it adjusted.
/// WARNING: if you change this you risk breaking ABI and a corrupted runtime.
#ifndef B3_MAX_MANIFOLD_POINTS
#define B3_MAX_MANIFOLD_POINTS 4
#endif
/// The number of iterations for gyroscopic torques.
#ifndef B3_GYROSCOPIC_ITERATIONS

View file

@ -303,6 +303,13 @@ typedef struct b3BodyDef
/// Sleep speed threshold, default is 0.05 meters per second
float sleepThreshold;
/// Continuous collision safety factor. The solver only uses continuous collision if there is a
/// risk of tunneling. If the body is moving fast enough to risk tunneling then it is considered a "fast body".
/// This improves performance and prevents movement hitches. If a body moving N meter risks tunneling, then the
/// body will be considered fast if it moves more than a safetyFactor times N meters over one full time step.
/// Non-dimensional. Recommended range [0.01, 0.5]. Default is 0.5 for high performance with low tunneling risk.
float safetyFactor;
/// Optional body name for debugging.
const char* name;
@ -1940,8 +1947,7 @@ typedef struct b3Sphere
* @{
*/
/// A solid capsule can be viewed as two hemispheres connected
/// by a rectangle.
/// A solid capsule can be viewed as two hemispheres connected by a cylinder.
typedef struct b3Capsule
{
/// Local center of the first hemisphere