From 0c9d8f3c41eba6991c1fc425caaf60f184800fbf Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Thu, 9 Feb 2012 20:26:18 +0100 Subject: [PATCH] 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. --- src/modules/physics/box2d/World.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/modules/physics/box2d/World.cpp b/src/modules/physics/box2d/World.cpp index 13c8ed45b..8e016d887 100644 --- a/src/modules/physics/box2d/World.cpp +++ b/src/modules/physics/box2d/World.cpp @@ -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();