Moving over from APE: Solid and Collidable flags?

Since Box2D has recently been ported to Flash/AS3 I've been investigating it, specifically to replace APE (which is particle-based, much simpler feature set, apparently slower).

On APE's equivalent of bodies (APE particles) there are two flags, solid and collidable. If collidable is false, the particle always "fails" collision tests, and thus passes through everything (like a cloud). If collidable is true, then collisions are detected and an event is fired to indicate such. Solid is then tested: if solid is true, the collision is resolved (correcting vector is applied to the solid particle); if solid is false, no correction is made, only the collision notification.

What would be the best way to implement these flags in Box2d? I could see where the collidable flag could be implemented by controlling the collision group or similar properties of a shape. I'm not so sure about solid... can Box2d detect collisions (and put the contact info on the contact list) but not resolve them on a particle by particle basis?
Box2D uses rigid bodies and collision flags are handled on a shape-by-shape basis.

With the solid flag, you are asking for sensors. This is on the TODO list, but won't be available for a month or so.

Another possibility is to use b2World::Query to query a AABB for shapes. This is how the mouse picking works in the test bed.
Erin Catto wrote:
With the solid flag, you are asking for sensors. This is on the TODO list, but won't be available for a month or so.


Hmm, won't be able to wait for that (we're launching the product in mid-January). I'm guessing sensors will basically be "bodies" that don't react to collisions but generate all of the contact information?

I've not dug into the contact generation/resolution code, but if I was willing to modify source, would it be possible/trivial to add a flag to a body that could be checked when the contacts are processed/generated in order to ignore the body? In other words, is there a logical place between collision detection and collision resolution where I could insert some conditional logic that's per-shape and/or per-body?

Quote:
Another possibility is to use b2World::Query to query a AABB for shapes. This is how the mouse picking works in the test bed.


Yeah, unfortunately APE allows for oriented bounding boxes so alot of our "collidable but not solid" objects are rotated (and some are circles).

This is a bum deal, and while it may not be that huge of a deal in the long term, it will definitely prevent us from moving to Box2d in the short term (which is a shame, because Box2d makes a lot of other things in our engine *way* simpler and faster, but the workarounds are already written!). Is it possible to leverage the collision detection API's directly to do shape-vs-shape testing?

Thanks for the quick responses!
If you are willing to dive into the source, implementing sensors is quite easy. When a sensor shape collides, let the b2Contact be created and the manifold be evaluated, but don't let the b2Contact be added to the b2ContactSolver.

Let me know if this doesn't work.
That does sound quite straightforward. Is your plan to make sensors just a customized type of body that does exactly what you described? Do you plan to allow sensors to be driven by physics (i.e. you can apply forces to them, they have a velocity, etc.) or will they just be shapes with a position?
A sensor would be a kind of shape. You can put shapes on moving or static bodies. Really, it is just a flag on the shape. The body doesn't care if it has a sensor shape. Of course, if a dynamic body only has sensor shapes, it won't be solid at all.
Hey Troy/Erin,

I've gone ahead and created the solution since well, I needed it too! I came from working with APE like Troy, and was probably using solid/collidable shapes in the same way, for sensors!

Here's how I solved the problem:

In the b2ShapeDef class, I added the variable "sensor" as a public boolean and declared it false in the constructor. In the b2Shape class, I added the variable "m_sensor" as a public boolean and set it's value to the b2ShapeDef.sensor value in the constructor. Finally in the b2ContactManager Collide function, just in the for loop below where the code checks to see if the bodies are sleeping I placed this chunk of code to match:

if (c.m_shape1.m_sensor ||
c.m_shape2.m_sensor)
{
continue;
}

And that's it! It seems to work alright so far. I'm affraid I haven't tested it thoroughly, but visually everything's working just fine and tracing out the basic shape contacts seem to show the sensors in the contact list, but no collision response.

Nice to see you in the Box2d Forums Troy, and I'm sure you get this enough Erin, but your engine's great. Thanks!

Hope that solves the sensor problem! 😉
Cool. I'll put this in 2.0.
One more catch! I just noticed that my radar/sensor has mass. Just trying to figure out how to remove the mass calculation properly to avoid giving the sensor low density instead.
I would guess that a sensor is attached to a body with other non-sensor shapes that have non-zero density, right? Then it is okay for the sensor to have zero density.

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