src/systems/CollisionDetectionSystem.cpp
void CollisionDetectionSystem::removeDuplicatedContactPointsInManifold(ContactManifoldInfo& manifold,
                                                                       const Array<ContactPointInfo>& potentialContactPoints) const {

    RP3D_PROFILE("CollisionDetectionSystem::removeDuplicatedContactPointsInManifold()", mProfiler);

    const decimal distThresholdSqr = SAME_CONTACT_POINT_DISTANCE_THRESHOLD * SAME_CONTACT_POINT_DISTANCE_THRESHOLD;

    // For each contact point of the manifold
    for (uint32 i=0; i < manifold.nbPotentialContactPoints; i++) {
        for (uint32 j=i+1; j < manifold.nbPotentialContactPoints; j++) {

            const ContactPointInfo& point1 = potentialContactPoints[manifold.potentialContactPointsIndices[i]];
            const ContactPointInfo& point2 = potentialContactPoints[manifold.potentialContactPointsIndices[j]];

            // Compute the distance between the two contact points
            const decimal distSqr = (point2.localPoint1 - point1.localPoint1).lengthSquare();

            // We have a found a duplicated contact point
            if (distSqr < distThresholdSqr) {

                // Remove the duplicated contact point
                manifold.potentialContactPointsIndices[j] = manifold.potentialContactPointsIndices[manifold.nbPotentialContactPoints-1];
                manifold.nbPotentialContactPoints--;

                j--;
            }
        }
    }
}
// Remove the duplicated contact points in a given contact manifold
Remove the duplicated contact points in a given contact manifold
Remove the duplicated contact points in a given contact manifold
void CollisionDetectionSystem::removeDuplicatedContactPointsInManifold(ContactManifoldInfo& manifold,
                                                                       const Array<ContactPointInfo>& potentialContactPoints) const {
    RP3D_PROFILE("CollisionDetectionSystem::removeDuplicatedContactPointsInManifold()", mProfiler);
    const decimal distThresholdSqr = SAME_CONTACT_POINT_DISTANCE_THRESHOLD * SAME_CONTACT_POINT_DISTANCE_THRESHOLD;
    for (uint32 i=0; i < manifold.nbPotentialContactPoints; i++) {
        for (uint32 j=i+1; j < manifold.nbPotentialContactPoints; j++) {
            const ContactPointInfo& point1 = potentialContactPoints[manifold.potentialContactPointsIndices[i]];
            const ContactPointInfo& point2 = potentialContactPoints[manifold.potentialContactPointsIndices[j]];
            const decimal distSqr = (point2.localPoint1 - point1.localPoint1).lengthSquare();
            if (distSqr < distThresholdSqr) {
                manifold.potentialContactPointsIndices[j] = manifold.potentialContactPointsIndices[manifold.nbPotentialContactPoints-1];
                manifold.nbPotentialContactPoints--;
                j--;
            }
        }
    }
}
void CollisionDetectionSystem :: removeDuplicatedContactPointsInManifold ( ContactManifoldInfo & manifold , const Array < ContactPointInfo > & potentialContactPoints ) const { RP3D_PROFILE ( " " , mProfiler ) ; const decimal distThresholdSqr = SAME_CONTACT_POINT_DISTANCE_THRESHOLD * SAME_CONTACT_POINT_DISTANCE_THRESHOLD ; for ( uint32 i = 0 ; i < manifold . nbPotentialContactPoints ; i ++ ) { for ( uint32 j = i + 1 ; j < manifold . nbPotentialContactPoints ; j ++ ) { const ContactPointInfo & point1 = potentialContactPoints [ manifold . potentialContactPointsIndices [ i ] ] ; const ContactPointInfo & point2 = potentialContactPoints [ manifold . potentialContactPointsIndices [ j ] ] ; const decimal distSqr = ( point2 . localPoint1 - point1 . localPoint1 ) . lengthSquare ( ) ; if ( distSqr < distThresholdSqr ) { manifold . potentialContactPointsIndices [ j ] = manifold . potentialContactPointsIndices [ manifold . nbPotentialContactPoints - 1 ] ; manifold . nbPotentialContactPoints -- ; j -- ; } } } }
Remove the duplicated contact points in a given contact manifold
Remove the duplicated contact points in a given contact manifold
// For each contact point of the manifold // Compute the distance between the two contact points // We have a found a duplicated contact point // Remove the duplicated contact point