mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Handle masks and categories in our contact filter
Turns out, setting our own contact filter bypasses the inbuilt mask and category handling, this means, however, that masks and categories are processed before your contact filter is called, so if you really want to do all the filtering manually, you should just make sure you never change the default masks and category, or restore it.
This commit is contained in:
@@ -109,6 +109,22 @@ namespace box2d
|
||||
|
||||
bool World::ContactFilter::process(Fixture * a, Fixture * b)
|
||||
{
|
||||
// Handle masks, reimplemented from the manual
|
||||
int filterA[3], filterB[3];
|
||||
// [0] categoryBits
|
||||
// [1] maskBits
|
||||
// [2] groupIndex
|
||||
a->getFilterData(filterA);
|
||||
b->getFilterData(filterB);
|
||||
|
||||
if (filterA[2] != 0 && // 0 is the default group, so this does not count
|
||||
filterA[2] == filterB[2]) // if they are in the same group
|
||||
return filterA[2] > 0; // Negative indexes mean you don't collide
|
||||
|
||||
if ((filterA[1] & filterB[0]) == 0 ||
|
||||
(filterB[1] & filterA[0]) == 0)
|
||||
return false; // A and B aren't set to collide
|
||||
|
||||
if (ref != 0)
|
||||
{
|
||||
lua_State * L = ref->getL();
|
||||
|
||||
Reference in New Issue
Block a user