Create the actual contact manifolds and contacts points
| 904 | |
| 905 | // Create the actual contact manifolds and contacts points |
| 906 | void CollisionDetectionSystem::createContacts() { |
| 907 | |
| 908 | RP3D_PROFILE("CollisionDetectionSystem::createContacts()", mProfiler); |
| 909 | |
| 910 | mCurrentContactManifolds->reserve(mCurrentContactPairs->size()); |
| 911 | mCurrentContactPoints->reserve(mCurrentContactManifolds->size()); |
| 912 | |
| 913 | // Process the contact pairs in the order defined by the islands such that the contact manifolds and |
| 914 | // contact points of a given island are packed together in the array of manifolds and contact points |
| 915 | const uint32 nbContactPairsToProcess = static_cast<uint32>(mWorld->mProcessContactPairsOrderIslands.size()); |
| 916 | for (uint32 p=0; p < nbContactPairsToProcess; p++) { |
| 917 | |
| 918 | uint32 contactPairIndex = mWorld->mProcessContactPairsOrderIslands[p]; |
| 919 | |
| 920 | ContactPair& contactPair = (*mCurrentContactPairs)[contactPairIndex]; |
| 921 | |
| 922 | contactPair.contactManifoldsIndex = static_cast<uint32>(mCurrentContactManifolds->size()); |
| 923 | contactPair.nbContactManifolds = contactPair.nbPotentialContactManifolds; |
| 924 | contactPair.contactPointsIndex = static_cast<uint32>(mCurrentContactPoints->size()); |
| 925 | |
| 926 | // For each potential contact manifold of the pair |
| 927 | for (uint32 m=0; m < contactPair.nbPotentialContactManifolds; m++) { |
| 928 | |
| 929 | ContactManifoldInfo& potentialManifold = mPotentialContactManifolds[contactPair.potentialContactManifoldsIndices[m]]; |
| 930 | assert(potentialManifold.nbPotentialContactPoints > 0); |
| 931 | |
| 932 | // Start index and number of contact points for this manifold |
| 933 | const uint32 contactPointsIndex = static_cast<uint32>(mCurrentContactPoints->size()); |
| 934 | const int8 nbContactPoints = static_cast<int8>(potentialManifold.nbPotentialContactPoints); |
| 935 | contactPair.nbToTalContactPoints += nbContactPoints; |
| 936 | |
| 937 | // Create and add the contact manifold |
| 938 | mCurrentContactManifolds->emplace(contactPair.body1Entity, contactPair.body2Entity, contactPair.collider1Entity, |
| 939 | contactPair.collider2Entity, contactPointsIndex, nbContactPoints); |
| 940 | |
| 941 | assert(potentialManifold.nbPotentialContactPoints > 0); |
| 942 | |
| 943 | // For each contact point of the manifold |
| 944 | for (uint32 c=0; c < potentialManifold.nbPotentialContactPoints; c++) { |
| 945 | |
| 946 | ContactPointInfo& potentialContactPoint = mPotentialContactPoints[potentialManifold.potentialContactPointsIndices[c]]; |
| 947 | |
| 948 | // Create and add the contact point |
| 949 | mCurrentContactPoints->emplace(potentialContactPoint, mWorld->mConfig.persistentContactDistanceThreshold); |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | // Initialize the current contacts with the contacts from the previous frame (for warmstarting) |
| 955 | initContactsWithPreviousOnes(); |
| 956 | |
| 957 | // Compute the lost contacts (contact pairs that were colliding in previous frame but not in this one) |
| 958 | computeLostContactPairs(); |
| 959 | |
| 960 | mPreviousContactPoints->clear(); |
| 961 | mPreviousContactManifolds->clear(); |
| 962 | mPreviousContactPairs->clear(); |
| 963 |