planeConvex method

bool planeConvex(
  1. Plane si,
  2. ConvexPolyhedron 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 planeConvex(
  Plane si,
  ConvexPolyhedron sj,
  Vec3 xi,
  Vec3 xj,
  Quaternion qi,
  Quaternion qj,
  Body bi,
  Body bj,
  [
    Shape? rsi,
    Shape? rsj,
    bool justTest = false
]){
  // Simply return the points behind the plane.
  final worldVertex = _planeConvexV;

  final worldNormal = _planeConvexNormal;
  worldNormal.set(0, 0, 1);
  qi.vmult(worldNormal, worldNormal) ;// Turn normal according to plane orientation

  int numContacts = 0;
  final relpos = _planeConvexRelpos;
  for (int i = 0; i != sj.vertices.length; i++) {
    // Get world convex vertex
    worldVertex.copy(sj.vertices[i]);
    qj.vmult(worldVertex, worldVertex);
    xj.vadd(worldVertex, worldVertex);
    worldVertex.vsub(xi, relpos);

    final dot = worldNormal.dot(relpos);
    if (dot <= 0.0) {
      if (justTest) {
        return true;
      }

      final r = createContactEquation(bi, bj, si, sj, rsi, rsj);

      // Get vertex position projected on plane
      final projected = _planeConvexProjected;
      worldNormal.scale(worldNormal.dot(relpos), projected);
      worldVertex.vsub(projected, projected);
      projected.vsub(xi, r.ri); // From plane to vertex projected on plane

      r.ni.copy(worldNormal) ;// Contact normal is the plane normal out from plane

      // rj is now just the vector from the convex center to the vertex
      worldVertex.vsub(xj, r.rj);

      // Make it relative to the body
      r.ri.vadd(xi, r.ri);
      r.ri.vsub(bi.position, r.ri);
      r.rj.vadd(xj, r.rj);
      r.rj.vsub(bj.position, r.rj);

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

  if (enableFrictionReduction && numContacts != 0) {
    createFrictionFromAverage(numContacts);
  }

  return false;
}