I am working on box2d physics game. In that i am facing one small problem that is for time interval I am making my physics body transparent to other physics body using group-index. That is working good. But, For some cases i want to know some of the b2body is colliding/overlapping with other bodies. For that, I tried to use isSensor property of b2fixture but i am not getting collision for transparent body.
My question is, Is it necessary to make all bodies isSensor true??
How can i solved this problem?
MyContactListner.mm
#import "MyContactListener.h"
#import "cocos2d.h"
MyContactListener::MyContactListener() : _contacts() {
}
MyContactListener::~MyContactListener() {
}
void MyContactListener::BeginContact(b2Contact* contact) {
MyContact myContact = { contact->GetFixtureA(), contact->GetFixtureB() };
_contacts.push_back(myContact);
}
void MyContactListener::EndContact(b2Contact* contact) {
MyContact myContact = { contact->GetFixtureA(), contact->GetFixtureB() };
std::vector<MyContact>::iterator pos;
pos = std::find(_contacts.begin(), _contacts.end(), myContact);
if (pos != _contacts.end()) {
_contacts.erase(pos);
}
}
void MyContactListener::PreSolve(b2Contact* contact,
const b2Manifold* oldManifold) {
}
void MyContactListener::PostSolve(b2Contact* contact,
const b2ContactImpulse* impulse) {
}
The point of the groupIndex and filter bits is to make fixtures ignore each other completely, so what you're describing sounds correct. If you want two fixtures to give you BeginContact/EndContact callbacks, you'll have to set the groupIndex and filter bits to allow it. You can see how the default check is done here: http://code.google.com/p/box2d/source/browse/trunk/Box2D/Box2D/Dynamics/b2WorldCallbacks.cpp
You can make your own subclass of b2ContactFilter to customize this behavior (use b2World::SetContactListener to tell the world to use your custom class).