It looks as though the patch only tests for one case of intersection (where A is
“northwest” of B), but misses all other cases (A contains B, A and B share a
colinear edge, A and B are identical, A is southeast of B, etc.),
It should pass all these tests. If A contains B, then A.topleft <
B.bottomright and A.bottomright > B.topleft. The same is true with the
other conditions.
plus it won’t
pass this quick test:
SDL_HasIntersection(A,B) == SDL_HasIntersection(B,A)
right?
No, it makes no difference which way round you test. It will succeed in
that test.
I’ve attached an image to demonstrate the test. Given the black
rectangle, A, testing against any of the red rectangles, B.
“If A.topleft < B.bottomright” translates to any of the black corners
labelled ‘1’ being anywhere in the blue quadrant.
“and A.bottomright > B.topleft” translates to any of the black corners
labelled ‘2’ being anywhere in the green quadrant.
If these two tests are true, then they must be intersecting. If they are
not both true, then there is no way they are intersecting.On Sun, 2012-10-21 at 18:06 -0400, John wrote:
On Mon, 2012-10-22 at 09:38 +0200, Tobias Leich wrote:
Hi, shouldn’t be the “Seperating Axis Theorem” the best solution for
this, since SDL_Rects are AABBs?
That seems like an overly complex method for simple AABB to AABB
collision detection. SAT is there for collision between more complex
shapes.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: collide.png
Type: image/png
Size: 4526 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20121022/6ae56746/attachment-0001.png
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20121022/6ae56746/attachment-0001.pgp