A question about BitMask.bit

This isn’t actual code or anything, but here’s the scenario -

I have four objects…


ObjA has BitMask.bit set to 20.
ObjB has BitMask.bit set to 20.
ObjC has BitMask.bit set to 19.
ObjD has BitMask.bit set to 19.

Here’s the question…

Would ObjA only register (collision wise) with other Objects that have BitMask.bit set to 20? and will ObjC only register with other Objects that have BitMask.bit set to 19?

I guess I’m kind of asking, does setting the BitMask.bit to a specific value create a layer of collision checking for all objects with the same value, while overlooking objects of a different value?

That question has been in my head for the longest, so I figured I might as well get it out.

Actuall, it’s BitMask32.bit, I believe. :slight_smile:

>>> a = BitMask32.bit(20)
>>> a
 0000 0000 0001 0000 0000 0000 0000 0000
>>> b = BitMask32.bit(19)
>>> b
 0000 0000 0000 1000 0000 0000 0000 0000
>>> a & b
 0000 0000 0000 0000 0000 0000 0000 0000

In words, BitMask32.bit(20) creates a bitmask with the twenty-first bit set to 1, and BitMask32.bit(19) creates a bitmask with the twentieth bit set to 1.
Because they don’t have overlapping bits, they do not interact in any way - as you can see by (a & b) which returns zero.

Only collision objects that have overlapping on-bits in the appropriate mask will collide with each other.

Crystal clear! :smiley:

One other thing…

If ObjA was a from object (bit 20), and where to collide with ObjK, into object (bit 16), according to your above statement, a collison would not happen

(unless it’s different depending on rather or not a object is Into or From; that was not visualize in my opening post).

What I want to know is, would P3D test for collision between two objects that will not collide because of different bit settings, or would the Engine ignore the possibility altogehter, overlooking needless work?

I know everything inserted into the Trav will be a From object (and a possible Into) and everything else outside the Trav is considered an Into.

That’s why I’m wondering if the engine would still perform the collison checking and then say later, “Hey, the bits aren’t right, so there’s no collision here.” or would P3D say, “Hey, the bits aren’t right here, so I’m not even going to bother with testing.”

or maybe it’s the testing that ultimately determines the outcome, therefore, even if the bits were different between two collision objects and they would not collide, the testing must still happen.

or is the testing for bits some kind of lower level testing and if the collision will happen, a full scale test is performed?

If you’re reading this rdb, I imagine you’re probably saying, “WTF” right about now. :laughing:

Just my mind wondering into engine logic again, even though engine programming is not my thing.

However, the better you understand an Engine, the better you can use it. :slight_smile:

I don’t know how it really works, but from some testing it looks like the collision elf first tests bit masks, then bounding volumes and only performs its magic when objects can collide.

I once had a bit of code for clicking on 3d objects and there was a big boost when I used a mask on the mouse ray to only pick objects when a button is clicked.

Yes, the whole point of the bitmasks is to early-out the needless test between objects that are not intended to collide. Using bitmasks in this way correctly can save considerable time in the collision computation.