Compare commits

...
Sign in to create a new pull request.
Author SHA1 Message Date
Meta Vens
6cfeeff232 Static assert RELAX_ITERATIONS == 1 beside stepNormalImpulse
stepNormalImpulse sums the impulse applied after each relax pass, which is
the step impulse only with one relax iteration. Also indents two stray
column-0 lines of the previous commit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 02:48:16 +01:00
Meta Vens
e421ffaf88 Contact points report the normal impulse applied over the whole step
Adds b3ManifoldPoint.stepNormalImpulse: the impulse each sub-step applied
(accumulated after the relax pass, plus restitution's delta), summed over the
step, in the scalar and SIMD solver paths. Exact only while RELAX_ITERATIONS
is 1. GameCult fork for Ymir (lodur:ruling:ymir-box3d-fork); upstream is
erincatto/box3d.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 02:22:49 +01:00
4 changed files with 18 additions and 0 deletions

View file

@ -2576,6 +2576,9 @@ typedef struct b3ManifoldPoint
/// to identify speculative contact points that had an interaction in the time step.
float totalNormalImpulse;
/// Sum over sub-steps of the impulse each sub-step applied, plus restitution: the step impulse.
float stepNormalImpulse;
/// Relative normal velocity pre-solve. Used for hit events. If the normal impulse is
/// zero then there was no hit. Negative means shapes are approaching.
float normalVelocity;

View file

@ -196,6 +196,7 @@ void b3PrepareContacts_Mesh( b3SolverBlock block, b3StepContext* context )
cp->baseSeparation = mp->separation - b3Dot( b3Sub( cp->rB, cp->rA ), normal );
cp->normalImpulse = warmStartScale * mp->normalImpulse;
cp->totalNormalImpulse = 0.0f;
cp->stepNormalImpulse = 0.0f;
b3Vec3 rA = cp->rA;
b3Vec3 rB = cp->rB;
@ -456,6 +457,7 @@ void b3SolveContacts_Mesh( b3SolverBlock block, b3StepContext* context, bool use
deltaImpulse = newImpulse - cp->normalImpulse;
cp->normalImpulse = newImpulse;
cp->totalNormalImpulse += newImpulse;
if ( useBias == false ) cp->stepNormalImpulse += newImpulse;
totalNormalImpulse += newImpulse;
totalTwistLimit += cp->leverArm * cp->normalImpulse;
@ -650,6 +652,7 @@ void b3ApplyRestitution_Mesh( b3SolverBlock block, b3StepContext* context )
impulse = newImpulse - cp->normalImpulse;
cp->normalImpulse = newImpulse;
cp->totalNormalImpulse += impulse;
cp->stepNormalImpulse += impulse;
// apply contact impulse
b3Vec3 P = b3MulSV( impulse, normal );
@ -754,6 +757,7 @@ void b3StoreImpulses_Mesh( b3SolverBlock block, b3StepContext* context, int work
b3ManifoldPoint* mp = manifold->points + pointIndex;
mp->normalImpulse = cp->normalImpulse;
mp->totalNormalImpulse = cp->totalNormalImpulse;
mp->stepNormalImpulse = cp->stepNormalImpulse;
mp->normalVelocity = cp->relativeVelocity;
if ( checkHitEvents && flagged == false &&
@ -1330,6 +1334,7 @@ typedef struct b3ContactConstraintPointWide
b3FloatW baseSeparations;
b3FloatW normalImpulses;
b3FloatW totalNormalImpulses;
b3FloatW stepNormalImpulses;
b3FloatW normalMasses;
b3FloatW leverArms;
b3FloatW relativeVelocities;
@ -1805,6 +1810,7 @@ void b3PrepareContacts_Convex( b3SolverBlock block, b3StepContext* context )
( (float*)&cp->normalImpulses )[lane] = warmStartScale * mp->normalImpulse;
( (float*)&cp->totalNormalImpulses )[lane] = 0.0f;
( (float*)&cp->stepNormalImpulses )[lane] = 0.0f;
b3Vec3 rnA = b3Cross( rA, normal );
b3Vec3 rnB = b3Cross( rB, normal );
@ -1892,6 +1898,7 @@ void b3PrepareContacts_Convex( b3SolverBlock block, b3StepContext* context )
( (float*)&cp->baseSeparations )[lane] = 0.0f;
( (float*)&cp->normalImpulses )[lane] = 0.0f;
( (float*)&cp->totalNormalImpulses )[lane] = 0.0f;
( (float*)&cp->stepNormalImpulses )[lane] = 0.0f;
( (float*)&cp->normalMasses )[lane] = 0.0f;
( (float*)&cp->relativeVelocities )[lane] = 0.0f;
( (float*)&cp->leverArms )[lane] = 0.0f;
@ -2051,6 +2058,7 @@ void b3SolveContacts_Convex( b3SolverBlock block, b3StepContext* context, bool u
b3FloatW deltaImpulse = b3SubW( newImpulse, cp->normalImpulses );
cp->normalImpulses = newImpulse;
cp->totalNormalImpulses = b3AddW( cp->totalNormalImpulses, newImpulse );
if ( useBias == false ) cp->stepNormalImpulses = b3AddW( cp->stepNormalImpulses, newImpulse );
totalNormalImpulse = b3AddW( totalNormalImpulse, newImpulse );
totalTwistLimit = b3AddW( totalTwistLimit, b3MulW( cp->leverArms, newImpulse ) );
@ -2232,6 +2240,7 @@ void b3ApplyRestitution_Convex( b3SolverBlock block, b3StepContext* context )
b3FloatW deltaImpulse = b3SubW( newImpulse, cp->normalImpulses );
cp->normalImpulses = newImpulse;
cp->totalNormalImpulses = b3AddW( cp->totalNormalImpulses, deltaImpulse );
cp->stepNormalImpulses = b3AddW( cp->stepNormalImpulses, deltaImpulse );
// Apply contact impulse
b3Vec3W P = b3MulSVW( deltaImpulse, c->normal );
@ -2335,6 +2344,7 @@ void b3StoreImpulses_Convex( b3SolverBlock block, b3StepContext* context, int wo
b3ManifoldPoint* mp = m->points + pointIndex;
mp->normalImpulse = normalImpulse[lane];
mp->totalNormalImpulse = totalNormalImpulse[lane];
mp->stepNormalImpulse = ((const float*)&cp->stepNormalImpulses)[lane];
mp->normalVelocity = normalVelocity[lane];
}

View file

@ -13,6 +13,7 @@ typedef struct b3ManifoldConstraintPoint
float relativeVelocity;
float normalImpulse;
float totalNormalImpulse;
float stepNormalImpulse;
float normalMass;
float leverArm;
} b3ManifoldConstraintPoint;

View file

@ -28,6 +28,10 @@
#define ITERATIONS 1
#define RELAX_ITERATIONS 1
// stepNormalImpulse (contact_solver.c) sums the impulse applied after each relax pass; it is the step
// impulse only with one relax pass per sub-step
_Static_assert( RELAX_ITERATIONS == 1, "stepNormalImpulse is exact only with one relax iteration" );
#if ( defined( __GNUC__ ) || defined( __clang__ ) ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
static void b3Pause( void )
{