Page 1 of 1

Can somebody please explain to me setMask?

Posted: Sun Nov 23, 2008 12:10 am
by Kuromeku
I don't understand at all? Is it bit-wise and shit, I'm not too keen on that. Same for setCategory, setCategoryBits and setMaskBits.

:?

Re: Can somebody please explain to me setMask?

Posted: Sun Nov 23, 2008 3:37 pm
by rude

Code: Select all

shape1:setCategory(1)
shape2:setCategory(2)

shape3:setMask(1) -- Does not collide with shape1
shape4:setMask(1, 2) -- Does not collide with shape1 nor shape2 (does collide with shape3)

Re: Can somebody please explain to me setMask?

Posted: Sun Nov 23, 2008 4:44 pm
by Kuromeku
What is mask bits and category bits?

Re: Can somebody please explain to me setMask?

Posted: Sun Nov 23, 2008 5:10 pm
by u9_
The box2d documentation will have a very good explanation of this (if i remember correctly), check it out :)

Re: Can somebody please explain to me setMask?

Posted: Sun Nov 23, 2008 6:26 pm
by Kuromeku
It doesn't, that's why I'm asking here.

;)

Re: Can somebody please explain to me setMask?

Posted: Sun Nov 23, 2008 11:33 pm
by surtic
I think the explanation is that a category can be a number between 0 and 15 (i.e. 16 categories).
So when you want to specify a list of categories, you can either list them:

Code: Select all

shape:setCategory(1,3,10)
Or you can use a single number to represent this list. To do that, you calculate the sum of 2^category and use the result.
In this case: bits = 2^1+2^3+2^10 = 2+8+1024 = 1034. Then you use the "bits" function:

Code: Select all

shape:setCategoryBits(1034)
Why "bits"? Because when you look at 1034 as bits (in binary notation), you get 0000010000001010. You have '1' for the categories the shape belongs to, and '0' for the categories it doesn't belong to. And the same can be used for the mask (i.e. categories the shape can collide with).

So the short answer is, yes, it's bit-wise and shit... ;)

Re: Can somebody please explain to me setMask?

Posted: Sun Nov 23, 2008 11:48 pm
by Kuromeku
Hmm, I think I understand a bit better, thanks.

Re: Can somebody please explain to me setMask?

Posted: Sat Apr 25, 2009 4:53 am
by athanazio
rude,
I believe the comment you did
shape1:setCategory(1)
shape2:setCategory(2)

shape3:setMask(1) -- Does not collide with shape1
shape4:setMask(1, 2) -- Does not collide with shape1 nor shape2 (does collide with shape3)
is very clear and should go to the documentation !!

Re: Can somebody please explain to me setMask?

Posted: Sat Apr 25, 2009 10:46 am
by rude
athanazio wrote:... is very clear and should go to the documentation !!
Then please add it to the issue tracker, or I'll forget it! I'm not going to update the docs until the new documentation system [1] is in place (unless there are errors).

[1]: Yes, YET another one.