polygon support in phys2d

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 :smiley:

Thanks for the patch (and the code comments, useful as they always are). I’ll integrate, test and commit asap.

Kev

New build including Gideon’s awesome changes is available at the Phys2D website:

http://www.cokeandcode.com/phys2d/

Demo Box is webstartable here:

http://www.cokeandcode.com/phys2d/phys2d.jnlp

Now includes the two polygon tests - thats the gears one above (start the demo box and hit P twice to go to the previous tests).

Nice work Gideon! The gears demo doesn’t look quite right to me - but hell, it’s pretty fantastic to watch even then :slight_smile:

Kev

That is really really good stuff

In the gears demo, the big wheel starts spinning before the small fast-rotating gear touches it…??

How come?

The gears demo is quite simple actually, to me it seems to behave quite accurately. The only thing to which a force is applied is the smallest gear. I was inspired by monowheels, a motercycle where one sits inside the wheel. Although it doesn’t really resemble one I must admit ;).

– edit: fixed the closing url tag

You are a freaking genius. I could go back to writing 2D stuff based solely on how cool the demo was.