RecastArea.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. //
  2. // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
  3. //
  4. // This software is provided 'as-is', without any express or implied
  5. // warranty. In no event will the authors be held liable for any damages
  6. // arising from the use of this software.
  7. // Permission is granted to anyone to use this software for any purpose,
  8. // including commercial applications, and to alter it and redistribute it
  9. // freely, subject to the following restrictions:
  10. // 1. The origin of this software must not be misrepresented; you must not
  11. // claim that you wrote the original software. If you use this software
  12. // in a product, an acknowledgment in the product documentation would be
  13. // appreciated but is not required.
  14. // 2. Altered source versions must be plainly marked as such, and must not be
  15. // misrepresented as being the original software.
  16. // 3. This notice may not be removed or altered from any source distribution.
  17. //
  18. #include <float.h>
  19. #define _USE_MATH_DEFINES
  20. #include <math.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include "Recast.h"
  25. #include "RecastAlloc.h"
  26. #include "RecastAssert.h"
  27. /// @par
  28. ///
  29. /// Basically, any spans that are closer to a boundary or obstruction than the specified radius
  30. /// are marked as unwalkable.
  31. ///
  32. /// This method is usually called immediately after the heightfield has been built.
  33. ///
  34. /// @see rcCompactHeightfield, rcBuildCompactHeightfield, rcConfig::walkableRadius
  35. bool rcErodeWalkableArea(rcContext* ctx, int radius, rcCompactHeightfield& chf)
  36. {
  37. rcAssert(ctx);
  38. const int w = chf.width;
  39. const int h = chf.height;
  40. ctx->startTimer(RC_TIMER_ERODE_AREA);
  41. unsigned char* dist = (unsigned char*)rcAlloc(sizeof(unsigned char)*chf.spanCount, RC_ALLOC_TEMP);
  42. if (!dist)
  43. {
  44. ctx->log(RC_LOG_ERROR, "erodeWalkableArea: Out of memory 'dist' (%d).", chf.spanCount);
  45. return false;
  46. }
  47. // Init distance.
  48. memset(dist, 0xff, sizeof(unsigned char)*chf.spanCount);
  49. // Mark boundary cells.
  50. for (int y = 0; y < h; ++y)
  51. {
  52. for (int x = 0; x < w; ++x)
  53. {
  54. const rcCompactCell& c = chf.cells[x+y*w];
  55. for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i)
  56. {
  57. if (chf.areas[i] == RC_NULL_AREA)
  58. {
  59. dist[i] = 0;
  60. }
  61. else
  62. {
  63. const rcCompactSpan& s = chf.spans[i];
  64. int nc = 0;
  65. for (int dir = 0; dir < 4; ++dir)
  66. {
  67. if (rcGetCon(s, dir) != RC_NOT_CONNECTED)
  68. {
  69. const int nx = x + rcGetDirOffsetX(dir);
  70. const int ny = y + rcGetDirOffsetY(dir);
  71. const int nidx = (int)chf.cells[nx+ny*w].index + rcGetCon(s, dir);
  72. if (chf.areas[nidx] != RC_NULL_AREA)
  73. {
  74. nc++;
  75. }
  76. }
  77. }
  78. // At least one missing neighbour.
  79. if (nc != 4)
  80. dist[i] = 0;
  81. }
  82. }
  83. }
  84. }
  85. unsigned char nd;
  86. // Pass 1
  87. for (int y = 0; y < h; ++y)
  88. {
  89. for (int x = 0; x < w; ++x)
  90. {
  91. const rcCompactCell& c = chf.cells[x+y*w];
  92. for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i)
  93. {
  94. const rcCompactSpan& s = chf.spans[i];
  95. if (rcGetCon(s, 0) != RC_NOT_CONNECTED)
  96. {
  97. // (-1,0)
  98. const int ax = x + rcGetDirOffsetX(0);
  99. const int ay = y + rcGetDirOffsetY(0);
  100. const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, 0);
  101. const rcCompactSpan& as = chf.spans[ai];
  102. nd = (unsigned char)rcMin((int)dist[ai]+2, 255);
  103. if (nd < dist[i])
  104. dist[i] = nd;
  105. // (-1,-1)
  106. if (rcGetCon(as, 3) != RC_NOT_CONNECTED)
  107. {
  108. const int aax = ax + rcGetDirOffsetX(3);
  109. const int aay = ay + rcGetDirOffsetY(3);
  110. const int aai = (int)chf.cells[aax+aay*w].index + rcGetCon(as, 3);
  111. nd = (unsigned char)rcMin((int)dist[aai]+3, 255);
  112. if (nd < dist[i])
  113. dist[i] = nd;
  114. }
  115. }
  116. if (rcGetCon(s, 3) != RC_NOT_CONNECTED)
  117. {
  118. // (0,-1)
  119. const int ax = x + rcGetDirOffsetX(3);
  120. const int ay = y + rcGetDirOffsetY(3);
  121. const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, 3);
  122. const rcCompactSpan& as = chf.spans[ai];
  123. nd = (unsigned char)rcMin((int)dist[ai]+2, 255);
  124. if (nd < dist[i])
  125. dist[i] = nd;
  126. // (1,-1)
  127. if (rcGetCon(as, 2) != RC_NOT_CONNECTED)
  128. {
  129. const int aax = ax + rcGetDirOffsetX(2);
  130. const int aay = ay + rcGetDirOffsetY(2);
  131. const int aai = (int)chf.cells[aax+aay*w].index + rcGetCon(as, 2);
  132. nd = (unsigned char)rcMin((int)dist[aai]+3, 255);
  133. if (nd < dist[i])
  134. dist[i] = nd;
  135. }
  136. }
  137. }
  138. }
  139. }
  140. // Pass 2
  141. for (int y = h-1; y >= 0; --y)
  142. {
  143. for (int x = w-1; x >= 0; --x)
  144. {
  145. const rcCompactCell& c = chf.cells[x+y*w];
  146. for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i)
  147. {
  148. const rcCompactSpan& s = chf.spans[i];
  149. if (rcGetCon(s, 2) != RC_NOT_CONNECTED)
  150. {
  151. // (1,0)
  152. const int ax = x + rcGetDirOffsetX(2);
  153. const int ay = y + rcGetDirOffsetY(2);
  154. const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, 2);
  155. const rcCompactSpan& as = chf.spans[ai];
  156. nd = (unsigned char)rcMin((int)dist[ai]+2, 255);
  157. if (nd < dist[i])
  158. dist[i] = nd;
  159. // (1,1)
  160. if (rcGetCon(as, 1) != RC_NOT_CONNECTED)
  161. {
  162. const int aax = ax + rcGetDirOffsetX(1);
  163. const int aay = ay + rcGetDirOffsetY(1);
  164. const int aai = (int)chf.cells[aax+aay*w].index + rcGetCon(as, 1);
  165. nd = (unsigned char)rcMin((int)dist[aai]+3, 255);
  166. if (nd < dist[i])
  167. dist[i] = nd;
  168. }
  169. }
  170. if (rcGetCon(s, 1) != RC_NOT_CONNECTED)
  171. {
  172. // (0,1)
  173. const int ax = x + rcGetDirOffsetX(1);
  174. const int ay = y + rcGetDirOffsetY(1);
  175. const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, 1);
  176. const rcCompactSpan& as = chf.spans[ai];
  177. nd = (unsigned char)rcMin((int)dist[ai]+2, 255);
  178. if (nd < dist[i])
  179. dist[i] = nd;
  180. // (-1,1)
  181. if (rcGetCon(as, 0) != RC_NOT_CONNECTED)
  182. {
  183. const int aax = ax + rcGetDirOffsetX(0);
  184. const int aay = ay + rcGetDirOffsetY(0);
  185. const int aai = (int)chf.cells[aax+aay*w].index + rcGetCon(as, 0);
  186. nd = (unsigned char)rcMin((int)dist[aai]+3, 255);
  187. if (nd < dist[i])
  188. dist[i] = nd;
  189. }
  190. }
  191. }
  192. }
  193. }
  194. const unsigned char thr = (unsigned char)(radius*2);
  195. for (int i = 0; i < chf.spanCount; ++i)
  196. if (dist[i] < thr)
  197. chf.areas[i] = RC_NULL_AREA;
  198. rcFree(dist);
  199. ctx->stopTimer(RC_TIMER_ERODE_AREA);
  200. return true;
  201. }
  202. static void insertSort(unsigned char* a, const int n)
  203. {
  204. int i, j;
  205. for (i = 1; i < n; i++)
  206. {
  207. const unsigned char value = a[i];
  208. for (j = i - 1; j >= 0 && a[j] > value; j--)
  209. a[j+1] = a[j];
  210. a[j+1] = value;
  211. }
  212. }
  213. /// @par
  214. ///
  215. /// This filter is usually applied after applying area id's using functions
  216. /// such as #rcMarkBoxArea, #rcMarkConvexPolyArea, and #rcMarkCylinderArea.
  217. ///
  218. /// @see rcCompactHeightfield
  219. bool rcMedianFilterWalkableArea(rcContext* ctx, rcCompactHeightfield& chf)
  220. {
  221. rcAssert(ctx);
  222. const int w = chf.width;
  223. const int h = chf.height;
  224. ctx->startTimer(RC_TIMER_MEDIAN_AREA);
  225. unsigned char* areas = (unsigned char*)rcAlloc(sizeof(unsigned char)*chf.spanCount, RC_ALLOC_TEMP);
  226. if (!areas)
  227. {
  228. ctx->log(RC_LOG_ERROR, "medianFilterWalkableArea: Out of memory 'areas' (%d).", chf.spanCount);
  229. return false;
  230. }
  231. // Init distance.
  232. memset(areas, 0xff, sizeof(unsigned char)*chf.spanCount);
  233. for (int y = 0; y < h; ++y)
  234. {
  235. for (int x = 0; x < w; ++x)
  236. {
  237. const rcCompactCell& c = chf.cells[x+y*w];
  238. for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i)
  239. {
  240. const rcCompactSpan& s = chf.spans[i];
  241. if (chf.areas[i] == RC_NULL_AREA)
  242. {
  243. areas[i] = chf.areas[i];
  244. continue;
  245. }
  246. unsigned char nei[9];
  247. for (int j = 0; j < 9; ++j)
  248. nei[j] = chf.areas[i];
  249. for (int dir = 0; dir < 4; ++dir)
  250. {
  251. if (rcGetCon(s, dir) != RC_NOT_CONNECTED)
  252. {
  253. const int ax = x + rcGetDirOffsetX(dir);
  254. const int ay = y + rcGetDirOffsetY(dir);
  255. const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, dir);
  256. if (chf.areas[ai] != RC_NULL_AREA)
  257. nei[dir*2+0] = chf.areas[ai];
  258. const rcCompactSpan& as = chf.spans[ai];
  259. const int dir2 = (dir+1) & 0x3;
  260. if (rcGetCon(as, dir2) != RC_NOT_CONNECTED)
  261. {
  262. const int ax2 = ax + rcGetDirOffsetX(dir2);
  263. const int ay2 = ay + rcGetDirOffsetY(dir2);
  264. const int ai2 = (int)chf.cells[ax2+ay2*w].index + rcGetCon(as, dir2);
  265. if (chf.areas[ai2] != RC_NULL_AREA)
  266. nei[dir*2+1] = chf.areas[ai2];
  267. }
  268. }
  269. }
  270. insertSort(nei, 9);
  271. areas[i] = nei[4];
  272. }
  273. }
  274. }
  275. memcpy(chf.areas, areas, sizeof(unsigned char)*chf.spanCount);
  276. rcFree(areas);
  277. ctx->stopTimer(RC_TIMER_MEDIAN_AREA);
  278. return true;
  279. }
  280. /// @par
  281. ///
  282. /// The value of spacial parameters are in world units.
  283. ///
  284. /// @see rcCompactHeightfield, rcMedianFilterWalkableArea
  285. void rcMarkBoxArea(rcContext* ctx, const float* bmin, const float* bmax, unsigned char areaId,
  286. rcCompactHeightfield& chf)
  287. {
  288. rcAssert(ctx);
  289. ctx->startTimer(RC_TIMER_MARK_BOX_AREA);
  290. int minx = (int)((bmin[0]-chf.bmin[0])/chf.cs);
  291. int miny = (int)((bmin[1]-chf.bmin[1])/chf.ch);
  292. int minz = (int)((bmin[2]-chf.bmin[2])/chf.cs);
  293. int maxx = (int)((bmax[0]-chf.bmin[0])/chf.cs);
  294. int maxy = (int)((bmax[1]-chf.bmin[1])/chf.ch);
  295. int maxz = (int)((bmax[2]-chf.bmin[2])/chf.cs);
  296. if (maxx < 0) return;
  297. if (minx >= chf.width) return;
  298. if (maxz < 0) return;
  299. if (minz >= chf.height) return;
  300. if (minx < 0) minx = 0;
  301. if (maxx >= chf.width) maxx = chf.width-1;
  302. if (minz < 0) minz = 0;
  303. if (maxz >= chf.height) maxz = chf.height-1;
  304. for (int z = minz; z <= maxz; ++z)
  305. {
  306. for (int x = minx; x <= maxx; ++x)
  307. {
  308. const rcCompactCell& c = chf.cells[x+z*chf.width];
  309. for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i)
  310. {
  311. rcCompactSpan& s = chf.spans[i];
  312. if ((int)s.y >= miny && (int)s.y <= maxy)
  313. {
  314. if (chf.areas[i] != RC_NULL_AREA)
  315. chf.areas[i] = areaId;
  316. }
  317. }
  318. }
  319. }
  320. ctx->stopTimer(RC_TIMER_MARK_BOX_AREA);
  321. }
  322. static int pointInPoly(int nvert, const float* verts, const float* p)
  323. {
  324. int i, j, c = 0;
  325. for (i = 0, j = nvert-1; i < nvert; j = i++)
  326. {
  327. const float* vi = &verts[i*3];
  328. const float* vj = &verts[j*3];
  329. if (((vi[2] > p[2]) != (vj[2] > p[2])) &&
  330. (p[0] < (vj[0]-vi[0]) * (p[2]-vi[2]) / (vj[2]-vi[2]) + vi[0]) )
  331. c = !c;
  332. }
  333. return c;
  334. }
  335. /// @par
  336. ///
  337. /// The value of spacial parameters are in world units.
  338. ///
  339. /// The y-values of the polygon vertices are ignored. So the polygon is effectively
  340. /// projected onto the xz-plane at @p hmin, then extruded to @p hmax.
  341. ///
  342. /// @see rcCompactHeightfield, rcMedianFilterWalkableArea
  343. void rcMarkConvexPolyArea(rcContext* ctx, const float* verts, const int nverts,
  344. const float hmin, const float hmax, unsigned char areaId,
  345. rcCompactHeightfield& chf)
  346. {
  347. rcAssert(ctx);
  348. ctx->startTimer(RC_TIMER_MARK_CONVEXPOLY_AREA);
  349. float bmin[3], bmax[3];
  350. rcVcopy(bmin, verts);
  351. rcVcopy(bmax, verts);
  352. for (int i = 1; i < nverts; ++i)
  353. {
  354. rcVmin(bmin, &verts[i*3]);
  355. rcVmax(bmax, &verts[i*3]);
  356. }
  357. bmin[1] = hmin;
  358. bmax[1] = hmax;
  359. int minx = (int)((bmin[0]-chf.bmin[0])/chf.cs);
  360. int miny = (int)((bmin[1]-chf.bmin[1])/chf.ch);
  361. int minz = (int)((bmin[2]-chf.bmin[2])/chf.cs);
  362. int maxx = (int)((bmax[0]-chf.bmin[0])/chf.cs);
  363. int maxy = (int)((bmax[1]-chf.bmin[1])/chf.ch);
  364. int maxz = (int)((bmax[2]-chf.bmin[2])/chf.cs);
  365. if (maxx < 0) return;
  366. if (minx >= chf.width) return;
  367. if (maxz < 0) return;
  368. if (minz >= chf.height) return;
  369. if (minx < 0) minx = 0;
  370. if (maxx >= chf.width) maxx = chf.width-1;
  371. if (minz < 0) minz = 0;
  372. if (maxz >= chf.height) maxz = chf.height-1;
  373. // TODO: Optimize.
  374. for (int z = minz; z <= maxz; ++z)
  375. {
  376. for (int x = minx; x <= maxx; ++x)
  377. {
  378. const rcCompactCell& c = chf.cells[x+z*chf.width];
  379. for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i)
  380. {
  381. rcCompactSpan& s = chf.spans[i];
  382. if (chf.areas[i] == RC_NULL_AREA)
  383. continue;
  384. if ((int)s.y >= miny && (int)s.y <= maxy)
  385. {
  386. float p[3];
  387. p[0] = chf.bmin[0] + (x+0.5f)*chf.cs;
  388. p[1] = 0;
  389. p[2] = chf.bmin[2] + (z+0.5f)*chf.cs;
  390. if (pointInPoly(nverts, verts, p))
  391. {
  392. chf.areas[i] = areaId;
  393. }
  394. }
  395. }
  396. }
  397. }
  398. ctx->stopTimer(RC_TIMER_MARK_CONVEXPOLY_AREA);
  399. }
  400. int rcOffsetPoly(const float* verts, const int nverts, const float offset,
  401. float* outVerts, const int maxOutVerts)
  402. {
  403. const float MITER_LIMIT = 1.20f;
  404. int n = 0;
  405. for (int i = 0; i < nverts; i++)
  406. {
  407. const int a = (i+nverts-1) % nverts;
  408. const int b = i;
  409. const int c = (i+1) % nverts;
  410. const float* va = &verts[a*3];
  411. const float* vb = &verts[b*3];
  412. const float* vc = &verts[c*3];
  413. float dx0 = vb[0] - va[0];
  414. float dy0 = vb[2] - va[2];
  415. float d0 = dx0*dx0 + dy0*dy0;
  416. if (d0 > 1e-6f)
  417. {
  418. d0 = 1.0f/rcSqrt(d0);
  419. dx0 *= d0;
  420. dy0 *= d0;
  421. }
  422. float dx1 = vc[0] - vb[0];
  423. float dy1 = vc[2] - vb[2];
  424. float d1 = dx1*dx1 + dy1*dy1;
  425. if (d1 > 1e-6f)
  426. {
  427. d1 = 1.0f/rcSqrt(d1);
  428. dx1 *= d1;
  429. dy1 *= d1;
  430. }
  431. const float dlx0 = -dy0;
  432. const float dly0 = dx0;
  433. const float dlx1 = -dy1;
  434. const float dly1 = dx1;
  435. float cross = dx1*dy0 - dx0*dy1;
  436. float dmx = (dlx0 + dlx1) * 0.5f;
  437. float dmy = (dly0 + dly1) * 0.5f;
  438. float dmr2 = dmx*dmx + dmy*dmy;
  439. bool bevel = dmr2 * MITER_LIMIT*MITER_LIMIT < 1.0f;
  440. if (dmr2 > 1e-6f)
  441. {
  442. const float scale = 1.0f / dmr2;
  443. dmx *= scale;
  444. dmy *= scale;
  445. }
  446. if (bevel && cross < 0.0f)
  447. {
  448. if (n+2 >= maxOutVerts)
  449. return 0;
  450. float d = (1.0f - (dx0*dx1 + dy0*dy1))*0.5f;
  451. outVerts[n*3+0] = vb[0] + (-dlx0+dx0*d)*offset;
  452. outVerts[n*3+1] = vb[1];
  453. outVerts[n*3+2] = vb[2] + (-dly0+dy0*d)*offset;
  454. n++;
  455. outVerts[n*3+0] = vb[0] + (-dlx1-dx1*d)*offset;
  456. outVerts[n*3+1] = vb[1];
  457. outVerts[n*3+2] = vb[2] + (-dly1-dy1*d)*offset;
  458. n++;
  459. }
  460. else
  461. {
  462. if (n+1 >= maxOutVerts)
  463. return 0;
  464. outVerts[n*3+0] = vb[0] - dmx*offset;
  465. outVerts[n*3+1] = vb[1];
  466. outVerts[n*3+2] = vb[2] - dmy*offset;
  467. n++;
  468. }
  469. }
  470. return n;
  471. }
  472. /// @par
  473. ///
  474. /// The value of spacial parameters are in world units.
  475. ///
  476. /// @see rcCompactHeightfield, rcMedianFilterWalkableArea
  477. void rcMarkCylinderArea(rcContext* ctx, const float* pos,
  478. const float r, const float h, unsigned char areaId,
  479. rcCompactHeightfield& chf)
  480. {
  481. rcAssert(ctx);
  482. ctx->startTimer(RC_TIMER_MARK_CYLINDER_AREA);
  483. float bmin[3], bmax[3];
  484. bmin[0] = pos[0] - r;
  485. bmin[1] = pos[1];
  486. bmin[2] = pos[2] - r;
  487. bmax[0] = pos[0] + r;
  488. bmax[1] = pos[1] + h;
  489. bmax[2] = pos[2] + r;
  490. const float r2 = r*r;
  491. int minx = (int)((bmin[0]-chf.bmin[0])/chf.cs);
  492. int miny = (int)((bmin[1]-chf.bmin[1])/chf.ch);
  493. int minz = (int)((bmin[2]-chf.bmin[2])/chf.cs);
  494. int maxx = (int)((bmax[0]-chf.bmin[0])/chf.cs);
  495. int maxy = (int)((bmax[1]-chf.bmin[1])/chf.ch);
  496. int maxz = (int)((bmax[2]-chf.bmin[2])/chf.cs);
  497. if (maxx < 0) return;
  498. if (minx >= chf.width) return;
  499. if (maxz < 0) return;
  500. if (minz >= chf.height) return;
  501. if (minx < 0) minx = 0;
  502. if (maxx >= chf.width) maxx = chf.width-1;
  503. if (minz < 0) minz = 0;
  504. if (maxz >= chf.height) maxz = chf.height-1;
  505. for (int z = minz; z <= maxz; ++z)
  506. {
  507. for (int x = minx; x <= maxx; ++x)
  508. {
  509. const rcCompactCell& c = chf.cells[x+z*chf.width];
  510. for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i)
  511. {
  512. rcCompactSpan& s = chf.spans[i];
  513. if (chf.areas[i] == RC_NULL_AREA)
  514. continue;
  515. if ((int)s.y >= miny && (int)s.y <= maxy)
  516. {
  517. const float sx = chf.bmin[0] + (x+0.5f)*chf.cs;
  518. const float sz = chf.bmin[2] + (z+0.5f)*chf.cs;
  519. const float dx = sx - pos[0];
  520. const float dz = sz - pos[2];
  521. if (dx*dx + dz*dz < r2)
  522. {
  523. chf.areas[i] = areaId;
  524. }
  525. }
  526. }
  527. }
  528. }
  529. ctx->stopTimer(RC_TIMER_MARK_CYLINDER_AREA);
  530. }