| 350 | } |
| 351 | |
| 352 | bool PhysicsWorld::collisionBeginCallback(PhysicsContact& contact) |
| 353 | { |
| 354 | bool ret = true; |
| 355 | |
| 356 | PhysicsShape* shapeA = contact.getShapeA(); |
| 357 | PhysicsShape* shapeB = contact.getShapeB(); |
| 358 | PhysicsBody* bodyA = shapeA->getBody(); |
| 359 | PhysicsBody* bodyB = shapeB->getBody(); |
| 360 | auto&& jointsA = bodyA->getJoints(); |
| 361 | |
| 362 | // check the joint is collision enable or not |
| 363 | for (PhysicsJoint* joint : jointsA) |
| 364 | { |
| 365 | if (std::find(_joints.begin(), _joints.end(), joint) == _joints.end()) |
| 366 | { |
| 367 | continue; |
| 368 | } |
| 369 | |
| 370 | if (!joint->isCollisionEnabled()) |
| 371 | { |
| 372 | PhysicsBody* body = joint->getBodyA() == bodyA ? joint->getBodyB() : joint->getBodyA(); |
| 373 | |
| 374 | if (body == bodyB) |
| 375 | { |
| 376 | contact.setNotificationEnable(false); |
| 377 | return false; |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | // bitmask check |
| 383 | if ((shapeA->getCategoryBitmask() & shapeB->getContactTestBitmask()) == 0 || |
| 384 | (shapeA->getContactTestBitmask() & shapeB->getCategoryBitmask()) == 0) |
| 385 | { |
| 386 | contact.setNotificationEnable(false); |
| 387 | } |
| 388 | |
| 389 | if (shapeA->getGroup() != 0 && shapeA->getGroup() == shapeB->getGroup()) |
| 390 | { |
| 391 | ret = shapeA->getGroup() > 0; |
| 392 | } |
| 393 | else |
| 394 | { |
| 395 | if ((shapeA->getCategoryBitmask() & shapeB->getCollisionBitmask()) == 0 || |
| 396 | (shapeB->getCategoryBitmask() & shapeA->getCollisionBitmask()) == 0) |
| 397 | { |
| 398 | ret = false; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | if (contact.isNotificationEnabled()) |
| 403 | { |
| 404 | contact.setEventCode(PhysicsContact::EventCode::BEGIN); |
| 405 | contact.setWorld(this); |
| 406 | _eventDispatcher->dispatchEvent(&contact); |
| 407 | } |
| 408 | |
| 409 | return ret ? contact.resetResult() : false; |
no test coverage detected