Page 1 of 1

[SOLVED] Groups, Categories, Masks, Filters...

Posted: Tue Jun 02, 2015 1:01 am
by volte
Hey folks. These forums feel a bit desolate, but I'll give it a shot anyway.

I'm trying to accomplish what I feel should be pretty simple... Somehow it's not working. I must not completely understand all this group/category/mask filtering... Doesn't sound that complicated, but my solution isn't working.

Code: Select all

	cpShapeSetFilter(shape, cpShapeFilterNew(uid, Game::Object::SHIP, Game::Object::PLANET));
	cpShapeSetFilter(shield_shape, cpShapeFilterNew(uid, Game::Object::SHIP, Game::Object::SHIP));
...
	cpShapeSetCollisionType(shape, Game::Object::Group::SHIP);
	cpShapeSetCollisionType(shield_shape, Game::Object::Group::SHIP);
All these shapes (two) are attached to a single body. I want the shield_shape to collide with other shield_shapes, I want the ship shape itself to do the colliding with planets. Well, neither of those collisions take place with this set up. What's up?

Re: Groups, Categories, Masks, Filters...

Posted: Tue Jun 02, 2015 2:04 am
by aisman
maybe:

Code: Select all

Game::Object::Group::SHIP != Game::Object::SHIP

Re: Groups, Categories, Masks, Filters...

Posted: Tue Jun 02, 2015 2:16 pm
by volte
aisman wrote:maybe:

Code: Select all

Game::Object::Group::SHIP != Game::Object::SHIP
Good eye, but that doesn't seem to be the issue. It's a small typo/nuance allowed in C++ (not sure about C?)

Code: Select all

namespace Game
{
	namespace Object
	{
		enum Group : cpBitmask
		{
			SHIP,
			PLANET
		};
	}
}

Re: Groups, Categories, Masks, Filters...

Posted: Wed Jun 03, 2015 12:12 pm
by volte
Alright, I'm silly. I figured it out.

As per the documentation
Category Mask Test: The categories of each shape are bitwise ANDed against the category mask of the other shape. If either result is 0, the shapes do not collide.
Group Test: Shapes shouldn’t collide with other shapes in the same non-zero group.
Well, enumerations start at 0. So, Game::Object::SHIP was 0, which means no group, no collision. Doh!

I just padded my enumeration like so, to fix it.

Code: Select all

		enum Group : cpBitmask
		{
			NONE,
			SHIP,
			PLANET
		};
HTH someone else!