I've been re-working through the tutorials on SAT and polygon collision response, but actually writing my own code based on the tutorials rather than copy-paste-fiddle-about like last time.
Much happier with the results. I don't pretend to fully understand it all, but I certainly understand it better than last time.
And, more importantly, I've managed to derive my own circle-circle and circle-polygon collision detection and response SAT stuff.
So unlike the previous demos I was releasing, a circle can be represented by a point and a radius now, rather than a many sided polygon.
Obviously the circle-polygon SAT is now more efficient, since (and I could have this wrong, but it works on screen) the only axes I need test are the normals of the polygon, plus one axis running parallel to the centre of the circle and either the centre of or one of the vertices of the polygon.
I can't really visualise why that works, but the tests I've run all detect correct collisions or the lack of, and the push vector (which I then normalise to use to reflect the angle with Vel=Vel-(2*Vel dot Normal)*Normal ) always seems to be correct.
And, hopefully even more obviously, circle-circle tests are far, far faster since there is no actual SAT involved, just a simple distance-between-centres < radius+radius to find an intersection, then just the subtraction of the distance from the sum of the radii, to get the push distance, then centre-centre to get the push direction, normalised then multiplied by the push distance to get the push vector.
Certainly all progress.
[EDIT] Nope - the circle/polygon tests are failing under some strange circumstances. Back to the drawing board. Bugger.
[EDIT] Got it working after many hours of messing about.
Just a daft GDI based app that bounces the white ball about off the random shapes. All seems to be okay.
DEMO here if you want to test it. Click the mouse to make the ball move towards where you click.
Scrap all that about the circle-polygon stuff above though. I'm now just testing the normals to the axes of the polygon, and projecting the circle onto the axis by first normalising the axis, then calculating the min and max for the circle like:
Seems to work.
[EDIT] Not quite. Actually also seem to need to test along each axis that is defined by the centre of the circle and each vertex of the polygon. Demo not updated but that seems to be perfect now.