Compute the middle-phase collision detection
| 344 | |
| 345 | // Compute the middle-phase collision detection |
| 346 | void CollisionDetectionSystem::computeMiddlePhase(NarrowPhaseInput& narrowPhaseInput, bool needToReportContacts, bool isWorldQuery) { |
| 347 | |
| 348 | RP3D_PROFILE("CollisionDetectionSystem::computeMiddlePhase()", mProfiler); |
| 349 | |
| 350 | // Reserve memory for the narrow-phase input using cached capacity from previous frame |
| 351 | narrowPhaseInput.reserveMemory(); |
| 352 | |
| 353 | // Remove the obsolete last frame collision infos and mark all the others as obsolete |
| 354 | mOverlappingPairs.clearObsoleteLastFrameCollisionInfos(); |
| 355 | |
| 356 | const uint32 nbEnabledColliderComponents = mCollidersComponents.getNbEnabledComponents(); |
| 357 | |
| 358 | // For each possible convex vs convex pair of bodies |
| 359 | const uint64 nbConvexVsConvexPairs = mOverlappingPairs.mConvexPairs.size(); |
| 360 | for (uint64 i=0; i < nbConvexVsConvexPairs; i++) { |
| 361 | |
| 362 | OverlappingPairs::ConvexOverlappingPair& overlappingPair = mOverlappingPairs.mConvexPairs[i]; |
| 363 | |
| 364 | assert(mCollidersComponents.getBroadPhaseId(overlappingPair.collider1) != -1); |
| 365 | assert(mCollidersComponents.getBroadPhaseId(overlappingPair.collider2) != -1); |
| 366 | assert(mCollidersComponents.getBroadPhaseId(overlappingPair.collider1) != mCollidersComponents.getBroadPhaseId(overlappingPair.collider2)); |
| 367 | |
| 368 | const Entity collider1Entity = overlappingPair.collider1; |
| 369 | const Entity collider2Entity = overlappingPair.collider2; |
| 370 | |
| 371 | const uint32 collider1Index = mCollidersComponents.getEntityIndex(collider1Entity); |
| 372 | const uint32 collider2Index = mCollidersComponents.getEntityIndex(collider2Entity); |
| 373 | |
| 374 | CollisionShape* collisionShape1 = mCollidersComponents.mCollisionShapes[collider1Index]; |
| 375 | CollisionShape* collisionShape2 = mCollidersComponents.mCollisionShapes[collider2Index]; |
| 376 | |
| 377 | NarrowPhaseAlgorithmType algorithmType = overlappingPair.narrowPhaseAlgorithmType; |
| 378 | |
| 379 | const bool isCollider1Trigger = mCollidersComponents.mIsTrigger[collider1Index]; |
| 380 | const bool isCollider2Trigger = mCollidersComponents.mIsTrigger[collider2Index]; |
| 381 | const bool isWorldQueryCollider1 = mCollidersComponents.mIsWorldQueryCollider[collider1Index]; |
| 382 | const bool isWorldQueryCollider2 = mCollidersComponents.mIsWorldQueryCollider[collider2Index]; |
| 383 | const bool isCollider1SimulationCollider = mCollidersComponents.mIsSimulationCollider[collider1Index]; |
| 384 | const bool isCollider2SimulationCollider = mCollidersComponents.mIsSimulationCollider[collider2Index]; |
| 385 | |
| 386 | const bool isCollider1SimulationColliderOrTrigger = isCollider1SimulationCollider || isCollider1Trigger; |
| 387 | const bool isCollider2SimulationColliderOrTrigger = isCollider2SimulationCollider || isCollider2Trigger; |
| 388 | |
| 389 | overlappingPair.collidingInCurrentFrame = false; |
| 390 | |
| 391 | const bool isBody1Enabled = collider1Index < nbEnabledColliderComponents; |
| 392 | const bool isBody2Enabled = collider2Index < nbEnabledColliderComponents; |
| 393 | |
| 394 | // Only test for collision for a world query and both colliders are world query colliders or |
| 395 | // if it is not a world query and both colliders are either triggers or simulation colliders |
| 396 | if ((isWorldQuery && isWorldQueryCollider1 && isWorldQueryCollider2) || |
| 397 | (!isWorldQuery && isCollider1SimulationColliderOrTrigger && isCollider2SimulationColliderOrTrigger)) { |
| 398 | |
| 399 | // If it is not a world query, we make sure that the two bodies are enabled |
| 400 | if (isWorldQuery || (!isWorldQuery && (isBody1Enabled || isBody2Enabled))) { |
| 401 | |
| 402 | const bool reportContacts = needToReportContacts && !isCollider1Trigger && !isCollider2Trigger; |
| 403 |
nothing calls this directly
no test coverage detected