Box2d Filter and doc
BlitzMax Forums/Brucey's Modules/Box2d Filter and doc
| ||
Hi Filter collision is probably one of the hardest part of Box2d. In documentation the ShouldCollide example has syntax bug. Should be : Local Collide:Int = (filter1.GetMaskBits() & filter2.GetCategoryBits()) <> 0 And .. (filter1.GetCategoryBits() & filter2.GetMaskBits()) <> 0 return collide Isn't there any way to register a b2ContactFilter ? Overrided ShouldCollide() is never called. About Collision Bits now Do you think it's better to do like this : Const PLAYERONLY_COLLISION_BYTE:Short = $0001:Short Const GOLFBALL_COLLISION_BYTE:Short = $0002:Short Const GOLFBALL_SENSOR_COLLISION_BYTE:Short = $0004:Short Const OBJECT_COLLISION_BYTE:Short = $0008:Short Const PLAYER_COLLISION_BYTE:Short = $0016:Short Const HOLE_COLLISION_BYTE:Short = $00032:Short Const GROUND_COLLISION_BYTE:Short = $0064:Short Or values should be rather like that : Const PLAYERONLY_COLLISION_BYTE:Short = $0001:Short Const GOLFBALL_COLLISION_BYTE:Short = $0002:Short Const GOLFBALL_SENSOR_COLLISION_BYTE:Short = $0004:Short Const OBJECT_COLLISION_BYTE:Short = $0008:Short Const PLAYER_COLLISION_BYTE:Short = $0010:Short '$0010:Short = 16 Const HOLE_COLLISION_BYTE:Short = $00020:Short '$0020:Short = 32 Const GROUND_COLLISION_BYTE:Short = $0040:Short '$0040:Short = 64 The thing is I found it very hard to setup correctly my player collision mask. Player should collide with everything at certain moment (see FULL_MASK_BITS) Sometimes Golfball must pass through (see PLAYER_MASK_BITS) when refiltering. And a certain kind of object (PLAYERONLY) shall never collide with anything except player. Const FULL_MASK_BITS:Short = $FFFF:Short Const PLAYER_MASK_BITS:Short = $FFFF:Short ~ GOLFBALL_COLLISION_BYTE Const PLAYERONLY_MASK_BITS:Short = $FFFF:Short ~ OBJECT_COLLISION_BYTE ~ GOLFBALL_COLLISION_BYTE ~ GOLFBALL_SENSOR_COLLISION_BYTE ~ HOLE_COLLISION_BYTE ~ GROUND_COLLISION_BYTE I know it sound confusing but I'm wondering if it's the good way to setup collision filters since everything work like that. Thanks if you can help |
| ||
I've fixed the docs, and tweaked the collision filter example to work properly. It seems that Short in BlitzMax is an unsigned 16 bit. Which confused things slightly, as the C++ example used uint16 and int16... so where -1 for int16 is still -1, for a Short, -1 = 65535. So now, the collision filter example works as expected. It also uses a contact filter object, of which the ShouldCollide method is called as expected, once the contact filter is added to the world. |
| ||
Thanks for this fix. So if I understand well the next Collision Bits values after $0001 $0002 $0004 $0008 are $0010 $0020 $0040 and not $0016 $0032 $0064 right ? Also, if I'm not changing the world.SetFilter() is the default ShouldCollide() method (hard coded in C++ I suppose) is quicker than the blitzMax one ? |
| ||
Bits are always like this in each column : $0, $1, $2, $4, $8.. so, after $08 it is $10... and so on. (since each hex column is a set of 4 bits) The default is probably quicker, yes. The ability to define your own, is useful of course if you want to apply your own special collision handling. I think the difficulty is understanding how the different flags and groups interact. Hopefully, now that the example works as it should, you can see what all the flags/groups do. |
| ||
Perfect ! Now things are more clear to me. Thanks :) |