Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CapsuleVsCapsuleAlgorithm.cpp #392

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading