I have been toying arround a physics engine with SAT collision detection.
Now, the collision detection part, works pretty good, but I am having some issues generating the manifold, and choosing a reference face: parallel faces.
Right now, I am using SAT collision detection with support points, as described by Dirk Gregorius on his GDC talk; but for the next step, is usually choosing the axis of least penetrarion as the collision normal; I found that the selected face is not always the contact face, since a mesh may have parallel faces, that share that same normal.
Since the choosing of a incident face, as far as I can tell is not hindered by this, the simplest solution is to clip the indicent faces with the whole reference collider, but that seems a bit overkill for this situations; and I am a bit stumped by this.
Does anyone know a solution for this kind of problem?
Here is my implementation of the Face to Face collision detection:
inline bool test_face_face_collision(const sColliderMesh &mesh1,
const sColliderMesh &mesh2,
uint32_t *face_collision_index,
float *collision_distance) {
float largest_distance = -FLT_MAX;
uint32_t face_index = 0;
for(uint32_t i = 0; i < mesh1.face_count; i++) {
sPlane face_plane = mesh1.get_plane_of_face(i);
sVector3 support_mesh2 = mesh2.get_support(face_plane.normal.invert());
float distance = face_plane.distance(support_mesh2);
if (largest_distance < distance) {
face_index = i;
largest_distance = distance;
}
}
*face_collision_index = face_index;
*collision_distance = largest_distance;
return (largest_distance <= 0.0f);
}