Capsule Shapes Redux

I've gotten capsule shapes to work with the new code. This time the capsules collide appropriately.



I didn't modify the project file because my VC++ sent it through the conversion wizard. I added the following files:

Collision/Shapes/b2CapsuleShape.h
Collision/Shapes/b2CapsuleShape.cpp
Dynamics/Contacts/b2CapsuleAndCircleContact.h
Dynamics/Contacts/b2CapsuleAndCircleContact.cpp
Dynamics/Contacts/b2CapsuleContact.h
Dynamics/Contacts/b2CapsuleContact.cpp
Dynamics/Contacts/b2PolygonAndCapsuleContact.h
Dynamics/Contacts/b2PolygonAndCapsuleContact.cpp

I modified the Raycast and PolyShapes tests to produce capsules for the '6' and '7' keys.


Hacks I used:

reintepret_cast to convert from a b2Segment* to b2Vec2* for the b2Distance support proxy.
It's actually a valid cast, assuming the structure doesn't change. I didn't want to allocate memory for the two points, and I have them stored as a b2Segment.

Conversion of b2CapsuleShape to b2PolygonShape for collisions, with modified radius.
The new edge polygons already do capsule collision, so I just used the polygon collision functions rather than writing my own. I chose to convert to polygon on each collision rather than precalculating the polygon because it was easiest and space efficient.

See updated patch further down thread.
Nice work Hanger!

If you like, file an issue here http://code.google.com/p/box2d/issues/list, and I will put your patch in the contributions folder.
Hi Hanger,
I've applied your patch successfully, but it doesn't seem to contain the new files you listed (only changes to existing files).
Did I miss something or did you forget to post them? I could use capsules, so thanks for posting your work!
Same thing as Beavis. No new files. I want to check this out as a possibility to add to the Farseer Physics engine.
Sorry about that. It might have helped to test out the patch before uploading. Here's a fixed (and quickly tested) patch.

matt: I'm not sure how well it would translate to Farseer. Most of what I did was to write some glue code to mess with the new two-sided polygons. The hard part would be to write b2CollideCapsuleAndX from scratch.
Thanks Hangar. It should be easy to integrate into Farseer 3.0 😉 it's based on Box2D 2.1.
Thank you Hanger, it works nicely now!
Updated the patch for revision 88. Also fixed a raycast bug I didn't notice before.

Original thread: https://box2d.org/forum/viewtopic.php?t=4090