createContactEquation method

ContactEquation createContactEquation(
  1. Body bi,
  2. Body bj,
  3. Shape si,
  4. Shape sj, [
  5. Shape? overrideShapeA,
  6. Shape? overrideShapeB,
])

Make a contact object, by using the internal pool or creating a one.

Implementation

ContactEquation createContactEquation(
  Body bi,
  Body bj,
  Shape si,
  Shape sj,
  [
    Shape? overrideShapeA,
    Shape? overrideShapeB
]){
  ContactEquation c;
  if (contactPointPool.isNotEmpty) {
    c = contactPointPool.removeLast();
    c.bi = bi;
    c.bj = bj;
  } else {
    c = ContactEquation(bi, bj);
  }

  c.enabled = bi.collisionResponse && bj.collisionResponse && si.collisionResponse && sj.collisionResponse;

  final cm = currentContactMaterial;

  c.restitution = cm.restitution;

  c.setSpookParams(cm.contactEquationStiffness, cm.contactEquationRelaxation, world.dt);

  final matA = si.material ?? bi.material;
  final matB = sj.material ?? bj.material;
  if (matA != null && matB != null && matA.restitution >= 0 && matB.restitution >= 0) {
    c.restitution = matA.restitution * matB.restitution;
  }

  c.si = overrideShapeA ?? si;
  c.sj = overrideShapeB ?? sj;

  return c;
}