convexConvex method

bool convexConvex(
  1. ConvexPolyhedron si,
  2. ConvexPolyhedron sj,
  3. Vector3 xi,
  4. Vector3 xj,
  5. Quaternion qi,
  6. Quaternion qj,
  7. Body bi,
  8. Body bj, [
  9. Shape? rsi,
  10. Shape? rsj,
  11. bool justTest = false,
  12. List<int>? faceListA,
  13. List<int>? faceListB,
])

Implementation

bool convexConvex(
  ConvexPolyhedron si,
  ConvexPolyhedron sj,
  Vector3 xi,
  Vector3 xj,
  Quaternion qi,
  Quaternion qj,
  Body bi,
  Body bj,
  [
    Shape? rsi,
    Shape? rsj,
    bool justTest = false,
    List<int>? faceListA,
    List<int>? faceListB
]){
  final sepAxis = _convexConvexSepAxis;

  if (xi.distanceTo(xj) > si.boundingSphereRadius + sj.boundingSphereRadius) {
    return false;
  }

  if (si.findSeparatingAxis(sj, xi, qi, xj, qj, sepAxis, faceListA, faceListB)) {
    final List<ConvexPolyhedronContactPoint> res = [];
    final q = _convexConvexQ;
    si.clipAgainstHull(xi, qi, sj, xj, qj, sepAxis, -100, 100, res);
    int numContacts = 0;
    for (int j = 0; j != res.length; j++) {
      if (justTest) {
        return true;
      }
      final r = createContactEquation(bi, bj, si, sj, rsi, rsj);
      final ri = r.ri;
      final rj = r.rj;
      r.ni..setFrom(sepAxis)..negate();
      q..setFrom(res[j].normal)..negate();
      q.scale2(res[j].depth, q);
      res[j].point.add2(q, ri);
      rj.setFrom(res[j].point);

      // Contact points are in world coordinates. Transform back to relative
      ri.sub2(xi, ri);
      rj.sub2(xj, rj);

      // Make relative to bodies
      ri.add2(xi, ri);
      ri.sub2(bi.position, ri);
      rj.add2(xj, rj);
      rj.sub2(bj.position, rj);

      result.add(r);
      numContacts++;
      if (!enableFrictionReduction) {
        createFrictionEquationsFromContact(r, frictionResult);
      }
    }
    if (enableFrictionReduction && numContacts != 0) {
      createFrictionFromAverage(numContacts);
    }
  }

  return false;
}