How MPR intersection and penetration testing works
masterThe Minkowski Portal Refinement (MPR) algorithm can be used for both intersection testing and penetration information.
Unlike GJK, MPR requires two additional functions for each object:
- A support function (same as GJK).
- A center function that returns the center (or any point near the center) of the object.
To use MPR:
- For intersection only: Use
ccdMPRIntersect(). - For penetration info: Use
ccdMPRPenetration(). - Set
ccd.mpr_tolerancein theccd_tstructure.
#include <ccd/ccd.h>
// Support function
void support(const void *obj, const ccd_vec3_t *dir, ccd_vec3_t *vec) { /* ... */ }
// Center function
void center(const void *_obj, ccd_vec3_t *center) {
obj_t *obj = (obj_t *)_obj;
ccdVec3Copy(center, &obj->pos);
}
int main() {
ccd_t ccd;
CCD_INIT(&ccd);
ccd.support1 = support;
ccd.support2 = support;
ccd.center1 = center;
ccd.center2 = center;
ccd.mpr_tolerance = 0.0001;
// Intersection test
int intersect = ccdMPRIntersect(obj1, obj2, &ccd);
// Penetration test
ccd_real_t depth;
ccd_vec3_t dir, pos;
int res = ccdMPRPenetration(obj1, obj2, &ccd, &depth, &dir, &pos);
}