9 #define REAL_infinity 1.0e30
10 #define REAL_EQUAL(a,b) (((a < b + EPSILON) && (a > b - EPSILON)) ? true : false)
11 #define REAL_GREAT(a,b) ((a > EPSILON + b)? true: false)
12 #define REAL_LESS(a,b) ((a + EPSILON < b)? true: false)
19 template<
typename Real>
25 template<
typename Real>
38 template<
typename Real>
55 template<
typename Real>
68 axisNormal = normal * l;
92 template<
typename Real>
94 DYN_FUNC
void computeReferenceEdgesAndBasis(
unsigned char* out,
SquareMatrix<Real, 3>* basis,
Vector<Real, 3>* e,
const Vector<Real, 3>& eR,
const Transform<Real, 3>& rtx,
Vector<Real, 3> n,
int axis)
96 n = rtx.rotation().transpose()*n;
101 auto rot_t = rtx.rotation();
116 outB.setCol(0, rot_t.col(1));
117 outB.setCol(1, rot_t.col(2));
118 outB.setCol(2, rot_t.col(0));
129 outB.setCol(0, rot_t.col(2));
130 outB.setCol(1, rot_t.col(1));
131 outB.setCol(2, -rot_t.col(0));
145 outB.setCol(0, rot_t.col(2));
146 outB.setCol(1, rot_t.col(0));
147 outB.setCol(2, rot_t.col(1));
158 outB.setCol(0, rot_t.col(2));
159 outB.setCol(1, -rot_t.col(0));
160 outB.setCol(2, -rot_t.col(1));
174 outB.setCol(0, -rot_t.col(1));
175 outB.setCol(1, rot_t.col(0));
176 outB.setCol(2, rot_t.col(2));
187 outB.setCol(0, -rot_t.col(1));
188 outB.setCol(1, -rot_t.col(0));
189 outB.setCol(2, -rot_t.col(2));
198 template<
typename Real>
201 n = -itx.rotation().transpose()*n;
204 if (absN.x > absN.y && absN.x > absN.z)
221 else if (absN.y > absN.x && absN.y > absN.z)
256 for (
int i = 0; i < 4; ++i)
257 out[i].v = itx * out[i].v;
261#define InFront( a ) \
265 ((a) >= float( 0.0 ))
268 ((a) < float( 0.005 ) && (a) > -float( 0.005 ))
270 template<
typename Real>
276 for (
int i = 0; i < inCount; ++i)
293 cv.
v = a.
v + (b.
v - a.
v) * (da / (da - db));
294 out[outCount++] = cv;
298 cv.
v = a.
v + (b.
v - a.
v) * (da / (da - db));
299 out[outCount++] = cv;
311 template<
typename Real>
319 for (
int i = 0; i < 4; ++i)
320 in[i].v = basis.transpose()*(incident[i].
v - rPos);
332 outCount =
orthographic(out,
Real(-1.0), e.x, 0, clipEdges[2], in, inCount);
337 inCount =
orthographic(in,
Real(-1.0), e.y, 1, clipEdges[3], out, outCount);
341 for (
int i = 0; i < inCount; ++i)
343 Real d = in[i].
v.z - e.z;
347 outVerts[outCount].
v = basis * in[i].
v + rPos;
348 outDepths[outCount++] = d;
358 template<
typename Real>
359 DYN_FUNC
inline void edgesContact(
Vector<Real, 3>& CA,
Vector<Real, 3>& CB,
const Vector<Real, 3>& PA,
const Vector<Real, 3>& QA,
const Vector<Real, 3>& PB,
const Vector<Real, 3>& QB)
370 Real denom = a * e - b * b;
372 Real TA = (b * f - c * e) / denom;
373 Real TB = (b * TA + f) / e;
380 template<
typename Real>
386 Real& intersectionDistance,
391 if (!((lowerBoundaryA > upperBoundaryB) || (lowerBoundaryB > upperBoundaryA)))
395 if (lowerBoundaryA < lowerBoundaryB)
397 if (upperBoundaryA > upperBoundaryB)
401 if (upperBoundaryB - lowerBoundaryA > upperBoundaryA - lowerBoundaryB)
405 boundaryA = upperBoundaryA;
406 boundaryB = lowerBoundaryB;
407 intersectionDistance = - (upperBoundaryA - lowerBoundaryB);
413 boundaryA = lowerBoundaryA;
414 boundaryB = upperBoundaryB;
415 intersectionDistance = - (upperBoundaryB - lowerBoundaryA);
422 boundaryA = upperBoundaryA;
423 boundaryB = lowerBoundaryB;
424 intersectionDistance = - (upperBoundaryA - lowerBoundaryB);
429 if (upperBoundaryA > upperBoundaryB)
433 boundaryA = lowerBoundaryA;
434 boundaryB = upperBoundaryB;
435 intersectionDistance = - (upperBoundaryB - lowerBoundaryA);
442 if (upperBoundaryB - lowerBoundaryA > upperBoundaryA - lowerBoundaryB)
446 boundaryA = upperBoundaryA;
447 boundaryB = lowerBoundaryB;
448 intersectionDistance = - (upperBoundaryA - lowerBoundaryB);
454 boundaryA = lowerBoundaryA;
455 boundaryB = upperBoundaryB;
456 intersectionDistance = - (upperBoundaryB - lowerBoundaryA);
466 if (upperBoundaryA < lowerBoundaryB)
468 boundaryA = upperBoundaryA;
469 boundaryB = lowerBoundaryB;
470 intersectionDistance = (lowerBoundaryB - upperBoundaryA);
473 if (upperBoundaryB < lowerBoundaryA)
475 boundaryA = lowerBoundaryA;
476 boundaryB = upperBoundaryB;
477 intersectionDistance = (lowerBoundaryA - upperBoundaryB);
482 template<
typename Real>
489 template<
typename Real>
495 Real currentBoundaryA,
496 Real currentBoundaryB,
504 currentN = ( (currentBoundaryB < currentBoundaryA) ^ (
REAL_LESS(currentDepth, 0)) ) ? -currentN : currentN;
507 depth = currentDepth;
509 boundaryA = currentBoundaryA;
510 boundaryB = currentBoundaryB;
514 template<
typename Real,
typename ShapeA,
typename ShapeB>
518 Real lowerBoundaryA, upperBoundaryA, lowerBoundaryB, upperBoundaryB;
521 projectOnAxis(lowerBoundaryA, upperBoundaryA, axisNormal, shapeA, radiusA);
522 projectOnAxis(lowerBoundaryB, upperBoundaryB, axisNormal, shapeB, radiusB);
524 checkSignedDistance(lowerBoundaryA, upperBoundaryA, lowerBoundaryB, upperBoundaryB, intersectionDistance, BoundaryA, BoundaryB);
528 template<
typename Real,
typename ShapeA,
typename ShapeB>
544 if (
N.norm() >
EPSILON)
N /=
N.norm();
else return;
552 template<
typename Real,
typename ShapeA,
typename ShapeB>
566 Vec3f N = dirA.cross(dirB);
569 if (
N.norm() >
EPSILON)
N /=
N.norm();
else return;
576 template<
typename Real,
typename ShapeA,
typename ShapeB>
590 if (
N.norm() >
EPSILON)
N /=
N.norm();
else return;
594 for (
int i = 0; i < 3; ++i)
596 sat.
update(type, bA, bB, D,
N, tri.
v[0], tri.
v[1], tri.
v[2]);
599 template<
typename Real,
typename ShapeA,
typename ShapeB>
613 if (
N.norm() >
EPSILON)
N /=
N.norm();
else return;
617 for (
int i = 0; i < 4; ++i)
619 sat.
update(type, bA, bB, D,
N, rect.
center, rect.
axis[0], rect.
axis[1],
Vec3f(rect.
extent[0], rect.
extent[1], 0.f));
623 template<
typename Real>
627 const Vec3f axisNormal,
632 lowerBoundary = upperBoundary = sphere.
center.dot(axisNormal);
634 lowerBoundary -= radius + sphere.
radius;
635 upperBoundary += radius + sphere.
radius;
638 template<
typename Real>
650 template<
typename Real>
662 template<
typename Real>
675 template<
typename Real>
679 const Vec3f axisNormal,
684 Real t = seg.
v0.dot(axisNormal); lowerBoundary = upperBoundary = t;
685 t = seg.
v1.dot(axisNormal); lowerBoundary = glm::min(lowerBoundary, t); upperBoundary = glm::max(upperBoundary, t);
687 lowerBoundary -= radius;
688 upperBoundary += radius;
691 template<
typename Real>
714 template<
typename Real>
736 template<
typename Real>
753 transA = m.
normal * (radiusA + depth);
754 transB = -m.
normal * radiusB;
756 for (
int i = 0; i < num; ++i) m.
pushContact(q[i], depth);
761 transA = m.
normal * (radiusA + depth);
762 transB = -m.
normal * radiusB;
764 for (
int i = 0; i < num; ++i) m.
pushContact(q[i], depth);
866 template<
typename Real>
870 const Vec3f axisNormal,
875 Real t = tri.
v[0].dot(axisNormal); lowerBoundary = upperBoundary = t;
876 t = tri.
v[1].dot(axisNormal); lowerBoundary = glm::min(lowerBoundary, t); upperBoundary = glm::max(upperBoundary, t);
877 t = tri.
v[2].dot(axisNormal); lowerBoundary = glm::min(lowerBoundary, t); upperBoundary = glm::max(upperBoundary, t);
879 lowerBoundary -= radius;
880 upperBoundary += radius;
883 template<
typename Real>
906 template<
typename Real>
928 template<
typename Real,
typename Shape>
946 transA = m.
normal * (radiusA + depth);
947 transB = -m.
normal * radiusB;
949 for (
int i = 0; i < num; ++i) m.
pushContact(q[i], depth);
954 transA = m.
normal * (radiusA + depth);
955 transB = -m.
normal * radiusB;
957 for (
int i = 0; i < num; ++i) m.
pushContact(q[i], depth);
962 transA = m.
normal * (radiusA + depth);
963 transB = -m.
normal * (radiusB);
965 for (
int i = 0; i < num; ++i) m.
pushContact(q[i], depth);
970 template<
typename Real>
974 const Vec3f axisNormal,
979 Real t = tet.
v[0].dot(axisNormal); lowerBoundary = upperBoundary = t;
980 t = tet.
v[1].dot(axisNormal); lowerBoundary = glm::min(lowerBoundary, t); upperBoundary = glm::max(upperBoundary, t);
981 t = tet.
v[2].dot(axisNormal); lowerBoundary = glm::min(lowerBoundary, t); upperBoundary = glm::max(upperBoundary, t);
982 t = tet.
v[3].dot(axisNormal); lowerBoundary = glm::min(lowerBoundary, t); upperBoundary = glm::max(upperBoundary, t);
984 lowerBoundary -= radius;
985 upperBoundary += radius;
988 template<
typename Real>
998 Tet3D tetTB =
Tet3D(tetB.
v[0] + transB, tetB.
v[1] + transB, tetB.
v[2] + transB, tetB.
v[3] + transB);
1011 template<
typename Real>
1021 Tet3D tetT =
Tet3D(tetB.
v[0] + transB, tetB.
v[1] + transB, tetB.
v[2] + transB, tetB.
v[3] + transB);
1033 template<
typename Real,
typename Shape>
1037 const Shape& shapeA,
1051 transA = m.
normal * (radiusA + depth);
1052 transB = -m.
normal * radiusB;
1054 for (
int i = 0; i < num; ++i) m.
pushContact(q[i], depth);
1059 transA = m.
normal * (radiusA + depth);
1060 transB = -m.
normal * radiusB;
1062 for (
int i = 0; i < num; ++i) m.
pushContact(q[i], depth);
1067 transA = m.
normal * (radiusA + depth);
1068 transB = -m.
normal * (radiusB);
1070 for (
int i = 0; i < num; ++i) m.
pushContact(q[i], depth);
1075 template<
typename Real>
1077 Real& lowerBoundary,
1078 Real& upperBoundary,
1079 const Vec3f axisNormal,
1091 p = (center - u * extent[0] - v * extent[1] - w * extent[2]);
1092 Real t = p.dot(axisNormal); lowerBoundary = upperBoundary = t;
1094 p = (center - u * extent[0] - v * extent[1] + w * extent[2]);
1095 t = p.dot(axisNormal); lowerBoundary = glm::min(lowerBoundary, t); upperBoundary = glm::max(upperBoundary, t);
1097 p = (center - u * extent[0] + v * extent[1] - w * extent[2]);
1098 t = p.dot(axisNormal); lowerBoundary = glm::min(lowerBoundary, t); upperBoundary = glm::max(upperBoundary, t);
1100 p = (center - u * extent[0] + v * extent[1] + w * extent[2]);
1101 t = p.dot(axisNormal); lowerBoundary = glm::min(lowerBoundary, t); upperBoundary = glm::max(upperBoundary, t);
1103 p = (center + u * extent[0] - v * extent[1] - w * extent[2]);
1104 t = p.dot(axisNormal); lowerBoundary = glm::min(lowerBoundary, t); upperBoundary = glm::max(upperBoundary, t);
1106 p = (center + u * extent[0] - v * extent[1] + w * extent[2]);
1107 t = p.dot(axisNormal); lowerBoundary = glm::min(lowerBoundary, t); upperBoundary = glm::max(upperBoundary, t);
1109 p = (center + u * extent[0] + v * extent[1] - w * extent[2]);
1110 t = p.dot(axisNormal); lowerBoundary = glm::min(lowerBoundary, t); upperBoundary = glm::max(upperBoundary, t);
1112 p = (center + u * extent[0] + v * extent[1] + w * extent[2]);
1113 t = p.dot(axisNormal); lowerBoundary = glm::min(lowerBoundary, t); upperBoundary = glm::max(upperBoundary, t);
1115 lowerBoundary -= radius;
1116 upperBoundary += radius;
1119 template<
typename Real>
1142 template<
typename Real>
1165 template<
typename Real,
typename Shape>
1169 const Shape& shapeA,
1183 transA = m.
normal * (radiusA + depth);
1184 transB = -m.
normal * radiusB;
1186 for (
int i = 0; i < num; ++i) m.
pushContact(q[i], depth);
1191 transA = m.
normal * (radiusA + depth);
1192 transB = -m.
normal * radiusB;
1194 for (
int i = 0; i < num; ++i) m.
pushContact(q[i], depth);
1199 transA = m.
normal * (radiusA + depth);
1200 transB = -m.
normal * (radiusB);
1202 for (
int i = 0; i < num; ++i) m.
pushContact(q[i], depth);
1208 template<
typename Real>
1220 template<
typename Real>
1225 MSDF(sat, sphereA, sphereB, radiusA, radiusB);
1238 template<
typename Real>
1248 checkAxisP(projP.
origin, pB);
1252 template<
typename Real>
1257 MSDF(sat, segB, sphereA, radiusB, radiusA);
1278 template<
typename Real>
1283 MSDF(sat, segA, sphereB, radiusA, radiusB);
1304 template<
typename Real>
1314 checkAxisP(projP.
origin, pB);
1319 template<
typename Real>
1324 MSDF(sat, triB, sphereA, radiusB, radiusA);
1337 template<
typename Real>
1342 MSDF(sat, triA, sphereB, radiusA, radiusB);
1363 template<
typename Real>
1373 checkAxisP(projP.
origin, pB);
1376 template<
typename Real>
1381 MSDF(sat, tetB, sphereA, radiusB, radiusA);
1395 template<
typename Real>
1400 MSDF(sat, tetA, sphereB, radiusA, radiusB);
1421 template<
typename Real>
1431 checkAxisP(projP.
origin, pB);
1434 template<
typename Real>
1439 MSDF(sat, boxB, sphereA, radiusB, radiusA);
1452 template<
typename Real>
1457 MSDF(sat, boxA, sphereB, radiusA, radiusB);
1471 template<
typename Real>
1479 for (
int j = 0; j < 2; j++)
1481 Vec3f pB = (j == 0) ? (segB.
v0) : (segB.
v1);
1484 checkAxisP(projP.
origin, pB);
1486 for (
int j = 0; j < 2; j++)
1488 Vec3f pA = (j == 0) ? (segA.
v0) : (segA.
v1);
1491 checkAxisP(pA, projP.
origin);
1496 checkAxisE(segA, segB);
1536 template<
typename Real>
1541 MSDF(sat, segA, segB, radiusA, radiusB);
1562 template<
typename Real>
1575 checkAxisE(
Segment3D(triA.
v[0], triA.
v[1]), segB);
1576 checkAxisE(
Segment3D(triA.
v[0], triA.
v[2]), segB);
1577 checkAxisE(
Segment3D(triA.
v[1], triA.
v[2]), segB);
1582 for (
int j = 0; j < 2; j++)
1584 Vec3f pB = (j == 0) ? (segB.
v0) : (segB.
v1);
1587 checkAxisP(projP.
origin, pB);
1590 for (
int j = 0; j < 3; j++)
1595 checkAxisP(pA, projP.
origin);
1647 template<
typename Real>
1652 MSDF(sat, triA, segB, radiusA, radiusB);
1666 template<
typename Real>
1671 MSDF(sat, triB, segA, radiusB, radiusA);
1686 template<
typename Real>
1695 checkAxisT(tetA.
face(0));
1696 checkAxisT(tetA.
face(1));
1697 checkAxisT(tetA.
face(2));
1698 checkAxisT(tetA.
face(3));
1702 checkAxisE(
Segment3D(tetA.
v[0], tetA.
v[1]), segB);
1703 checkAxisE(
Segment3D(tetA.
v[0], tetA.
v[2]), segB);
1704 checkAxisE(
Segment3D(tetA.
v[1], tetA.
v[2]), segB);
1705 checkAxisE(
Segment3D(tetA.
v[0], tetA.
v[3]), segB);
1706 checkAxisE(
Segment3D(tetA.
v[1], tetA.
v[3]), segB);
1707 checkAxisE(
Segment3D(tetA.
v[2], tetA.
v[3]), segB);
1712 for (
int j = 0; j < 2; j++)
1714 Vec3f pB = (j == 0) ? (segB.
v0) : (segB.
v1);
1717 checkAxisP(projP.
origin, pB);
1720 for (
int j = 0; j < 4; j++)
1725 checkAxisP(pA, projP.
origin);
1839 template<
typename Real>
1844 MSDF(sat, tetB, segA, radiusB, radiusA);
1857 template<
typename Real>
1862 MSDF(sat, tetA, segB, radiusA, radiusB);
1878 template<
typename Real>
1888 for (
int j = 0; j < 6; j++)
1896 for (
int j = 0; j < 12; j++)
1899 checkAxisE(edgeA, segB);
1904 for (
int j = 0; j < 2; j++)
1906 Vec3f pB = (j == 0) ? (segB.
v0) : (segB.
v1);
1909 checkAxisP(projP.
origin, pB);
1912 for (
int j = 0; j < 8; j++)
1917 checkAxisP(pA, projP.
origin);
2042 template<
typename Real>
2047 MSDF(sat, boxB, segA, radiusB, radiusA);
2061 template<
typename Real>
2066 MSDF(sat, boxA, segB, radiusA, radiusB);
2082 template<
typename Real>
2087 auto checkAxisT = [&](
Triangle3D face,
auto type) {
checkAxisTri(sat, triA, triB, radiusA, radiusB, face, type); };
2097 for (
int i = 0; i < 3; i++)
2098 for (
int j = 0; j < 3; j++)
2100 int ni = (i == 2) ? 0 : i + 1;
2101 int nj = (j == 2) ? 0 : j + 1;
2106 for (
int j = 0; j < 3; j++)
2111 checkAxisP(pA, projP.
origin);
2114 for (
int j = 0; j < 3; j++)
2119 checkAxisP(projP.
origin, pB);
2172 template<
typename Real>
2177 MSDF(sat, triA, triB, radiusA, radiusB);
2192 template<
typename Real>
2197 auto checkAxisT = [&](
Triangle3D face,
auto type) {
checkAxisTri(sat, tetA, triB, radiusA, radiusB, face, type); };
2210 for (
int i = 0; i < 6; i++)
2211 for (
int j = 0; j < 3; j++)
2213 int nj = (j == 2) ? 0 : j + 1;
2218 for (
int j = 0; j < 4; j++)
2223 checkAxisP(pA, projP.
origin);
2226 for (
int j = 0; j < 3; j++)
2231 checkAxisP(projP.
origin, pB);
2290 template<
typename Real>
2295 MSDF(sat, tetB, triA, radiusA, radiusB);
2308 template<
typename Real>
2313 MSDF(sat, tetA, triB, radiusA, radiusB);
2327 template<
typename Real>
2337 for (
int j = 0; j < 6; j++) checkAxisR(boxA.
face(j));
2342 for (
int i = 0; i < 12; i++)
2343 for (
int j = 0; j < 3; j++)
2345 int nj = (j == 2) ? 0 : j + 1;
2350 for (
int j = 0; j < 8; j++)
2355 checkAxisP(pA, projP.
origin);
2358 for (
int j = 0; j < 3; j++)
2363 checkAxisP(projP.
origin, pB);
2420 template<
typename Real>
2425 MSDF(sat, boxB, triA, radiusA, radiusB);
2438 template<
typename Real>
2443 MSDF(sat, boxA, triB, radiusA, radiusB);
2457 template<
typename Real>
2462 auto checkAxisT = [&](
Triangle3D face,
auto type) {
checkAxisTri(sat, tetA, tetB, radiusA, radiusB, face, type); };
2478 for (
int i = 0; i < 6; i++)
2479 for (
int j = 0; j < 6; j++)
2483 checkAxisE(edgeA, edgeB);
2488 for (
int j = 0; j < 4; j++)
2493 checkAxisP(pA, projP.
origin);
2496 for (
int j = 0; j < 4; j++)
2501 checkAxisP(pA, projP.
origin);
2564 template<
typename Real>
2569 MSDF(sat, tetA, tetB, radiusA, radiusB);
2583 template<
typename Real>
2594 for (
int j = 0; j < 6; j++) checkAxisR(boxA.
face(j));
2595 checkAxisT(tetB.
face(0));
2596 checkAxisT(tetB.
face(1));
2597 checkAxisT(tetB.
face(2));
2598 checkAxisT(tetB.
face(3));
2603 for (
int i = 0; i < 12; i++)
2604 for (
int j = 0; j < 6; j++)
2606 checkAxisE(boxA.
edge(i), tetB.
edge(j));
2610 for (
int j = 0; j < 8; j++)
2615 checkAxisP(pA, projP.
origin);
2618 for (
int j = 0; j < 4; j++)
2623 checkAxisP(projP.
origin, pB);
2683 template<
typename Real>
2688 MSDF(sat, boxB, tetA, radiusA, radiusB);
2701 template<
typename Real>
2706 MSDF(sat, boxA, tetB, radiusA, radiusB);
2720 template<
typename Real>
2725 auto checkAxisR = [&](
Rectangle3D face,
auto type) {
checkAxisRect(sat, boxA, boxB, radiusA, radiusB, face, type); };
2730 for (
int j = 0; j < 6; j++) checkAxisR(boxA.
face(j),
CT_RECTA);
2731 for (
int j = 0; j < 6; j++) checkAxisR(boxB.
face(j),
CT_RECTB);
2736 for (
int i = 0; i < 12; i++)
2737 for (
int j = 0; j < 12; j++)
2739 checkAxisE(boxA.
edge(i), boxB.
edge(j));
2743 for (
int j = 0; j < 8; j++)
2748 checkAxisP(pA, projP.
origin);
2751 for (
int j = 0; j < 8; j++)
2756 checkAxisP(projP.
origin, pB);
2815 template<
typename Real>
2820 MSDF(sat, boxA, boxB, radiusA, radiusB);
2834 template<
typename Real>
2835 DYN_FUNC
void computeSupportEdge(
Vector<Real, 3>& aOut,
Vector<Real, 3>& bOut,
const SquareMatrix<Real, 3>& rot,
const Vector<Real, 3>& trans,
const Vector<Real, 3>& e,
Vector<Real, 3> n)
2837 n = rot.transpose()*n;
2842 if (absN.x > absN.y)
2845 if (absN.y > absN.z)
2862 if (absN.x > absN.z)
2886 aOut = rot * a + trans;
2887 bOut = rot * b + trans;
2890 template<
typename Real>
2901 rotA.setCol(0, box0.
u);
2902 rotA.setCol(1, box0.
v);
2903 rotA.setCol(2, box0.
w);
2906 rotB.setCol(0, box1.
u);
2907 rotB.setCol(1, box1.
v);
2908 rotB.setCol(2, box1.
w);
2911 Matrix3D C = rotA.transpose() * rotB;
2913 bool parallel =
false;
2914 const float kCosTol = float(1.0e-6);
2915 for (
int i = 0; i < 3; ++i)
2917 for (
int j = 0; j < 3; ++j)
2919 float val =
abs(C(i, j));
2922 if (val + kCosTol >=
float(1.0))
2928 Matrix3D absC_t = absC.transpose();
2984 rA = eA.y * absC(2, 0) + eA.z * absC(1, 0);
2985 rB = eB.y * absC(0, 2) + eB.z * absC(0, 1);
2986 s =
abs(t.z * C(1, 0) - t.y * C(2, 0)) - (rA + rB);
2987 if (
trackEdgeAxis(eAxis, eMax, nE, 6, s,
Vector<Real, 3>(
float(0.0), -C(2, 0), C(1, 0))))
2991 rA = eA.y * absC(2, 1) + eA.z * absC(1, 1);
2992 rB = eB.x * absC(0, 2) + eB.z * absC(0, 0);
2993 s =
abs(t.z * C(1, 1) - t.y * C(2, 1)) - (rA + rB);
2994 if (
trackEdgeAxis(eAxis, eMax, nE, 7, s,
Vector<Real, 3>(
float(0.0), -C(2, 1), C(1, 1))))
2998 rA = eA.y * absC(2, 2) + eA.z * absC(1, 2);
2999 rB = eB.x * absC(0, 1) + eB.y * absC(0, 0);
3000 s =
abs(t.z * C(1, 2) - t.y * C(2, 2)) - (rA + rB);
3001 if (
trackEdgeAxis(eAxis, eMax, nE, 8, s,
Vector<Real, 3>(
float(0.0), -C(2, 2), C(1, 2))))
3005 rA = eA.x * absC(2, 0) + eA.z * absC(0, 0);
3006 rB = eB.y * absC(1, 2) + eB.z * absC(1, 1);
3007 s =
abs(t.x * C(2, 0) - t.z * C(0, 0)) - (rA + rB);
3008 if (
trackEdgeAxis(eAxis, eMax, nE, 9, s,
Vector<Real, 3>(C(2, 0),
float(0.0), -C(0, 0))))
3012 rA = eA.x * absC(2, 1) + eA.z * absC(0, 1);
3013 rB = eB.x * absC(1, 2) + eB.z * absC(1, 0);
3014 s =
abs(t.x * C(2, 1) - t.z * C(0, 1)) - (rA + rB);
3015 if (
trackEdgeAxis(eAxis, eMax, nE, 10, s,
Vector<Real, 3>(C(2, 1),
float(0.0), -C(0, 1))))
3019 rA = eA.x * absC(2, 2) + eA.z * absC(0, 2);
3020 rB = eB.x * absC(1, 1) + eB.y * absC(1, 0);
3021 s =
abs(t.x * C(2, 2) - t.z * C(0, 2)) - (rA + rB);
3022 if (
trackEdgeAxis(eAxis, eMax, nE, 11, s,
Vector<Real, 3>(C(2, 2),
float(0.0), -C(0, 2))))
3026 rA = eA.x * absC(1, 0) + eA.y * absC(0, 0);
3027 rB = eB.y * absC(2, 2) + eB.z * absC(2, 1);
3028 s =
abs(t.y * C(0, 0) - t.x * C(1, 0)) - (rA + rB);
3029 if (
trackEdgeAxis(eAxis, eMax, nE, 12, s,
Vector<Real, 3>(-C(1, 0), C(0, 0),
float(0.0))))
3033 rA = eA.x * absC(1, 1) + eA.y * absC(0, 1);
3034 rB = eB.x * absC(2, 2) + eB.z * absC(2, 0);
3035 s =
abs(t.y * C(0, 1) - t.x * C(1, 1)) - (rA + rB);
3036 if (
trackEdgeAxis(eAxis, eMax, nE, 13, s,
Vector<Real, 3>(-C(1, 1), C(0, 1),
float(0.0))))
3040 rA = eA.x * absC(1, 2) + eA.y * absC(0, 2);
3041 rB = eB.x * absC(2, 1) + eB.y * absC(2, 0);
3042 s =
abs(t.y * C(0, 2) - t.x * C(1, 2)) - (rA + rB);
3043 if (
trackEdgeAxis(eAxis, eMax, nE, 14, s,
Vector<Real, 3>(-C(1, 2), C(0, 2),
float(0.0))))
3048 const float kRelTol = float(0.95);
3049 const float kAbsTol = float(0.01);
3053 float faceMax = std::max(aMax, bMax);
3054 if (kRelTol * eMax > faceMax + kAbsTol)
3062 if (kRelTol * bMax > aMax + kAbsTol)
3076 if (n.dot(v) <
float(0.0))
3114 unsigned char clipEdges[4];
3123 outNum =
clip(out, depths, rtx.translation(), e, clipEdges, basis, incident);
3128 m.
normal = flip ? -n : n;
3130 for (
int i = 0; i < outNum; ++i)
3132 m.
contacts[i].position = flip ? (out[i].
v + depths[i] * m.
normal) : out[i].
v;
3133 m.
contacts[i].penetration = depths[i];
3141 if (n.dot(v) <
float(0.0))
3160 template<
typename Real>
3169 bool bInside = c0.
inside(box);
3171 Segment3D dir = bInside ? c0 - vproj : vproj - c0;
3184 template<
typename Real>
3209 template<
typename Real>
3233 template<
typename Real>
3241 template<
typename Real>
3243 Real& lowerBoundary1,
3244 Real& upperBoundary1,
3245 Real& lowerBoundary2,
3246 Real& upperBoundary2,
3247 Real& intersectionDistance,
3259 lowerBoundary1 = seg.
v0.dot(axisNormal) - cap.
radius;
3260 upperBoundary1 = seg.
v0.dot(axisNormal) + cap.
radius;
3261 lowerBoundary1 = glm::min(lowerBoundary1, seg.
v1.dot(axisNormal) - cap.
radius);
3262 upperBoundary1 = glm::max(upperBoundary1, seg.
v1.dot(axisNormal) + cap.
radius);
3271 p = (center - u * extent[0] - v * extent[1] - w * extent[2]);
3272 lowerBoundary2 = upperBoundary2 = p.dot(axisNormal);
3274 p = (center - u * extent[0] - v * extent[1] + w * extent[2]);
3275 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
3276 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
3278 p = (center - u * extent[0] + v * extent[1] - w * extent[2]);
3279 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
3280 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
3282 p = (center - u * extent[0] + v * extent[1] + w * extent[2]);
3283 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
3284 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
3286 p = (center + u * extent[0] - v * extent[1] - w * extent[2]);
3287 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
3288 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
3290 p = (center + u * extent[0] - v * extent[1] + w * extent[2]);
3291 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
3292 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
3294 p = (center + u * extent[0] + v * extent[1] - w * extent[2]);
3295 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
3296 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
3298 p = (center + u * extent[0] + v * extent[1] + w * extent[2]);
3299 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
3300 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
3302 return checkOverlap(lowerBoundary1, upperBoundary1, lowerBoundary2, upperBoundary2, intersectionDistance, boundary1, boundary2);
3305 template<
typename Real>
3307 Real lowerBoundary1,
3308 Real upperBoundary1,
3309 Real lowerBoundary2,
3310 Real upperBoundary2,
3311 Real& intersectionDistance,
3316 if (!((lowerBoundary1 > upperBoundary2) || (lowerBoundary2 > upperBoundary1)))
3318 if (lowerBoundary1 < lowerBoundary2)
3320 if (upperBoundary1 > upperBoundary2)
3322 if (upperBoundary2 - lowerBoundary1 > upperBoundary1 - lowerBoundary2)
3324 boundary1 = upperBoundary1;
3325 boundary2 = lowerBoundary2;
3326 intersectionDistance =
abs(boundary1 - boundary2);
3330 boundary1 = lowerBoundary1;
3331 boundary2 = upperBoundary2;
3332 intersectionDistance =
abs(boundary1 - boundary2);
3337 intersectionDistance = upperBoundary1 - lowerBoundary2;
3338 boundary1 = upperBoundary1;
3339 boundary2 = lowerBoundary2;
3344 if (upperBoundary1 > upperBoundary2)
3346 intersectionDistance = upperBoundary2 - lowerBoundary1;
3347 boundary1 = lowerBoundary1;
3348 boundary2 = upperBoundary2;
3353 if (upperBoundary2 - lowerBoundary1 > upperBoundary1 - lowerBoundary2)
3355 boundary1 = upperBoundary1;
3356 boundary2 = lowerBoundary2;
3357 intersectionDistance =
abs(boundary1 - boundary2);
3361 boundary1 = lowerBoundary1;
3362 boundary2 = upperBoundary2;
3363 intersectionDistance =
abs(boundary1 - boundary2);
3369 intersectionDistance =
Real(0.0f);
3373 template<
typename Real>
3375 Real& lowerBoundary1,
3376 Real& upperBoundary1,
3377 Real& lowerBoundary2,
3378 Real& upperBoundary2,
3379 Real& intersectionDistance,
3390 lowerBoundary1 = seg.
v0.dot(axisNormal) - cap.
radius;
3391 upperBoundary1 = seg.
v0.dot(axisNormal) + cap.
radius;
3392 lowerBoundary1 = glm::min(lowerBoundary1, seg.
v1.dot(axisNormal) - cap.
radius);
3393 upperBoundary1 = glm::max(upperBoundary1, seg.
v1.dot(axisNormal) + cap.
radius);
3395 for (
int i = 0; i < 4; i++)
3400 lowerBoundary2 = upperBoundary2 = tet.
v[0].dot(axisNormal);
3404 lowerBoundary2 = glm::min(lowerBoundary2, tet.
v[i].dot(axisNormal));
3405 upperBoundary2 = glm::max(upperBoundary2, tet.
v[i].dot(axisNormal));
3410 return checkOverlapTetTri(lowerBoundary1, upperBoundary1, lowerBoundary2, upperBoundary2, intersectionDistance, boundary1, boundary2);
3414 template<
typename Real>
3436 Real boundaryMin = glm::min(boundary1, boundary2);
3437 Real boundaryMax = glm::max(boundary1, boundary2);
3440 if (
abs(cap.
endPoint().dot(axisNormal) - boundaryMin) <
abs(depth))
3441 boundaryPoints1[cnt1++] = cap.
endPoint();
3450 p = (center - u * extent[0] - v * extent[1] - w * extent[2]);
3451 if (
abs(p.dot(axisNormal) - boundaryMin) <
abs(depth))
3452 boundaryPoints2[cnt2++] = p;
3454 p = (center - u * extent[0] - v * extent[1] + w * extent[2]);
3455 if (
abs(p.dot(axisNormal) - boundaryMin) <
abs(depth))
3456 boundaryPoints2[cnt2++] = p;
3458 p = (center - u * extent[0] + v * extent[1] - w * extent[2]);
3459 if (
abs(p.dot(axisNormal) - boundaryMin) <
abs(depth))
3460 boundaryPoints2[cnt2++] = p;
3462 p = (center - u * extent[0] + v * extent[1] + w * extent[2]);
3463 if (
abs(p.dot(axisNormal) - boundaryMin) <
abs(depth))
3464 boundaryPoints2[cnt2++] = p;
3466 p = (center + u * extent[0] - v * extent[1] - w * extent[2]);
3467 if (
abs(p.dot(axisNormal) - boundaryMin) <
abs(depth))
3468 boundaryPoints2[cnt2++] = p;
3470 p = (center + u * extent[0] - v * extent[1] + w * extent[2]);
3471 if (
abs(p.dot(axisNormal) - boundaryMin) <
abs(depth))
3472 boundaryPoints2[cnt2++] = p;
3474 p = (center + u * extent[0] + v * extent[1] - w * extent[2]);
3475 if (
abs(p.dot(axisNormal) - boundaryMin) <
abs(depth))
3476 boundaryPoints2[cnt2++] = p;
3478 p = (center + u * extent[0] + v * extent[1] + w * extent[2]);
3479 if (
abs(p.dot(axisNormal) - boundaryMin) <
abs(depth))
3480 boundaryPoints2[cnt2++] = p;
3483 if (cnt1 == 1 || cnt2 == 1)
3485 m.
normal = (boundary1 < boundary2) ? -axisNormal : axisNormal;
3487 m.
contacts[0].position = (cnt1 == 1) ? boundaryPoints1[0] : boundaryPoints2[0];
3497 Segment3D s2(boundaryPoints2[0], boundaryPoints2[1]);
3499 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
3511 for (
int tmp_i = 1; tmp_i < 4; tmp_i++)
3512 for (
int tmp_j = tmp_i + 1; tmp_j < 4; tmp_j++)
3514 if ((boundaryPoints2[tmp_i] - boundaryPoints2[0]).
dot(boundaryPoints2[tmp_j] - boundaryPoints2[0]) <
EPSILON)
3516 int tmp_k = 1 + 2 + 3 - tmp_i - tmp_j;
3520 boundaryPoints2[1] = p2;
3521 boundaryPoints2[2] = p3;
3522 boundaryPoints2[3] = p4;
3533 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
3534 Triangle3D t2(boundaryPoints2[0], boundaryPoints2[1], boundaryPoints2[2]);
3543 if (dirTmp1.cross(axisNormal).norm() < 1e-4)
3549 if (dirTmp2.cross(axisNormal).norm() < 1e-4)
3555 t2 =
Triangle3D(boundaryPoints2[3], boundaryPoints2[1], boundaryPoints2[2]);
3562 if (dirTmp1.cross(axisNormal).norm() < 1e-4)
3568 if (dirTmp2.cross(axisNormal).norm() < 1e-4)
3574 for (
int i = 0; i < 4; i++)
3578 s2 =
Segment3D(boundaryPoints2[0], boundaryPoints2[i]);
3580 s2 =
Segment3D(boundaryPoints2[3], boundaryPoints2[i - 2]);
3586 if ((!dir.
isValid()) || dir.
direction().normalize().cross(axisNormal).norm() < 1e-4)
3589 if ((dir.
v0 - s1.
v0).norm() > 1e-4 && (dir.
v0 - s1.
v1).norm() > 1e-4)
3602 template<
typename Real>
3613 unsigned char boundaryPoints1[4], boundaryPoints2[4];
3618 for (
unsigned char i = 0; i < 4; i++)
3620 if (
abs(tet.
v[i].dot(axisNormal) - boundary1) <
abs(sMax))
3621 boundaryPoints1[cnt1 ++] = i;
3627 boundaryPoints2[cnt2 ++] = 0;
3632 boundaryPoints2[cnt2++] = 1;
3636 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
3638 m.
contacts[0].position = tet.
v[boundaryPoints1[0]];
3644 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
3652 Segment3D s1(tet.
v[boundaryPoints1[0]], tet.
v[boundaryPoints1[1]]);
3658 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
3667 Triangle3D t1(tet.
v[boundaryPoints1[0]], tet.
v[boundaryPoints1[1]], tet.
v[boundaryPoints1[2]]);
3673 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
3677 if (dirTmp1.cross(axisNormal).norm() < 1e-5)
3683 if (dirTmp2.cross(axisNormal).norm() < 1e-5)
3689 for (
int i = 0; i < 3; i++)
3691 Segment3D s1(t1.
v[(i + 1) % 3], t1.
v[(i + 2) % 3]);
3693 if ((!dir.
isValid()) || dir.
direction().normalize().cross(axisNormal).norm() < 1e-5)
3695 if ((dir.
v0 - s2.
v0).norm() > 1e-5 && (dir.
v0 - s2.
v1).norm() > 1e-5)
3709 template<
typename Real>
3720 unsigned char boundaryPoints1[4], boundaryPoints2[4];
3725 for (
unsigned char i = 0; i < 4; i++)
3727 if (
abs(tet.
v[i].dot(axisNormal) - boundary1) <
abs(sMax) +
EPSILON)
3728 boundaryPoints1[cnt1++] = i;
3731 for (
unsigned char i = 0; i < 3; i++)
3733 if (
abs(triangle.
v[i].dot(axisNormal) - boundary2) <
abs(sMax) +
EPSILON)
3734 boundaryPoints2[cnt2++] = i;
3739 if (cnt1 == 1 || cnt2 == 1)
3741 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
3743 m.
contacts[0].position = (cnt1 == 1) ? tet.
v[boundaryPoints1[0]] : triangle.
v[boundaryPoints2[0]];
3749 Segment3D s1(tet.
v[boundaryPoints1[0]], tet.
v[boundaryPoints1[1]]);
3753 Segment3D s2(triangle.
v[boundaryPoints2[0]], triangle.
v[boundaryPoints2[1]]);
3755 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
3764 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
3765 Triangle3D t2(triangle.
v[boundaryPoints2[0]], triangle.
v[boundaryPoints2[1]], triangle.
v[boundaryPoints2[2]]);
3768 if (dirTmp1.cross(axisNormal).norm() < 1e-5)
3774 if (dirTmp2.cross(axisNormal).norm() < 1e-5)
3780 for (
int i = 0; i < 3; i++)
3782 Segment3D s2(t2.
v[(i + 1) % 3], t2.
v[(i + 2) % 3]);
3785 if ((!dir.
isValid()) || dir.
direction().normalize().cross(axisNormal).norm() < 1e-5)
3788 if ((dir.
v0 - s1.
v0).norm() > 1e-5 && (dir.
v0 - s1.
v1).norm() > 1e-5)
3800 Triangle3D t1(tet.
v[boundaryPoints1[0]], tet.
v[boundaryPoints1[1]], tet.
v[boundaryPoints1[2]]);
3804 Segment3D s2(triangle.
v[boundaryPoints2[0]], triangle.
v[boundaryPoints2[1]]);
3806 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
3810 if (dirTmp1.cross(axisNormal).norm() < 1e-5)
3816 if (dirTmp2.cross(axisNormal).norm() < 1e-5)
3822 for (
int i = 0; i < 3; i++)
3824 Segment3D s1(t1.
v[(i + 1) % 3], t1.
v[(i + 2) % 3]);
3826 if ((!dir.
isValid()) || dir.
direction().normalize().cross(axisNormal).norm() < 1e-5)
3828 if ((dir.
v0 - s2.
v0).norm() > 1e-5 && (dir.
v0 - s2.
v1).norm() > 1e-5)
3839 Triangle3D t1(tet.
v[boundaryPoints1[0]], tet.
v[boundaryPoints1[1]], tet.
v[boundaryPoints1[2]]);
3843 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
3845 for (
int i = 0; i < 3; i++)
3860 for (
int j = 0; j < 3; j++)
3862 Segment3D s1(t1.
v[(i + 1) % 3], t1.
v[(i + 2) % 3]);
3863 Segment3D s2(t2.
v[(j + 1) % 3], t2.
v[(j + 2) % 3]);
3865 if ((!dir.
isValid()) || dir.
direction().normalize().cross(axisNormal).norm() < 1e-5)
3867 if ((dir.
v0 - s1.
v0).norm() > 1e-5 && (dir.
v0 - s1.
v1).norm() > 1e-5)
3881 template<
typename Real>
3895 bool bInter =
false;
3903 if (sMax < 0) bInter =
true;
3910 if (!bInter)
return;
3916 Real lowerBoundary1, upperBoundary1, lowerBoundary2, upperBoundary2;
3917 Real l1, u1, l2, u2;
3921 Real boundary1, boundary2, b1, b2;
3924 axisTmp = box.
u / box.
u.norm();
3925 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, box, cap) ==
false)
3932 if (sIntersect < sMax)
3935 lowerBoundary1 = l1;
3936 lowerBoundary2 = l2;
3937 upperBoundary1 = u1;
3938 upperBoundary2 = u2;
3947 axisTmp = box.
v / box.
v.norm();
3948 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, box, cap) ==
false)
3955 if (sIntersect < sMax)
3958 lowerBoundary1 = l1;
3959 lowerBoundary2 = l2;
3960 upperBoundary1 = u1;
3961 upperBoundary2 = u2;
3969 axisTmp = box.
w / box.
w.norm();
3970 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, box, cap) ==
false)
3977 if (sIntersect < sMax)
3980 lowerBoundary1 = l1;
3981 lowerBoundary2 = l2;
3982 upperBoundary1 = u1;
3983 upperBoundary2 = u2;
3992 for (
int j = 0; j < 3; j++)
3995 axisTmp = dirCap.cross(boxDir);
3998 axisTmp /= axisTmp.norm();
4006 axisTmp /= axisTmp.norm();
4008 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, box, cap) ==
false)
4015 if (sIntersect < sMax)
4018 lowerBoundary1 = l1;
4019 lowerBoundary2 = l2;
4020 upperBoundary1 = u1;
4021 upperBoundary2 = u2;
4039 template<
typename Real>
4047 template<
typename Real>
4054 Real lowerBoundary1, upperBoundary1, lowerBoundary2, upperBoundary2;
4055 Real l1, u1, l2, u2;
4059 Real boundary1, boundary2, b1, b2;
4063 for (
int i = 0; i < 4; i++)
4066 axisTmp = tet.
face(i).normal();
4067 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet, tri) ==
false)
4075 if (sIntersect < sMax)
4078 lowerBoundary1 = l1;
4079 lowerBoundary2 = l2;
4080 upperBoundary1 = u1;
4081 upperBoundary2 = u2;
4092 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet, tri) ==
false)
4100 if (sIntersect < sMax)
4103 lowerBoundary1 = l1;
4104 lowerBoundary2 = l2;
4105 upperBoundary1 = u1;
4106 upperBoundary2 = u2;
4113 const int segmentIndex[6][2] = {
4122 const int triIndex[6][2] = {
4128 for (
int i = 0; i < 6; i++)
4129 for(
int j = 0; j < 3; j ++)
4133 dirTri /= dirTri.norm();
4134 dirTet /= dirTet.norm();
4135 axisTmp = dirTet.cross(dirTri);
4138 axisTmp /= axisTmp.norm();
4146 axisTmp /= axisTmp.norm();
4148 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet, tri) ==
false)
4156 if (sIntersect < sMax)
4159 lowerBoundary1 = l1;
4160 lowerBoundary2 = l2;
4161 upperBoundary1 = u1;
4162 upperBoundary2 = u2;
4170 axisTmp = (tet.
v[0] + tet.
v[1] + tet.
v[2] + tet.
v[3]) / 4.0f - (tri.
v[0] + tri.
v[1] + tri.
v[2]) / 3.0f;
4171 axisTmp /= axisTmp.norm();
4172 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet, tri) ==
false)
4180 if (sIntersect < sMax)
4183 lowerBoundary1 = l1;
4184 lowerBoundary2 = l2;
4185 upperBoundary1 = u1;
4186 upperBoundary2 = u2;
4197 template<
typename Real>
4205 template<
typename Real>
4212 Real lowerBoundary1, upperBoundary1, lowerBoundary2, upperBoundary2;
4213 Real l1, u1, l2, u2;
4217 Real boundary1, boundary2, b1, b2;
4220 for (
int i = 0; i < 4; i++)
4223 axisTmp = tet.
face(i).normal();
4224 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet, cap) ==
false)
4231 if (sIntersect < sMax)
4234 lowerBoundary1 = l1;
4235 lowerBoundary2 = l2;
4236 upperBoundary1 = u1;
4237 upperBoundary2 = u2;
4244 axisTmp = tet.
face(i).normal();
4245 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet, cap) ==
false)
4252 if (sIntersect < sMax)
4255 lowerBoundary1 = l1;
4256 lowerBoundary2 = l2;
4257 upperBoundary1 = u1;
4258 upperBoundary2 = u2;
4266 const int segmentIndex[6][2] = {
4278 axisTmp /= axisTmp.norm();
4280 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet, cap) ==
false)
4287 if (sIntersect < sMax)
4290 lowerBoundary1 = l1;
4291 lowerBoundary2 = l2;
4292 upperBoundary1 = u1;
4293 upperBoundary2 = u2;
4300 for (
int i = 0; i < 6; i++)
4307 axisTmp = dirTet.cross(dirCap);
4310 axisTmp /= axisTmp.norm();
4318 axisTmp /= axisTmp.norm();
4320 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet, cap) ==
false)
4327 if (sIntersect < sMax)
4330 lowerBoundary1 = l1;
4331 lowerBoundary2 = l2;
4332 upperBoundary1 = u1;
4333 upperBoundary2 = u2;
4349 template<
typename Real>
4357 template<
typename Real>
4365 template<
typename Real>
4370 auto c0 = sphere0.
center;
4371 auto c1 = sphere1.
center;
4377 Real sMax = dir.norm() - r0 - r1;
4381 m.
normal = dir.normalize();
4387 template<
typename Real>
4389 Real lowerBoundary1,
4390 Real upperBoundary1,
4391 Real lowerBoundary2,
4392 Real upperBoundary2,
4393 Real& intersectionDistance,
4398 if (!((lowerBoundary1 > upperBoundary2) || (lowerBoundary2 > upperBoundary1)))
4400 if (lowerBoundary1 < lowerBoundary2)
4402 if (upperBoundary1 > upperBoundary2)
4407 if (upperBoundary2 - lowerBoundary1 > upperBoundary1 - lowerBoundary2)
4411 boundary1 = upperBoundary1;
4412 boundary2 = lowerBoundary2;
4413 intersectionDistance = upperBoundary1 - lowerBoundary2;
4419 boundary1 = lowerBoundary1;
4420 boundary2 = upperBoundary2;
4421 intersectionDistance = upperBoundary2 - lowerBoundary1;
4428 intersectionDistance = upperBoundary1 - lowerBoundary2;
4429 boundary1 = upperBoundary1;
4430 boundary2 = lowerBoundary2;
4435 if (upperBoundary1 > upperBoundary2)
4439 intersectionDistance = upperBoundary2 - lowerBoundary1;
4440 boundary1 = lowerBoundary1;
4441 boundary2 = upperBoundary2;
4448 if (upperBoundary2 - lowerBoundary1 > upperBoundary1 - lowerBoundary2)
4452 boundary1 = upperBoundary1;
4453 boundary2 = lowerBoundary2;
4454 intersectionDistance = upperBoundary1 - lowerBoundary2;
4460 boundary1 = lowerBoundary1;
4461 boundary2 = upperBoundary2;
4462 intersectionDistance = upperBoundary2 - lowerBoundary1;
4470 intersectionDistance =
Real(0.0f);
4474 template<
typename Real>
4476 Real& lowerBoundary1,
4477 Real& upperBoundary1,
4478 Real& lowerBoundary2,
4479 Real& upperBoundary2,
4480 Real& intersectionDistance,
4489 for (
int i = 0; i < 4; i++)
4493 lowerBoundary1 = upperBoundary1 = tet1.
v[0].dot(axisNormal);
4494 lowerBoundary2 = upperBoundary2 = tet2.
v[0].dot(axisNormal);
4498 lowerBoundary1 = glm::min(lowerBoundary1, tet1.
v[i].dot(axisNormal));
4499 lowerBoundary2 = glm::min(lowerBoundary2, tet2.
v[i].dot(axisNormal));
4500 upperBoundary1 = glm::max(upperBoundary1, tet1.
v[i].dot(axisNormal));
4501 upperBoundary2 = glm::max(upperBoundary2, tet2.
v[i].dot(axisNormal));
4510 return checkOverlap(lowerBoundary1, upperBoundary1, lowerBoundary2, upperBoundary2, intersectionDistance, boundary1, boundary2);
4514 template<
typename Real>
4516 Real& lowerBoundary1,
4517 Real& upperBoundary1,
4518 Real& lowerBoundary2,
4519 Real& upperBoundary2,
4520 Real& intersectionDistance,
4529 for (
int i = 0; i < 4; i++)
4533 lowerBoundary1 = upperBoundary1 = tet.
v[0].dot(axisNormal);
4537 lowerBoundary1 = glm::min(lowerBoundary1, tet.
v[i].dot(axisNormal));
4538 upperBoundary1 = glm::max(upperBoundary1, tet.
v[i].dot(axisNormal));
4542 for (
int i = 0; i < 3; i++)
4545 lowerBoundary2 = upperBoundary2 = tri.
v[i].dot(axisNormal);
4548 lowerBoundary2 = glm::min(lowerBoundary2, tri.
v[i].dot(axisNormal));
4549 upperBoundary2 = glm::max(upperBoundary2, tri.
v[i].dot(axisNormal));
4557 template<
typename Real>
4559 Real& lowerBoundary1,
4560 Real& upperBoundary1,
4561 Real& lowerBoundary2,
4562 Real& upperBoundary2,
4563 Real& intersectionDistance,
4572 for (
int i = 0; i < 4; i++)
4575 lowerBoundary1 = upperBoundary1 = tet.
v[0].dot(axisNormal);
4578 lowerBoundary1 = glm::min(lowerBoundary1, tet.
v[i].dot(axisNormal));
4579 upperBoundary1 = glm::max(upperBoundary1, tet.
v[i].dot(axisNormal));
4589 p = (center - u * extent[0] - v * extent[1] - w * extent[2]);
4590 lowerBoundary2 = upperBoundary2 = p.dot(axisNormal);
4592 p = (center - u * extent[0] - v * extent[1] + w * extent[2]);
4593 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
4594 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
4596 p = (center - u * extent[0] + v * extent[1] - w * extent[2]);
4597 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
4598 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
4600 p = (center - u * extent[0] + v * extent[1] + w * extent[2]);
4601 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
4602 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
4604 p = (center + u * extent[0] - v * extent[1] - w * extent[2]);
4605 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
4606 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
4608 p = (center + u * extent[0] - v * extent[1] + w * extent[2]);
4609 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
4610 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
4612 p = (center + u * extent[0] + v * extent[1] - w * extent[2]);
4613 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
4614 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
4616 p = (center + u * extent[0] + v * extent[1] + w * extent[2]);
4617 lowerBoundary2 = glm::min(lowerBoundary2, p.dot(axisNormal));
4618 upperBoundary2 = glm::max(upperBoundary2, p.dot(axisNormal));
4620 return checkOverlap(lowerBoundary1, upperBoundary1, lowerBoundary2, upperBoundary2, intersectionDistance, boundary1, boundary2);
4624 template<
typename Real>
4635 unsigned char boundaryPoints1[4], boundaryPoints2[4];
4640 for (
unsigned char i = 0; i < 4; i++)
4642 if (
abs(tet1.
v[i].dot(axisNormal) - boundary1) <
abs(sMax))
4643 boundaryPoints1[cnt1 ++] = i;
4644 if (
abs(tet2.
v[i].dot(axisNormal) - boundary2) <
abs(sMax))
4645 boundaryPoints2[cnt2 ++] = i;
4648 if (cnt1 == 1 || cnt2 == 1)
4651 m.
normal = (boundary1 > boundary2) ? axisNormal : - axisNormal;
4653 m.
contacts[0].position = (cnt1 == 1) ? tet1.
v[boundaryPoints1[0]] : tet2.
v[boundaryPoints2[0]];
4659 Segment3D s1(tet1.
v[boundaryPoints1[0]], tet1.
v[boundaryPoints1[1]]);
4663 Segment3D s2(tet2.
v[boundaryPoints2[0]], tet2.
v[boundaryPoints2[1]]);
4665 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
4674 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
4675 Triangle3D t2(tet2.
v[boundaryPoints2[0]], tet2.
v[boundaryPoints2[1]], tet2.
v[boundaryPoints2[2]]);
4679 if (dirTmp1.cross(axisNormal).norm() < 1e-5)
4685 if (dirTmp2.cross(axisNormal).norm() < 1e-5)
4692 for (
int i = 0; i < 3; i++)
4694 Segment3D s2(t2.
v[(i + 1) % 3], t2.
v[(i + 2) % 3]);
4707 if ((dir.
v0 - s1.
v0).norm() > 1e-5 && (dir.
v0 - s1.
v1).norm() > 1e-5)
4719 Triangle3D t1(tet1.
v[boundaryPoints1[0]], tet1.
v[boundaryPoints1[1]], tet1.
v[boundaryPoints1[2]]);
4723 Segment3D s2(tet2.
v[boundaryPoints2[0]], tet2.
v[boundaryPoints2[1]]);
4725 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
4729 if (dirTmp1.cross(axisNormal).norm() < 1e-5)
4736 if (dirTmp2.cross(axisNormal).norm() < 1e-5)
4743 for (
int i = 0; i < 3; i++)
4745 Segment3D s1(t1.
v[(i + 1) % 3], t1.
v[(i + 2) % 3]);
4752 if ((dir.
v0 - s2.
v0).norm() > 1e-5 && (dir.
v0 - s2.
v1).norm() > 1e-5)
4763 Triangle3D t1(tet1.
v[boundaryPoints1[0]], tet1.
v[boundaryPoints1[1]], tet1.
v[boundaryPoints1[2]]);
4764 Triangle3D t2(tet2.
v[boundaryPoints2[0]], tet2.
v[boundaryPoints2[1]], tet2.
v[boundaryPoints2[2]]);
4767 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
4769 for (
int i = 0; i < 3; i++)
4784 for (
int j = 0; j < 3; j++)
4786 Segment3D s1(t1.
v[(i + 1) % 3], t1.
v[(i + 2) % 3]);
4787 Segment3D s2(t2.
v[(j + 1) % 3], t2.
v[(j + 2) % 3]);
4797 if ((dir.
v0 - s1.
v0).norm() > 1e-5 && (dir.
v0 - s1.
v1).norm() > 1e-5)
4813 template<
typename Real>
4824 unsigned char boundaryPoints1[4];
4830 for (
unsigned char i = 0; i < 4; i++)
4832 if (
abs(tet.
v[i].dot(axisNormal) - boundary1) <
abs(sMax))
4833 boundaryPoints1[cnt1++] = i;
4842 p = (center - u * extent[0] - v * extent[1] - w * extent[2]);
4843 if (
abs(p.dot(axisNormal) - boundary2) <
abs(sMax))
4844 boundaryPoints2[cnt2++] = p;
4846 p = (center - u * extent[0] - v * extent[1] + w * extent[2]);
4847 if (
abs(p.dot(axisNormal) - boundary2) <
abs(sMax))
4848 boundaryPoints2[cnt2++] = p;
4850 p = (center - u * extent[0] + v * extent[1] - w * extent[2]);
4851 if (
abs(p.dot(axisNormal) - boundary2) <
abs(sMax))
4852 boundaryPoints2[cnt2++] = p;
4854 p = (center - u * extent[0] + v * extent[1] + w * extent[2]);
4855 if (
abs(p.dot(axisNormal) - boundary2) <
abs(sMax))
4856 boundaryPoints2[cnt2++] = p;
4858 p = (center + u * extent[0] - v * extent[1] - w * extent[2]);
4859 if (
abs(p.dot(axisNormal) - boundary2) <
abs(sMax))
4860 boundaryPoints2[cnt2++] = p;
4862 p = (center + u * extent[0] - v * extent[1] + w * extent[2]);
4863 if (
abs(p.dot(axisNormal) - boundary2) <
abs(sMax))
4864 boundaryPoints2[cnt2++] = p;
4866 p = (center + u * extent[0] + v * extent[1] - w * extent[2]);
4867 if (
abs(p.dot(axisNormal) - boundary2) <
abs(sMax))
4868 boundaryPoints2[cnt2++] = p;
4870 p = (center + u * extent[0] + v * extent[1] + w * extent[2]);
4871 if (
abs(p.dot(axisNormal) - boundary2) <
abs(sMax))
4872 boundaryPoints2[cnt2++] = p;
4875 if (cnt1 == 1 || cnt2 == 1)
4877 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
4879 m.
contacts[0].position = (cnt1 == 1) ? tet.
v[boundaryPoints1[0]] : boundaryPoints2[0];
4885 Segment3D s1(tet.
v[boundaryPoints1[0]], tet.
v[boundaryPoints1[1]]);
4889 Segment3D s2(boundaryPoints2[0], boundaryPoints2[1]);
4891 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
4903 for(
int tmp_i = 1; tmp_i < 4; tmp_i ++)
4904 for (
int tmp_j = tmp_i + 1; tmp_j < 4; tmp_j++)
4906 if ((boundaryPoints2[tmp_i] - boundaryPoints2[0]).
dot(boundaryPoints2[tmp_j] - boundaryPoints2[0]) <
EPSILON)
4908 int tmp_k = 1 + 2 + 3 - tmp_i - tmp_j;
4912 boundaryPoints2[1] = p2;
4913 boundaryPoints2[2] = p3;
4914 boundaryPoints2[3] = p4;
4925 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
4926 Triangle3D t2(boundaryPoints2[0], boundaryPoints2[1], boundaryPoints2[2]);
4935 if (dirTmp1.cross(axisNormal).norm() < 1e-4)
4941 if (dirTmp2.cross(axisNormal).norm() < 1e-4)
4947 t2 =
Triangle3D(boundaryPoints2[3], boundaryPoints2[1], boundaryPoints2[2]);
4954 if (dirTmp1.cross(axisNormal).norm() < 1e-4)
4960 if (dirTmp2.cross(axisNormal).norm() < 1e-4)
4966 for (
int i = 0; i < 4; i++)
4970 s2 =
Segment3D(boundaryPoints2[0], boundaryPoints2[i]);
4972 s2 =
Segment3D(boundaryPoints2[3], boundaryPoints2[i - 2]);
4978 if ((!dir.
isValid()) || dir.
direction().normalize().cross(axisNormal).norm() < 1e-4)
4981 if ((dir.
v0 - s1.
v0).norm() > 1e-4 && (dir.
v0 - s1.
v1).norm() > 1e-4)
4993 Triangle3D t1(tet.
v[boundaryPoints1[0]], tet.
v[boundaryPoints1[1]], tet.
v[boundaryPoints1[2]]);
5000 Segment3D s2(boundaryPoints2[0], boundaryPoints2[1]);
5002 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
5006 if (dirTmp1.cross(axisNormal).norm() < 1e-4)
5012 if (dirTmp2.cross(axisNormal).norm() < 1e-4)
5018 for (
int i = 0; i < 3; i++)
5020 Segment3D s1(t1.
v[(i + 1) % 3], t1.
v[(i + 2) % 3]);
5022 if ((!dir.
isValid()) || dir.
direction().normalize().cross(axisNormal).norm() < 1e-4)
5024 if ((dir.
v0 - s2.
v0).norm() > 1e-4 && (dir.
v0 - s2.
v1).norm() > 1e-4)
5035 Triangle3D t1(tet.
v[boundaryPoints1[0]], tet.
v[boundaryPoints1[1]], tet.
v[boundaryPoints1[2]]);
5042 for (
int tmp_i = 1; tmp_i < 4; tmp_i++)
5043 for (
int tmp_j = tmp_i + 1; tmp_j < 4; tmp_j++)
5045 if ((boundaryPoints2[tmp_i] - boundaryPoints2[0]).
dot(boundaryPoints2[tmp_j] - boundaryPoints2[0]) <
EPSILON)
5047 int tmp_k = 1 + 2 + 3 - tmp_i - tmp_j;
5051 boundaryPoints2[1] = p2;
5052 boundaryPoints2[2] = p3;
5053 boundaryPoints2[3] = p4;
5059 m.
normal = (boundary1 > boundary2) ? axisNormal : -axisNormal;
5061 for(
int i = 0; i < 4; i ++)
5062 if ((
Point3D(boundaryPoints2[i]).project(t1).origin - boundaryPoints2[i]).
cross(t1.
normal()).norm() < 1e-4)
5070 for (
int i = 0; i < 3; i++)
5072 Triangle3D t2(boundaryPoints2[0], boundaryPoints2[1], boundaryPoints2[2]);
5080 t2 =
Triangle3D(boundaryPoints2[3], boundaryPoints2[1], boundaryPoints2[2]);
5090 Segment3D s1(t1.
v[(i + 1) % 3], t1.
v[(i + 2) % 3]);
5091 Segment3D s2(boundaryPoints2[0], boundaryPoints2[1]);
5095 if ((dir.
v0 - s1.
v0).norm() > 1e-4 && (dir.
v0 - s1.
v1).norm() > 1e-4)
5105 s2 =
Segment3D(boundaryPoints2[0], boundaryPoints2[2]);
5109 if ((dir.
v0 - s1.
v0).norm() > 1e-4 && (dir.
v0 - s1.
v1).norm() > 1e-4)
5117 s2 =
Segment3D(boundaryPoints2[3], boundaryPoints2[2]);
5121 if ((dir.
v0 - s1.
v0).norm() > 1e-4 && (dir.
v0 - s1.
v1).norm() > 1e-4)
5129 s2 =
Segment3D(boundaryPoints2[3], boundaryPoints2[1]);
5133 if ((dir.
v0 - s1.
v0).norm() > 1e-4 && (dir.
v0 - s1.
v1).norm() > 1e-4)
5149 template<
typename Real>
5156 Real lowerBoundary1, upperBoundary1, lowerBoundary2, upperBoundary2;
5157 Real l1, u1, l2, u2;
5161 Real boundary1, boundary2, b1, b2;
5168 for(
int i = 0; i < 4; i ++)
5171 axisTmp = tet0.
face(i).normal();
5172 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet0, tet1) ==
false)
5179 if (sIntersect < sMax)
5182 lowerBoundary1 = l1;
5183 lowerBoundary2 = l2;
5184 upperBoundary1 = u1;
5185 upperBoundary2 = u2;
5192 axisTmp = tet1.
face(i).normal();
5193 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet0, tet1) ==
false)
5200 if (sIntersect < sMax)
5203 lowerBoundary1 = l1;
5204 lowerBoundary2 = l2;
5205 upperBoundary1 = u1;
5206 upperBoundary2 = u2;
5214 const int segmentIndex[6][2] = {
5223 for(
int i = 0; i < 6; i ++)
5224 for (
int j = 0; j < 6; j++)
5226 Vector<Real, 3> dirTet1 = tet0.
v[segmentIndex[i][0]] - tet0.
v[segmentIndex[i][1]];
5227 Vector<Real, 3> dirTet2 = tet1.
v[segmentIndex[j][0]] - tet1.
v[segmentIndex[j][1]];
5228 axisTmp = dirTet1.cross(dirTet2);
5231 axisTmp /= axisTmp.norm();
5239 axisTmp /= axisTmp.norm();
5241 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet0, tet1) ==
false)
5248 if (sIntersect < sMax)
5251 lowerBoundary1 = l1;
5252 lowerBoundary2 = l2;
5253 upperBoundary1 = u1;
5254 upperBoundary2 = u2;
5268 template<
typename Real>
5275 Real lowerBoundary1, upperBoundary1, lowerBoundary2, upperBoundary2;
5276 Real l1, u1, l2, u2;
5280 Real boundary1, boundary2, b1, b2;
5282 for (
int i = 0; i < 4; i++)
5285 axisTmp = tet.
face(i).normal();
5286 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet, box) ==
false)
5293 if (sIntersect < sMax)
5296 lowerBoundary1 = l1;
5297 lowerBoundary2 = l2;
5298 upperBoundary1 = u1;
5299 upperBoundary2 = u2;
5308 axisTmp = box.
u / box.
u.norm();
5309 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet, box) ==
false)
5316 if (sIntersect < sMax)
5319 lowerBoundary1 = l1;
5320 lowerBoundary2 = l2;
5321 upperBoundary1 = u1;
5322 upperBoundary2 = u2;
5331 axisTmp = box.
v / box.
v.norm();
5332 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet, box) ==
false)
5339 if (sIntersect < sMax)
5342 lowerBoundary1 = l1;
5343 lowerBoundary2 = l2;
5344 upperBoundary1 = u1;
5345 upperBoundary2 = u2;
5353 axisTmp = box.
w / box.
w.norm();
5354 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet, box) ==
false)
5361 if (sIntersect < sMax)
5364 lowerBoundary1 = l1;
5365 lowerBoundary2 = l2;
5366 upperBoundary1 = u1;
5367 upperBoundary2 = u2;
5374 const int segmentIndex[6][2] = {
5384 for (
int i = 0; i < 6; i++)
5387 for(
int j = 0; j < 3; j ++)
5390 axisTmp = dirTet.cross(boxDir);
5393 axisTmp /= axisTmp.norm();
5401 axisTmp /= axisTmp.norm();
5403 if (
checkOverlapAxis(l1, u1, l2, u2, sIntersect, b1, b2, axisTmp, tet, box) ==
false)
5410 if (sIntersect < sMax)
5413 lowerBoundary1 = l1;
5414 lowerBoundary2 = l2;
5415 upperBoundary1 = u1;
5416 upperBoundary2 = u2;
5427 template<
typename Real>
5435 template<
typename Real>
5444 bool bInside = c0.
inside(tet);
5446 Segment3D dir = bInside ? c0 - vproj : vproj - c0;
5458 template<
typename Real>
5466 template<
typename Real>
5495 template<
typename Real>
TSeparationData< Real > SeparationData
SquareMatrix< Real, 3 > Matrix3D
static DYN_FUNC void MSDF(SeparationData &sat, const Sphere3D &sphereA, const Sphere3D &sphereB, const Real radiusA, const Real radiusB)
TSegment3D< Real > Segment3D
TCapsule3D< Real > Capsule3D
TSphere3D< Real > Sphere3D
Transform< Real, 3 > Transform3D
TOrientedBox3D< Real > OBox3D
TTriangle3D< Real > Triangle3D
static DYN_FUNC void request(Manifold &m, const Sphere3D &sphereA, const Sphere3D &sphereB, const Real radiusA, const Real radiusB)
TManifold< Real > Manifold
DYN_FUNC TSegment3D< Real > centerline() const
DYN_FUNC Coord3D endPoint() const
DYN_FUNC Coord3D startPoint() const
Coord3D u
three unit vectors u, v and w forming a right-handed orthornormal basis
DYN_FUNC TPoint3D< Real > vertex(const int i) const
DYN_FUNC TSegment3D< Real > edge(const int i) const
DYN_FUNC TRectangle3D< Real > face(const int i) const
Coord3D extent
half the dimension in each of the u, v, and w directions
Coord3D center
centerpoint
DYN_FUNC TPoint3D< Real > project(const TLine3D< Real > &line) const
project a point onto linear components – lines, rays and segments
DYN_FUNC bool inside(const TLine3D< Real > &line) const
check whether a point strictly lies inside (excluding boundary) a 1D geometric primitive
Coord3D axis[2]
two orthonormal unit axis
DYN_FUNC TPoint3D< Real > vertex(const int i) const
DYN_FUNC Coord3D normal() const
DYN_FUNC Coord3D & endPoint()
DYN_FUNC Coord3D direction() const
DYN_FUNC TSegment3D< Real > proximity(const TSegment3D< Real > &segment) const
DYN_FUNC bool isValid() const
DYN_FUNC bool intersect(const TPlane3D< Real > &plane, TPoint3D< Real > &interPt) const
DYN_FUNC Coord3D & startPoint()
DYN_FUNC Rectangle3D rect()
DYN_FUNC Vector< Real, 3 > pointB()
DYN_FUNC SeparationType face()
DYN_FUNC Triangle3D tri()
DYN_FUNC SeparationType type()
DYN_FUNC void update(SeparationType type, Real BoundaryA, Real BoundaryB, Real Depth, Vec3f N, Vec3f a0, Vec3f a1, Vec3f a2=Vec3f(0.), Vec3f a3=Vec3f(0.))
DYN_FUNC Vector< Real, 3 > normal()
3D geometric primitives in three-dimensional space
vertices are ordered so that the normal vectors for the triangular faces point outwards 3 / | \ 0 - 2...
DYN_FUNC TSegment3D< Real > edge(const int index) const
DYN_FUNC TTriangle3D< Real > face(const int index) const
DYN_FUNC Real volume() const
DYN_FUNC Coord3D normal() const
DYN_FUNC int intrSegWithPlane(Vec3f *q, Vec3f oA, Vec3f nA, Vec3f b0, Vec3f b1)
DYN_FUNC int intrBoxWithPlane(Vec3f *q, Vec3f oA, Vec3f nA, Vec3f center, Vec3f halfU, Vec3f halfV, Vec3f halfW)
DYN_FUNC int intrPolyWithRect(Vec3f *q, int n, Vec3f *p, Vec3f a0, Vec3f a1, Vec3f a2, Vec3f a3)
DYN_FUNC int intrTetWithPlane(Vec3f *q, Vec3f oA, Vec3f nA, Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3)
DYN_FUNC int intrPolyWithTri(Vec3f *q, int n, Vec3f *p, Vec3f a0, Vec3f a1, Vec3f a2)
DYN_FUNC int intrTriWithPlane(Vec3f *q, Vec3f oA, Vec3f nA, Vec3f b0, Vec3f b1, Vec3f b2)
This is an implementation of AdditiveCCD based on peridyno.
DYN_FUNC void computeSupportEdge(Vector< Real, 3 > &aOut, Vector< Real, 3 > &bOut, const SquareMatrix< Real, 3 > &rot, const Vector< Real, 3 > &trans, const Vector< Real, 3 > &e, Vector< Real, 3 > n)
DYN_FUNC int sign(T const &a, T const EPS=EPSILON)
DYN_FUNC void checkAxisPoint(TSeparationData< Real > &sat, ShapeA &shapeA, ShapeB &shapeB, const Real radiusA, const Real radiusB, Vec3f pA, Vec3f pB, const Real rA=0.f, const Real rB=0.f)
DYN_FUNC void computeReferenceEdgesAndBasis(unsigned char *out, SquareMatrix< Real, 3 > *basis, Vector< Real, 3 > *e, const Vector< Real, 3 > &eR, const Transform< Real, 3 > &rtx, Vector< Real, 3 > n, int axis)
DYN_FUNC void setupContactOnSphere(TManifold< Real > &m, TSeparationData< Real > &sat, const TSphere3D< Real > &sphereB, const Real radiusA, const Real radiusB)
DYN_FUNC void updateSDF(Real &boundaryA, Real &boundaryB, Real &depth, Vec3f &normal, Real currentBoundaryA, Real currentBoundaryB, Real currentDepth, Vec3f currentN)
DYN_FUNC Vector< T, 3 > cross(Vector< T, 3 > const &U, Vector< T, 3 > const &V)
DYN_FUNC void setupContactTets(Real boundary1, Real boundary2, const Vector< Real, 3 > axisNormal, Tet3D tet, Capsule3D cap, Real sMax, TManifold< Real > &m)
DYN_FUNC T dot(Vector< T, 2 > const &U, Vector< T, 2 > const &V)
DYN_FUNC void checkAxisRect(TSeparationData< Real > &sat, ShapeA &shapeA, ShapeB &shapeB, const Real radiusA, const Real radiusB, Rectangle3D rect, SeparationType type)
DYN_FUNC void computeIncidentFace(ClipVertex *out, const Transform< Real, 3 > &itx, const Vector< Real, 3 > &e, Vector< Real, 3 > n)
DYN_FUNC void projectOnAxis(Real &lowerBoundary, Real &upperBoundary, const Vec3f axisNormal, Sphere3D sphere, const Real radius)
TRectangle3D< double > Rectangle3D
DYN_FUNC void setupContactOnBox(TManifold< Real > &m, TSeparationData< Real > &sat, const Shape &shapeA, const TOrientedBox3D< Real > &boxB, const Real radiusA, const Real radiusB)
DYN_FUNC T abs(const T &v)
TTriangle3D< double > Triangle3D
DYN_FUNC void checkAxisEdge(TSeparationData< Real > &sat, ShapeA &shapeA, ShapeB &shapeB, const Real radiusA, const Real radiusB, Segment3D edgeA, Segment3D edgeB)
DYN_FUNC bool checkPointInBoundary(const Vec3f &p, const Vec3f &N, const Real &b, const Real &r)
DYN_FUNC int ClippingWithRect(Vector< Real, 3 > *q, const TRectangle3D< Real > &rectA, const TSphere3D< Real > &sphereB, const Vector< Real, 3 > &transA, const Vector< Real, 3 > &transB)
DYN_FUNC void setupContactCaps(Real boundary1, Real boundary2, const Vector< Real, 3 > axisNormal, TCapsule3D< Real > cap, TOrientedBox3D< Real > box, Real depth, TManifold< Real > &m)
DYN_FUNC int ClippingWithTri(Vector< Real, 3 > *q, const TTriangle3D< Real > &triA, const TSphere3D< Real > &sphereB, const Vector< Real, 3 > &transA, const Vector< Real, 3 > &transB)
DYN_FUNC void setupContactTetTri(Real boundary1, Real boundary2, const Vector< Real, 3 > axisNormal, Tet3D tet, Triangle3D triangle, Real sMax, TManifold< Real > &m)
TOrientedBox3D< double > OrientedBox3D
DYN_FUNC void checkSignedDistance(Real lowerBoundaryA, Real upperBoundaryA, Real lowerBoundaryB, Real upperBoundaryB, Real &intersectionDistance, Real &boundaryA, Real &boundaryB)
DYN_FUNC void setupContactOnSeg(TManifold< Real > &m, TSeparationData< Real > &sat, const TSegment3D< Real > &segB, const Real radiusA, const Real radiusB)
DYN_FUNC void swapContactPair(TManifold< Real > &m)
TCapsule3D< double > Capsule3D
DYN_FUNC bool checkOverlapTetTri(Real lowerBoundary1, Real upperBoundary1, Real lowerBoundary2, Real upperBoundary2, Real &intersectionDistance, Real &boundary1, Real &boundary2)
TPoint3D< double > Point3D
DYN_FUNC void setupContactOnTri(TManifold< Real > &m, TSeparationData< Real > &sat, const Shape &shapeA, const TTriangle3D< Real > &triB, const Real radiusA, const Real radiusB)
DYN_FUNC void edgesContact(Vector< Real, 3 > &CA, Vector< Real, 3 > &CB, const Vector< Real, 3 > &PA, const Vector< Real, 3 > &QA, const Vector< Real, 3 > &PB, const Vector< Real, 3 > &QB)
DYN_FUNC void checkSignedDistanceAxis(Real &intersectionDistance, Real &BoundaryA, Real &BoundaryB, const Vec3f axisNormal, ShapeA &shapeA, ShapeB &shapeB, const Real radiusA, const Real radiusB)
DYN_FUNC float fsign(Real v)
DYN_FUNC int orthographic(ClipVertex *out, Real sign, Real e, int axis, int clipEdge, ClipVertex *in, int inCount)
DYN_FUNC bool trackFaceAxis(int &axis, Real &sMax, Vector< Real, 3 > &axisNormal, int n, Real s, const Vector< Real, 3 > &normal)
DYN_FUNC bool trackEdgeAxis(int &axis, Real &sMax, Vector< Real, 3 > &axisNormal, int n, Real s, const Vector< Real, 3 > &normal)
TSphere3D< double > Sphere3D
DYN_FUNC void setupContactOnTet(TManifold< Real > &m, TSeparationData< Real > &sat, const Shape &shapeA, const TTet3D< Real > &tetB, const Real radiusA, const Real radiusB)
TSegment3D< double > Segment3D
DYN_FUNC void checkAxisTri(TSeparationData< Real > &sat, ShapeA &shapeA, ShapeB &shapeB, const Real radiusA, const Real radiusB, Triangle3D tri, SeparationType type)
DYN_FUNC int clip(ClipVertex *outVerts, float *outDepths, const Vector< Real, 3 > &rPos, const Vector< Real, 3 > &e, unsigned char *clipEdges, const SquareMatrix< Real, 3 > &basis, ClipVertex *incident)
DYN_FUNC bool checkOverlapAxis(Real &lowerBoundary1, Real &upperBoundary1, Real &lowerBoundary2, Real &upperBoundary2, Real &intersectionDistance, Real &boundary1, Real &boundary2, const Vector< Real, 3 > axisNormal, OrientedBox3D box, Capsule3D cap)
DYN_FUNC bool checkOverlap(Real lowerBoundary1, Real upperBoundary1, Real lowerBoundary2, Real upperBoundary2, Real &intersectionDistance, Real &boundary1, Real &boundary2)
DYN_FUNC void pushContact(const Vector< Real, 3 > &pos, const Real &dep)
TContact< Real > contacts[8]