@@ -182,19 +182,27 @@ bool CapsuleVsCapsuleAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseI
182
182
if (closestPointsDistanceSquare > MACHINE_EPSILON) {
183
183
184
184
decimal closestPointsDistance = std::sqrt (closestPointsDistanceSquare);
185
- closestPointsSeg1ToSeg2 /= closestPointsDistance;
185
+ decimal penetrationDepth = sumRadius - closestPointsDistance;
186
186
187
- const Vector3 contactPointCapsule1Local = capsule1ToCapsule2SpaceTransform.getInverse () * (closestPointCapsule1Seg + closestPointsSeg1ToSeg2 * capsule1Radius);
188
- const Vector3 contactPointCapsule2Local = closestPointCapsule2Seg - closestPointsSeg1ToSeg2 * capsule2Radius;
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 ) {
189
190
190
- const Vector3 normalWorld = narrowPhaseInfoBatch. narrowPhaseInfos [batchIndex]. shape2ToWorldTransform . getOrientation () * closestPointsSeg1ToSeg2 ;
191
+ closestPointsSeg1ToSeg2 /= closestPointsDistance ;
191
192
192
- decimal penetrationDepth = sumRadius - closestPointsDistance;
193
+ const Vector3 contactPointCapsule1Local = capsule1ToCapsule2SpaceTransform.getInverse () * (closestPointCapsule1Seg + closestPointsSeg1ToSeg2 * capsule1Radius);
194
+ const Vector3 contactPointCapsule2Local = closestPointCapsule2Seg - closestPointsSeg1ToSeg2 * capsule2Radius;
193
195
194
- // Create the contact info object
195
- narrowPhaseInfoBatch.addContactPoint (batchIndex, normalWorld, penetrationDepth, contactPointCapsule1Local, contactPointCapsule2Local);
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
+
201
+ narrowPhaseInfoBatch.narrowPhaseInfos [batchIndex].isColliding = true ;
202
+ isCollisionFound = true ;
203
+ }
196
204
}
197
- else { // The segment are overlapping (degenerate case)
205
+ else if (sumRadius > 0 ) { // The segment are overlapping (degenerate case)
198
206
199
207
// If the capsule segments are parralel
200
208
if (areCapsuleInnerSegmentsParralel) {
@@ -231,11 +239,11 @@ bool CapsuleVsCapsuleAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseI
231
239
// Create the contact info object
232
240
narrowPhaseInfoBatch.addContactPoint (batchIndex, normalWorld, sumRadius, contactPointCapsule1Local, contactPointCapsule2Local);
233
241
}
242
+
243
+ narrowPhaseInfoBatch.narrowPhaseInfos [batchIndex].isColliding = true ;
244
+ isCollisionFound = true ;
234
245
}
235
246
}
236
-
237
- narrowPhaseInfoBatch.narrowPhaseInfos [batchIndex].isColliding = true ;
238
- isCollisionFound = true ;
239
247
}
240
248
}
241
249
0 commit comments