bool PhysicsWorld::collisionBeginCallback(PhysicsContact& contact) { bool ret = true; PhysicsShape* shapeA = contact.getShapeA(); PhysicsShape* shapeB = contact.getShapeB(); PhysicsBody* bodyA = shapeA->getBody(); PhysicsBody* bodyB = shapeB->getBody(); std::vector<PhysicsJoint*> jointsA = bodyA->getJoints(); // check the joint is collision enable or not for (PhysicsJoint* joint : jointsA) { if (std::find(_joints.begin(), _joints.end(), joint) == _joints.end()) { continue; } if (!joint->isCollisionEnabled()) { PhysicsBody* body = joint->getBodyA() == bodyA ? joint->getBodyB() : joint->getBodyA(); if (body == bodyB) { contact.setNotificationEnable(false); return false; } } } // bitmask check if ((shapeA->getCategoryBitmask() & shapeB->getContactTestBitmask()) == 0 || (shapeA->getContactTestBitmask() & shapeB->getCategoryBitmask()) == 0) { contact.setNotificationEnable(false); } if (shapeA->getGroup() != 0 && shapeA->getGroup() == shapeB->getGroup()) { ret = shapeA->getGroup() > 0; } else { if ((shapeA->getCategoryBitmask() & shapeB->getCollisionBitmask()) == 0 || (shapeB->getCategoryBitmask() & shapeA->getCollisionBitmask()) == 0) { ret = false; } } if (contact.isNotificationEnabled()) { contact.setEventCode(PhysicsContact::EventCode::BEGIN); contact.setWorld(this); _eventDispatcher->dispatchEvent(&contact); } return ret ? contact.resetResult() : false; }
bool PhysicsWorld::collisionPreSolveCallback(PhysicsContact& contact) { if (!contact.isNotificationEnabled()) { return true; } contact.setEventCode(PhysicsContact::EventCode::PRESOLVE); contact.setWorld(this); _eventDispatcher->dispatchEvent(&contact); return contact.resetResult(); }
int PhysicsWorld::collisionPreSolveCallback(PhysicsContact& contact) { if (!contact.isNotificationEnabled()) { cpArbiterIgnore(static_cast<cpArbiter*>(contact._contactInfo)); return true; } contact.setEventCode(PhysicsContact::EventCode::PRESOLVE); contact.setWorld(this); _scene->getEventDispatcher()->dispatchEvent(&contact); return contact.resetResult(); }
int PhysicsWorld::collisionPreSolveCallback(PhysicsContact& contact) { if (!contact.isNotificationEnabled()) { cpArbiterIgnore(static_cast<cpArbiter*>(contact.m_pContactInfo)); return true; } contact.setEventCode(PhysicsContact::EventCode::PRESOLVE); contact.setWorld(this); EventCustom event(PHYSICSCONTACT_EVENT_NAME); event.setUserData(&contact); m_pScene->getEventDispatcher()->dispatchEvent(&event); return contact.resetResult(); }