38 #ifndef FCL_NARROWPHASE_DETAIL_BOXBOX_INL_H 39 #define FCL_NARROWPHASE_DETAIL_BOXBOX_INL_H 41 #include "fcl/narrowphase/detail/primitive_shape_algorithm/box_box.h" 53 void lineClosestApproach(
const Vector3<double>& pa,
const Vector3<double>& ua,
54 const Vector3<double>& pb,
const Vector3<double>& ub,
55 double* alpha,
double* beta);
59 int intersectRectQuad2(
double h[2],
double p[8],
double ret[16]);
63 void cullPoints2(
int n,
double p[],
int m,
int i0,
int iret[]);
68 const Vector3<double>& side1,
69 const Transform3<double>& tf1,
70 const Vector3<double>& side2,
71 const Transform3<double>& tf2,
72 Vector3<double>& normal,
76 std::vector<ContactPoint<double>>& contacts);
80 bool boxBoxIntersect(
const Box<double>& s1,
const Transform3<double>& tf1,
81 const Box<double>& s2,
const Transform3<double>& tf2,
82 std::vector<ContactPoint<double>>* contacts_);
86 void lineClosestApproach(
const Vector3<S>& pa,
const Vector3<S>& ua,
87 const Vector3<S>& pb,
const Vector3<S>& ub,
90 Vector3<S> p = pb - pa;
94 S d = 1 - uaub * uaub;
103 *alpha = (q1 + uaub * q2) * d;
104 *beta = (uaub * q1 + q2) * d;
109 template <
typename S>
110 int intersectRectQuad2(S h[2], S p[8], S ret[16])
118 for(
int dir = 0; dir <= 1; ++dir)
121 for(
int sign = -1; sign <= 1; sign += 2)
127 for(
int i = nq; i > 0; --i)
130 if(sign * pq[dir] < h[dir])
143 S* nextq = (i > 1) ? pq+2 : q;
144 if((sign*pq[dir] < h[dir]) ^ (sign*nextq[dir] < h[dir]))
147 pr[1-dir] = pq[1-dir] + (nextq[1-dir]-pq[1-dir]) /
148 (nextq[dir]-pq[dir]) * (sign*h[dir]-pq[dir]);
149 pr[dir] = sign*h[dir];
161 r = (q == ret) ? buffer : ret;
167 if(q != ret) memcpy(ret, q, nr*2*
sizeof(S));
172 template <
typename S>
173 void cullPoints2(
int n, S p[],
int m,
int i0,
int iret[])
184 cx = 0.5 * (p[0] + p[2]);
185 cy = 0.5 * (p[1] + p[3]);
191 for(
int i = 0; i < n-1; ++i)
193 q = p[i*2]*p[i*2+3] - p[i*2+2]*p[i*2+1];
195 cx += q*(p[i*2]+p[i*2+2]);
196 cy += q*(p[i*2+1]+p[i*2+3]);
198 q = p[n*2-2]*p[1] - p[0]*p[n*2-1];
199 if(std::abs(a+q) > std::numeric_limits<S>::epsilon())
204 cx = a*(cx + q*(p[n*2-2]+p[0]));
205 cy = a*(cy + q*(p[n*2-1]+p[1]));
211 for(
int i = 0; i < n; ++i)
212 A[i] = atan2(p[i*2+1]-cy,p[i*2]-cx);
216 for(
int i = 0; i < n; ++i) avail[i] = 1;
221 for(
int j = 1; j < m; ++j)
223 a = j*(2*pi/m) + A[i0];
224 if (a > pi) a -= 2*pi;
225 S maxdiff= 1e9, diff;
228 for(
int i = 0; i < n; ++i)
232 diff = std::abs(A[i]-a);
233 if(diff > pi) diff = 2*pi - diff;
247 template <
typename S,
typename DerivedA,
typename DerivedB>
249 const Vector3<S>& side1,
250 const Eigen::MatrixBase<DerivedA>& R1,
251 const Eigen::MatrixBase<DerivedB>& T1,
252 const Vector3<S>& side2,
253 const Eigen::MatrixBase<DerivedA>& R2,
254 const Eigen::MatrixBase<DerivedB>& T2,
259 std::vector<ContactPoint<S>>& contacts)
261 const S fudge_factor = S(1.05);
264 int invert_normal, code;
266 Vector3<S> p = T2 - T1;
267 Vector3<S> pp = R1.transpose() * p;
270 Vector3<S> A = side1 * 0.5;
271 Vector3<S> B = side2 * 0.5;
274 Matrix3<S> R = R1.transpose() * R2;
275 Matrix3<S> Q = R.cwiseAbs();
288 int best_col_id = -1;
289 const Eigen::MatrixBase<DerivedA>* normalR = 0;
292 s = - std::numeric_limits<S>::max();
298 s2 = std::abs(tmp) - (Q.row(0).dot(B) + A[0]);
299 if(s2 > 0) { *return_code = 0;
return 0; }
305 invert_normal = (tmp < 0);
310 s2 = std::abs(tmp) - (Q.row(1).dot(B) + A[1]);
311 if(s2 > 0) { *return_code = 0;
return 0; }
317 invert_normal = (tmp < 0);
322 s2 = std::abs(tmp) - (Q.row(2).dot(B) + A[2]);
323 if(s2 > 0) { *return_code = 0;
return 0; }
329 invert_normal = (tmp < 0);
334 tmp = R2.col(0).dot(p);
335 s2 = std::abs(tmp) - (Q.col(0).dot(A) + B[0]);
336 if(s2 > 0) { *return_code = 0;
return 0; }
342 invert_normal = (tmp < 0);
346 tmp = R2.col(1).dot(p);
347 s2 = std::abs(tmp) - (Q.col(1).dot(A) + B[1]);
348 if(s2 > 0) { *return_code = 0;
return 0; }
354 invert_normal = (tmp < 0);
358 tmp = R2.col(2).dot(p);
359 s2 = std::abs(tmp) - (Q.col(2).dot(A) + B[2]);
360 if(s2 > 0) { *return_code = 0;
return 0; }
366 invert_normal = (tmp < 0);
375 S eps = std::numeric_limits<S>::epsilon();
378 tmp = pp[2] * R(1, 0) - pp[1] * R(2, 0);
379 s2 = std::abs(tmp) - (A[1] * Q(2, 0) + A[2] * Q(1, 0) + B[1] * Q(0, 2) + B[2] * Q(0, 1));
380 if(s2 > 0) { *return_code = 0;
return 0; }
381 n = Vector3<S>(0, -R(2, 0), R(1, 0));
386 if(s2 * fudge_factor > s)
391 invert_normal = (tmp < 0);
396 tmp = pp[2] * R(1, 1) - pp[1] * R(2, 1);
397 s2 = std::abs(tmp) - (A[1] * Q(2, 1) + A[2] * Q(1, 1) + B[0] * Q(0, 2) + B[2] * Q(0, 0));
398 if(s2 > 0) { *return_code = 0;
return 0; }
399 n = Vector3<S>(0, -R(2, 1), R(1, 1));
404 if(s2 * fudge_factor > s)
409 invert_normal = (tmp < 0);
414 tmp = pp[2] * R(1, 2) - pp[1] * R(2, 2);
415 s2 = std::abs(tmp) - (A[1] * Q(2, 2) + A[2] * Q(1, 2) + B[0] * Q(0, 1) + B[1] * Q(0, 0));
416 if(s2 > 0) { *return_code = 0;
return 0; }
417 n = Vector3<S>(0, -R(2, 2), R(1, 2));
422 if(s2 * fudge_factor > s)
427 invert_normal = (tmp < 0);
433 tmp = pp[0] * R(2, 0) - pp[2] * R(0, 0);
434 s2 = std::abs(tmp) - (A[0] * Q(2, 0) + A[2] * Q(0, 0) + B[1] * Q(1, 2) + B[2] * Q(1, 1));
435 if(s2 > 0) { *return_code = 0;
return 0; }
436 n = Vector3<S>(R(2, 0), 0, -R(0, 0));
441 if(s2 * fudge_factor > s)
446 invert_normal = (tmp < 0);
451 tmp = pp[0] * R(2, 1) - pp[2] * R(0, 1);
452 s2 = std::abs(tmp) - (A[0] * Q(2, 1) + A[2] * Q(0, 1) + B[0] * Q(1, 2) + B[2] * Q(1, 0));
453 if(s2 > 0) { *return_code = 0;
return 0; }
454 n = Vector3<S>(R(2, 1), 0, -R(0, 1));
459 if(s2 * fudge_factor > s)
464 invert_normal = (tmp < 0);
469 tmp = pp[0] * R(2, 2) - pp[2] * R(0, 2);
470 s2 = std::abs(tmp) - (A[0] * Q(2, 2) + A[2] * Q(0, 2) + B[0] * Q(1, 1) + B[1] * Q(1, 0));
471 if(s2 > 0) { *return_code = 0;
return 0; }
472 n = Vector3<S>(R(2, 2), 0, -R(0, 2));
477 if(s2 * fudge_factor > s)
482 invert_normal = (tmp < 0);
488 tmp = pp[1] * R(0, 0) - pp[0] * R(1, 0);
489 s2 = std::abs(tmp) - (A[0] * Q(1, 0) + A[1] * Q(0, 0) + B[1] * Q(2, 2) + B[2] * Q(2, 1));
490 if(s2 > 0) { *return_code = 0;
return 0; }
491 n = Vector3<S>(-R(1, 0), R(0, 0), 0);
496 if(s2 * fudge_factor > s)
501 invert_normal = (tmp < 0);
506 tmp = pp[1] * R(0, 1) - pp[0] * R(1, 1);
507 s2 = std::abs(tmp) - (A[0] * Q(1, 1) + A[1] * Q(0, 1) + B[0] * Q(2, 2) + B[2] * Q(2, 0));
508 if(s2 > 0) { *return_code = 0;
return 0; }
509 n = Vector3<S>(-R(1, 1), R(0, 1), 0);
514 if(s2 * fudge_factor > s)
519 invert_normal = (tmp < 0);
524 tmp = pp[1] * R(0, 2) - pp[0] * R(1, 2);
525 s2 = std::abs(tmp) - (A[0] * Q(1, 2) + A[1] * Q(0, 2) + B[0] * Q(2, 1) + B[1] * Q(2, 0));
526 if(s2 > 0) { *return_code = 0;
return 0; }
527 n = Vector3<S>(-R(1, 2), R(0, 2), 0);
532 if(s2 * fudge_factor > s)
537 invert_normal = (tmp < 0);
544 if (!code) { *return_code = code;
return 0; }
548 if(best_col_id != -1)
549 normal = normalR->col(best_col_id);
551 normal = R1 * normalC;
567 for(
int j = 0; j < 3; ++j)
569 sign = (R1.col(j).dot(normal) > 0) ? 1 : -1;
570 pa += R1.col(j) * (A[j] * sign);
576 for(
int j = 0; j < 3; ++j)
578 sign = (R2.col(j).dot(normal) > 0) ? -1 : 1;
579 pb += R2.col(j) * (B[j] * sign);
583 Vector3<S> ua(R1.col((code-7)/3));
584 Vector3<S> ub(R2.col((code-7)%3));
586 lineClosestApproach(pa, ua, pb, ub, &alpha, &beta);
593 contacts.emplace_back(normal, pb, -*depth);
604 const Eigen::MatrixBase<DerivedA> *Ra, *Rb;
605 const Eigen::MatrixBase<DerivedB> *pa, *pb;
606 const Vector3<S> *Sa, *Sb;
629 Vector3<S> normal2, nr, anr;
635 nr = Rb->transpose() * normal2;
676 center = (*pb) - (*pa) + Rb->col(lanr) * ((*Sb)[lanr]);
678 center = (*pb) - (*pa) - Rb->col(lanr) * ((*Sb)[lanr]);
681 int codeN, code1, code2;
704 S c1, c2, m11, m12, m21, m22;
705 c1 = Ra->col(code1).dot(center);
706 c2 = Ra->col(code2).dot(center);
710 Vector3<S> tempRac = Ra->col(code1);
711 m11 = Rb->col(a1).dot(tempRac);
712 m12 = Rb->col(a2).dot(tempRac);
713 tempRac = Ra->col(code2);
714 m21 = Rb->col(a1).dot(tempRac);
715 m22 = Rb->col(a2).dot(tempRac);
717 S k1 = m11 * (*Sb)[a1];
718 S k2 = m21 * (*Sb)[a1];
719 S k3 = m12 * (*Sb)[a2];
720 S k4 = m22 * (*Sb)[a2];
721 quad[0] = c1 - k1 - k3;
722 quad[1] = c2 - k2 - k4;
723 quad[2] = c1 - k1 + k3;
724 quad[3] = c2 - k2 + k4;
725 quad[4] = c1 + k1 + k3;
726 quad[5] = c2 + k2 + k4;
727 quad[6] = c1 + k1 - k3;
728 quad[7] = c2 + k2 - k4;
732 rect[0] = (*Sa)[code1];
733 rect[1] = (*Sa)[code2];
737 int n_intersect = intersectRectQuad2(rect, quad, ret);
738 if(n_intersect < 1) { *return_code = code;
return 0; }
744 Vector3<S> points[8];
746 S det1 = 1.f/(m11*m22 - m12*m21);
752 for(
int j = 0; j < n_intersect; ++j)
754 S k1 = m22*(ret[j*2]-c1) - m12*(ret[j*2+1]-c2);
755 S k2 = -m21*(ret[j*2]-c1) + m11*(ret[j*2+1]-c2);
756 points[cnum] = center + Rb->col(a1) * k1 + Rb->col(a2) * k2;
757 dep[cnum] = (*Sa)[codeN] - normal2.dot(points[cnum]);
760 ret[cnum*2] = ret[j*2];
761 ret[cnum*2+1] = ret[j*2+1];
765 if(cnum < 1) { *return_code = code;
return 0; }
768 if(maxc > cnum) maxc = cnum;
769 if(maxc < 1) maxc = 1;
776 for(
int j = 0; j < cnum; ++j)
778 Vector3<S> pointInWorld = points[j] + (*pa);
779 contacts.emplace_back(normal, pointInWorld, -dep[j]);
785 for(
int j = 0; j < cnum; ++j)
787 Vector3<S> pointInWorld = points[j] + (*pa) - normal * dep[j];
788 contacts.emplace_back(normal, pointInWorld, -dep[j]);
798 for(
int i = 1; i < cnum; ++i)
800 if(dep[i] > maxdepth)
808 cullPoints2(cnum, ret, maxc, i1, iret);
810 for(
int j = 0; j < maxc; ++j)
812 Vector3<S> posInWorld = points[iret[j]] + (*pa);
814 contacts.emplace_back(normal, posInWorld, -dep[iret[j]]);
816 contacts.emplace_back(normal, posInWorld - normal * dep[iret[j]], -dep[iret[j]]);
826 template <
typename S>
828 const Vector3<S>& side1,
829 const Transform3<S>& tf1,
830 const Vector3<S>& side2,
831 const Transform3<S>& tf2,
836 std::vector<ContactPoint<S>>& contacts)
838 const S fudge_factor = S(1.05);
841 const Vector3<S> p = tf2.translation() - tf1.translation();
842 const Vector3<S> pp = tf1.linear().transpose() * p;
845 const Vector3<S> A = side1 * 0.5;
846 const Vector3<S> B = side2 * 0.5;
849 const Matrix3<S> R = tf1.linear().transpose() * tf2.linear();
850 Matrix3<S> Q = R.cwiseAbs();
862 int best_col_id = -1;
863 const Transform3<S>* normalT =
nullptr;
865 S s = - std::numeric_limits<S>::max();
866 int invert_normal = 0;
871 S s2 = std::abs(tmp) - (Q.row(0).dot(B) + A[0]);
872 if(s2 > 0) { *return_code = 0;
return 0; }
878 invert_normal = (tmp < 0);
883 s2 = std::abs(tmp) - (Q.row(1).dot(B) + A[1]);
884 if(s2 > 0) { *return_code = 0;
return 0; }
890 invert_normal = (tmp < 0);
895 s2 = std::abs(tmp) - (Q.row(2).dot(B) + A[2]);
896 if(s2 > 0) { *return_code = 0;
return 0; }
902 invert_normal = (tmp < 0);
907 tmp = tf2.linear().col(0).dot(p);
908 s2 = std::abs(tmp) - (Q.col(0).dot(A) + B[0]);
909 if(s2 > 0) { *return_code = 0;
return 0; }
915 invert_normal = (tmp < 0);
919 tmp = tf2.linear().col(1).dot(p);
920 s2 = std::abs(tmp) - (Q.col(1).dot(A) + B[1]);
921 if(s2 > 0) { *return_code = 0;
return 0; }
927 invert_normal = (tmp < 0);
931 tmp = tf2.linear().col(2).dot(p);
932 s2 = std::abs(tmp) - (Q.col(2).dot(A) + B[2]);
933 if(s2 > 0) { *return_code = 0;
return 0; }
939 invert_normal = (tmp < 0);
948 S eps = std::numeric_limits<S>::epsilon();
951 tmp = pp[2] * R(1, 0) - pp[1] * R(2, 0);
952 s2 = std::abs(tmp) - (A[1] * Q(2, 0) + A[2] * Q(1, 0) + B[1] * Q(0, 2) + B[2] * Q(0, 1));
953 if(s2 > 0) { *return_code = 0;
return 0; }
954 n = Vector3<S>(0, -R(2, 0), R(1, 0));
959 if(s2 * fudge_factor > s)
964 invert_normal = (tmp < 0);
969 tmp = pp[2] * R(1, 1) - pp[1] * R(2, 1);
970 s2 = std::abs(tmp) - (A[1] * Q(2, 1) + A[2] * Q(1, 1) + B[0] * Q(0, 2) + B[2] * Q(0, 0));
971 if(s2 > 0) { *return_code = 0;
return 0; }
972 n = Vector3<S>(0, -R(2, 1), R(1, 1));
977 if(s2 * fudge_factor > s)
982 invert_normal = (tmp < 0);
987 tmp = pp[2] * R(1, 2) - pp[1] * R(2, 2);
988 s2 = std::abs(tmp) - (A[1] * Q(2, 2) + A[2] * Q(1, 2) + B[0] * Q(0, 1) + B[1] * Q(0, 0));
989 if(s2 > 0) { *return_code = 0;
return 0; }
990 n = Vector3<S>(0, -R(2, 2), R(1, 2));
995 if(s2 * fudge_factor > s)
1000 invert_normal = (tmp < 0);
1006 tmp = pp[0] * R(2, 0) - pp[2] * R(0, 0);
1007 s2 = std::abs(tmp) - (A[0] * Q(2, 0) + A[2] * Q(0, 0) + B[1] * Q(1, 2) + B[2] * Q(1, 1));
1008 if(s2 > 0) { *return_code = 0;
return 0; }
1009 n = Vector3<S>(R(2, 0), 0, -R(0, 0));
1014 if(s2 * fudge_factor > s)
1019 invert_normal = (tmp < 0);
1024 tmp = pp[0] * R(2, 1) - pp[2] * R(0, 1);
1025 s2 = std::abs(tmp) - (A[0] * Q(2, 1) + A[2] * Q(0, 1) + B[0] * Q(1, 2) + B[2] * Q(1, 0));
1026 if(s2 > 0) { *return_code = 0;
return 0; }
1027 n = Vector3<S>(R(2, 1), 0, -R(0, 1));
1032 if(s2 * fudge_factor > s)
1037 invert_normal = (tmp < 0);
1042 tmp = pp[0] * R(2, 2) - pp[2] * R(0, 2);
1043 s2 = std::abs(tmp) - (A[0] * Q(2, 2) + A[2] * Q(0, 2) + B[0] * Q(1, 1) + B[1] * Q(1, 0));
1044 if(s2 > 0) { *return_code = 0;
return 0; }
1045 n = Vector3<S>(R(2, 2), 0, -R(0, 2));
1050 if(s2 * fudge_factor > s)
1055 invert_normal = (tmp < 0);
1061 tmp = pp[1] * R(0, 0) - pp[0] * R(1, 0);
1062 s2 = std::abs(tmp) - (A[0] * Q(1, 0) + A[1] * Q(0, 0) + B[1] * Q(2, 2) + B[2] * Q(2, 1));
1063 if(s2 > 0) { *return_code = 0;
return 0; }
1064 n = Vector3<S>(-R(1, 0), R(0, 0), 0);
1069 if(s2 * fudge_factor > s)
1074 invert_normal = (tmp < 0);
1079 tmp = pp[1] * R(0, 1) - pp[0] * R(1, 1);
1080 s2 = std::abs(tmp) - (A[0] * Q(1, 1) + A[1] * Q(0, 1) + B[0] * Q(2, 2) + B[2] * Q(2, 0));
1081 if(s2 > 0) { *return_code = 0;
return 0; }
1082 n = Vector3<S>(-R(1, 1), R(0, 1), 0);
1087 if(s2 * fudge_factor > s)
1092 invert_normal = (tmp < 0);
1097 tmp = pp[1] * R(0, 2) - pp[0] * R(1, 2);
1098 s2 = std::abs(tmp) - (A[0] * Q(1, 2) + A[1] * Q(0, 2) + B[0] * Q(2, 1) + B[1] * Q(2, 0));
1099 if(s2 > 0) { *return_code = 0;
return 0; }
1100 n = Vector3<S>(-R(1, 2), R(0, 2), 0);
1105 if(s2 * fudge_factor > s)
1110 invert_normal = (tmp < 0);
1117 if (!code) { *return_code = code;
return 0; }
1121 if(best_col_id != -1)
1122 normal = normalT->linear().col(best_col_id);
1124 normal = tf1.linear() * normalC;
1137 Vector3<S> pa(tf1.translation());
1140 for(
int j = 0; j < 3; ++j)
1142 sign = (tf1.linear().col(j).dot(normal) > 0) ? 1 : -1;
1143 pa += tf1.linear().col(j) * (A[j] * sign);
1147 Vector3<S> pb(tf2.translation());
1149 for(
int j = 0; j < 3; ++j)
1151 sign = (tf2.linear().col(j).dot(normal) > 0) ? -1 : 1;
1152 pb += tf2.linear().col(j) * (B[j] * sign);
1156 Vector3<S> ua(tf1.linear().col((code-7)/3));
1157 Vector3<S> ub(tf2.linear().col((code-7)%3));
1159 lineClosestApproach(pa, ua, pb, ub, &alpha, &beta);
1166 contacts.emplace_back(normal, pb, -*depth);
1167 *return_code = code;
1177 const Transform3<S> *Ta, *Tb;
1178 const Vector3<S> *Sa, *Sb;
1197 Vector3<S> normal2, nr, anr;
1203 nr = Tb->linear().transpose() * normal2;
1204 anr = nr.cwiseAbs();
1244 center = Tb->translation() - Ta->translation() + Tb->linear().col(lanr) * ((*Sb)[lanr]);
1246 center = Tb->translation() - Ta->translation() - Tb->linear().col(lanr) * ((*Sb)[lanr]);
1249 int codeN, code1, code2;
1252 else codeN = code-4;
1272 S c1, c2, m11, m12, m21, m22;
1273 c1 = Ta->linear().col(code1).dot(center);
1274 c2 = Ta->linear().col(code2).dot(center);
1278 Vector3<S> tempRac = Ta->linear().col(code1);
1279 m11 = Tb->linear().col(a1).dot(tempRac);
1280 m12 = Tb->linear().col(a2).dot(tempRac);
1281 tempRac = Ta->linear().col(code2);
1282 m21 = Tb->linear().col(a1).dot(tempRac);
1283 m22 = Tb->linear().col(a2).dot(tempRac);
1285 S k1 = m11 * (*Sb)[a1];
1286 S k2 = m21 * (*Sb)[a1];
1287 S k3 = m12 * (*Sb)[a2];
1288 S k4 = m22 * (*Sb)[a2];
1289 quad[0] = c1 - k1 - k3;
1290 quad[1] = c2 - k2 - k4;
1291 quad[2] = c1 - k1 + k3;
1292 quad[3] = c2 - k2 + k4;
1293 quad[4] = c1 + k1 + k3;
1294 quad[5] = c2 + k2 + k4;
1295 quad[6] = c1 + k1 - k3;
1296 quad[7] = c2 + k2 - k4;
1300 rect[0] = (*Sa)[code1];
1301 rect[1] = (*Sa)[code2];
1305 int n_intersect = intersectRectQuad2(rect, quad, ret);
1306 if(n_intersect < 1) { *return_code = code;
return 0; }
1312 Vector3<S> points[8];
1314 S det1 = 1.f/(m11*m22 - m12*m21);
1320 for(
int j = 0; j < n_intersect; ++j)
1322 S k1 = m22*(ret[j*2]-c1) - m12*(ret[j*2+1]-c2);
1323 S k2 = -m21*(ret[j*2]-c1) + m11*(ret[j*2+1]-c2);
1324 points[cnum] = center + Tb->linear().col(a1) * k1 + Tb->linear().col(a2) * k2;
1325 dep[cnum] = (*Sa)[codeN] - normal2.dot(points[cnum]);
1328 ret[cnum*2] = ret[j*2];
1329 ret[cnum*2+1] = ret[j*2+1];
1333 if(cnum < 1) { *return_code = code;
return 0; }
1336 if(maxc > cnum) maxc = cnum;
1337 if(maxc < 1) maxc = 1;
1344 for(
int j = 0; j < cnum; ++j)
1346 Vector3<S> pointInWorld = points[j] + Ta->translation();
1347 contacts.emplace_back(normal, pointInWorld, -dep[j]);
1353 for(
int j = 0; j < cnum; ++j)
1355 Vector3<S> pointInWorld = points[j] + Ta->translation() - normal * dep[j];
1356 contacts.emplace_back(normal, pointInWorld, -dep[j]);
1365 S maxdepth = dep[0];
1366 for(
int i = 1; i < cnum; ++i)
1368 if(dep[i] > maxdepth)
1376 cullPoints2(cnum, ret, maxc, i1, iret);
1378 for(
int j = 0; j < maxc; ++j)
1380 Vector3<S> posInWorld = points[iret[j]] + Ta->translation();
1382 contacts.emplace_back(normal, posInWorld, -dep[iret[j]]);
1384 contacts.emplace_back(normal, posInWorld - normal * dep[iret[j]], -dep[iret[j]]);
1389 *return_code = code;
1394 template <
typename S>
1395 bool boxBoxIntersect(
const Box<S>& s1,
const Transform3<S>& tf1,
1396 const Box<S>& s2,
const Transform3<S>& tf2,
1397 std::vector<ContactPoint<S>>* contacts_)
1399 std::vector<ContactPoint<S>> contacts;
1403 boxBox2(s1.side, tf1,
1405 normal, &depth, &return_code,
1409 *contacts_ = contacts;
1411 return return_code != 0;
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
static constexpr S pi()
The mathematical constant pi.
Definition: constants.h:49