2
0

bounds.cpp 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  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)
  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. return mad(axis, tt, _line.pos);
  827. }
  828. Vec3 closestPoint(const Plane& _plane, const Vec3& _point)
  829. {
  830. const float dist = distance(_plane, _point);
  831. return sub(_point, mul(_plane.normal, dist) );
  832. }
  833. Vec3 closestPoint(const Aabb& _aabb, const Vec3& _point)
  834. {
  835. return clamp(_point, _aabb.min, _aabb.max);
  836. }
  837. Vec3 closestPoint(const Obb& _obb, const Vec3& _point)
  838. {
  839. Srt srt = toSrt(_obb.mtx);
  840. const Vec3 obbSpacePos = mul(sub(_point, srt.translation), invert(srt.rotation) );
  841. Aabb aabb;
  842. toAabb(aabb, srt.scale);
  843. const Vec3 pos = closestPoint(aabb, obbSpacePos);
  844. return add(mul(pos, srt.rotation), srt.translation);
  845. }
  846. Vec3 closestPoint(const Triangle& _triangle, const Vec3& _point)
  847. {
  848. Plane plane;
  849. calcPlane(plane, _triangle);
  850. const Vec3 pos = closestPoint(plane, _point);
  851. const Vec3 uvw = barycentric(_triangle, pos);
  852. return cartesian(_triangle, clamp<Vec3>(uvw, 0.0f, 1.0f) );
  853. }
  854. bool overlap(const Sphere& _sphere, const Vec3& _pos)
  855. {
  856. const Vec3 ba = sub(_sphere.center, _pos);
  857. const float rsq = square(_sphere.radius);
  858. return dot(ba, ba) <= rsq;
  859. }
  860. bool overlap(const Sphere& _sphereA, const Sphere& _sphereB)
  861. {
  862. const Vec3 ba = sub(_sphereA.center, _sphereB.center);
  863. const float rsq = square(_sphereA.radius + _sphereB.radius);
  864. return dot(ba, ba) <= rsq;
  865. }
  866. bool overlap(const Sphere& _sphere, const Aabb& _aabb)
  867. {
  868. const Vec3 pos = closestPoint(_aabb, _sphere.center);
  869. return overlap(_sphere, pos);
  870. }
  871. bool overlap(const Sphere& _sphere, const Plane& _plane)
  872. {
  873. return bx::abs(distance(_plane, _sphere.center) ) <= _sphere.radius;
  874. }
  875. bool overlap(const Sphere& _sphere, const Triangle& _triangle)
  876. {
  877. Plane plane;
  878. calcPlane(plane, _triangle);
  879. if (!overlap(_sphere, plane) )
  880. {
  881. return false;
  882. }
  883. const Vec3 pos = closestPoint(plane, _sphere.center);
  884. const Vec3 uvw = barycentric(_triangle, pos);
  885. const float nr = -_sphere.radius;
  886. return uvw.x >= nr
  887. && uvw.y >= nr
  888. && uvw.z >= nr
  889. ;
  890. }
  891. bool overlap(const Sphere& _sphere, const Cylinder& _cylinder)
  892. {
  893. BX_UNUSED(_sphere, _cylinder);
  894. return false;
  895. }
  896. bool overlap(const Sphere& _sphere, const Capsule& _capsule)
  897. {
  898. const Vec3 pos = closestPoint(LineSegment{_capsule.pos, _capsule.end}, _sphere.center);
  899. return overlap(_sphere, Sphere{pos, _capsule.radius});
  900. }
  901. bool overlap(const Sphere& _sphere, const Cone& _cone)
  902. {
  903. BX_UNUSED(_sphere, _cone);
  904. return false;
  905. }
  906. bool overlap(const Sphere& _sphere, const Disk& _disk)
  907. {
  908. if (!overlap(_sphere, Sphere{_disk.center, _disk.radius}) )
  909. {
  910. return false;
  911. }
  912. Plane plane;
  913. calcPlane(plane, _disk.normal, _disk.center);
  914. return overlap(_sphere, plane);
  915. }
  916. bool overlap(const Sphere& _sphere, const Obb& _obb)
  917. {
  918. const Vec3 pos = closestPoint(_obb, _sphere.center);
  919. return overlap(_sphere, pos);
  920. }
  921. bool overlap(const Aabb& _aabb, const Vec3& _pos)
  922. {
  923. const Vec3 ac = getCenter(_aabb);
  924. const Vec3 ae = getExtents(_aabb);
  925. const Vec3 abc = bx::abs(sub(ac, _pos) );
  926. return abc.x <= ae.x
  927. && abc.y <= ae.y
  928. && abc.z <= ae.z
  929. ;
  930. }
  931. bool overlap(const Aabb& _aabb, const Sphere& _sphere)
  932. {
  933. return overlap(_sphere, _aabb);
  934. }
  935. uint32_t overlapTestMask(const Aabb& _aabbA, const Aabb& _aabbB)
  936. {
  937. /// Returns 0 is two AABB don't overlap, otherwise returns flags of overlap
  938. /// test.
  939. const uint32_t ltMinX = _aabbA.max.x < _aabbB.min.x;
  940. const uint32_t gtMaxX = _aabbA.min.x > _aabbB.max.x;
  941. const uint32_t ltMinY = _aabbA.max.y < _aabbB.min.y;
  942. const uint32_t gtMaxY = _aabbA.min.y > _aabbB.max.y;
  943. const uint32_t ltMinZ = _aabbA.max.z < _aabbB.min.z;
  944. const uint32_t gtMaxZ = _aabbA.min.z > _aabbB.max.z;
  945. return 0
  946. | (ltMinX << 0)
  947. | (gtMaxX << 1)
  948. | (ltMinY << 2)
  949. | (gtMaxY << 3)
  950. | (ltMinZ << 4)
  951. | (gtMaxZ << 5)
  952. ;
  953. }
  954. bool overlap(const Aabb& _aabbA, const Aabb& _aabbB)
  955. {
  956. #if 0
  957. return 0 != overlapTestMask(_aabbA, _aabbB);
  958. #else
  959. const Vec3 ac = getCenter(_aabbA);
  960. const Vec3 bc = getCenter(_aabbB);
  961. const Vec3 abc = bx::abs(sub(ac, bc) );
  962. const Vec3 ae = getExtents(_aabbA);
  963. const Vec3 be = getExtents(_aabbB);
  964. const Vec3 abe = add(ae, be);
  965. return abc.x <= abe.x
  966. && abc.y <= abe.y
  967. && abc.z <= abe.z
  968. ;
  969. #endif // 0
  970. }
  971. bool overlap(const Aabb& _aabb, const Plane& _plane)
  972. {
  973. const Vec3 center = getCenter(_aabb);
  974. const float dist = distance(_plane, center);
  975. const Vec3 extents = getExtents(_aabb);
  976. const Vec3 normal = bx::abs(_plane.normal);
  977. const float radius = dot(extents, normal);
  978. return bx::abs(dist) <= radius;
  979. }
  980. static constexpr Vec3 kAxis[] =
  981. {
  982. { 1.0f, 0.0f, 0.0f },
  983. { 0.0f, 1.0f, 0.0f },
  984. { 0.0f, 0.0f, 1.0f },
  985. };
  986. bool overlap(const Aabb& _aabb, const Triangle& _triangle)
  987. {
  988. Aabb triAabb;
  989. toAabb(triAabb, _triangle);
  990. if (!overlap(_aabb, triAabb) )
  991. {
  992. return false;
  993. }
  994. Plane plane;
  995. calcPlane(plane, _triangle);
  996. if (!overlap(_aabb, plane) )
  997. {
  998. return false;
  999. }
  1000. const Vec3 center = getCenter(_aabb);
  1001. const Vec3 v0 = sub(_triangle.v0, center);
  1002. const Vec3 v1 = sub(_triangle.v1, center);
  1003. const Vec3 v2 = sub(_triangle.v2, center);
  1004. const Vec3 edge[] =
  1005. {
  1006. sub(v1, v0),
  1007. sub(v2, v1),
  1008. sub(v0, v2),
  1009. };
  1010. for (uint32_t ii = 0; ii < 3; ++ii)
  1011. {
  1012. for (uint32_t jj = 0; jj < 3; ++jj)
  1013. {
  1014. const Vec3 axis = cross(kAxis[ii], edge[jj]);
  1015. const Range1 aabbR = projectToAxis(axis, _aabb);
  1016. const Range1 triR = projectToAxis(axis, _triangle);
  1017. if (!overlap(aabbR, triR) )
  1018. {
  1019. return false;
  1020. }
  1021. }
  1022. }
  1023. return true;
  1024. }
  1025. bool overlap(const Aabb& _aabb, const Cylinder& _cylinder)
  1026. {
  1027. BX_UNUSED(_aabb, _cylinder);
  1028. return false;
  1029. }
  1030. bool overlap(const Aabb& _aabb, const Capsule& _capsule)
  1031. {
  1032. BX_UNUSED(_aabb, _capsule);
  1033. return false;
  1034. }
  1035. bool overlap(const Aabb& _aabb, const Cone& _cone)
  1036. {
  1037. BX_UNUSED(_aabb, _cone);
  1038. return false;
  1039. }
  1040. bool overlap(const Aabb& _aabb, const Disk& _disk)
  1041. {
  1042. if (!overlap(_aabb, Sphere{_disk.center, _disk.radius}) )
  1043. {
  1044. return false;
  1045. }
  1046. Plane plane;
  1047. calcPlane(plane, _disk.normal, _disk.center);
  1048. return overlap(_aabb, plane);
  1049. }
  1050. bool overlap(const Aabb& _aabb, const Obb& _obb)
  1051. {
  1052. BX_UNUSED(_aabb, _obb);
  1053. return false;
  1054. }
  1055. bool overlap(const Triangle& _triangle, const Vec3& _pos)
  1056. {
  1057. const Vec3 uvw = barycentric(_triangle, _pos);
  1058. return uvw.x >= 0.0f
  1059. && uvw.y >= 0.0f
  1060. && uvw.z >= 0.0f
  1061. ;
  1062. }
  1063. bool overlap(const Triangle& _triangle, const Sphere& _sphere)
  1064. {
  1065. return overlap(_sphere, _triangle);
  1066. }
  1067. bool overlap(const Triangle& _triangle, const Aabb& _aabb)
  1068. {
  1069. return overlap(_aabb, _triangle);
  1070. }
  1071. bool overlap(const Triangle& _triangle, const Plane& _plane)
  1072. {
  1073. const float dist0 = distance(_plane, _triangle.v0);
  1074. const float dist1 = distance(_plane, _triangle.v1);
  1075. const float dist2 = distance(_plane, _triangle.v2);
  1076. const float minDist = min(dist0, dist1, dist2);
  1077. const float maxDist = max(dist0, dist1, dist2);
  1078. return 0.0f > minDist
  1079. && 0.0f < maxDist
  1080. ;
  1081. }
  1082. bool overlap(const Triangle& _triangleA, const Triangle& _triangleB)
  1083. {
  1084. BX_UNUSED(_triangleA, _triangleB);
  1085. return false;
  1086. }
  1087. bool overlap(const Triangle& _triangle, const Cylinder& _cylinder)
  1088. {
  1089. BX_UNUSED(_triangle, _cylinder);
  1090. return false;
  1091. }
  1092. bool overlap(const Triangle& _triangle, const Capsule& _capsule)
  1093. {
  1094. BX_UNUSED(_triangle, _capsule);
  1095. return false;
  1096. }
  1097. bool overlap(const Triangle& _triangle, const Cone& _cone)
  1098. {
  1099. BX_UNUSED(_triangle, _cone);
  1100. return false;
  1101. }
  1102. bool overlap(const Triangle& _triangle, const Disk& _disk)
  1103. {
  1104. if (!overlap(_triangle, Sphere{_disk.center, _disk.radius}) )
  1105. {
  1106. return false;
  1107. }
  1108. Plane plane;
  1109. calcPlane(plane, _disk.normal, _disk.center);
  1110. return overlap(_triangle, plane);
  1111. }
  1112. bool overlap(const Triangle& _triangle, const Obb& _obb)
  1113. {
  1114. BX_UNUSED(_triangle, _obb);
  1115. return false;
  1116. }