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:
Erin Catto 2026-07-11 23:26:31 -07:00 • committed by GitHub
commit e961bfb7bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 136 additions and 102 deletions

View file

@ -118,33 +118,33 @@ static void b3IntegrateVelocitiesTask( b3SolverBlock block, b3StepContext* conte
b3Vec3 omega2 = omega1;
// Symmetric inertia tensor: 6 unique entries (column-major)
const float i00 = inertiaLocal.cx.x;
const float i01 = inertiaLocal.cy.x;
const float i02 = inertiaLocal.cz.x;
const float i11 = inertiaLocal.cy.y;
const float i12 = inertiaLocal.cz.y;
const float i22 = inertiaLocal.cz.z;
float i00 = inertiaLocal.cx.x;
float i01 = inertiaLocal.cy.x;
float i02 = inertiaLocal.cz.x;
float i11 = inertiaLocal.cy.y;
float i12 = inertiaLocal.cz.y;
float i22 = inertiaLocal.cz.z;
for ( int gyroIteration = 0; gyroIteration < 1; ++gyroIteration )
{
const float w1 = omega2.x;
const float w2 = omega2.y;
const float w3 = omega2.z;
float w1 = omega2.x;
float w2 = omega2.y;
float w3 = omega2.z;
// Iw = I * omega2 (shared between residual and Jacobian)
const float Iw1 = i00 * w1 + i01 * w2 + i02 * w3;
const float Iw2 = i01 * w1 + i11 * w2 + i12 * w3;
const float Iw3 = i02 * w1 + i12 * w2 + i22 * w3;
float Iw1 = i00 * w1 + i01 * w2 + i02 * w3;
float Iw2 = i01 * w1 + i11 * w2 + i12 * w3;
float Iw3 = i02 * w1 + i12 * w2 + i22 * w3;
// Residual: b = I*(omega2 - omega1) + h * (omega2 × I*omega2)
const b3Vec3 dw = b3Sub( omega2, omega1 );
// Residual: b = I * (omega2 - omega1) + h * cross(omega2, I * omega2)
b3Vec3 dw = b3Sub( omega2, omega1 );
b3Vec3 b = {
i00 * dw.x + i01 * dw.y + i02 * dw.z + h * ( w2 * Iw3 - w3 * Iw2 ),
i01 * dw.x + i11 * dw.y + i12 * dw.z + h * ( w3 * Iw1 - w1 * Iw3 ),
i02 * dw.x + i12 * dw.y + i22 * dw.z + h * ( w1 * Iw2 - w2 * Iw1 ),
};
// Jacobian J = I + h * (skew(omega2) * I - skew(I*omega2))
// Jacobian J = I + h * (skew(omega2) * I - skew(I * omega2))
// Jacobian derived by Erin Catto, Ph.D. Do not attempt to do this without a Ph.D.
// Doubled inertia terms above fold into Iw, e.g. row 2 col 1: i00*w3 - i02*w1 - Iw3.
b3Matrix3 J = {