I've had an unhappy week too.
One method you could use is a "Point Inside/Outside polygon test", aka a scanline test.
Point Inside/Outside polygon test
INPUT: Point P=(x,y) and a polygon.
OUTPUT: True or False, and possibly a normal vector of the collision surface.
1. Consider the point P = (x,y) which we're testing for collisions.
2. Consider the infinite horizontal line through that point. (x from -inf to +inf, at the same y) This is called a
scanline.
3. Determine which line segments the scanline passes through. This is simply a case of if one end vertex is >=y and the other end vertex <y.
4. Create a list of those line segments, and calculate the point (x[i], y) where the line segment [i] intersect the scanline.
5. Order the line segments by that x intersect value.
6. Travelling from from left to right along the scanline, we start off outside the polygon. After the first point (x[1],y), we are inside the polygon. After the second point (x[2],y) we are outside the polygon, and so on, alternating in/out.
7. Our point P will be in one of those sectors. Test which one.
We can use this as follows:
If PointInPolygon(x,y) = true and PointInPolygon(x+vx*dt, y+vy*dt) = false then // point tries to exit polygon in this physics step.
If you want normal vectors, those can be calculated extra.
Here's some code...
http://www.ecse.rpi.edu/Homepages/wrf/R ... npoly.html