Box2D SetSolid() - Contact Patch

BlitzMax Forums/Brucey's Modules/Box2D SetSolid() - Contact Patch

Armitage 1982(Posted 2011) [#1]
I have a little something I would like to share with you.
This patch works with the last v1.0.4 of the bah.Box2D (official Box2d rev 207). I did it because this version of the Box2d module will probably never be updated anymore and is way too much different from the current Box2d version (please, someone port it :p).

With this add-on you'll be able to switch on/off any Collision Responses while keeping Contact Points available.
This is a main feature to develop One Sided Platform or One Way Door thanks to Box2D.

All it does is :
- Adding a void b2Contact::SetSolid(bool value)
- Modify each virtual b2ContactListener to include b2Contact when Add/Persist/Remove/Result is callback for a b2ContactPoint.

This old idea comes from Chriswa on the official Box2d forum when preSolve() didn't exist yet to create One Side Platform (http://box2d.org/forum/viewtopic.php?f=8&t=1748&hilit=mario),
which is the case of the only BlitzMax Box2d available to date.


You can find the modified sources here:
http://www.filefactory.com/file/cf965e1/n/Box2d_SetSolid_Contact_Patch.zip

Just drop these files on a fresh bah.box2d.mod v1.0.4 (don't forget a precious backup if you try this on your working version).

Then all you have to do is to implement yourself the b2ContactListener in order to change the solidity of your shapes while collecting contact Point for processing them later.

To give you an idea, this is a rough copy of my b2ContactListener implementation.
I've added plenty of comments a few minutes ago so excuse me if there is typo or errors...



NOTE: This patch does not work correctly with b2EdgeShape ! Unfortunately, b2EdgeShape use his own math to resolve wrong side collision. However, a solution should exist I guess.

Hope this help :)

Last edited 2011

Last edited 2012


Armitage 1982(Posted 2012) [#2]
Changed
Local deltaAng:Float = normalAng - (solidityAng * Pi / 180.0)

by
Local deltaAng:Float = (normalAng - solidityAng) * Pi / 180.0


This will fix the mess of the resolution method!
I was actually mixing Radians and Degrees... ahhh, trigonometry !