Skip to content

Commit

Permalink
Merge branch 'CapsuleVsCapsuleFix' of https://github.com/robertocapua…
Browse files Browse the repository at this point in the history
…no/reactphysics3d into robertocapuano-CapsuleVsCapsuleFix
  • Loading branch information
DanielChappuis committed Sep 17, 2024
2 parents de0994d + b508b87 commit f0cfae4
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,19 @@ bool CapsuleVsCapsuleAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseI
if (closestPointsDistanceSquare > MACHINE_EPSILON) {

decimal closestPointsDistance = std::sqrt(closestPointsDistanceSquare);
decimal penetrationDepth = sumRadius - closestPointsDistance;
closestPointsSeg1ToSeg2 /= closestPointsDistance;

// Make sure the penetration depth is not zero (even if the previous condition test was true the penetration depth can still be
// zero because of precision issue of the computation at the previous line)
if (penetrationDepth > 0) {
const Vector3 contactPointCapsule1Local = capsule1ToCapsule2SpaceTransform.getInverse() * (closestPointCapsule1Seg + closestPointsSeg1ToSeg2 * capsule1Radius);
const Vector3 contactPointCapsule2Local = closestPointCapsule2Seg - closestPointsSeg1ToSeg2 * capsule2Radius;

closestPointsSeg1ToSeg2 /= closestPointsDistance;
const Vector3 normalWorld = narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].shape2ToWorldTransform.getOrientation() * closestPointsSeg1ToSeg2;

const Vector3 contactPointCapsule1Local = capsule1ToCapsule2SpaceTransform.getInverse() * (closestPointCapsule1Seg + closestPointsSeg1ToSeg2 * capsule1Radius);
const Vector3 contactPointCapsule2Local = closestPointCapsule2Seg - closestPointsSeg1ToSeg2 * capsule2Radius;
decimal penetrationDepth = std::max(sumRadius - closestPointsDistance, MACHINE_EPSILON);

const Vector3 normalWorld = narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].shape2ToWorldTransform.getOrientation() * closestPointsSeg1ToSeg2;

// Create the contact info object
narrowPhaseInfoBatch.addContactPoint(batchIndex, normalWorld, penetrationDepth, contactPointCapsule1Local, contactPointCapsule2Local);
}
// Create the contact info object
narrowPhaseInfoBatch.addContactPoint(batchIndex, normalWorld, penetrationDepth, contactPointCapsule1Local, contactPointCapsule2Local);
}
else if (sumRadius > 0){ // The segment are overlapping (degenerate case)
else { // The segment are overlapping (degenerate case)

// If the capsule segments are parralel
if (areCapsuleInnerSegmentsParralel) {
Expand Down

0 comments on commit f0cfae4

Please sign in to comment.