DanielChappuis / reactphysics3d

Open source C++ physics engine library in 3D
http://www.reactphysics3d.com
zlib License
1.54k stars 224 forks source link

Collision category bits #344

Open ghost opened 1 year ago

ghost commented 1 year ago

Here's the docs:

enum Category { CATEGORY1 = 0x0001, CATEGORY2 = 0x0002, CATEGORY3 = 0x0004 };

When I start extending this, such as:

enum Category { CATEGORY1 = 0x0001, CATEGORY2 = 0x0002, CATEGORY3 = 0x0004 CATEGORY4 = 0x0008 CATEGORY5 = 0x0016 CATEGORY6 = 0x0032 CATEGORY7 = 0x0064 };

I find that say CATEGORY4 | CATEGORY7 also tests true with CATEGORY2 - what am I doing wrong?

ghost commented 1 year ago

found it,

DanielChappuis commented 1 year ago

found it,

What did you find exactly? Did you find an issue in your code or in the library?

ghost commented 1 year ago

Well, I think it was an issue with trying to use higher 0x00 numbers. Enum (I believe) defaults to an Unsigned 32 bit number, and I see that RP3D expects Unsigned short, although I thought that the cast would work. Anyway, I just declare my collision categories like this and it worked:

static const U16 TEAM_0_ACTOR_COLLISION_CATEGORY = 256; static const U16 TEAM_1_ACTOR_COLLISION_CATEGORY = 512; static const U16 TEAM_2_ACTOR_COLLISION_CATEGORY = 1024; static const U16 TEAM_3_ACTOR_COLLISION_CATEGORY = 2048; static const U16 TEAM_4_ACTOR_COLLISION_CATEGORY = 4096; static const U16 TEAM_5_ACTOR_COLLISION_CATEGORY = 8192;

MintPaw commented 1 year ago

I'm guessing this feature isn't well tested because it's not often used. But this collision filtering seems totally broken in my application. I can't prevent collisions between spheres/boxes and triangle meshes, even if I set collider->setCollideWithMaskBits(0); every frame.

It does work if you set the bits to 0 on the first frame, but if you wait and set it later, it doesn't work. Is this the intended behavior?