CollisionAlgorithmsMatrix.cpp 18 KB

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