Re:How I implemented 2D collision detection in Pistol Slut
by maryrosecook on Wednesday January 19, 2011 @09:44AM
(#2119836)
Great. I'll check out the separating axis test, too - thanks. Incidentally, I believe The Render Engine, the framework I used, has just introduced support for this technique.
Re:How I implemented 2D collision detection in Pistol Slut
by JoeAltmaier on Thursday January 20, 2011 @09:33AM
(#2123720)
You can also rotate the axes to align with one object's motion. Then the 'axis test' reduces to one axis, and collision is a line-segment test.
In your axis-aligned case, you would project the objects you test on both axes (x and y). If the do not overlap on any one of the axes, they do not collide, otherwise they do. To handle movement you project each objects movement vector on the axes as well and add that to the objects projected interval.
To find out which grid squares that are covered by a polygon amounts to resterization, which you can find many tutorials for with google.
Axis aligned boxes are trivial to rasterize. For more complex shapes you write a rasterizer for triangles and handle arbitrary polygons by breaking them up into triangles (google "ear clipping").