Skip to content

Commit b508b87

Browse files
Update CapsuleVsCapsuleAlgorithm.cpp
restored previous change
1 parent 5807924 commit b508b87

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,24 +182,19 @@ bool CapsuleVsCapsuleAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseI
182182
if (closestPointsDistanceSquare > MACHINE_EPSILON) {
183183

184184
decimal closestPointsDistance = std::sqrt(closestPointsDistanceSquare);
185-
decimal penetrationDepth = sumRadius - closestPointsDistance;
185+
closestPointsSeg1ToSeg2 /= closestPointsDistance;
186186

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

191-
closestPointsSeg1ToSeg2 /= closestPointsDistance;
190+
const Vector3 normalWorld = narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].shape2ToWorldTransform.getOrientation() * closestPointsSeg1ToSeg2;
192191

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

196-
const Vector3 normalWorld = narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].shape2ToWorldTransform.getOrientation() * closestPointsSeg1ToSeg2;
197-
198-
// Create the contact info object
199-
narrowPhaseInfoBatch.addContactPoint(batchIndex, normalWorld, penetrationDepth, contactPointCapsule1Local, contactPointCapsule2Local);
200-
}
194+
// Create the contact info object
195+
narrowPhaseInfoBatch.addContactPoint(batchIndex, normalWorld, penetrationDepth, contactPointCapsule1Local, contactPointCapsule2Local);
201196
}
202-
else if (sumRadius > 0){ // The segment are overlapping (degenerate case)
197+
else { // The segment are overlapping (degenerate case)
203198

204199
// If the capsule segments are parralel
205200
if (areCapsuleInnerSegmentsParralel) {

0 commit comments

Comments
 (0)