detectCollision method

  1. @override
void detectCollision(
  1. Shape shape1,
  2. Shape shape2,
  3. ContactManifold manifold
)
override

Detect collision of the shapes provided

Implementation

@override
void detectCollision(Shape shape1,Shape shape2,ContactManifold manifold){
  if(shape1 is Tetra && shape2 is Tetra){
    Vector3 pos1 = shape1.position;
    Vector3 pos2 = shape2.position;
    Vector3 vec3_1 = Vector3(pos1.x, pos1.y, pos1.z);
    Vector3 vec3_2 = Vector3(pos2.x, pos2.y, pos2.z);
    Vector3? intersect;

    // Yes, it is a brute force approach but it works for now...
    for(int i = 0; i < shape2.faces.length; i++){
      intersect = triangleIntersect(vec3_1, vec3_2, shape2.faces[i], false);//vec3_1.angleTo(vec3_2)

      if(intersect != null){
        manifold.addPointVec(Vector3(intersect.x, intersect.y, intersect.z));
      }
    }
  }
}