Need help with layers.

Official forum for the Chipmunk2D Physics Library.
Post Reply
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Need help with layers.

Post by scorp »

I know what bitmasks are, but due to my crappy programming skills I just don't understand how to use them.

For example, i want my shape to occupy layers 5,8 and 31.

shape->layers=(?????);
What should i type instead of "?????"?


Sorry for a stupid question, which isn't even about chipmunk. :oops:
Last edited by scorp on Mon May 19, 2008 9:01 am, edited 2 times in total.
supertommy
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm
Contact:

Re: Need help with layers.

Post by supertommy »

The general idea is that you want bits 5, 8 and 31 to be '1' and the rest of the bits to be '0'. I find that the following line is a nice way of accomplishing that:

Code: Select all

shape->layers = 1 << 5 | 1 << 8 | 1 << 31
Alternatively, either of the following are completely equivalent:

Code: Select all

shape->layers = 0x80000000 | 0x00000100 | 0x00000020
shape->layers = 0x80000120
(I've assumed that you meant the layer number to be zero-based, i.e.: the first layer is layer 0)
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Re: Need help with layers.

Post by scorp »

Big-big thx for examples!!!
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests