bounds.cpp 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. /*
  2. * Copyright 2011-2019 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #include <bx/debug.h>
  6. #include <bx/rng.h>
  7. #include <bx/math.h>
  8. #include "bounds.h"
  9. using namespace bx;
  10. Vec3 getCenter(const Aabb& _aabb)
  11. {
  12. return mul(add(_aabb.min, _aabb.max), 0.5f);
  13. }
  14. Vec3 getExtents(const Aabb& _aabb)
  15. {
  16. return mul(sub(_aabb.max, _aabb.min), 0.5f);
  17. }
  18. Vec3 getCenter(const Triangle& _triangle)
  19. {
  20. return mul(add(add(_triangle.v0, _triangle.v1), _triangle.v2), 1.0f/3.0f);
  21. }
  22. void toAabb(Aabb& _outAabb, const bx::Vec3& _extents)
  23. {
  24. _outAabb.min = neg(_extents);
  25. _outAabb.max = _extents;
  26. }
  27. void toAabb(Aabb& _outAabb, const Vec3& _center, const Vec3& _extents)
  28. {
  29. _outAabb.min = sub(_center, _extents);
  30. _outAabb.max = add(_center, _extents);
  31. }
  32. void toAabb(Aabb& _outAabb, const Cylinder& _cylinder)
  33. {
  34. // Reference(s):
  35. // - https://web.archive.org/web/20181113055756/http://iquilezles.org/www/articles/diskbbox/diskbbox.htm
  36. //
  37. const Vec3 axis = sub(_cylinder.end, _cylinder.pos);
  38. const Vec3 asq = mul(axis, axis);
  39. const Vec3 nsq = mul(asq, 1.0f/dot(axis, axis) );
  40. const Vec3 one = { 1.0f, 1.0f, 1.0f };
  41. const Vec3 tmp = sub(one, nsq);
  42. const float inv = 1.0f / (tmp.x*tmp.y*tmp.z);
  43. const Vec3 extent =
  44. {
  45. _cylinder.radius * tmp.x * sqrt( (nsq.x + nsq.y * nsq.z) * inv),
  46. _cylinder.radius * tmp.y * sqrt( (nsq.y + nsq.z * nsq.x) * inv),
  47. _cylinder.radius * tmp.z * sqrt( (nsq.z + nsq.x * nsq.y) * inv),
  48. };
  49. const Vec3 minP = sub(_cylinder.pos, extent);
  50. const Vec3 minE = sub(_cylinder.end, extent);
  51. const Vec3 maxP = add(_cylinder.pos, extent);
  52. const Vec3 maxE = add(_cylinder.end, extent);
  53. _outAabb.min = min(minP, minE);
  54. _outAabb.max = max(maxP, maxE);
  55. }
  56. void toAabb(Aabb& _outAabb, const Disk& _disk)
  57. {
  58. // Reference(s):
  59. // - https://web.archive.org/web/20181113055756/http://iquilezles.org/www/articles/diskbbox/diskbbox.htm
  60. //
  61. const Vec3 nsq = mul(_disk.normal, _disk.normal);
  62. const Vec3 one = { 1.0f, 1.0f, 1.0f };
  63. const Vec3 tmp = sub(one, nsq);
  64. const float inv = 1.0f / (tmp.x*tmp.y*tmp.z);
  65. const Vec3 extent =
  66. {
  67. _disk.radius * tmp.x * sqrt( (nsq.x + nsq.y * nsq.z) * inv),
  68. _disk.radius * tmp.y * sqrt( (nsq.y + nsq.z * nsq.x) * inv),
  69. _disk.radius * tmp.z * sqrt( (nsq.z + nsq.x * nsq.y) * inv),
  70. };
  71. _outAabb.min = sub(_disk.center, extent);
  72. _outAabb.max = add(_disk.center, extent);
  73. }
  74. void toAabb(Aabb& _outAabb, const Obb& _obb)
  75. {
  76. Vec3 xyz = { 1.0f, 1.0f, 1.0f };
  77. Vec3 tmp = mul(xyz, _obb.mtx);
  78. _outAabb.min = tmp;
  79. _outAabb.max = tmp;
  80. for (uint32_t ii = 1; ii < 8; ++ii)
  81. {
  82. xyz.x = ii & 1 ? -1.0f : 1.0f;
  83. xyz.y = ii & 2 ? -1.0f : 1.0f;
  84. xyz.z = ii & 4 ? -1.0f : 1.0f;
  85. tmp = mul(xyz, _obb.mtx);
  86. _outAabb.min = min(_outAabb.min, tmp);
  87. _outAabb.max = max(_outAabb.max, tmp);
  88. }
  89. }
  90. void toAabb(Aabb& _outAabb, const Sphere& _sphere)
  91. {
  92. const float radius = _sphere.radius;
  93. _outAabb.min = sub(_sphere.center, radius);
  94. _outAabb.max = add(_sphere.center, radius);
  95. }
  96. void toAabb(Aabb& _outAabb, const Triangle& _triangle)
  97. {
  98. _outAabb.min = min(_triangle.v0, _triangle.v1, _triangle.v2);
  99. _outAabb.max = max(_triangle.v0, _triangle.v1, _triangle.v2);
  100. }
  101. void aabbTransformToObb(Obb& _obb, const Aabb& _aabb, const float* _mtx)
  102. {
  103. toObb(_obb, _aabb);
  104. float result[16];
  105. mtxMul(result, _obb.mtx, _mtx);
  106. memCopy(_obb.mtx, result, sizeof(result) );
  107. }
  108. void toAabb(Aabb& _outAabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
  109. {
  110. Vec3 mn, mx;
  111. uint8_t* vertex = (uint8_t*)_vertices;
  112. mn = mx = load<Vec3>(vertex);
  113. vertex += _stride;
  114. for (uint32_t ii = 1; ii < _numVertices; ++ii)
  115. {
  116. const Vec3 pos = load<Vec3>(vertex);
  117. vertex += _stride;
  118. mn = min(pos, mn);
  119. mx = max(pos, mx);
  120. }
  121. _outAabb.min = mn;
  122. _outAabb.max = mx;
  123. }
  124. void toAabb(Aabb& _outAabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
  125. {
  126. Vec3 mn, mx;
  127. uint8_t* vertex = (uint8_t*)_vertices;
  128. mn = mx = mul(load<Vec3>(vertex), _mtx);
  129. vertex += _stride;
  130. for (uint32_t ii = 1; ii < _numVertices; ++ii)
  131. {
  132. Vec3 pos = mul(load<Vec3>(vertex), _mtx);
  133. vertex += _stride;
  134. mn = min(pos, mn);
  135. mx = max(pos, mx);
  136. }
  137. _outAabb.min = mn;
  138. _outAabb.max = mx;
  139. }
  140. float calcAreaAabb(const Aabb& _aabb)
  141. {
  142. const float ww = _aabb.max.x - _aabb.min.x;
  143. const float hh = _aabb.max.y - _aabb.min.y;
  144. const float dd = _aabb.max.z - _aabb.min.z;
  145. return 2.0f * (ww*hh + ww*dd + hh*dd);
  146. }
  147. void aabbExpand(Aabb& _outAabb, float _factor)
  148. {
  149. _outAabb.min.x -= _factor;
  150. _outAabb.min.y -= _factor;
  151. _outAabb.min.z -= _factor;
  152. _outAabb.max.x += _factor;
  153. _outAabb.max.y += _factor;
  154. _outAabb.max.z += _factor;
  155. }
  156. void aabbExpand(Aabb& _outAabb, const Vec3& _pos)
  157. {
  158. _outAabb.min = min(_outAabb.min, _pos);
  159. _outAabb.max = max(_outAabb.max, _pos);
  160. }
  161. void toObb(Obb& _outObb, const Aabb& _aabb)
  162. {
  163. memSet(_outObb.mtx, 0, sizeof(_outObb.mtx) );
  164. _outObb.mtx[ 0] = (_aabb.max.x - _aabb.min.x) * 0.5f;
  165. _outObb.mtx[ 5] = (_aabb.max.y - _aabb.min.y) * 0.5f;
  166. _outObb.mtx[10] = (_aabb.max.z - _aabb.min.z) * 0.5f;
  167. _outObb.mtx[12] = (_aabb.min.x + _aabb.max.x) * 0.5f;
  168. _outObb.mtx[13] = (_aabb.min.y + _aabb.max.y) * 0.5f;
  169. _outObb.mtx[14] = (_aabb.min.z + _aabb.max.z) * 0.5f;
  170. _outObb.mtx[15] = 1.0f;
  171. }
  172. void calcObb(Obb& _outObb, const void* _vertices, uint32_t _numVertices, uint32_t _stride, uint32_t _steps)
  173. {
  174. Aabb aabb;
  175. toAabb(aabb, _vertices, _numVertices, _stride);
  176. float minArea = calcAreaAabb(aabb);
  177. Obb best;
  178. toObb(best, aabb);
  179. float angleStep = float(kPiHalf/_steps);
  180. float ax = 0.0f;
  181. float mtx[16];
  182. for (uint32_t ii = 0; ii < _steps; ++ii)
  183. {
  184. float ay = 0.0f;
  185. for (uint32_t jj = 0; jj < _steps; ++jj)
  186. {
  187. float az = 0.0f;
  188. for (uint32_t kk = 0; kk < _steps; ++kk)
  189. {
  190. mtxRotateXYZ(mtx, ax, ay, az);
  191. float mtxT[16];
  192. mtxTranspose(mtxT, mtx);
  193. toAabb(aabb, mtxT, _vertices, _numVertices, _stride);
  194. float area = calcAreaAabb(aabb);
  195. if (area < minArea)
  196. {
  197. minArea = area;
  198. aabbTransformToObb(best, aabb, mtx);
  199. }
  200. az += angleStep;
  201. }
  202. ay += angleStep;
  203. }
  204. ax += angleStep;
  205. }
  206. memCopy(&_outObb, &best, sizeof(Obb) );
  207. }
  208. void calcMaxBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
  209. {
  210. Aabb aabb;
  211. toAabb(aabb, _vertices, _numVertices, _stride);
  212. Vec3 center = getCenter(aabb);
  213. float maxDistSq = 0.0f;
  214. uint8_t* vertex = (uint8_t*)_vertices;
  215. for (uint32_t ii = 0; ii < _numVertices; ++ii)
  216. {
  217. const Vec3& pos = load<Vec3>(vertex);
  218. vertex += _stride;
  219. const Vec3 tmp = sub(pos, center);
  220. const float distSq = dot(tmp, tmp);
  221. maxDistSq = max(distSq, maxDistSq);
  222. }
  223. _sphere.center = center;
  224. _sphere.radius = sqrt(maxDistSq);
  225. }
  226. void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride, float _step)
  227. {
  228. RngMwc rng;
  229. uint8_t* vertex = (uint8_t*)_vertices;
  230. Vec3 center;
  231. float* position = (float*)&vertex[0];
  232. center.x = position[0];
  233. center.y = position[1];
  234. center.z = position[2];
  235. position = (float*)&vertex[1*_stride];
  236. center.x += position[0];
  237. center.y += position[1];
  238. center.z += position[2];
  239. center.x *= 0.5f;
  240. center.y *= 0.5f;
  241. center.z *= 0.5f;
  242. float xx = position[0] - center.x;
  243. float yy = position[1] - center.y;
  244. float zz = position[2] - center.z;
  245. float maxDistSq = xx*xx + yy*yy + zz*zz;
  246. float radiusStep = _step * 0.37f;
  247. bool done;
  248. do
  249. {
  250. done = true;
  251. for (uint32_t ii = 0, index = rng.gen()%_numVertices; ii < _numVertices; ++ii, index = (index + 1)%_numVertices)
  252. {
  253. position = (float*)&vertex[index*_stride];
  254. xx = position[0] - center.x;
  255. yy = position[1] - center.y;
  256. zz = position[2] - center.z;
  257. float distSq = xx*xx + yy*yy + zz*zz;
  258. if (distSq > maxDistSq)
  259. {
  260. done = false;
  261. center.x += xx * radiusStep;
  262. center.y += yy * radiusStep;
  263. center.z += zz * radiusStep;
  264. maxDistSq = lerp(maxDistSq, distSq, _step);
  265. break;
  266. }
  267. }
  268. } while (!done);
  269. _sphere.center = center;
  270. _sphere.radius = sqrt(maxDistSq);
  271. }
  272. void buildFrustumPlanes(Plane* _result, const float* _viewProj)
  273. {
  274. const float xw = _viewProj[ 3];
  275. const float yw = _viewProj[ 7];
  276. const float zw = _viewProj[11];
  277. const float ww = _viewProj[15];
  278. const float xz = _viewProj[ 2];
  279. const float yz = _viewProj[ 6];
  280. const float zz = _viewProj[10];
  281. const float wz = _viewProj[14];
  282. Plane& near = _result[0];
  283. Plane& far = _result[1];
  284. Plane& left = _result[2];
  285. Plane& right = _result[3];
  286. Plane& top = _result[4];
  287. Plane& bottom = _result[5];
  288. near.normal.x = xw - xz;
  289. near.normal.y = yw - yz;
  290. near.normal.z = zw - zz;
  291. near.dist = ww - wz;
  292. far.normal.x = xw + xz;
  293. far.normal.y = yw + yz;
  294. far.normal.z = zw + zz;
  295. far.dist = ww + wz;
  296. const float xx = _viewProj[ 0];
  297. const float yx = _viewProj[ 4];
  298. const float zx = _viewProj[ 8];
  299. const float wx = _viewProj[12];
  300. left.normal.x = xw - xx;
  301. left.normal.y = yw - yx;
  302. left.normal.z = zw - zx;
  303. left.dist = ww - wx;
  304. right.normal.x = xw + xx;
  305. right.normal.y = yw + yx;
  306. right.normal.z = zw + zx;
  307. right.dist = ww + wx;
  308. const float xy = _viewProj[ 1];
  309. const float yy = _viewProj[ 5];
  310. const float zy = _viewProj[ 9];
  311. const float wy = _viewProj[13];
  312. top.normal.x = xw + xy;
  313. top.normal.y = yw + yy;
  314. top.normal.z = zw + zy;
  315. top.dist = ww + wy;
  316. bottom.normal.x = xw - xy;
  317. bottom.normal.y = yw - yy;
  318. bottom.normal.z = zw - zy;
  319. bottom.dist = ww - wy;
  320. Plane* plane = _result;
  321. for (uint32_t ii = 0; ii < 6; ++ii)
  322. {
  323. const float invLen = 1.0f/length(plane->normal);
  324. plane->normal = normalize(plane->normal);
  325. plane->dist *= invLen;
  326. ++plane;
  327. }
  328. }
  329. Vec3 intersectPlanes(const Plane& _pa, const Plane& _pb, const Plane& _pc)
  330. {
  331. const Vec3 axb = cross(_pa.normal, _pb.normal);
  332. const Vec3 bxc = cross(_pb.normal, _pc.normal);
  333. const Vec3 cxa = cross(_pc.normal, _pa.normal);
  334. const Vec3 tmp0 = mul(bxc, _pa.dist);
  335. const Vec3 tmp1 = mul(cxa, _pb.dist);
  336. const Vec3 tmp2 = mul(axb, _pc.dist);
  337. const Vec3 tmp3 = add(tmp0, tmp1);
  338. const Vec3 tmp4 = add(tmp3, tmp2);
  339. const float denom = dot(_pa.normal, bxc);
  340. const Vec3 result = mul(tmp4, -1.0f/denom);
  341. return result;
  342. }
  343. Ray makeRay(float _x, float _y, const float* _invVp)
  344. {
  345. Ray ray;
  346. const Vec3 near = { _x, _y, 0.0f };
  347. ray.pos = mulH(near, _invVp);
  348. const Vec3 far = { _x, _y, 1.0f };
  349. Vec3 tmp = mulH(far, _invVp);
  350. const Vec3 dir = sub(tmp, ray.pos);
  351. ray.dir = normalize(dir);
  352. return ray;
  353. }
  354. inline Vec3 getPointAt(const Ray& _ray, float _t)
  355. {
  356. return add(mul(_ray.dir, _t), _ray.pos);
  357. }
  358. bool intersect(const Ray& _ray, const Aabb& _aabb, Hit* _hit)
  359. {
  360. const Vec3 invDir = rcp(_ray.dir);
  361. const Vec3 tmp0 = sub(_aabb.min, _ray.pos);
  362. const Vec3 t0 = mul(tmp0, invDir);
  363. const Vec3 tmp1 = sub(_aabb.max, _ray.pos);
  364. const Vec3 t1 = mul(tmp1, invDir);
  365. const Vec3 mn = min(t0, t1);
  366. const Vec3 mx = max(t0, t1);
  367. const float tmin = max(mn.x, mn.y, mn.z);
  368. const float tmax = min(mx.x, mx.y, mx.z);
  369. if (0.0f > tmax
  370. || tmin > tmax)
  371. {
  372. return false;
  373. }
  374. if (NULL != _hit)
  375. {
  376. _hit->plane.normal.x = float( (t1.x == tmin) - (t0.x == tmin) );
  377. _hit->plane.normal.y = float( (t1.y == tmin) - (t0.y == tmin) );
  378. _hit->plane.normal.z = float( (t1.z == tmin) - (t0.z == tmin) );
  379. _hit->plane.dist = tmin;
  380. _hit->pos = getPointAt(_ray, tmin);
  381. }
  382. return true;
  383. }
  384. static constexpr Aabb kUnitAabb =
  385. {
  386. { -1.0f, -1.0f, -1.0f },
  387. { 1.0f, 1.0f, 1.0f },
  388. };
  389. bool intersect(const Ray& _ray, const Obb& _obb, Hit* _hit)
  390. {
  391. Aabb aabb;
  392. toAabb(aabb, _obb);
  393. if (!intersect(_ray, aabb) )
  394. {
  395. return false;
  396. }
  397. float mtxInv[16];
  398. mtxInverse(mtxInv, _obb.mtx);
  399. Ray obbRay;
  400. obbRay.pos = mul(_ray.pos, mtxInv);
  401. obbRay.dir = mulXyz0(_ray.dir, mtxInv);
  402. if (intersect(obbRay, kUnitAabb, _hit) )
  403. {
  404. if (NULL != _hit)
  405. {
  406. _hit->pos = mul(_hit->pos, _obb.mtx);
  407. const Vec3 tmp = mulXyz0(_hit->plane.normal, _obb.mtx);
  408. _hit->plane.normal = normalize(tmp);
  409. }
  410. return true;
  411. }
  412. return false;
  413. }
  414. bool intersect(const Ray& _ray, const Disk& _disk, Hit* _hit)
  415. {
  416. Plane plane;
  417. plane.normal = _disk.normal;
  418. plane.dist = -dot(_disk.center, _disk.normal);
  419. Hit tmpHit;
  420. _hit = NULL != _hit ? _hit : &tmpHit;
  421. if (intersect(_ray, plane, _hit) )
  422. {
  423. const Vec3 tmp = sub(_disk.center, _hit->pos);
  424. return dot(tmp, tmp) <= square(_disk.radius);
  425. }
  426. return false;
  427. }
  428. static bool intersect(const Ray& _ray, const Cylinder& _cylinder, bool _capsule, Hit* _hit)
  429. {
  430. Vec3 axis = sub(_cylinder.end, _cylinder.pos);
  431. const Vec3 rc = sub(_ray.pos, _cylinder.pos);
  432. const Vec3 dxa = cross(_ray.dir, axis);
  433. const float len = length(dxa);
  434. const Vec3 normal = normalize(dxa);
  435. const float dist = bx::abs(dot(rc, normal) );
  436. if (dist > _cylinder.radius)
  437. {
  438. return false;
  439. }
  440. Vec3 vo = cross(rc, axis);
  441. const float t0 = -dot(vo, normal) / len;
  442. vo = normalize(cross(normal, axis) );
  443. const float rsq = square(_cylinder.radius);
  444. const float ddoto = dot(_ray.dir, vo);
  445. const float ss = t0 - bx::abs(sqrt(rsq - square(dist) ) / ddoto);
  446. if (0.0f > ss)
  447. {
  448. return false;
  449. }
  450. const Vec3 point = getPointAt(_ray, ss);
  451. const float axisLen = length(axis);
  452. axis = normalize(axis);
  453. const float pdota = dot(_cylinder.pos, axis);
  454. const float height = dot(point, axis) - pdota;
  455. if (0.0f < height
  456. && axisLen > height)
  457. {
  458. if (NULL != _hit)
  459. {
  460. const float t1 = height / axisLen;
  461. const Vec3 pointOnAxis = lerp(_cylinder.pos, _cylinder.end, t1);
  462. _hit->pos = point;
  463. const Vec3 tmp = sub(point, pointOnAxis);
  464. _hit->plane.normal = normalize(tmp);
  465. _hit->plane.dist = ss;
  466. }
  467. return true;
  468. }
  469. if (_capsule)
  470. {
  471. const float rdota = dot(_ray.pos, axis);
  472. const float pp = rdota - pdota;
  473. const float t1 = pp / axisLen;
  474. const Vec3 pointOnAxis = lerp(_cylinder.pos, _cylinder.end, t1);
  475. const Vec3 axisToRay = sub(_ray.pos, pointOnAxis);
  476. if (_cylinder.radius < length(axisToRay)
  477. && 0.0f > ss)
  478. {
  479. return false;
  480. }
  481. Sphere sphere;
  482. sphere.radius = _cylinder.radius;
  483. sphere.center = 0.0f >= height
  484. ? _cylinder.pos
  485. : _cylinder.end
  486. ;
  487. return intersect(_ray, sphere, _hit);
  488. }
  489. Plane plane;
  490. Vec3 pos;
  491. if (0.0f >= height)
  492. {
  493. plane.normal = neg(axis);
  494. pos = _cylinder.pos;
  495. }
  496. else
  497. {
  498. plane.normal = axis;
  499. pos = _cylinder.end;
  500. }
  501. plane.dist = -dot(pos, plane.normal);
  502. Hit tmpHit;
  503. _hit = NULL != _hit ? _hit : &tmpHit;
  504. if (intersect(_ray, plane, _hit) )
  505. {
  506. const Vec3 tmp = sub(pos, _hit->pos);
  507. return dot(tmp, tmp) <= rsq;
  508. }
  509. return false;
  510. }
  511. bool intersect(const Ray& _ray, const Cylinder& _cylinder, Hit* _hit)
  512. {
  513. return intersect(_ray, _cylinder, false, _hit);
  514. }
  515. bool intersect(const Ray& _ray, const Capsule& _capsule, Hit* _hit)
  516. {
  517. BX_STATIC_ASSERT(sizeof(Capsule) == sizeof(Cylinder) );
  518. return intersect(_ray, *( (const Cylinder*)&_capsule), true, _hit);
  519. }
  520. bool intersect(const Ray& _ray, const Cone& _cone, Hit* _hit)
  521. {
  522. const Vec3 axis = sub(_cone.pos, _cone.end);
  523. const float len = length(axis);
  524. const Vec3 normal = normalize(axis);
  525. Disk disk;
  526. disk.center = _cone.pos;
  527. disk.normal = normal;
  528. disk.radius = _cone.radius;
  529. Hit tmpInt;
  530. Hit* out = NULL != _hit ? _hit : &tmpInt;
  531. bool hit = intersect(_ray, disk, out);
  532. const Vec3 ro = sub(_ray.pos, _cone.end);
  533. const float hyp = sqrt(square(_cone.radius) + square(len) );
  534. const float cosaSq = square(len/hyp);
  535. const float ndoto = dot(normal, ro);
  536. const float ndotd = dot(normal, _ray.dir);
  537. const float aa = square(ndotd) - cosaSq;
  538. const float bb = 2.0f * (ndotd*ndoto - dot(_ray.dir, ro)*cosaSq);
  539. const float cc = square(ndoto) - dot(ro, ro)*cosaSq;
  540. float det = bb*bb - 4.0f*aa*cc;
  541. if (0.0f > det)
  542. {
  543. return hit;
  544. }
  545. det = sqrt(det);
  546. const float invA2 = 1.0f / (2.0f*aa);
  547. const float t1 = (-bb - det) * invA2;
  548. const float t2 = (-bb + det) * invA2;
  549. float tt = t1;
  550. if (0.0f > t1
  551. || (0.0f < t2 && t2 < t1) )
  552. {
  553. tt = t2;
  554. }
  555. if (0.0f > tt)
  556. {
  557. return hit;
  558. }
  559. const Vec3 hitPos = getPointAt(_ray, tt);
  560. const Vec3 point = sub(hitPos, _cone.end);
  561. const float hh = dot(normal, point);
  562. if (0.0f > hh
  563. || len < hh)
  564. {
  565. return hit;
  566. }
  567. if (NULL != _hit)
  568. {
  569. if (!hit
  570. || tt < _hit->plane.dist)
  571. {
  572. _hit->plane.dist = tt;
  573. _hit->pos = hitPos;
  574. const float scale = hh / dot(point, point);
  575. const Vec3 pointScaled = mul(point, scale);
  576. const Vec3 tmp = sub(pointScaled, normal);
  577. _hit->plane.normal = normalize(tmp);
  578. }
  579. }
  580. return true;
  581. }
  582. bool intersect(const Ray& _ray, const Plane& _plane, Hit* _hit)
  583. {
  584. const float dist = distance(_plane, _ray.pos);
  585. if (0.0f > dist)
  586. {
  587. return false;
  588. }
  589. const float ndotd = dot(_ray.dir, _plane.normal);
  590. if (0.0f < ndotd)
  591. {
  592. return false;
  593. }
  594. if (NULL != _hit)
  595. {
  596. _hit->plane.normal = _plane.normal;
  597. float tt = -dist/ndotd;
  598. _hit->plane.dist = tt;
  599. _hit->pos = getPointAt(_ray, tt);
  600. }
  601. return true;
  602. }
  603. bool intersect(const Ray& _ray, const Sphere& _sphere, Hit* _hit)
  604. {
  605. const Vec3 rs = sub(_ray.pos, _sphere.center);
  606. const float bb = dot(rs, _ray.dir);
  607. if (0.0f < bb)
  608. {
  609. return false;
  610. }
  611. const float aa = dot(_ray.dir, _ray.dir);
  612. const float cc = dot(rs, rs) - square(_sphere.radius);
  613. const float discriminant = bb*bb - aa*cc;
  614. if (0.0f >= discriminant)
  615. {
  616. return false;
  617. }
  618. const float sqrtDiscriminant = sqrt(discriminant);
  619. const float invA = 1.0f / aa;
  620. const float tt = -(bb + sqrtDiscriminant)*invA;
  621. if (0.0f >= tt)
  622. {
  623. return false;
  624. }
  625. if (NULL != _hit)
  626. {
  627. _hit->plane.dist = tt;
  628. const Vec3 point = getPointAt(_ray, tt);
  629. _hit->pos = point;
  630. const Vec3 tmp = sub(point, _sphere.center);
  631. _hit->plane.normal = normalize(tmp);
  632. }
  633. return true;
  634. }
  635. bool intersect(const Ray& _ray, const Triangle& _triangle, Hit* _hit)
  636. {
  637. const Vec3 edge10 = sub(_triangle.v1, _triangle.v0);
  638. const Vec3 edge02 = sub(_triangle.v0, _triangle.v2);
  639. const Vec3 normal = cross(edge02, edge10);
  640. const Vec3 vo = sub(_triangle.v0, _ray.pos);
  641. const Vec3 dxo = cross(_ray.dir, vo);
  642. const float det = dot(normal, _ray.dir);
  643. if (0.0f < det)
  644. {
  645. return false;
  646. }
  647. const float invDet = 1.0f/det;
  648. const float bz = dot(dxo, edge02) * invDet;
  649. const float by = dot(dxo, edge10) * invDet;
  650. const float bx = 1.0f - by - bz;
  651. if (0.0f > bx
  652. || 0.0f > by
  653. || 0.0f > bz)
  654. {
  655. return false;
  656. }
  657. if (NULL != _hit)
  658. {
  659. _hit->plane.normal = normalize(normal);
  660. const float tt = dot(normal, vo) * invDet;
  661. _hit->plane.dist = tt;
  662. _hit->pos = getPointAt(_ray, tt);
  663. }
  664. return true;
  665. }
  666. Vec3 barycentric(const Triangle& _triangle, const Vec3& _pos)
  667. {
  668. const Vec3 v0 = sub(_triangle.v1, _triangle.v0);
  669. const Vec3 v1 = sub(_triangle.v2, _triangle.v0);
  670. const Vec3 v2 = sub(_pos, _triangle.v0);
  671. const float dot00 = dot(v0, v0);
  672. const float dot01 = dot(v0, v1);
  673. const float dot02 = dot(v0, v2);
  674. const float dot11 = dot(v1, v1);
  675. const float dot12 = dot(v1, v2);
  676. const float invDenom = 1.0f/(dot00*dot11 - square(dot01) );
  677. const float uu = (dot11*dot02 - dot01*dot12)*invDenom;
  678. const float vv = (dot00*dot12 - dot01*dot02)*invDenom;
  679. const float ww = 1.0f - uu - vv;
  680. return { uu, vv, ww };
  681. }
  682. Vec3 cartesian(const Triangle& _triangle, const Vec3& _uvw)
  683. {
  684. const Vec3 b0 = mul(_triangle.v0, _uvw.x);
  685. const Vec3 b1 = mul(_triangle.v1, _uvw.y);
  686. const Vec3 b2 = mul(_triangle.v2, _uvw.z);
  687. return add(add(b0, b1), b2);
  688. }
  689. void calcPlane(Plane& _outPlane, const Triangle& _triangle)
  690. {
  691. calcPlane(_outPlane, _triangle.v0, _triangle.v1, _triangle.v2);
  692. }
  693. struct Range1
  694. {
  695. float start;
  696. float end;
  697. };
  698. bool overlap(const Range1& _a, const Range1& _b)
  699. {
  700. return _a.end > _b.start
  701. && _b.end > _a.start
  702. ;
  703. }
  704. float projectToAxis(const Vec3& _axis, const Vec3& _point)
  705. {
  706. return dot(_axis, _point);
  707. }
  708. Range1 projectToAxis(const Vec3& _axis, const Aabb& _aabb)
  709. {
  710. const float extent = bx::abs(dot(abs(_axis), getExtents(_aabb) ) );
  711. const float center = dot( _axis , getCenter (_aabb) );
  712. return
  713. {
  714. center - extent,
  715. center + extent,
  716. };
  717. }
  718. Range1 projectToAxis(const Vec3& _axis, const Triangle& _triangle)
  719. {
  720. const float a0 = dot(_axis, _triangle.v0);
  721. const float a1 = dot(_axis, _triangle.v1);
  722. const float a2 = dot(_axis, _triangle.v2);
  723. return
  724. {
  725. min(a0, a1, a2),
  726. max(a0, a1, a2),
  727. };
  728. }
  729. struct Srt
  730. {
  731. Quaternion rotation;
  732. Vec3 translation;
  733. Vec3 scale;
  734. };
  735. Srt toSrt(const void* _mtx)
  736. {
  737. Srt result;
  738. const float* mtx = (const float*)_mtx;
  739. result.translation = { mtx[12], mtx[13], mtx[14] };
  740. float xx = mtx[ 0];
  741. float xy = mtx[ 1];
  742. float xz = mtx[ 2];
  743. float yx = mtx[ 4];
  744. float yy = mtx[ 5];
  745. float yz = mtx[ 6];
  746. float zx = mtx[ 8];
  747. float zy = mtx[ 9];
  748. float zz = mtx[10];
  749. result.scale =
  750. {
  751. sqrt(xx*xx + xy*xy + xz*xz),
  752. sqrt(yx*yx + yy*yy + yz*yz),
  753. sqrt(zx*zx + zy*zy + zz*zz),
  754. };
  755. const Vec3 invScale = rcp(result.scale);
  756. xx *= invScale.x;
  757. xy *= invScale.x;
  758. xz *= invScale.x;
  759. yx *= invScale.y;
  760. yy *= invScale.y;
  761. yz *= invScale.y;
  762. zx *= invScale.z;
  763. zy *= invScale.z;
  764. zz *= invScale.z;
  765. const float trace = xx + yy + zz;
  766. if (0.0f < trace)
  767. {
  768. const float invS = 0.5f * rsqrt(trace + 1.0f);
  769. result.rotation =
  770. {
  771. (yz - zy) * invS,
  772. (zx - xz) * invS,
  773. (xy - yx) * invS,
  774. 0.25f / invS,
  775. };
  776. }
  777. else
  778. {
  779. if (xx > yy
  780. && xx > zz)
  781. {
  782. const float invS = 0.5f * sqrt(max(1.0f + xx - yy - zz, 1e-8f) );
  783. result.rotation =
  784. {
  785. 0.25f / invS,
  786. (xy + yx) * invS,
  787. (xz + zx) * invS,
  788. (yz - zy) * invS,
  789. };
  790. }
  791. else if (yy > zz)
  792. {
  793. const float invS = 0.5f * sqrt(max(1.0f + yy - xx - zz, 1e-8f) );
  794. result.rotation =
  795. {
  796. (xy + yx) * invS,
  797. 0.25f / invS,
  798. (yz + zy) * invS,
  799. (zx - xz) * invS,
  800. };
  801. }
  802. else
  803. {
  804. const float invS = 0.5f * sqrt(max(1.0f + zz - xx - yy, 1e-8f) );
  805. result.rotation =
  806. {
  807. (xz + zx) * invS,
  808. (yz + zy) * invS,
  809. 0.25f / invS,
  810. (xy - yx) * invS,
  811. };
  812. }
  813. }
  814. return result;
  815. }
  816. struct LineSegment
  817. {
  818. Vec3 pos;
  819. Vec3 end;
  820. };
  821. Vec3 closestPoint(const LineSegment& _line, const Vec3& _point, float& _outT)
  822. {
  823. const Vec3 axis = sub(_line.end, _line.pos);
  824. const float lengthSq = dot(axis, axis);
  825. const float tt = clamp(projectToAxis(axis, sub(_point, _line.pos) ) / lengthSq, 0.0f, 1.0f);
  826. _outT = tt;
  827. return mad(axis, tt, _line.pos);
  828. }
  829. Vec3 closestPoint(const LineSegment& _line, const Vec3& _point)
  830. {
  831. float ignore;
  832. return closestPoint(_line, _point, ignore);
  833. }
  834. Vec3 closestPoint(const Plane& _plane, const Vec3& _point)
  835. {
  836. const float dist = distance(_plane, _point);
  837. return sub(_point, mul(_plane.normal, dist) );
  838. }
  839. Vec3 closestPoint(const Aabb& _aabb, const Vec3& _point)
  840. {
  841. return clamp(_point, _aabb.min, _aabb.max);
  842. }
  843. Vec3 closestPoint(const Obb& _obb, const Vec3& _point)
  844. {
  845. Srt srt = toSrt(_obb.mtx);
  846. const Vec3 obbSpacePos = mul(sub(_point, srt.translation), invert(srt.rotation) );
  847. Aabb aabb;
  848. toAabb(aabb, srt.scale);
  849. const Vec3 pos = closestPoint(aabb, obbSpacePos);
  850. return add(mul(pos, srt.rotation), srt.translation);
  851. }
  852. Vec3 closestPoint(const Triangle& _triangle, const Vec3& _point)
  853. {
  854. Plane plane;
  855. calcPlane(plane, _triangle);
  856. const Vec3 pos = closestPoint(plane, _point);
  857. const Vec3 uvw = barycentric(_triangle, pos);
  858. return cartesian(_triangle, clamp<Vec3>(uvw, 0.0f, 1.0f) );
  859. }
  860. bool overlap(const Sphere& _sphere, const Vec3& _pos)
  861. {
  862. const Vec3 ba = sub(_sphere.center, _pos);
  863. const float rsq = square(_sphere.radius);
  864. return dot(ba, ba) <= rsq;
  865. }
  866. bool overlap(const Sphere& _sphereA, const Sphere& _sphereB)
  867. {
  868. const Vec3 ba = sub(_sphereA.center, _sphereB.center);
  869. const float rsq = square(_sphereA.radius + _sphereB.radius);
  870. return dot(ba, ba) <= rsq;
  871. }
  872. bool overlap(const Sphere& _sphere, const Aabb& _aabb)
  873. {
  874. const Vec3 pos = closestPoint(_aabb, _sphere.center);
  875. return overlap(_sphere, pos);
  876. }
  877. bool overlap(const Sphere& _sphere, const Plane& _plane)
  878. {
  879. return bx::abs(distance(_plane, _sphere.center) ) <= _sphere.radius;
  880. }
  881. bool overlap(const Sphere& _sphere, const Triangle& _triangle)
  882. {
  883. Plane plane;
  884. calcPlane(plane, _triangle);
  885. if (!overlap(_sphere, plane) )
  886. {
  887. return false;
  888. }
  889. const Vec3 pos = closestPoint(plane, _sphere.center);
  890. const Vec3 uvw = barycentric(_triangle, pos);
  891. const float nr = -_sphere.radius;
  892. return uvw.x >= nr
  893. && uvw.y >= nr
  894. && uvw.z >= nr
  895. ;
  896. }
  897. bool overlap(const Sphere& _sphere, const Cylinder& _cylinder)
  898. {
  899. BX_UNUSED(_sphere, _cylinder);
  900. return false;
  901. }
  902. bool overlap(const Sphere& _sphere, const Capsule& _capsule)
  903. {
  904. const Vec3 pos = closestPoint(LineSegment{_capsule.pos, _capsule.end}, _sphere.center);
  905. return overlap(_sphere, Sphere{pos, _capsule.radius});
  906. }
  907. bool overlap(const Sphere& _sphere, const Cone& _cone)
  908. {
  909. float tt;
  910. const Vec3 pos = closestPoint(LineSegment{_cone.pos, _cone.end}, _sphere.center, tt);
  911. return overlap(_sphere, Sphere{pos, lerp(_cone.radius, 0.0f, tt)});
  912. }
  913. bool overlap(const Sphere& _sphere, const Disk& _disk)
  914. {
  915. if (!overlap(_sphere, Sphere{_disk.center, _disk.radius}) )
  916. {
  917. return false;
  918. }
  919. Plane plane;
  920. calcPlane(plane, _disk.normal, _disk.center);
  921. return overlap(_sphere, plane);
  922. }
  923. bool overlap(const Sphere& _sphere, const Obb& _obb)
  924. {
  925. const Vec3 pos = closestPoint(_obb, _sphere.center);
  926. return overlap(_sphere, pos);
  927. }
  928. bool overlap(const Aabb& _aabb, const Vec3& _pos)
  929. {
  930. const Vec3 ac = getCenter(_aabb);
  931. const Vec3 ae = getExtents(_aabb);
  932. const Vec3 abc = bx::abs(sub(ac, _pos) );
  933. return abc.x <= ae.x
  934. && abc.y <= ae.y
  935. && abc.z <= ae.z
  936. ;
  937. }
  938. bool overlap(const Aabb& _aabb, const Sphere& _sphere)
  939. {
  940. return overlap(_sphere, _aabb);
  941. }
  942. uint32_t overlapTestMask(const Aabb& _aabbA, const Aabb& _aabbB)
  943. {
  944. /// Returns 0 is two AABB don't overlap, otherwise returns flags of overlap
  945. /// test.
  946. const uint32_t ltMinX = _aabbA.max.x < _aabbB.min.x;
  947. const uint32_t gtMaxX = _aabbA.min.x > _aabbB.max.x;
  948. const uint32_t ltMinY = _aabbA.max.y < _aabbB.min.y;
  949. const uint32_t gtMaxY = _aabbA.min.y > _aabbB.max.y;
  950. const uint32_t ltMinZ = _aabbA.max.z < _aabbB.min.z;
  951. const uint32_t gtMaxZ = _aabbA.min.z > _aabbB.max.z;
  952. return 0
  953. | (ltMinX << 0)
  954. | (gtMaxX << 1)
  955. | (ltMinY << 2)
  956. | (gtMaxY << 3)
  957. | (ltMinZ << 4)
  958. | (gtMaxZ << 5)
  959. ;
  960. }
  961. bool overlap(const Aabb& _aabbA, const Aabb& _aabbB)
  962. {
  963. #if 0
  964. return 0 != overlapTestMask(_aabbA, _aabbB);
  965. #else
  966. const Vec3 ac = getCenter(_aabbA);
  967. const Vec3 bc = getCenter(_aabbB);
  968. const Vec3 abc = bx::abs(sub(ac, bc) );
  969. const Vec3 ae = getExtents(_aabbA);
  970. const Vec3 be = getExtents(_aabbB);
  971. const Vec3 abe = add(ae, be);
  972. return abc.x <= abe.x
  973. && abc.y <= abe.y
  974. && abc.z <= abe.z
  975. ;
  976. #endif // 0
  977. }
  978. bool overlap(const Aabb& _aabb, const Plane& _plane)
  979. {
  980. const Vec3 center = getCenter(_aabb);
  981. const float dist = distance(_plane, center);
  982. const Vec3 extents = getExtents(_aabb);
  983. const Vec3 normal = bx::abs(_plane.normal);
  984. const float radius = dot(extents, normal);
  985. return bx::abs(dist) <= radius;
  986. }
  987. static constexpr Vec3 kAxis[] =
  988. {
  989. { 1.0f, 0.0f, 0.0f },
  990. { 0.0f, 1.0f, 0.0f },
  991. { 0.0f, 0.0f, 1.0f },
  992. };
  993. bool overlap(const Aabb& _aabb, const Triangle& _triangle)
  994. {
  995. Aabb triAabb;
  996. toAabb(triAabb, _triangle);
  997. if (!overlap(_aabb, triAabb) )
  998. {
  999. return false;
  1000. }
  1001. Plane plane;
  1002. calcPlane(plane, _triangle);
  1003. if (!overlap(_aabb, plane) )
  1004. {
  1005. return false;
  1006. }
  1007. const Vec3 center = getCenter(_aabb);
  1008. const Vec3 v0 = sub(_triangle.v0, center);
  1009. const Vec3 v1 = sub(_triangle.v1, center);
  1010. const Vec3 v2 = sub(_triangle.v2, center);
  1011. const Vec3 edge[] =
  1012. {
  1013. sub(v1, v0),
  1014. sub(v2, v1),
  1015. sub(v0, v2),
  1016. };
  1017. for (uint32_t ii = 0; ii < 3; ++ii)
  1018. {
  1019. for (uint32_t jj = 0; jj < 3; ++jj)
  1020. {
  1021. const Vec3 axis = cross(kAxis[ii], edge[jj]);
  1022. const Range1 aabbR = projectToAxis(axis, _aabb);
  1023. const Range1 triR = projectToAxis(axis, _triangle);
  1024. if (!overlap(aabbR, triR) )
  1025. {
  1026. return false;
  1027. }
  1028. }
  1029. }
  1030. return true;
  1031. }
  1032. bool overlap(const Aabb& _aabb, const Cylinder& _cylinder)
  1033. {
  1034. BX_UNUSED(_aabb, _cylinder);
  1035. return false;
  1036. }
  1037. bool overlap(const Aabb& _aabb, const Capsule& _capsule)
  1038. {
  1039. BX_UNUSED(_aabb, _capsule);
  1040. return false;
  1041. }
  1042. bool overlap(const Aabb& _aabb, const Cone& _cone)
  1043. {
  1044. BX_UNUSED(_aabb, _cone);
  1045. return false;
  1046. }
  1047. bool overlap(const Aabb& _aabb, const Disk& _disk)
  1048. {
  1049. if (!overlap(_aabb, Sphere{_disk.center, _disk.radius}) )
  1050. {
  1051. return false;
  1052. }
  1053. Plane plane;
  1054. calcPlane(plane, _disk.normal, _disk.center);
  1055. return overlap(_aabb, plane);
  1056. }
  1057. bool overlap(const Aabb& _aabb, const Obb& _obb)
  1058. {
  1059. BX_UNUSED(_aabb, _obb);
  1060. return false;
  1061. }
  1062. bool overlap(const Triangle& _triangle, const Vec3& _pos)
  1063. {
  1064. const Vec3 uvw = barycentric(_triangle, _pos);
  1065. return uvw.x >= 0.0f
  1066. && uvw.y >= 0.0f
  1067. && uvw.z >= 0.0f
  1068. ;
  1069. }
  1070. bool overlap(const Triangle& _triangle, const Sphere& _sphere)
  1071. {
  1072. return overlap(_sphere, _triangle);
  1073. }
  1074. bool overlap(const Triangle& _triangle, const Aabb& _aabb)
  1075. {
  1076. return overlap(_aabb, _triangle);
  1077. }
  1078. bool overlap(const Triangle& _triangle, const Plane& _plane)
  1079. {
  1080. const float dist0 = distance(_plane, _triangle.v0);
  1081. const float dist1 = distance(_plane, _triangle.v1);
  1082. const float dist2 = distance(_plane, _triangle.v2);
  1083. const float minDist = min(dist0, dist1, dist2);
  1084. const float maxDist = max(dist0, dist1, dist2);
  1085. return 0.0f > minDist
  1086. && 0.0f < maxDist
  1087. ;
  1088. }
  1089. bool overlap(const Triangle& _triangleA, const Triangle& _triangleB)
  1090. {
  1091. BX_UNUSED(_triangleA, _triangleB);
  1092. return false;
  1093. }
  1094. bool overlap(const Triangle& _triangle, const Cylinder& _cylinder)
  1095. {
  1096. BX_UNUSED(_triangle, _cylinder);
  1097. return false;
  1098. }
  1099. bool overlap(const Triangle& _triangle, const Capsule& _capsule)
  1100. {
  1101. BX_UNUSED(_triangle, _capsule);
  1102. return false;
  1103. }
  1104. bool overlap(const Triangle& _triangle, const Cone& _cone)
  1105. {
  1106. BX_UNUSED(_triangle, _cone);
  1107. return false;
  1108. }
  1109. bool overlap(const Triangle& _triangle, const Disk& _disk)
  1110. {
  1111. if (!overlap(_triangle, Sphere{_disk.center, _disk.radius}) )
  1112. {
  1113. return false;
  1114. }
  1115. Plane plane;
  1116. calcPlane(plane, _disk.normal, _disk.center);
  1117. return overlap(_triangle, plane);
  1118. }
  1119. bool overlap(const Triangle& _triangle, const Obb& _obb)
  1120. {
  1121. BX_UNUSED(_triangle, _obb);
  1122. return false;
  1123. }