correction = correction * 0.9;
//correction=correction>0?0:correction;
// the normal constraint
final NCPConstraint c = new NCPConstraint();
c.assign(b1,b2,
nB1, nB2, nB3, nB4,
nJ1, nJ2, nJ3, nJ4,
lowerNormalLimit, Double.POSITIVE_INFINITY,
null,
-(unf-uni)-correction, -correction) ;
// set distance (unused in simulator)
c.distance = cp.distance;
//normal-friction coupling
final NCPConstraint coupling = enableCoupling?c:null;
//set the correct friction setting for this contact
c.mu = cp.friction;
//first tangent
final Vector3 t2J1 = t2;
final Vector3 t2J2 = r1.cross(t2);
final Vector3 t2J3 = t2.negate();
final Vector3 t2J4 = r2.cross(t2).negate();
final Vector3 t2B1 = b1.isFixed()? new Vector3(): M1.multiply(t2J1);
final Vector3 t2B2 = b1.isFixed()? new Vector3(): I1.multiply(t2J2);
final Vector3 t2B3 = b2.isFixed()? new Vector3(): M2.multiply(t2J3);
final Vector3 t2B4 = b2.isFixed()? new Vector3(): I2.multiply(t2J4);
//then the tangential friction constraints
double ut1i = t2J1.dot(b1.state.velocity) + t2J2.dot(b1.state.omega) + t2J3.dot(b2.state.velocity) + t2J4.dot(b2.state.omega); //relativeVelocity(b1,b2,p,t2);
double ut1f = 0;
//double t2Fext = t2B1.dot(b1.state.FCm) + t2B2.dot(b1.state.tauCm) + t2B3.dot(b2.state.FCm) + t2B4.dot(b2.state.tauCm);
final NCPConstraint c2 = new NCPConstraint();
c2.assign(b1,b2,
t2B1, t2B2, t2B3, t2B4,
t2J1, t2J2, t2J3, t2J4,
-frictionBoundMagnitude, frictionBoundMagnitude,
coupling,
-(ut1f-ut1i),
0
);
//second tangent
final Vector3 t3J1 = t3;
final Vector3 t3J2 = r1.cross(t3);
final Vector3 t3J3 = t3.negate();
final Vector3 t3J4 = r2.cross(t3).negate();
final Vector3 t3B1 = b1.isFixed()? new Vector3(): M1.multiply(t3J1);
final Vector3 t3B2 = b1.isFixed()? new Vector3(): I1.multiply(t3J2);
final Vector3 t3B3 = b2.isFixed()? new Vector3(): M2.multiply(t3J3);
final Vector3 t3B4 = b2.isFixed()? new Vector3(): I2.multiply(t3J4);
double ut2i = t3J1.dot(b1.state.velocity) + t3J2.dot(b1.state.omega) + t3J3.dot(b2.state.velocity) + t3J4.dot(b2.state.omega); //relativeVelocity(b1,b2,p,t2);
double ut2f = 0;
final NCPConstraint c3 = new NCPConstraint();
c3.assign(b1,b2,
t3B1, t3B2, t3B3, t3B4,
t3J1, t3J2, t3J3, t3J4,
-frictionBoundMagnitude, frictionBoundMagnitude,
coupling,
-(ut2f-ut2i), 0