debugdraw.cpp 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. /*
  2. * Copyright 2011-2023 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  4. */
  5. #include "common.h"
  6. #include "bgfx_utils.h"
  7. #include <entry/cmd.h>
  8. #include <entry/input.h>
  9. #include <debugdraw/debugdraw.h>
  10. #include "camera.h"
  11. #include "imgui/imgui.h"
  12. #include <bx/uint32_t.h>
  13. namespace
  14. {
  15. static DdVertex s_bunnyVertices[] =
  16. {
  17. { 25.0883f, -44.2788f, 31.0055f },
  18. { 0.945623f, 53.5504f, -24.6146f },
  19. { -0.94455f, -14.3443f, -16.8223f },
  20. { -20.1103f, -48.6664f, 12.6763f },
  21. { -1.60652f, -26.3165f, -24.5424f },
  22. { -30.6284f, -53.6299f, 14.7666f },
  23. { 1.69145f, -43.8075f, -15.2065f },
  24. { -20.5139f, 21.0521f, -5.40868f },
  25. { -13.9518f, 53.6299f, -39.1193f },
  26. { -21.7912f, 48.7801f, -42.0995f },
  27. { -26.8408f, 23.6537f, -17.7324f },
  28. { -23.1196f, 33.9692f, 4.91483f },
  29. { -12.3236f, -41.6303f, 31.8324f },
  30. { 27.6427f, -5.05034f, -11.3201f },
  31. { 32.2565f, 1.30521f, 30.2671f },
  32. { 47.2723f, -27.0974f, 11.1774f },
  33. { 33.598f, 10.5888f, 7.95916f },
  34. { -13.2898f, 12.6234f, 5.55953f },
  35. { -32.7364f, 19.0648f, -10.5736f },
  36. { -32.7536f, 31.4158f, -1.40712f },
  37. { -25.3672f, 30.2874f, -12.4682f },
  38. { 32.921f, -36.8408f, -12.0254f },
  39. { -37.7251f, -33.8989f, 0.378443f },
  40. { -35.6341f, -0.246891f, -9.25165f },
  41. { -16.7041f, -50.0254f, -15.6177f },
  42. { 24.6604f, -53.5319f, -11.1059f },
  43. { -7.77574f, -53.5719f, -16.6655f },
  44. { 20.6241f, 13.3489f, 0.376349f },
  45. { -44.2889f, 29.5222f, 18.7918f },
  46. { 18.5805f, 16.3651f, 12.6351f },
  47. { -23.7853f, 31.7598f, -6.54093f },
  48. { 24.7518f, -53.5075f, 2.14984f },
  49. { -45.7912f, -17.6301f, 21.1198f },
  50. { 51.8403f, -33.1847f, 24.3337f },
  51. { -47.5343f, -4.32792f, 4.06232f },
  52. { -50.6832f, -12.442f, 11.0994f },
  53. { -49.5132f, 19.2782f, 3.17559f },
  54. { -39.4881f, 29.0208f, -6.70431f },
  55. { -52.7286f, 1.23232f, 9.74872f },
  56. { 26.505f, -16.1297f, -17.0487f },
  57. { -25.367f, 20.0473f, -8.44282f },
  58. { -24.5797f, -10.3143f, -18.3154f },
  59. { -28.6707f, 6.12074f, 27.8025f },
  60. { -16.9868f, 22.6819f, 1.37408f },
  61. { -37.2678f, 23.9443f, -9.4945f },
  62. { -24.8562f, 21.3763f, 18.8847f },
  63. { -47.1879f, 3.8542f, -4.74621f },
  64. { 38.0706f, -7.33673f, -7.6099f },
  65. { -34.8833f, -3.57074f, 26.4838f },
  66. { 12.3797f, 5.46782f, 32.9762f },
  67. { -31.5974f, -22.956f, 30.5827f },
  68. { -6.80953f, 48.055f, -18.5116f },
  69. { 6.3474f, -15.1622f, -24.4726f },
  70. { -25.5733f, 25.2452f, -34.4736f },
  71. { -23.8955f, 31.8323f, -40.8696f },
  72. { -11.8622f, 38.2304f, -43.3125f },
  73. { -20.4918f, 41.2409f, -3.11271f },
  74. { 24.9806f, -8.53455f, 37.2862f },
  75. { -52.8935f, 5.3376f, 28.246f },
  76. { 34.106f, -41.7941f, 30.962f },
  77. { -1.26914f, 35.6664f, -18.7177f },
  78. { -0.13048f, 44.7288f, -28.7163f },
  79. { 2.47929f, 0.678165f, -14.6892f },
  80. { -31.8649f, -14.2299f, 32.2998f },
  81. { -19.774f, 30.8258f, 5.77293f },
  82. { 49.8059f, -37.125f, 4.97284f },
  83. { -28.0581f, -26.439f, -14.8316f },
  84. { -9.12066f, -27.3987f, -12.8592f },
  85. { -13.8752f, -29.9821f, 32.5962f },
  86. { -6.6222f, -10.9884f, 33.5007f },
  87. { -21.2664f, -53.6089f, -3.49195f },
  88. { -0.628672f, 52.8093f, -9.88088f },
  89. { 8.02417f, 51.8956f, -21.5834f },
  90. { -44.6547f, 11.9973f, 34.7897f },
  91. { -7.55466f, 37.9035f, -0.574101f },
  92. { 52.8252f, -27.1986f, 11.6429f },
  93. { -0.934591f, 9.81861f, 0.512566f },
  94. { -3.01043f, 5.70605f, 22.0954f },
  95. { -34.6337f, 44.5964f, -31.1713f },
  96. { -26.9017f, 35.1991f, -32.4307f },
  97. { 15.9884f, -8.92223f, -14.7411f },
  98. { -22.8337f, -43.458f, 26.7274f },
  99. { -31.9864f, -47.0243f, 9.36972f },
  100. { -36.9436f, 24.1866f, 29.2521f },
  101. { -26.5411f, 29.6549f, 21.2867f },
  102. { 33.7644f, -24.1886f, -13.8513f },
  103. { -2.44749f, -17.0148f, 41.6617f },
  104. { -38.364f, -13.9823f, -12.5705f },
  105. { -10.2972f, -51.6584f, 38.935f },
  106. { 1.28109f, -43.4943f, 36.6288f },
  107. { -19.7784f, -44.0413f, -4.23994f },
  108. { 37.0944f, -53.5479f, 27.6467f },
  109. { 24.9642f, -37.1722f, 35.7038f },
  110. { 37.5851f, 5.64874f, 21.6702f },
  111. { -17.4738f, -53.5734f, 30.0664f },
  112. { -8.93088f, 45.3429f, -34.4441f },
  113. { -17.7111f, -6.5723f, 29.5162f },
  114. { 44.0059f, -17.4408f, -5.08686f },
  115. { -46.2534f, -22.6115f, 0.702059f },
  116. { 43.9321f, -33.8575f, 4.31819f },
  117. { 41.6762f, -7.37115f, 27.6798f },
  118. { 8.20276f, -42.0948f, -18.0893f },
  119. { 26.2678f, -44.6777f, -10.6835f },
  120. { 17.709f, 13.1542f, 25.1769f },
  121. { -35.9897f, 3.92007f, 35.8198f },
  122. { -23.9323f, -37.3142f, -2.39396f },
  123. { 5.19169f, 46.8851f, -28.7587f },
  124. { -37.3072f, -35.0484f, 16.9719f },
  125. { 45.0639f, -28.5255f, 22.3465f },
  126. { -34.4175f, 35.5861f, -21.7562f },
  127. { 9.32684f, -12.6655f, 42.189f },
  128. { 1.00938f, -31.7694f, 43.1914f },
  129. { -45.4666f, -3.71104f, 19.2248f },
  130. { -28.7999f, -50.8481f, 31.5232f },
  131. { 35.2212f, -45.9047f, 0.199736f },
  132. { 40.3f, -53.5889f, 7.47622f },
  133. { 29.0515f, 5.1074f, -10.002f },
  134. { 13.4336f, 4.84341f, -9.72327f },
  135. { 11.0617f, -26.245f, -24.9471f },
  136. { -35.6056f, -51.2531f, 0.436527f },
  137. { -10.6863f, 34.7374f, -36.7452f },
  138. { -51.7652f, 27.4957f, 7.79363f },
  139. { -50.1898f, 18.379f, 26.3763f },
  140. { -49.6836f, -1.32722f, 26.2828f },
  141. { 19.0363f, -16.9114f, 41.8511f },
  142. { 32.7141f, -21.501f, 36.0025f },
  143. { 12.5418f, -28.4244f, 43.3125f },
  144. { -19.5634f, 42.6328f, -27.0687f },
  145. { -16.1942f, 6.55011f, 19.4066f },
  146. { 46.9886f, -18.8482f, 22.1332f },
  147. { 45.9697f, -3.76781f, 4.10111f },
  148. { -28.2912f, 51.3277f, -35.1815f },
  149. { -40.2796f, -27.7518f, 22.8684f },
  150. { -22.7984f, -38.9977f, 22.158f },
  151. { 54.0614f, -35.6096f, 12.694f },
  152. { 44.2064f, -53.6029f, 18.8679f },
  153. { 19.789f, -29.517f, -19.6094f },
  154. { -34.3769f, 34.8566f, 9.92517f },
  155. { -23.7518f, -45.0319f, 8.71282f },
  156. { -12.7978f, 3.55087f, -13.7108f },
  157. { -54.0614f, 8.83831f, 8.91353f },
  158. { 16.2986f, -53.5717f, 34.065f },
  159. { -36.6243f, -53.5079f, 24.6495f },
  160. { 16.5794f, -48.5747f, 35.5681f },
  161. { -32.3263f, 41.4526f, -18.7388f },
  162. { -18.8488f, 9.62627f, -8.81052f },
  163. { 5.35849f, 36.3616f, -12.9346f },
  164. { 6.19167f, 34.497f, -17.965f },
  165. };
  166. static const uint16_t s_bunnyTriList[] =
  167. {
  168. 80, 2, 52,
  169. 0, 143, 92,
  170. 51, 1, 71,
  171. 96, 128, 77,
  172. 67, 2, 41,
  173. 85, 39, 52,
  174. 58, 123, 38,
  175. 99, 21, 114,
  176. 55, 9, 54,
  177. 136, 102, 21,
  178. 3, 133, 81,
  179. 101, 136, 4,
  180. 5, 82, 3,
  181. 6, 90, 24,
  182. 7, 40, 145,
  183. 33, 75, 134,
  184. 55, 8, 9,
  185. 10, 40, 20,
  186. 46, 140, 38,
  187. 74, 64, 11,
  188. 89, 88, 12,
  189. 147, 60, 7,
  190. 47, 116, 13,
  191. 59, 129, 108,
  192. 147, 72, 106,
  193. 33, 108, 75,
  194. 100, 57, 14,
  195. 129, 130, 15,
  196. 32, 35, 112,
  197. 16, 29, 27,
  198. 107, 98, 132,
  199. 130, 116, 47,
  200. 17, 43, 7,
  201. 54, 44, 53,
  202. 46, 34, 23,
  203. 87, 41, 23,
  204. 40, 10, 18,
  205. 8, 131, 9,
  206. 11, 19, 56,
  207. 11, 137, 19,
  208. 19, 20, 30,
  209. 28, 121, 137,
  210. 122, 140, 36,
  211. 15, 130, 97,
  212. 28, 84, 83,
  213. 114, 21, 102,
  214. 87, 98, 22,
  215. 41, 145, 23,
  216. 133, 68, 12,
  217. 90, 70, 24,
  218. 31, 25, 26,
  219. 98, 34, 35,
  220. 16, 27, 116,
  221. 28, 83, 122,
  222. 29, 103, 77,
  223. 40, 30, 20,
  224. 14, 49, 103,
  225. 31, 26, 142,
  226. 78, 9, 131,
  227. 80, 62, 2,
  228. 6, 67, 105,
  229. 32, 48, 63,
  230. 60, 30, 7,
  231. 33, 135, 91,
  232. 116, 130, 16,
  233. 47, 13, 39,
  234. 70, 119, 5,
  235. 24, 26, 6,
  236. 102, 25, 31,
  237. 103, 49, 77,
  238. 16, 130, 93,
  239. 125, 126, 124,
  240. 111, 86, 110,
  241. 4, 52, 2,
  242. 87, 34, 98,
  243. 4, 6, 101,
  244. 29, 76, 27,
  245. 112, 35, 34,
  246. 6, 4, 67,
  247. 72, 1, 106,
  248. 26, 24, 70,
  249. 36, 37, 121,
  250. 81, 113, 142,
  251. 44, 109, 37,
  252. 122, 58, 38,
  253. 96, 48, 128,
  254. 71, 11, 56,
  255. 73, 122, 83,
  256. 52, 39, 80,
  257. 40, 18, 145,
  258. 82, 5, 119,
  259. 10, 20, 120,
  260. 139, 145, 41,
  261. 3, 142, 5,
  262. 76, 117, 27,
  263. 95, 120, 20,
  264. 104, 45, 42,
  265. 128, 43, 17,
  266. 44, 37, 36,
  267. 128, 45, 64,
  268. 143, 111, 126,
  269. 34, 46, 38,
  270. 97, 130, 47,
  271. 142, 91, 115,
  272. 114, 31, 115,
  273. 125, 100, 129,
  274. 48, 96, 63,
  275. 62, 41, 2,
  276. 69, 77, 49,
  277. 133, 50, 68,
  278. 60, 51, 30,
  279. 4, 118, 52,
  280. 53, 55, 54,
  281. 95, 8, 55,
  282. 121, 37, 19,
  283. 65, 75, 99,
  284. 51, 56, 30,
  285. 14, 57, 110,
  286. 58, 122, 73,
  287. 59, 92, 125,
  288. 42, 45, 128,
  289. 49, 14, 110,
  290. 60, 147, 61,
  291. 76, 62, 117,
  292. 69, 49, 86,
  293. 26, 5, 142,
  294. 46, 44, 36,
  295. 63, 50, 132,
  296. 128, 64, 43,
  297. 75, 108, 15,
  298. 134, 75, 65,
  299. 68, 69, 86,
  300. 62, 76, 145,
  301. 142, 141, 91,
  302. 67, 66, 105,
  303. 69, 68, 96,
  304. 119, 70, 90,
  305. 33, 91, 108,
  306. 136, 118, 4,
  307. 56, 51, 71,
  308. 1, 72, 71,
  309. 23, 18, 44,
  310. 104, 123, 73,
  311. 106, 1, 61,
  312. 86, 111, 68,
  313. 83, 45, 104,
  314. 30, 56, 19,
  315. 15, 97, 99,
  316. 71, 74, 11,
  317. 15, 99, 75,
  318. 25, 102, 6,
  319. 12, 94, 81,
  320. 135, 33, 134,
  321. 138, 133, 3,
  322. 76, 29, 77,
  323. 94, 88, 141,
  324. 115, 31, 142,
  325. 36, 121, 122,
  326. 4, 2, 67,
  327. 9, 78, 79,
  328. 137, 121, 19,
  329. 69, 96, 77,
  330. 13, 62, 80,
  331. 8, 127, 131,
  332. 143, 141, 89,
  333. 133, 12, 81,
  334. 82, 119, 138,
  335. 45, 83, 84,
  336. 21, 85, 136,
  337. 126, 110, 124,
  338. 86, 49, 110,
  339. 13, 116, 117,
  340. 22, 66, 87,
  341. 141, 88, 89,
  342. 64, 45, 84,
  343. 79, 78, 109,
  344. 26, 70, 5,
  345. 14, 93, 100,
  346. 68, 50, 63,
  347. 90, 105, 138,
  348. 141, 0, 91,
  349. 105, 90, 6,
  350. 0, 92, 59,
  351. 17, 145, 76,
  352. 29, 93, 103,
  353. 113, 81, 94,
  354. 39, 85, 47,
  355. 132, 35, 32,
  356. 128, 48, 42,
  357. 93, 29, 16,
  358. 145, 18, 23,
  359. 108, 129, 15,
  360. 32, 112, 48,
  361. 66, 41, 87,
  362. 120, 95, 55,
  363. 96, 68, 63,
  364. 85, 99, 97,
  365. 18, 53, 44,
  366. 22, 98, 107,
  367. 98, 35, 132,
  368. 95, 127, 8,
  369. 137, 64, 84,
  370. 18, 10, 53,
  371. 21, 99, 85,
  372. 54, 79, 44,
  373. 100, 93, 130,
  374. 142, 3, 81,
  375. 102, 101, 6,
  376. 93, 14, 103,
  377. 42, 48, 104,
  378. 87, 23, 34,
  379. 66, 22, 105,
  380. 106, 61, 147,
  381. 72, 74, 71,
  382. 109, 144, 37,
  383. 115, 65, 99,
  384. 107, 132, 133,
  385. 94, 12, 88,
  386. 108, 91, 59,
  387. 43, 64, 74,
  388. 109, 78, 144,
  389. 43, 147, 7,
  390. 91, 135, 115,
  391. 111, 110, 126,
  392. 38, 112, 34,
  393. 142, 113, 94,
  394. 54, 9, 79,
  395. 120, 53, 10,
  396. 138, 3, 82,
  397. 114, 102, 31,
  398. 134, 65, 115,
  399. 105, 22, 107,
  400. 125, 129, 59,
  401. 37, 144, 19,
  402. 17, 76, 77,
  403. 89, 12, 111,
  404. 41, 66, 67,
  405. 13, 117, 62,
  406. 116, 27, 117,
  407. 136, 52, 118,
  408. 51, 60, 61,
  409. 138, 119, 90,
  410. 53, 120, 55,
  411. 68, 111, 12,
  412. 122, 121, 28,
  413. 123, 58, 73,
  414. 110, 57, 124,
  415. 47, 85, 97,
  416. 44, 79, 109,
  417. 126, 125, 92,
  418. 43, 74, 146,
  419. 20, 19, 127,
  420. 128, 17, 77,
  421. 72, 146, 74,
  422. 115, 99, 114,
  423. 140, 122, 38,
  424. 133, 105, 107,
  425. 129, 100, 130,
  426. 131, 144, 78,
  427. 95, 20, 127,
  428. 123, 48, 112,
  429. 102, 136, 101,
  430. 89, 111, 143,
  431. 28, 137, 84,
  432. 133, 132, 50,
  433. 125, 57, 100,
  434. 38, 123, 112,
  435. 124, 57, 125,
  436. 135, 134, 115,
  437. 23, 44, 46,
  438. 136, 85, 52,
  439. 41, 62, 139,
  440. 137, 11, 64,
  441. 104, 48, 123,
  442. 133, 138, 105,
  443. 145, 139, 62,
  444. 25, 6, 26,
  445. 7, 30, 40,
  446. 46, 36, 140,
  447. 141, 143, 0,
  448. 132, 32, 63,
  449. 83, 104, 73,
  450. 19, 144, 127,
  451. 142, 94, 141,
  452. 39, 13, 80,
  453. 92, 143, 126,
  454. 127, 144, 131,
  455. 51, 61, 1,
  456. 91, 0, 59,
  457. 17, 7, 145,
  458. 43, 146, 147,
  459. 146, 72, 147,
  460. };
  461. struct Shape
  462. {
  463. struct Type
  464. {
  465. enum Enum
  466. {
  467. Sphere,
  468. Aabb,
  469. Triangle,
  470. Capsule,
  471. Plane,
  472. Disk,
  473. Obb,
  474. Cone,
  475. Cylinder,
  476. Count
  477. };
  478. };
  479. Shape() : type(uint8_t(Type::Count) ) {}
  480. Shape(const bx::Aabb & _a) : type(uint8_t(Type::Aabb ) ) { bx::memCopy(data, &_a, sizeof(_a) ); }
  481. Shape(const bx::Capsule & _a) : type(uint8_t(Type::Capsule ) ) { bx::memCopy(data, &_a, sizeof(_a) ); }
  482. Shape(const bx::Cone & _a) : type(uint8_t(Type::Cone ) ) { bx::memCopy(data, &_a, sizeof(_a) ); }
  483. Shape(const bx::Cylinder & _a) : type(uint8_t(Type::Cylinder) ) { bx::memCopy(data, &_a, sizeof(_a) ); }
  484. Shape(const bx::Disk & _a) : type(uint8_t(Type::Disk ) ) { bx::memCopy(data, &_a, sizeof(_a) ); }
  485. Shape(const bx::Obb & _a) : type(uint8_t(Type::Obb ) ) { bx::memCopy(data, &_a, sizeof(_a) ); }
  486. Shape(const bx::Plane & _a) : type(uint8_t(Type::Plane ) ) { bx::memCopy(data, &_a, sizeof(_a) ); }
  487. Shape(const bx::Sphere & _a) : type(uint8_t(Type::Sphere ) ) { bx::memCopy(data, &_a, sizeof(_a) ); }
  488. Shape(const bx::Triangle & _a) : type(uint8_t(Type::Triangle) ) { bx::memCopy(data, &_a, sizeof(_a) ); }
  489. uint8_t data[64];
  490. uint8_t type;
  491. };
  492. #define OVERLAP(_shapeType) \
  493. bool overlap(const _shapeType& _shapeA, const Shape& _shapeB) \
  494. { \
  495. switch (_shapeB.type) \
  496. { \
  497. case Shape::Type::Aabb: return bx::overlap(_shapeA, *reinterpret_cast<const bx::Aabb *>(_shapeB.data) ); \
  498. case Shape::Type::Capsule: return bx::overlap(_shapeA, *reinterpret_cast<const bx::Capsule *>(_shapeB.data) ); \
  499. case Shape::Type::Cone: return bx::overlap(_shapeA, *reinterpret_cast<const bx::Cone *>(_shapeB.data) ); \
  500. case Shape::Type::Cylinder: return bx::overlap(_shapeA, *reinterpret_cast<const bx::Cylinder *>(_shapeB.data) ); \
  501. case Shape::Type::Disk: return bx::overlap(_shapeA, *reinterpret_cast<const bx::Disk *>(_shapeB.data) ); \
  502. case Shape::Type::Obb: return bx::overlap(_shapeA, *reinterpret_cast<const bx::Obb *>(_shapeB.data) ); \
  503. case Shape::Type::Plane: return bx::overlap(_shapeA, *reinterpret_cast<const bx::Plane *>(_shapeB.data) ); \
  504. case Shape::Type::Sphere: return bx::overlap(_shapeA, *reinterpret_cast<const bx::Sphere *>(_shapeB.data) ); \
  505. case Shape::Type::Triangle: return bx::overlap(_shapeA, *reinterpret_cast<const bx::Triangle *>(_shapeB.data) ); \
  506. } \
  507. return false; \
  508. }
  509. OVERLAP(bx::Aabb);
  510. OVERLAP(bx::Capsule);
  511. OVERLAP(bx::Cone);
  512. OVERLAP(bx::Cylinder);
  513. OVERLAP(bx::Disk);
  514. OVERLAP(bx::Obb);
  515. OVERLAP(bx::Plane);
  516. OVERLAP(bx::Sphere);
  517. OVERLAP(bx::Triangle);
  518. #undef OVERLAP
  519. void initA(Shape& _outShape, Shape::Type::Enum _type, bx::Vec3 _pos)
  520. {
  521. switch (_type)
  522. {
  523. case Shape::Type::Aabb:
  524. {
  525. bx::Aabb aabb;
  526. toAabb(aabb, _pos, { 0.5f, 0.5f, 0.5f });
  527. _outShape = Shape(aabb);
  528. }
  529. break;
  530. case Shape::Type::Capsule:
  531. _outShape = Shape(bx::Capsule
  532. {
  533. { bx::add(_pos, {0.0f, -1.0f, 0.0f}) },
  534. { bx::add(_pos, {0.0f, 1.0f, 0.0f}) },
  535. 0.5f,
  536. });
  537. break;
  538. case Shape::Type::Cone:
  539. _outShape = Shape(bx::Cone
  540. {
  541. { bx::add(_pos, {0.0f, -1.0f, 0.0f}) },
  542. { bx::add(_pos, {0.0f, 1.0f, 0.0f}) },
  543. 0.5f,
  544. });
  545. break;
  546. case Shape::Type::Cylinder:
  547. _outShape = Shape(bx::Cylinder
  548. {
  549. { bx::add(_pos, {0.0f, -1.0f, 0.0f}) },
  550. { bx::add(_pos, {0.0f, 1.0f, 0.0f}) },
  551. 0.5f,
  552. });
  553. break;
  554. case Shape::Type::Disk:
  555. _outShape = Shape(bx::Disk
  556. {
  557. _pos,
  558. bx::normalize(bx::Vec3{0.0f, 1.0f, 1.0f}),
  559. 0.5f,
  560. });
  561. break;
  562. case Shape::Type::Obb:
  563. {
  564. bx::Obb obb;
  565. bx::mtxSRT(obb.mtx
  566. , 0.25f
  567. , 1.0f
  568. , 0.25f
  569. , bx::toRad(50.0f)
  570. , bx::toRad(15.0f)
  571. , bx::toRad(45.0f)
  572. , _pos.x
  573. , _pos.y
  574. , _pos.z
  575. );
  576. _outShape = Shape(obb);
  577. }
  578. break;
  579. case Shape::Type::Sphere:
  580. _outShape = Shape(bx::Sphere{_pos, 0.5f});
  581. break;
  582. case Shape::Type::Plane:
  583. {
  584. bx::Plane plane(bx::InitNone);
  585. bx::calcPlane(plane, bx::normalize(bx::Vec3{0.0f, 1.0f, 1.0f}), _pos);
  586. _outShape = Shape(plane);
  587. }
  588. break;
  589. case Shape::Type::Triangle:
  590. _outShape = Shape(bx::Triangle
  591. {
  592. { bx::add(_pos, {-0.4f, 0.0f, -0.4f}) },
  593. { bx::add(_pos, { 0.0f, -0.3f, 0.5f}) },
  594. { bx::add(_pos, { 0.0f, 0.5f, 0.3f}) },
  595. });
  596. break;
  597. default: break;
  598. }
  599. }
  600. void initB(Shape& _outShape, Shape::Type::Enum _type, bx::Vec3 _pos)
  601. {
  602. switch (_type)
  603. {
  604. case Shape::Type::Aabb:
  605. {
  606. bx::Aabb aabb;
  607. toAabb(aabb, _pos, { 0.5f, 0.5f, 0.5f });
  608. _outShape = Shape(aabb);
  609. }
  610. break;
  611. case Shape::Type::Capsule:
  612. _outShape = Shape(bx::Capsule
  613. {
  614. { bx::add(_pos, {0.0f, -1.0f, 0.1f}) },
  615. { bx::add(_pos, {0.0f, 1.0f, 0.0f}) },
  616. 0.2f,
  617. });
  618. break;
  619. case Shape::Type::Cone:
  620. _outShape = Shape(bx::Cone
  621. {
  622. { bx::add(_pos, {0.0f, -1.0f, 0.1f}) },
  623. { bx::add(_pos, {0.0f, 1.0f, 0.0f}) },
  624. 0.2f,
  625. });
  626. break;
  627. case Shape::Type::Cylinder:
  628. _outShape = Shape(bx::Cylinder
  629. {
  630. { bx::add(_pos, {0.0f, -1.0f, 0.1f}) },
  631. { bx::add(_pos, {0.0f, 1.0f, 0.0f}) },
  632. 0.2f,
  633. });
  634. break;
  635. case Shape::Type::Disk:
  636. _outShape = Shape(bx::Disk
  637. {
  638. _pos,
  639. bx::normalize(bx::Vec3{1.0f, 1.0f, 0.0f}),
  640. 0.5f,
  641. });
  642. break;
  643. case Shape::Type::Obb:
  644. {
  645. bx::Obb obb;
  646. bx::mtxSRT(obb.mtx
  647. , 1.0f
  648. , 0.25f
  649. , 0.25f
  650. , bx::toRad(10.0f)
  651. , bx::toRad(30.0f)
  652. , bx::toRad(70.0f)
  653. , _pos.x
  654. , _pos.y
  655. , _pos.z
  656. );
  657. _outShape = Shape(obb);
  658. }
  659. break;
  660. case Shape::Type::Plane:
  661. {
  662. bx::Plane plane(bx::InitNone);
  663. bx::calcPlane(plane, bx::normalize(bx::Vec3{1.0f, 1.0f, 0.0f}), _pos);
  664. _outShape = Shape(plane);
  665. }
  666. break;
  667. case Shape::Type::Sphere:
  668. _outShape = Shape(bx::Sphere{_pos, 0.5f});
  669. break;
  670. case Shape::Type::Triangle:
  671. _outShape = Shape(bx::Triangle
  672. {
  673. { bx::add(_pos, {-0.4f, 0.0f, -0.4f}) },
  674. { bx::add(_pos, {-0.5f, -0.3f, 0.0f}) },
  675. { bx::add(_pos, { 0.3f, 0.5f, 0.0f}) },
  676. });
  677. break;
  678. default: break;
  679. }
  680. }
  681. int32_t overlap(const Shape& _shapeA, const Shape& _shapeB)
  682. {
  683. switch (_shapeA.type)
  684. {
  685. case Shape::Type::Aabb: return ::overlap(*reinterpret_cast<const bx::Aabb *>(_shapeA.data), _shapeB);
  686. case Shape::Type::Capsule: return ::overlap(*reinterpret_cast<const bx::Capsule *>(_shapeA.data), _shapeB);
  687. case Shape::Type::Cone: return ::overlap(*reinterpret_cast<const bx::Cone *>(_shapeA.data), _shapeB);
  688. case Shape::Type::Cylinder: return ::overlap(*reinterpret_cast<const bx::Cylinder *>(_shapeA.data), _shapeB);
  689. case Shape::Type::Disk: return ::overlap(*reinterpret_cast<const bx::Disk *>(_shapeA.data), _shapeB);
  690. case Shape::Type::Obb: return ::overlap(*reinterpret_cast<const bx::Obb *>(_shapeA.data), _shapeB);
  691. case Shape::Type::Plane: return ::overlap(*reinterpret_cast<const bx::Plane *>(_shapeA.data), _shapeB);
  692. case Shape::Type::Sphere: return ::overlap(*reinterpret_cast<const bx::Sphere *>(_shapeA.data), _shapeB);
  693. case Shape::Type::Triangle: return ::overlap(*reinterpret_cast<const bx::Triangle *>(_shapeA.data), _shapeB);
  694. }
  695. return 2;
  696. }
  697. void draw(DebugDrawEncoder& _dde, const Shape& _shape, const bx::Vec3 _pos)
  698. {
  699. switch (_shape.type)
  700. {
  701. case Shape::Type::Aabb: _dde.draw (*reinterpret_cast<const bx::Aabb *>(_shape.data) ); break;
  702. case Shape::Type::Capsule: _dde.draw (*reinterpret_cast<const bx::Capsule *>(_shape.data) ); break;
  703. case Shape::Type::Cone: _dde.draw (*reinterpret_cast<const bx::Cone *>(_shape.data) ); break;
  704. case Shape::Type::Cylinder: _dde.draw (*reinterpret_cast<const bx::Cylinder *>(_shape.data) ); break;
  705. case Shape::Type::Disk: _dde.draw (*reinterpret_cast<const bx::Disk *>(_shape.data) ); break;
  706. case Shape::Type::Obb: _dde.draw (*reinterpret_cast<const bx::Obb *>(_shape.data) ); break;
  707. case Shape::Type::Plane: { _dde.drawGrid( reinterpret_cast<const bx::Plane *>(_shape.data)->normal, _pos, 9, 0.3f); } break;
  708. case Shape::Type::Sphere: _dde.draw (*reinterpret_cast<const bx::Sphere *>(_shape.data) ); break;
  709. case Shape::Type::Triangle: _dde.draw (*reinterpret_cast<const bx::Triangle *>(_shape.data) ); break;
  710. }
  711. }
  712. void imageCheckerboard(void* _dst, uint32_t _width, uint32_t _height, uint32_t _step, uint32_t _0, uint32_t _1)
  713. {
  714. uint32_t* dst = (uint32_t*)_dst;
  715. for (uint32_t yy = 0; yy < _height; ++yy)
  716. {
  717. for (uint32_t xx = 0; xx < _width; ++xx)
  718. {
  719. uint32_t abgr = ( (xx/_step)&1) ^ ( (yy/_step)&1) ? _1 : _0;
  720. *dst++ = abgr;
  721. }
  722. }
  723. }
  724. class ExampleDebugDraw : public entry::AppI
  725. {
  726. public:
  727. ExampleDebugDraw(const char* _name, const char* _description, const char* _url)
  728. : entry::AppI(_name, _description, _url)
  729. {
  730. }
  731. void init(int32_t _argc, const char* const* _argv, uint32_t _width, uint32_t _height) override
  732. {
  733. Args args(_argc, _argv);
  734. m_width = _width;
  735. m_height = _height;
  736. m_debug = BGFX_DEBUG_NONE;
  737. m_reset = BGFX_RESET_VSYNC | BGFX_RESET_MSAA_X16;
  738. bgfx::Init init;
  739. init.type = args.m_type;
  740. init.vendorId = args.m_pciId;
  741. init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
  742. init.platformData.ndt = entry::getNativeDisplayHandle();
  743. init.platformData.type = entry::getNativeWindowHandleType(entry::kDefaultWindowHandle);
  744. init.resolution.width = m_width;
  745. init.resolution.height = m_height;
  746. init.resolution.reset = m_reset;
  747. bgfx::init(init);
  748. // Enable m_debug text.
  749. bgfx::setDebug(m_debug);
  750. // Set view 0 clear state.
  751. bgfx::setViewClear(0
  752. , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
  753. , 0x303030ff
  754. , 1.0f
  755. , 0
  756. );
  757. m_timeOffset = bx::getHPCounter();
  758. cameraCreate();
  759. cameraSetPosition({ 0.0f, 2.0f, -12.0f });
  760. cameraSetVerticalAngle(0.0f);
  761. ddInit();
  762. uint8_t data[32*32*4];
  763. imageCheckerboard(data, 32, 32, 4, 0xff808080, 0xffc0c0c0);
  764. m_sprite = ddCreateSprite(32, 32, data);
  765. m_bunny = ddCreateGeometry(
  766. BX_COUNTOF(s_bunnyVertices)
  767. , s_bunnyVertices
  768. , BX_COUNTOF(s_bunnyTriList)
  769. , s_bunnyTriList
  770. );
  771. imguiCreate();
  772. }
  773. virtual int shutdown() override
  774. {
  775. imguiDestroy();
  776. ddDestroy(m_bunny);
  777. ddDestroy(m_sprite);
  778. ddShutdown();
  779. cameraDestroy();
  780. // Shutdown bgfx.
  781. bgfx::shutdown();
  782. return 0;
  783. }
  784. template<typename Ty>
  785. bool intersect(DebugDrawEncoder* _dde, const bx::Ray& _ray, const Ty& _shape)
  786. {
  787. bx::Hit hit;
  788. if (bx::intersect(_ray, _shape, &hit) )
  789. {
  790. _dde->push();
  791. _dde->setWireframe(false);
  792. _dde->setColor(0xff0000ff);
  793. _dde->drawCone(hit.pos, bx::mad(hit.plane.normal, 0.7f, hit.pos), 0.1f);
  794. _dde->pop();
  795. return true;
  796. }
  797. return false;
  798. }
  799. bool update() override
  800. {
  801. if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) )
  802. {
  803. imguiBeginFrame(
  804. m_mouseState.m_mx
  805. , m_mouseState.m_my
  806. , (m_mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0)
  807. | (m_mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
  808. | (m_mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
  809. , m_mouseState.m_mz
  810. , uint16_t(m_width)
  811. , uint16_t(m_height)
  812. );
  813. showExampleDialog(this);
  814. ImGui::SetNextWindowPos(
  815. ImVec2(m_width - m_width / 5.0f - 10.0f, 10.0f)
  816. , ImGuiCond_FirstUseEver
  817. );
  818. ImGui::SetNextWindowSize(
  819. ImVec2(m_width / 5.0f, m_height / 3.0f)
  820. , ImGuiCond_FirstUseEver
  821. );
  822. ImGui::Begin("Settings"
  823. , NULL
  824. , 0
  825. );
  826. static float amplitudeMul = 0.0f;
  827. ImGui::SliderFloat("Amplitude", &amplitudeMul, 0.0f, 1.0f);
  828. static float timeScale = 1.0f;
  829. ImGui::SliderFloat("T scale", &timeScale, -1.0f, 1.0f);
  830. ImGui::End();
  831. imguiEndFrame();
  832. int64_t now = bx::getHPCounter() - m_timeOffset;
  833. static int64_t last = now;
  834. const int64_t frameTime = now - last;
  835. last = now;
  836. const double freq = double(bx::getHPFrequency() );
  837. const float deltaTime = float(frameTime/freq);
  838. // Update camera.
  839. cameraUpdate(deltaTime, m_mouseState, ImGui::MouseOverArea() );
  840. float view[16];
  841. cameraGetViewMtx(view);
  842. float proj[16];
  843. // Set view and projection matrix for view 0.
  844. {
  845. bx::mtxProj(proj, 60.0f, float(m_width)/float(m_height), 0.1f, 100.0f, bgfx::getCaps()->homogeneousDepth);
  846. bgfx::setViewTransform(0, view, proj);
  847. bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  848. }
  849. float mtxVp[16];
  850. bx::mtxMul(mtxVp, view, proj);
  851. float mtxInvVp[16];
  852. bx::mtxInverse(mtxInvVp, mtxVp);
  853. const bx::Vec3 at = { 0.0f, 0.0f, 0.0f };
  854. const bx::Vec3 eye = { 5.0f, 10.0f, 5.0f };
  855. bx::mtxLookAt(view, eye, at);
  856. bx::mtxProj(proj, 45.0f, float(m_width)/float(m_height), 1.0f, 15.0f, bgfx::getCaps()->homogeneousDepth);
  857. bx::mtxMul(mtxVp, view, proj);
  858. bx::Ray ray = bx::makeRay(
  859. (float(m_mouseState.m_mx)/float(m_width) * 2.0f - 1.0f)
  860. , -(float(m_mouseState.m_my)/float(m_height) * 2.0f - 1.0f)
  861. , mtxInvVp
  862. );
  863. constexpr uint32_t kSelected = 0xff80ffff;
  864. constexpr uint32_t kOverlapA = 0xff0000ff;
  865. constexpr uint32_t kOverlapB = 0xff8080ff;
  866. DebugDrawEncoder dde;
  867. dde.begin(0);
  868. dde.drawAxis(0.0f, 0.0f, 0.0f);
  869. dde.push();
  870. bx::Aabb aabb =
  871. {
  872. { 5.0f, 1.0f, 1.0f },
  873. { 10.0f, 5.0f, 5.0f },
  874. };
  875. dde.setWireframe(true);
  876. dde.setColor(intersect(&dde, ray, aabb) ? kSelected : 0xff00ff00);
  877. dde.draw(aabb);
  878. dde.pop();
  879. static float time = 0.0f;
  880. time += deltaTime*timeScale;
  881. bx::Obb obb;
  882. bx::mtxRotateX(obb.mtx, time);
  883. dde.setWireframe(true);
  884. dde.setColor(intersect(&dde, ray, obb) ? kSelected : 0xffffffff);
  885. dde.draw(obb);
  886. bx::mtxSRT(obb.mtx, 1.0f, 1.0f, 1.0f, time*0.23f, time, 0.0f, 3.0f, 0.0f, 0.0f);
  887. dde.push();
  888. bx::toAabb(aabb, obb);
  889. dde.setWireframe(true);
  890. dde.setColor(0xff0000ff);
  891. dde.draw(aabb);
  892. dde.pop();
  893. dde.setWireframe(false);
  894. dde.setColor(intersect(&dde, ray, obb) ? kSelected : 0xffffffff);
  895. dde.draw(obb);
  896. dde.setColor(0xffffffff);
  897. dde.push();
  898. {
  899. float bunny[16];
  900. bx::mtxSRT(bunny, 0.03f, 0.03f, 0.03f, 0.0f, 0.0f, 0.0f, -3.0f, 0.0f, 0.0f);
  901. dde.setTransform(bunny);
  902. const bool wireframe = bx::mod(time, 2.0f) > 1.0f;
  903. dde.setWireframe(wireframe);
  904. dde.setColor(wireframe ? 0xffff00ff : 0xff00ff00);
  905. dde.draw(m_bunny);
  906. dde.setTransform(NULL);
  907. }
  908. dde.pop();
  909. {
  910. const bx::Vec3 normal = { 0.0f, 1.0f, 0.0f };
  911. const bx::Vec3 pos = { 0.0f, -2.0f, 0.0f };
  912. bx::Plane plane(bx::InitNone);
  913. bx::calcPlane(plane, normal, pos);
  914. dde.setColor(false
  915. || intersect(&dde, ray, plane)
  916. ? kSelected
  917. : 0xffffffff
  918. );
  919. dde.drawGrid(Axis::Y, pos, 128, 1.0f);
  920. }
  921. dde.drawFrustum(mtxVp);
  922. dde.push();
  923. bx::Sphere sphere = { { 0.0f, 5.0f, 0.0f }, 1.0f };
  924. dde.setColor(intersect(&dde, ray, sphere) ? kSelected : 0xfff0c0ff);
  925. dde.setWireframe(true);
  926. dde.setLod(3);
  927. dde.draw(sphere);
  928. dde.setWireframe(false);
  929. sphere.center.x = -2.0f;
  930. dde.setColor(intersect(&dde, ray, sphere) ? kSelected : 0xc0ffc0ff);
  931. dde.setLod(2);
  932. dde.draw(sphere);
  933. sphere.center.x = -4.0f;
  934. dde.setColor(intersect(&dde, ray, sphere) ? kSelected : 0xa0f0ffff);
  935. dde.setLod(1);
  936. dde.draw(sphere);
  937. sphere.center.x = -6.0f;
  938. dde.setColor(intersect(&dde, ray, sphere) ? kSelected : 0xffc0ff00);
  939. dde.setLod(0);
  940. dde.draw(sphere);
  941. dde.pop();
  942. dde.setColor(0xffffffff);
  943. dde.push();
  944. {
  945. const bx::Vec3 normal = { 0.0f, 0.0f, 1.0f };
  946. const bx::Vec3 center = { -8.0f, 0.0f, 0.0f };
  947. dde.push();
  948. dde.setStipple(true, 1.0f, time*0.1f);
  949. dde.setColor(0xff0000ff);
  950. dde.drawCircle(normal, center, 1.0f, 0.5f + bx::sin(time*10.0f) );
  951. dde.pop();
  952. dde.setSpin(time);
  953. dde.drawQuad(m_sprite, normal, center, 2.0f);
  954. }
  955. dde.pop();
  956. dde.push();
  957. dde.setStipple(true, 1.0f, -time*0.1f);
  958. dde.drawCircle(Axis::Z, -8.0f, 0.0f, 0.0f, 1.25f, 2.0f);
  959. dde.pop();
  960. dde.push();
  961. dde.setLod(UINT8_MAX);
  962. dde.push();
  963. dde.setSpin(time*0.3f);
  964. {
  965. bx::Cone cone =
  966. {
  967. { -11.0f, 4.0f, 0.0f },
  968. { -13.0f, 6.0f, 1.0f },
  969. 1.0f
  970. };
  971. bx::Cylinder cylinder =
  972. {
  973. { -9.0f, 2.0f, -1.0f },
  974. { -11.0f, 4.0f, 0.0f },
  975. 0.5f
  976. };
  977. dde.setColor(false
  978. || intersect(&dde, ray, cone)
  979. || intersect(&dde, ray, cylinder)
  980. ? kSelected
  981. : 0xffffffff
  982. );
  983. dde.draw(cone);
  984. dde.draw(cylinder);
  985. }
  986. dde.pop();
  987. {
  988. dde.setLod(0);
  989. bx::Capsule capsule =
  990. {
  991. { 0.0f, 7.0f, 0.0f },
  992. { -6.0f, 7.0f, 0.0f },
  993. 0.5f
  994. };
  995. dde.setColor(intersect(&dde, ray, capsule) ? kSelected : 0xffffffff);
  996. dde.draw(capsule);
  997. }
  998. dde.pop();
  999. dde.push();
  1000. float mtx[16];
  1001. bx::mtxSRT(mtx
  1002. , 1.0f, 1.0f, 1.0f
  1003. , 0.0f, time, time*0.53f
  1004. , -10.0f, 1.0f, 10.0f
  1005. );
  1006. bx::Cylinder cylinder =
  1007. {
  1008. { -10.0f, 1.0f, 10.0f },
  1009. { 0.0f, 0.0f, 0.0f },
  1010. 1.0f
  1011. };
  1012. cylinder.end = bx::mul({ 0.0f, 4.0f, 0.0f }, mtx);
  1013. dde.setColor(intersect(&dde, ray, cylinder) ? kSelected : 0xffffffff);
  1014. dde.draw(cylinder);
  1015. dde.push();
  1016. toAabb(aabb, cylinder);
  1017. dde.setWireframe(true);
  1018. dde.setColor(0xff0000ff);
  1019. dde.draw(aabb);
  1020. dde.pop();
  1021. dde.pop();
  1022. dde.drawOrb(-11.0f, 0.0f, 0.0f, 1.0f);
  1023. dde.push();
  1024. {
  1025. constexpr uint32_t colorA[] =
  1026. {
  1027. 0xffffffff,
  1028. kOverlapA,
  1029. 0xff666666,
  1030. 0xff6666ff,
  1031. };
  1032. constexpr uint32_t colorB[] =
  1033. {
  1034. 0xffffffff,
  1035. kOverlapB,
  1036. 0xff888888,
  1037. 0xff8888ff,
  1038. };
  1039. constexpr float kStep = 3.0f;
  1040. bx::Vec3 posA =
  1041. {
  1042. -4.5f*kStep,
  1043. 1.0f,
  1044. 20.0f,
  1045. };
  1046. for (uint32_t ii = 0; ii < Shape::Type::Count; ++ii)
  1047. {
  1048. const bx::Vec3 posB = bx::add(posA,
  1049. {
  1050. amplitudeMul*bx::sin(time*0.39f) * 1.03f,
  1051. amplitudeMul*bx::cos(time*0.79f) * 1.03f,
  1052. amplitudeMul*bx::cos(time) * 1.03f,
  1053. });
  1054. for (uint32_t jj = 0; jj < Shape::Type::Count; ++jj)
  1055. {
  1056. const bx::Vec3 pa = bx::add(posA, {jj*kStep, 0.0f, 0.0f});
  1057. const bx::Vec3 pb = bx::add(posB, {jj*kStep, 0.0f, 0.0f});
  1058. Shape shapeA, shapeB;
  1059. initA(shapeA, Shape::Type::Enum(ii), pa);
  1060. initB(shapeB, Shape::Type::Enum(jj), pb);
  1061. int32_t olp = overlap(shapeA, shapeB);
  1062. dde.setColor(colorA[olp]);
  1063. dde.setWireframe(false);
  1064. draw(dde, shapeA, pa);
  1065. dde.setColor(colorB[olp]);
  1066. dde.setWireframe(true);
  1067. draw(dde, shapeB, pb);
  1068. }
  1069. posA = bx::add(posA, {0.0f, 0.0f, kStep});
  1070. }
  1071. }
  1072. dde.pop();
  1073. dde.end();
  1074. // Advance to next frame. Rendering thread will be kicked to
  1075. // process submitted rendering primitives.
  1076. bgfx::frame();
  1077. return true;
  1078. }
  1079. return false;
  1080. }
  1081. entry::MouseState m_mouseState;
  1082. SpriteHandle m_sprite;
  1083. GeometryHandle m_bunny;
  1084. int64_t m_timeOffset;
  1085. uint32_t m_width;
  1086. uint32_t m_height;
  1087. uint32_t m_debug;
  1088. uint32_t m_reset;
  1089. };
  1090. } // namespace
  1091. ENTRY_IMPLEMENT_MAIN(
  1092. ExampleDebugDraw
  1093. , "29-debugdraw"
  1094. , "Debug draw."
  1095. , "https://bkaradzic.github.io/bgfx/examples.html#debugdraw"
  1096. );