calcRollingFriction method

double calcRollingFriction(
  1. Body body0,
  2. Body body1,
  3. Vec3 frictionPosWorld,
  4. Vec3 frictionDirectionWorld,
  5. double maxImpulse,
)

Implementation

double calcRollingFriction(
  Body body0,
  Body body1,
  Vec3 frictionPosWorld,
  Vec3 frictionDirectionWorld,
  double maxImpulse,
){
  double j1 = 0;
  final contactPosWorld = frictionPosWorld;

  // final rel_pos1 = Vec3();
  // final rel_pos2 = Vec3();
  final vel1 = _calcRollingFrictionVel1;
  final vel2 = _calcRollingFrictionVel2;
  final vel = _calcRollingFrictionVel;
  // contactPosWorld.vsub(body0.position, rel_pos1);
  // contactPosWorld.vsub(body1.position, rel_pos2);

  body0.getVelocityAtWorldPoint(contactPosWorld, vel1);
  body1.getVelocityAtWorldPoint(contactPosWorld, vel2);
  vel1.vsub(vel2, vel);

  final vrel = frictionDirectionWorld.dot(vel);

  final denom0 = computeImpulseDenominator(body0, frictionPosWorld, frictionDirectionWorld);
  final denom1 = computeImpulseDenominator(body1, frictionPosWorld, frictionDirectionWorld);
  const relaxation = 1;
  final jacDiagABInv = relaxation / (denom0 + denom1);

  // calculate j that moves us to zero relative velocity
  j1 = -vrel * jacDiagABInv;

  if (maxImpulse < j1) {
    j1 = maxImpulse;
  }
  if (j1 < -maxImpulse) {
    j1 = -maxImpulse;
  }

  return j1;
}