I finally decided to post a patch of my work on polygon support for phys2d. Hopefully it will be integrated into phys2d soon. It seems to be working quite well, but further testing has to prove that. Note that I did not finish line collision support as I was planning to, it took me too long to get that done as well. This means that line-line collisions are not supported at all and collisions with the endpoints a line gives somewhat strange results. Some other features added by the patch:
- bitmasks for collision groups
- very basic ambient damping
- collider factory (should still be converted to a table-based method
- … maybe more small things that I forgot…
The patch also ads two demo’s, the first one is showing off colliding objects of all shapes and the second one some gear construction that I made for fun.
http://gideon.home.fmf.nl/all-shapes.gif
http://gideon.home.fmf.nl/polygonCollisions.gif
For now I’m totally fed up with this stuff so don’t expect updates very soon. The code is quite thoroughly documented (well, my code is :P) and I’d be happy to answer any questions. If I ever have another go at this, I’d limit myself to convex polygons and use a well documented algorithm like lin-canny or v-clip to implement this. Getting a proper penetration depth and collision normal really is a major problem and I think there will still be issues with strange shapes. I have a very strong feeling that my solution is unnecessarily complicated :-.
The code also contains some commented out pieces of code that could be useful in the future. For example line-line collisions is actually implemented, but disabled because a small piece of functionality is missing. There’s also some commented out code in the Arbiter class of which I wrote a different version which reuses vector objects and some other things, it’s ugly but made the thing run significantly faster.
Finally the patch. I hope you make good use of it