I've been implementing the SAT based on:
On page 7, in the table, it refers the 15 axis to test so we can find a collision, but with just Ax, Ay and Az, I'm already getting collisions.
Why do i need to test all the other cases? Is there any situation where just Ax, Ay and Az are not enough?
Answer
You may be geting false positives. Collisions detected but not really colliding.
The number 15 comes from
- 3 axes from object A (face normals)
- 3 axes from object B (face normals)
- 9 axes from all the pairs of edges of A and edges of B (3x3)
- =15 in total
The 9 axes are made up of cross products of edges of A and edges of B
- Ae1 x Be1 (Edge 1 of A cross edge 1 of B)
- Ae1 x Be2
- Ae1 x Be3
- Ae2 x Be1
- ... and so on
The first 6 axes (from the face normals) are used to check if there a corner of one object is intersecting a face of the other object. (or more correctly to eliminate these kinds of collisions)
The set of 9 axes formed by the cross products of edges are used to consider edge on edge collision detection, where there is not a vertex penetrating the other object. Like the 'almost' collision in the photo below. Lets assume for the rest of this answer that the two boxes in the picture are not actually colliding, but are separated by a tiny distance.
Lets look at what happens if we just use the 6 face normals for SAT. The first image below shows one axis from the blue box and 2 axes from the yellow box. If we project both objects on to these axes, we will get an overlap on all three. The second image below shows the remaining two axes of the blue box and the remaining axis of the yellow box. Again projecting on these axes will show overlaps on all 3.
So just only checking the 6 face normals will show overlaps on all 6 axes, which, according to the SAT, means that the objects are colliding, because we have not been able to find a separation. But of course, these object are not colliding. The reason we have not found a separation is because we have not looked hard enough!
So how are we to find this gap? The image below show an axis on which projection of both objects will reveal a separation.
Where do we get this axis from?
If you imagine sliding a piece of stiff card into the gap, that card will be part of the separating plane. If we project on to the normal of that plane (black arrow in picture above), we will see the separation. We know what that plane is because we have two vectors which lie on that plane) One vector is aligned with the edge of blue and the other vector is aligned with the edge of yellow and as we all know the normal to a plane is simply the cross product of two vectors lying on the plane.
So for OOBBs we need to check every combination(9 of them) of cross products of the edges of the two objects to make sure we are not missing any edge-edge separations.
No comments:
Post a Comment