Friction center weighted average (#71)
The central friction anchors now have C0 continuity by using a weighted average. Reduces jitter while letting the spinning top function correctly. Fixes #65
This commit is contained in:
parent
e9f6f1d0aa
commit
e961bfb7bf
21 changed files with 136 additions and 102 deletions
|
|
@ -188,7 +188,7 @@ static int CompoundMaterialDistinct( void )
|
|||
|
||||
static int CompoundMaterialCrossShape( void )
|
||||
{
|
||||
// One material shared across capsule, hull, and sphere → 1 material slot.
|
||||
// One material shared across capsule, hull, and sphere -> 1 material slot.
|
||||
b3SurfaceMaterial mat = MakeMaterial( 0.5f, 99 );
|
||||
|
||||
b3CompoundCapsuleDef cap = { .capsule = { { 0, 0, 0 }, { 1, 0, 0 }, 0.25f }, .material = mat };
|
||||
|
|
@ -422,14 +422,14 @@ static int CompoundChildDispatch( void )
|
|||
};
|
||||
b3CompoundData* c = b3CreateCompound( &def );
|
||||
|
||||
// Index ordering is capsules → hulls → meshes → spheres.
|
||||
// Index ordering is capsules -> hulls -> meshes -> spheres.
|
||||
ENSURE( b3GetCompoundChild( c, 0 ).type == b3_capsuleShape );
|
||||
ENSURE( b3GetCompoundChild( c, 1 ).type == b3_capsuleShape );
|
||||
ENSURE( b3GetCompoundChild( c, 2 ).type == b3_hullShape );
|
||||
ENSURE( b3GetCompoundChild( c, 3 ).type == b3_meshShape );
|
||||
ENSURE( b3GetCompoundChild( c, 4 ).type == b3_sphereShape );
|
||||
|
||||
// Capsule and sphere children always report identity transform — the position
|
||||
// Capsule and sphere children always report identity transform. The position
|
||||
// is encoded in the shape itself (capsule->center{1,2}, sphere->center).
|
||||
b3ChildShape cap0 = b3GetCompoundChild( c, 0 );
|
||||
ENSURE_SMALL( cap0.transform.p.x, FLT_EPSILON );
|
||||
|
|
@ -514,7 +514,7 @@ static int CompoundRayCastClosest( void )
|
|||
b3CastOutput out = b3RayCastCompound( c, &input );
|
||||
ENSURE( out.hit == true );
|
||||
|
||||
// Front face of the nearer sphere is at x=4 → fraction 4/20 = 0.2.
|
||||
// Front face of the nearer sphere is at x=4 -> fraction 4/20 = 0.2.
|
||||
ENSURE_SMALL( out.fraction - 0.2f, 1e-4f );
|
||||
ENSURE_SMALL( out.normal.x + 1.0f, 1e-4f );
|
||||
ENSURE( out.childIndex == 0 );
|
||||
|
|
@ -528,7 +528,7 @@ static int CompoundRayCastClosest( void )
|
|||
|
||||
static int CompoundRayCastHullNormalRotation( void )
|
||||
{
|
||||
// A unit box rotated 90° about Z, placed at compound +X. The ray hits the
|
||||
// A unit box rotated 90 degrees about Z, placed at compound +X. The ray hits the
|
||||
// face that, in compound space, points back toward -X. Verifies that the
|
||||
// normal returned by the cast has been rotated from hull-local space back
|
||||
// into compound space.
|
||||
|
|
@ -575,7 +575,7 @@ static int CompoundShapeCastClosest( void )
|
|||
};
|
||||
b3CastOutput out = b3ShapeCastCompound( c, &input );
|
||||
ENSURE( out.hit == true );
|
||||
// Closest contact: caster radius 0.25 + sphere radius 1.0 → first contact at x ≈ 3.75.
|
||||
// Closest contact: caster radius 0.25 + sphere radius 1.0 -> first contact at x ~= 3.75.
|
||||
ENSURE_SMALL( out.fraction - 3.75f / 20.0f, 1e-3f );
|
||||
ENSURE( out.childIndex == 0 );
|
||||
|
||||
|
|
@ -640,7 +640,7 @@ static int CompoundQuery( void )
|
|||
b3CompoundDef def = { .spheres = spheres, .sphereCount = 3 };
|
||||
b3CompoundData* c = b3CreateCompound( &def );
|
||||
|
||||
// Tight box around the middle sphere — only it should be reported.
|
||||
// Tight box around the middle sphere. Only it should be reported.
|
||||
b3AABB middle = { { -1, -1, -1 }, { 1, 1, 1 } };
|
||||
struct QueryAccumulator acc = { .stopAfter = -1 };
|
||||
b3QueryCompound( c, middle, QueryCallback, &acc );
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@
|
|||
// Double precision accumulates body positions in double, so the settle/sleep step and the
|
||||
// state hash differ from the float build. Both modes are internally deterministic.
|
||||
#if defined( BOX3D_DOUBLE_PRECISION )
|
||||
#define EXPECTED_SLEEP_STEP 301
|
||||
#define EXPECTED_HASH 0xE4844A97
|
||||
#define EXPECTED_SLEEP_STEP 297
|
||||
#define EXPECTED_HASH 0x27FF38C1
|
||||
#else
|
||||
#define EXPECTED_SLEEP_STEP 269
|
||||
#define EXPECTED_HASH 0x50313037
|
||||
#define EXPECTED_SLEEP_STEP 308
|
||||
#define EXPECTED_HASH 0x1E5EDD79
|
||||
#endif
|
||||
|
||||
static int SingleMultithreadingTest( int workerCount )
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ static int RayCastFlatField( void )
|
|||
|
||||
b3HeightFieldData* hf = b3CreateHeightField( &def );
|
||||
|
||||
// Origin sits clearly inside triangle 0 of cell (1, 1) — off the cell
|
||||
// Origin sits clearly inside triangle 0 of cell (1, 1). Off the cell
|
||||
// diagonal x+z = 3. The translation overshoots the surface so the hit
|
||||
// fraction is strictly less than maxFraction.
|
||||
b3RayCastInput input = { 0 };
|
||||
|
|
@ -168,13 +168,13 @@ static int OverlapAtSurface( void )
|
|||
b3Vec3 scale = { 1.0f, 1.0f, 1.0f };
|
||||
b3HeightFieldData* hf = b3CreateGrid( 4, 4, scale, false );
|
||||
|
||||
// Sphere center 1.0 above the surface, radius 0.5 — clear gap.
|
||||
// Sphere center 1.0 above the surface, radius 0.5. Clear gap.
|
||||
b3Vec3 above = { 1.5f, 1.0f, 1.5f };
|
||||
b3ShapeProxy proxyAbove = { &above, 1, 0.5f };
|
||||
bool hitAbove = b3OverlapHeightField( hf, b3Transform_identity, &proxyAbove );
|
||||
ENSURE( hitAbove == false );
|
||||
|
||||
// Sphere centered on the surface — radius pokes through.
|
||||
// Sphere centered on the surface. Radius pokes through.
|
||||
b3Vec3 through = { 1.5f, 0.0f, 1.5f };
|
||||
b3ShapeProxy proxyThrough = { &through, 1, 0.5f };
|
||||
bool hitThrough = b3OverlapHeightField( hf, b3Transform_identity, &proxyThrough );
|
||||
|
|
@ -431,7 +431,7 @@ static int ShapeCastBruteForce( void )
|
|||
// Brute-force ray cast: cast the ray against every (non-hole) triangle and keep
|
||||
// the closest hit. b3GetHeightFieldTriangle returns vertices in the same winding
|
||||
// order that b3ShapeCastHeightField feeds to b3IntersectRayTriangle, so this is a
|
||||
// pure traversal/culling check — the per-triangle math is identical.
|
||||
// pure traversal/culling check. The per-triangle math is identical.
|
||||
static b3CastOutput BruteForceRayCast( const b3HeightFieldData* hf, const b3RayCastInput* input )
|
||||
{
|
||||
b3CastOutput best = { 0 };
|
||||
|
|
|
|||
Loading…
Reference in a new issue