Collision Filtering

I am not sure if this is a limitation on the collision filtering. Because I need filtering for more than two shapes.

Here is a scenerio.

I have 4 rectangle walls, 5 Circles, 5 Squares.

1. If I wish the Circles and Squares to collide with the Rectangles
2. The Circles to collide with the Squares.
3. The Circles to collide with the Circles.
4. The Squares NOT to collide with the Squares.

How do I use the collision filtering feature to achieve this? If cant is there another way? Thanks
I haven't used collision filtering myself, I assume that categoryBits of 0x0 means that it collides with everything (probably the default, since there's no way to mask 0x0 with a bit):

EDIT. Correction, the default categoryBits is 0x1, 0x0 means that it'll never collide with anything. Fixed code:

I'm assuming that you want your circles to collide with everything. Since maskBits is 0xFFFF by default and judging from your example, all you want is squares not to collide with each other, this code is all you really need (you don't even ened to set categoryBits for circles if it's as simple as you described):

squareDef.categoryBits = 0x2;
squareDef.maskBits = ~0x2; // = 0xFFFD

That means that squares will collide with everything else than each other.
This is possible using group categories/masks, check the collision filtering example in the manual.
http://box2d.org/manual.html

Just give each group an category bit, i.e
walls = 0x0001
circles = 0x0002
squares = 0x0004
(shapeDef.categoryBits = category)

Then mask out the categories you don't want it to collide with
walls = 0xffff
circles = 0xffff
squares = 0xffff & ~0x0004
(shapeDef.maskBits = mask)

Hope that's right, good luck
-Matt
You don't even need own category for circles in this particular case, as it's really just copy of same rules as walls. Unless he'll need something more complex in future.
Guys, you don't know how much I appreaciate your help.

It is working! 😀

I did refer to manual, just that I did not understand what masking was all about.

You guys are great, cheers!

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