sphereSphere method

bool sphereSphere(
  1. Sphere si,
  2. Sphere sj,
  3. Vec3 xi,
  4. Vec3 xj,
  5. Quaternion qi,
  6. Quaternion qj,
  7. Body bi,
  8. Body bj, [
  9. Shape? rsi,
  10. Shape? rsj,
  11. bool justTest = false,
])

Implementation

bool sphereSphere(
  Sphere si,
  Sphere sj,
  Vec3 xi,
  Vec3 xj,
  Quaternion qi,
  Quaternion qj,
  Body bi,
  Body bj,
  [
    Shape? rsi,
    Shape? rsj,
    bool justTest = false
]){
  if (justTest) {
    return xi.distanceSquared(xj) < math.pow((si.radius + sj.radius),2);
  }

  // We will have only one contact in this case
  final contactEq = createContactEquation(bi, bj, si, sj, rsi, rsj);

  // Contact normal
  xj.vsub(xi, contactEq.ni);
  contactEq.ni.normalize();

  // Contact point locations
  contactEq.ri.copy(contactEq.ni);
  contactEq.rj.copy(contactEq.ni);
  contactEq.ri.scale(si.radius, contactEq.ri);
  contactEq.rj.scale(-sj.radius, contactEq.rj);

  contactEq.ri.vadd(xi, contactEq.ri);
  contactEq.ri.vsub(bi.position, contactEq.ri);

  contactEq.rj.vadd(xj, contactEq.rj);
  contactEq.rj.vsub(bj.position, contactEq.rj);

  result.add(contactEq);

  createFrictionEquationsFromContact(contactEq, frictionResult);

  return false;
}