some extra help on bitmasks.

Hello everyone I thought for a moment that maybe I had the hang of Panda3d collisions until I came across bit masks… so yes, there are other threads where people have asked this question but they haven’t help we very much so really I just have some some specific questions.

  1. what are ‘bits’ the manual says “The collide masks are represented using a BitMask32 object, which is really just a 32-bit integer with some additional methods for getting and setting particular bits.” I don’t get “32-bit integer” and “particular bits”

  2. Why are they called ‘masks’ (this might help me understand what they are)

  3. what do these numbers mean - (code from manual)

        
goodMask = BitMask32(0x1)
badMask = BitMask32(0x2)
floorMask = BitMask32(0x4)

the ones after BitMask32 “(0x4)”, “(0x2)” and “(0x1)”

and if there’s any other information that you could give me that you might think will help me understand bitmasks a bit better, it would be greatly appreciated.

thanks.

I don’t like the manual using that interface and I don’t like that example, there is something much more simpler:

goodMask = BitMask32.bit(1)
badMask = BitMask32.bit(2)
floorMask = BitMask32.bit(3) 

‘32-bit integer’ is just a number, it is a set of 32 ‘particular bits’ like:
0000 0000 0000 0000 0000 0000 0000 0001
or
0000 0000 0000 0000 0000 0000 0000 0010

You can imagine it as a list of 32 true/false values

So, if you use something like

mask=BitMask32.bit(15)

then you set the 15th bit to 1

It’s called a mask because… well I don’t know, someone in the past must have been an airbrush painter. It’s not a panda3d specific idea: en.wikipedia.org/wiki/Mask_%28computing%29

I’d like to expand a little (or perhaps a bit :stuck_out_tongue:) on the description of “bits”, as well as explain the 0x- numbers that you give, as I understand them.

First of all, bits:

You know, I imagine, what a “megabyte” is - a unit of data, essentially, a measure of how much “space” is used in storage or memory. Here “mega” is a prefix that indicates a certain number of the base word (“byte”) - either 1 048 576 or 1 000 000, depending on who you ask and the context. You can thus store 1 048 576 single-byte objects in the space taken up by 1 single-megabyte object (excluding space used for bookkeeping).

In the same manner, a byte is 8 bits - you might store 8 1-bit objects in the space taken by 1 single-byte object.

The bit is the smallest unit of information used in a computer, and has two states: 1 or 0. Using binary notation, numbers can be expressed in terms of bits:
2 in standard base 10 is 10 in binary
3 in base 10 is 11 in binary
4 in base 10 is 100 in binary
10 in base 10 is 1010 in binary,
etc.

(For a more detailed explanation, try this article.)

As wezu mentioned, an integer can be expressed in binary - indeed, is so expressed from the computer’s perspective. We can thus make use of this notation by considering each bit of a given number to represent a simple state - on or off. The number itself isn’t important, in general; only the individual states of the various bits are important.

As to the 0x- numbers, those are hexadecimal - another way of writing numbers that is not uncommon in programming; it has the advantages that a single digit in hexadecimal is 16 bits, that two digits are 32 bits, and that it makes for fairly compact numbers. The “0x” prefix simply identifies the numbers as being hexadecimal.

thanks guys!,cleared that up pretty well.