CollisionAlgorithmsMatrix.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. #include "anki/collision/CollisionAlgorithmsMatrix.h"
  2. #include "anki/collision/Collision.h"
  3. #include "anki/util/Assert.h"
  4. #include "anki/math/Math.h"
  5. #include <limits>
  6. namespace anki {
  7. //==============================================================================
  8. template<typename T>
  9. bool CollisionAlgorithmsMatrix::tcollide(const CollisionShape& a,
  10. const CollisionShape& b)
  11. {
  12. const T& t = static_cast<const T&>(a);
  13. switch(b.getCollisionShapeType())
  14. {
  15. case CollisionShape::CST_LINE_SEG:
  16. return collide(t, static_cast<const LineSegment&>(b));
  17. case CollisionShape::CST_RAY:
  18. return collide(t, static_cast<const Ray&>(b));
  19. case CollisionShape::CST_PLANE:
  20. return collide(t, static_cast<const Plane&>(b));
  21. case CollisionShape::CST_SPHERE:
  22. return collide(t, static_cast<const Sphere&>(b));
  23. case CollisionShape::CST_AABB:
  24. return collide(t, static_cast<const Aabb&>(b));
  25. case CollisionShape::CST_OBB:
  26. return collide(t, static_cast<const Obb&>(b));
  27. case CollisionShape::CST_PERSPECTIVE_CAMERA_FRUSTRUM:
  28. return collide(t, static_cast<const PerspectiveCameraShape&>(b));
  29. default:
  30. ANKI_ASSERT(0 && "Forgot something");
  31. }
  32. }
  33. //==============================================================================
  34. bool CollisionAlgorithmsMatrix::collide(const CollisionShape& a,
  35. const CollisionShape& b)
  36. {
  37. switch(a.getCollisionShapeType())
  38. {
  39. case CollisionShape::CST_LINE_SEG:
  40. return tcollide<LineSegment>(a, b);
  41. case CollisionShape::CST_RAY:
  42. return tcollide<Ray>(a, b);
  43. case CollisionShape::CST_PLANE:
  44. return tcollide<Plane>(a, b);
  45. case CollisionShape::CST_SPHERE:
  46. return tcollide<Sphere>(a, b);
  47. case CollisionShape::CST_AABB:
  48. return tcollide<Aabb>(a, b);
  49. case CollisionShape::CST_OBB:
  50. return tcollide<Obb>(a, b);
  51. case CollisionShape::CST_PERSPECTIVE_CAMERA_FRUSTRUM:
  52. return tcollide<PerspectiveCameraShape>(a, b);
  53. default:
  54. ANKI_ASSERT(0 && "Forgot something");
  55. }
  56. }
  57. //==============================================================================
  58. // 1st row =
  59. //==============================================================================
  60. //==============================================================================
  61. bool CollisionAlgorithmsMatrix::collide(const Ls& /*a*/, const Ls& /*b*/)
  62. {
  63. ANKI_ASSERT(0 && "N/A");
  64. return false;
  65. }
  66. //==============================================================================
  67. bool CollisionAlgorithmsMatrix::collide(const Ls& ls, const Obb& obb)
  68. {
  69. float maxS = std::numeric_limits<float>::min();
  70. float minT = std::numeric_limits<float>::max();
  71. // compute difference vector
  72. Vec3 diff = obb.getCenter() - ls.getOrigin();
  73. // for each axis do
  74. for(int i = 0; i < 3; ++i)
  75. {
  76. // get axis i
  77. Vec3 axis = obb.getRotation().getColumn(i);
  78. // project relative vector onto axis
  79. float e = axis.dot(diff);
  80. float f = ls.getDirection().dot(axis);
  81. // ray is parallel to plane
  82. if(Math::isZero(f))
  83. {
  84. // ray passes by box
  85. if(-e - obb.getExtend()[i] > 0.0 || -e + obb.getExtend()[i] > 0.0)
  86. {
  87. return false;
  88. }
  89. continue;
  90. }
  91. float s = (e - obb.getExtend()[i]) / f;
  92. float t = (e + obb.getExtend()[i]) / f;
  93. // fix order
  94. if(s > t)
  95. {
  96. float temp = s;
  97. s = t;
  98. t = temp;
  99. }
  100. // adjust min and max values
  101. if(s > maxS)
  102. {
  103. maxS = s;
  104. }
  105. if(t < minT)
  106. {
  107. minT = t;
  108. }
  109. // check for intersection failure
  110. if(minT < 0.0 || maxS > 1.0 || maxS > minT)
  111. {
  112. return false;
  113. }
  114. }
  115. // done, have intersection
  116. return true;
  117. }
  118. //==============================================================================
  119. bool CollisionAlgorithmsMatrix::collide(const Ls& /*a*/, const Pcs& /*b*/)
  120. {
  121. ANKI_ASSERT(0 && "Not implemented yet");
  122. return false;
  123. }
  124. //==============================================================================
  125. bool CollisionAlgorithmsMatrix::collide(const Ls& ls, const Plane& p)
  126. {
  127. return ls.testPlane(p) == 0.0;
  128. }
  129. //==============================================================================
  130. bool CollisionAlgorithmsMatrix::collide(const Ls& /*a*/, const Ray& /*b*/)
  131. {
  132. ANKI_ASSERT(0 && "N/A");
  133. return false;
  134. }
  135. //==============================================================================
  136. bool CollisionAlgorithmsMatrix::collide(const Ls& ls, const Sphere& s)
  137. {
  138. const Vec3& v = ls.getDirection();
  139. Vec3 w0 = s.getCenter() - ls.getOrigin();
  140. float w0dv = w0.dot(v);
  141. float rsq = s.getRadius() * s.getRadius();
  142. if(w0dv < 0.0) // if the ang is >90
  143. {
  144. return w0.getLengthSquared() <= rsq;
  145. }
  146. Vec3 w1 = w0 - v; // aka center - P1, where P1 = seg.origin + seg.dir
  147. float w1dv = w1.dot(v);
  148. if(w1dv > 0.0) // if the ang is <90
  149. {
  150. return w1.getLengthSquared() <= rsq;
  151. }
  152. // the big parenthesis is the projection of w0 to v
  153. Vec3 tmp = w0 - (v * (w0.dot(v) / v.getLengthSquared()));
  154. return tmp.getLengthSquared() <= rsq;
  155. }
  156. //==============================================================================
  157. bool CollisionAlgorithmsMatrix::collide(const Ls& ls, const Aabb& aabb)
  158. {
  159. float maxS = std::numeric_limits<float>::min();
  160. float minT = std::numeric_limits<float>::max();
  161. // do tests against three sets of planes
  162. for(int i = 0; i < 3; ++i)
  163. {
  164. // segment is parallel to plane
  165. if(Math::isZero(ls.getDirection()[i]))
  166. {
  167. // segment passes by box
  168. if(ls.getOrigin()[i] < aabb.getMin()[i] ||
  169. ls.getOrigin()[i] > aabb.getMax()[i])
  170. {
  171. return false;
  172. }
  173. }
  174. else
  175. {
  176. // compute intersection parameters and sort
  177. float s = (aabb.getMin()[i] - ls.getOrigin()[i]) /
  178. ls.getDirection()[i];
  179. float t = (aabb.getMax()[i] - ls.getOrigin()[i]) /
  180. ls.getDirection()[i];
  181. if(s > t)
  182. {
  183. float temp = s;
  184. s = t;
  185. t = temp;
  186. }
  187. // adjust min and max values
  188. if(s > maxS)
  189. {
  190. maxS = s;
  191. }
  192. if(t < minT)
  193. {
  194. minT = t;
  195. }
  196. // check for intersection failure
  197. if(minT < 0.0 || maxS > 1.0 || maxS > minT)
  198. {
  199. return false;
  200. }
  201. }
  202. }
  203. // done, have intersection
  204. return true;
  205. }
  206. //==============================================================================
  207. // 2nd row =
  208. //==============================================================================
  209. //==============================================================================
  210. bool CollisionAlgorithmsMatrix::collide(const Obb& o0, const Obb& o1)
  211. {
  212. // extent vectors
  213. const Vec3& a = o0.getExtend();
  214. const Vec3& b = o1.getExtend();
  215. // test factors
  216. float cTest, aTest, bTest;
  217. bool parallelAxes = false;
  218. // transpose of rotation of B relative to A, i.e. (R_b^T * R_a)^T
  219. Mat3 rt = o0.getRotation().getTransposed() * o1.getRotation();
  220. // absolute value of relative rotation matrix
  221. Mat3 rabs;
  222. for(uint i = 0; i < 3; ++i)
  223. {
  224. for(uint j = 0; j < 3; ++j)
  225. {
  226. rabs(i, j) = fabs(rt(i, j));
  227. // if magnitude of dot product between axes is close to one
  228. if(rabs(i, j) + Math::EPSILON >= 1.0)
  229. {
  230. // then box A and box B have near-parallel axes
  231. parallelAxes = true;
  232. }
  233. }
  234. }
  235. // relative translation (in A's frame)
  236. Vec3 c = o0.getRotation().getTransposed() *
  237. (o1.getCenter() - o0.getCenter());
  238. // separating axis A0
  239. cTest = fabs(c.x());
  240. aTest = a.x();
  241. bTest = b.x() * rabs(0, 0) + b.y() * rabs(0, 1) + b.z() * rabs(0, 2);
  242. if(cTest > aTest + bTest)
  243. {
  244. return false;
  245. }
  246. // separating axis A1
  247. cTest = fabs(c.y());
  248. aTest = a.y();
  249. bTest = b.x() * rabs(1, 0) + b.y() * rabs(1, 1) + b.z() * rabs(1, 2);
  250. if(cTest > aTest + bTest)
  251. {
  252. return false;
  253. }
  254. // separating axis A2
  255. cTest = fabs(c.z());
  256. aTest = a.z();
  257. bTest = b.x() * rabs(2, 0) + b.y() * rabs(2, 1) + b.z() * rabs(2, 2);
  258. if(cTest > aTest + bTest)
  259. {
  260. return false;
  261. }
  262. // separating axis B0
  263. cTest = fabs(c.x() * rt(0, 0) + c.y() * rt(1, 0) + c.z() * rt(2, 0));
  264. aTest = a.x() * rabs(0, 0) + a.y() * rabs(1, 0) + a.z() * rabs(2, 0);
  265. bTest = b.x();
  266. if(cTest > aTest + bTest)
  267. {
  268. return false;
  269. }
  270. // separating axis B1
  271. cTest = fabs(c.x() * rt(0, 1) + c.y() * rt(1, 1) + c.z() * rt(2, 1));
  272. aTest = a.x() * rabs(0, 1) + a.y() * rabs(1, 1) + a.z() * rabs(2, 1);
  273. bTest = b.y();
  274. if(cTest > aTest + bTest)
  275. {
  276. return false;
  277. }
  278. // separating axis B2
  279. cTest = fabs(c.x() * rt(0, 2) + c.y() * rt(1, 2) + c.z() * rt(2, 2));
  280. aTest = a.x() * rabs(0, 2) + a.y() * rabs(1, 2) + a.z() * rabs(2, 2);
  281. bTest = b.z();
  282. if(cTest > aTest + bTest)
  283. {
  284. return false;
  285. }
  286. // if the two boxes have parallel axes, we're done, intersection
  287. if(parallelAxes)
  288. {
  289. return true;
  290. }
  291. // separating axis A0 x B0
  292. cTest = fabs(c.z() * rt(1, 0) - c.y() * rt(2, 0));
  293. aTest = a.y() * rabs(2, 0) + a.z() * rabs(1, 0);
  294. bTest = b.y() * rabs(0, 2) + b.z() * rabs(0, 1);
  295. if(cTest > aTest + bTest)
  296. {
  297. return false;
  298. }
  299. // separating axis A0 x B1
  300. cTest = fabs(c.z() * rt(1, 1) - c.y() * rt(2, 1));
  301. aTest = a.y() * rabs(2, 1) + a.z() * rabs(1, 1);
  302. bTest = b.x() * rabs(0, 2) + b.z() * rabs(0, 0);
  303. if(cTest > aTest + bTest)
  304. {
  305. return false;
  306. }
  307. // separating axis A0 x B2
  308. cTest = fabs(c.z() * rt(1, 2) - c.y() * rt(2, 2));
  309. aTest = a.y() * rabs(2, 2) + a.z() * rabs(1, 2);
  310. bTest = b.x() * rabs(0, 1) + b.y() * rabs(0, 0);
  311. if(cTest > aTest + bTest)
  312. {
  313. return false;
  314. }
  315. // separating axis A1 x B0
  316. cTest = fabs(c.x() * rt(2, 0) - c.z() * rt(0, 0));
  317. aTest = a.x() * rabs(2, 0) + a.z() * rabs(0, 0);
  318. bTest = b.y() * rabs(1, 2) + b.z() * rabs(1, 1);
  319. if(cTest > aTest + bTest)
  320. {
  321. return false;
  322. }
  323. // separating axis A1 x B1
  324. cTest = fabs(c.x() * rt(2, 1) - c.z() * rt(0, 1));
  325. aTest = a.x() * rabs(2, 1) + a.z() * rabs(0, 1);
  326. bTest = b.x() * rabs(1, 2) + b.z() * rabs(1, 0);
  327. if(cTest > aTest + bTest)
  328. {
  329. return false;
  330. }
  331. // separating axis A1 x B2
  332. cTest = fabs(c.x() * rt(2, 2) - c.z() * rt(0, 2));
  333. aTest = a.x() * rabs(2, 2) + a.z() * rabs(0, 2);
  334. bTest = b.x() * rabs(1, 1) + b.y() * rabs(1, 0);
  335. if(cTest > aTest + bTest)
  336. {
  337. return false;
  338. }
  339. // separating axis A2 x B0
  340. cTest = fabs(c.y() * rt(0, 0) - c.x() * rt(1, 0));
  341. aTest = a.x() * rabs(1, 0) + a.y() * rabs(0, 0);
  342. bTest = b.y() * rabs(2, 2) + b.z() * rabs(2, 1);
  343. if(cTest > aTest + bTest)
  344. {
  345. return false;
  346. }
  347. // separating axis A2 x B1
  348. cTest = fabs(c.y() * rt(0, 1) - c.x() * rt(1, 1));
  349. aTest = a.x() * rabs(1, 1) + a.y() * rabs(0, 1);
  350. bTest = b.x() * rabs(2, 2) + b.z() * rabs(2, 0);
  351. if(cTest > aTest + bTest)
  352. {
  353. return false;
  354. }
  355. // separating axis A2 x B2
  356. cTest = fabs(c.y() * rt(0, 2) - c.x() * rt(1, 2));
  357. aTest = a.x() * rabs(1, 2) + a.y() * rabs(0, 2);
  358. bTest = b.x() * rabs(2, 1) + b.y() * rabs(2, 0);
  359. if(cTest > aTest + bTest)
  360. {
  361. return false;
  362. }
  363. // all tests failed, have intersection
  364. return true;
  365. }
  366. //==============================================================================
  367. bool CollisionAlgorithmsMatrix::collide(const Obb& a, const Pcs& b)
  368. {
  369. ANKI_ASSERT(0 && "Not impelented yet");
  370. return false;
  371. }
  372. //==============================================================================
  373. bool CollisionAlgorithmsMatrix::collide(const Obb& a, const Plane& b)
  374. {
  375. return a.testPlane(b) == 0.0;
  376. }
  377. //==============================================================================
  378. bool CollisionAlgorithmsMatrix::collide(const Obb& obb, const Ray& r)
  379. {
  380. Aabb aabb_(-obb.getExtend(), obb.getExtend());
  381. Ray newray;
  382. Mat3 rottrans = obb.getRotation().getTransposed();
  383. newray.getOrigin() = rottrans * (r.getOrigin() - obb.getCenter());
  384. newray.getDirection() = rottrans * r.getDirection();
  385. return collide(newray, aabb_);
  386. }
  387. //==============================================================================
  388. bool CollisionAlgorithmsMatrix::collide(const Obb& obb, const Sphere& s)
  389. {
  390. Aabb aabb_(-obb.getExtend(), obb.getExtend()); // aabb_ is in "this" frame
  391. Vec3 newCenter = obb.getRotation().getTransposed() *
  392. (s.getCenter() - obb.getCenter());
  393. Sphere sphere_(newCenter, s.getRadius()); // sphere1 to "this" fame
  394. return collide(sphere_, aabb_);
  395. }
  396. //==============================================================================
  397. bool CollisionAlgorithmsMatrix::collide(const Obb& obb, const Aabb& aabb)
  398. {
  399. Vec3 center_ = (aabb.getMax() + aabb.getMin()) * 0.5;
  400. Vec3 extends_ = (aabb.getMax() - aabb.getMin()) * 0.5;
  401. Obb obb_(center_, Mat3::getIdentity(), extends_);
  402. return collide(obb, obb_);
  403. }
  404. //==============================================================================
  405. // 3rd line (PCS) =
  406. //==============================================================================
  407. //==============================================================================
  408. bool CollisionAlgorithmsMatrix::collide(const Pcs& a, const Pcs& b)
  409. {
  410. ANKI_ASSERT(0 && "Not implemented yet");
  411. return false;
  412. }
  413. //==============================================================================
  414. bool CollisionAlgorithmsMatrix::collide(const Pcs& a, const Plane& b)
  415. {
  416. ANKI_ASSERT(0 && "Not implemented yet");
  417. return false;
  418. }
  419. //==============================================================================
  420. bool CollisionAlgorithmsMatrix::collide(const Pcs& a, const Ray& b)
  421. {
  422. ANKI_ASSERT(0 && "Not implemented yet");
  423. return false;
  424. }
  425. //==============================================================================
  426. bool CollisionAlgorithmsMatrix::collide(const Pcs& a, const Sphere& b)
  427. {
  428. ANKI_ASSERT(0 && "Not implemented yet");
  429. return false;
  430. }
  431. //==============================================================================
  432. bool CollisionAlgorithmsMatrix::collide(const Pcs& a, const Aabb& b)
  433. {
  434. ANKI_ASSERT(0 && "Not implemented yet");
  435. return false;
  436. }
  437. //==============================================================================
  438. // 4th line (P) =
  439. //==============================================================================
  440. //==============================================================================
  441. bool CollisionAlgorithmsMatrix::collide(const Plane& p0, const Plane& p1)
  442. {
  443. return p0.getNormal() != p1.getNormal();
  444. }
  445. //==============================================================================
  446. bool CollisionAlgorithmsMatrix::collide(const Plane& p, const Ray& r)
  447. {
  448. return r.testPlane(p) == 0.0;
  449. }
  450. //==============================================================================
  451. bool CollisionAlgorithmsMatrix::collide(const Plane& p, const Sphere& s)
  452. {
  453. return s.testPlane(p) == 0.0;
  454. }
  455. //==============================================================================
  456. bool CollisionAlgorithmsMatrix::collide(const Plane& p, const Aabb& aabb)
  457. {
  458. return aabb.testPlane(p) == 0.0;
  459. }
  460. //==============================================================================
  461. // 5th line (R) =
  462. //==============================================================================
  463. //==============================================================================
  464. bool CollisionAlgorithmsMatrix::collide(const Ray& a, const Ray& b)
  465. {
  466. ANKI_ASSERT(0 && "N/A");
  467. return false;
  468. }
  469. //==============================================================================
  470. bool CollisionAlgorithmsMatrix::collide(const Ray& r, const Sphere& s)
  471. {
  472. Vec3 w(s.getCenter() - r.getOrigin());
  473. const Vec3& v = r.getDirection();
  474. float proj = v.dot(w);
  475. float wsq = w.getLengthSquared();
  476. float rsq = s.getRadius() * s.getRadius();
  477. if(proj < 0.0 && wsq > rsq)
  478. {
  479. return false;
  480. }
  481. float vsq = v.getLengthSquared();
  482. return (vsq * wsq - proj * proj <= vsq * rsq);
  483. }
  484. //==============================================================================
  485. bool CollisionAlgorithmsMatrix::collide(const Ray& r, const Aabb& aabb)
  486. {
  487. float maxS = std::numeric_limits<float>::min();
  488. float minT = std::numeric_limits<float>::max();
  489. // do tests against three sets of planes
  490. for(int i = 0; i < 3; ++i)
  491. {
  492. // ray is parallel to plane
  493. if(Math::isZero(r.getDirection()[i]))
  494. {
  495. // ray passes by box
  496. if(r.getOrigin()[i] < aabb.getMin()[i] ||
  497. r.getOrigin()[i] > aabb.getMax()[i])
  498. {
  499. return false;
  500. }
  501. }
  502. else
  503. {
  504. // compute intersection parameters and sort
  505. float s = (aabb.getMin()[i] - r.getOrigin()[i]) /
  506. r.getDirection()[i];
  507. float t = (aabb.getMax()[i] - r.getOrigin()[i]) /
  508. r.getDirection()[i];
  509. if(s > t)
  510. {
  511. float temp = s;
  512. s = t;
  513. t = temp;
  514. }
  515. // adjust min and max values
  516. if(s > maxS)
  517. {
  518. maxS = s;
  519. }
  520. if(t < minT)
  521. {
  522. minT = t;
  523. }
  524. // check for intersection failure
  525. if(minT < 0.0 || maxS > minT)
  526. {
  527. return false;
  528. }
  529. }
  530. }
  531. // done, have intersection
  532. return true;
  533. }
  534. //==============================================================================
  535. // 6th line (S) =
  536. //==============================================================================
  537. //==============================================================================
  538. bool CollisionAlgorithmsMatrix::collide(const Sphere& a, const Sphere& b)
  539. {
  540. float tmp = a.getRadius() + b.getRadius();
  541. return (a.getCenter() - b.getCenter()).getLengthSquared() <= tmp * tmp;
  542. }
  543. //==============================================================================
  544. bool CollisionAlgorithmsMatrix::collide(const Sphere& s, const Aabb& aabb)
  545. {
  546. const Vec3& c = s.getCenter();
  547. // find the box's closest point to the sphere
  548. Vec3 cp; // Closest Point
  549. for(uint i = 0; i < 3; i++)
  550. {
  551. // if the center is greater than the max then the closest
  552. // point is the max
  553. if(c[i] > aabb.getMax()[i])
  554. {
  555. cp[i] = aabb.getMax()[i];
  556. }
  557. else if(c[i] < aabb.getMin()[i]) // relative to the above
  558. {
  559. cp[i] = aabb.getMin()[i];
  560. }
  561. else
  562. {
  563. // the c lies between min and max
  564. cp[i] = c[i];
  565. }
  566. }
  567. float rsq = s.getRadius() * s.getRadius();
  568. // if the c lies totaly inside the box then the sub is the zero,
  569. // this means that the length is also zero and thus its always smaller
  570. // than rsq
  571. Vec3 sub = c - cp;
  572. if(sub.getLengthSquared() <= rsq)
  573. {
  574. return true;
  575. }
  576. return false;
  577. }
  578. //==============================================================================
  579. // 7th line (AABB) =
  580. //==============================================================================
  581. //==============================================================================
  582. bool CollisionAlgorithmsMatrix::collide(const Aabb& a, const Aabb& b)
  583. {
  584. // if separated in x direction
  585. if(a.getMin().x() > b.getMax().x() || b.getMin().x() > a.getMax().x())
  586. {
  587. return false;
  588. }
  589. // if separated in y direction
  590. if(a.getMin().y() > b.getMax().y() || b.getMin().y() > a.getMax().y())
  591. {
  592. return false;
  593. }
  594. // if separated in z direction
  595. if(a.getMin().z() > b.getMax().z() || b.getMin().z() > a.getMax().z())
  596. {
  597. return false;
  598. }
  599. // no separation, must be intersecting
  600. return true;
  601. }
  602. } // end namespace