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

Official forum for the Chipmunk2D Physics Library.
Post Reply
volte
Posts: 5
Joined: Wed Jun 01, 2011 11:14 pm
Contact:

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

Post 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?
Last edited by volte on Wed Jun 03, 2015 12:13 pm, edited 1 time in total.
aisman
Posts: 145
Joined: Tue Mar 04, 2008 2:21 am
Contact:

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

Post by aisman »

maybe:

Code: Select all

Game::Object::Group::SHIP != Game::Object::SHIP
Chipmunk4PB: The fastest way to write games together with PureBasic and the Chipmunk physics engine.
volte
Posts: 5
Joined: Wed Jun 01, 2011 11:14 pm
Contact:

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

Post 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
		};
	}
}
volte
Posts: 5
Joined: Wed Jun 01, 2011 11:14 pm
Contact:

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

Post 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!
Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests