Skip to content

Commit

Permalink
Fixed divison by zero in the computation of a direction vector in ccd…
Browse files Browse the repository at this point in the history
…MPRPenetration. (fixes #49)

In some cases, a touching contact is found in the findPenetr function. In this
case the direction vector is set to (0, 0, 0).
  • Loading branch information
danfis committed Dec 22, 2018
1 parent 5cac8f5 commit 7931e76
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/mpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,16 @@ static void findPenetr(const void *obj1, const void *obj2, const ccd_t *ccd,
&ccdSimplexPoint(portal, 3)->v,
pdir);
*depth = CCD_SQRT(*depth);
ccdVec3Normalize(pdir);
if (ccdIsZero(*depth)){
// If depth is zero, then we have a touching contact.
// So following findPenetrTouch(), we assign zero to
// the direction vector (it can actually be anything
// according to the decription of ccdMPRPenetration
// function).
ccdVec3Copy(pdir, ccd_vec3_origin);
}else{
ccdVec3Normalize(pdir);
}

// barycentric coordinates:
findPos(obj1, obj2, ccd, portal, pos);
Expand Down

0 comments on commit 7931e76

Please sign in to comment.