MCPcopy Create free account
hub / github.com/axmolengine/axmol / findRandomPointAroundCircle

Method findRandomPointAroundCircle

3rdparty/recast/DetourNavMeshQuery.cpp:317–498  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

315}
316
317dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const float* centerPos, const float maxRadius,
318 const dtQueryFilter* filter, float (*frand)(),
319 dtPolyRef* randomRef, float* randomPt) const
320{
321 dtAssert(m_nav);
322 dtAssert(m_nodePool);
323 dtAssert(m_openList);
324
325 // Validate input
326 if (!m_nav->isValidPolyRef(startRef) ||
327 !centerPos || !dtVisfinite(centerPos) ||
328 maxRadius < 0 || !dtMathIsfinite(maxRadius) ||
329 !filter || !frand || !randomRef || !randomPt)
330 {
331 return DT_FAILURE | DT_INVALID_PARAM;
332 }
333
334 const dtMeshTile* startTile = 0;
335 const dtPoly* startPoly = 0;
336 m_nav->getTileAndPolyByRefUnsafe(startRef, &startTile, &startPoly);
337 if (!filter->passFilter(startRef, startTile, startPoly))
338 return DT_FAILURE | DT_INVALID_PARAM;
339
340 m_nodePool->clear();
341 m_openList->clear();
342
343 dtNode* startNode = m_nodePool->getNode(startRef);
344 dtVcopy(startNode->pos, centerPos);
345 startNode->pidx = 0;
346 startNode->cost = 0;
347 startNode->total = 0;
348 startNode->id = startRef;
349 startNode->flags = DT_NODE_OPEN;
350 m_openList->push(startNode);
351
352 dtStatus status = DT_SUCCESS;
353
354 const float radiusSqr = dtSqr(maxRadius);
355 float areaSum = 0.0f;
356
357 const dtMeshTile* randomTile = 0;
358 const dtPoly* randomPoly = 0;
359 dtPolyRef randomPolyRef = 0;
360
361 while (!m_openList->empty())
362 {
363 dtNode* bestNode = m_openList->pop();
364 bestNode->flags &= ~DT_NODE_OPEN;
365 bestNode->flags |= DT_NODE_CLOSED;
366
367 // Get poly and tile.
368 // The API input has been cheked already, skip checking internal data.
369 const dtPolyRef bestRef = bestNode->id;
370 const dtMeshTile* bestTile = 0;
371 const dtPoly* bestPoly = 0;
372 m_nav->getTileAndPolyByRefUnsafe(bestRef, &bestTile, &bestPoly);
373
374 // Place random locations on on ground.

Callers

nothing calls this directly

Calls 15

dtVisfiniteFunction · 0.85
dtMathIsfiniteFunction · 0.85
dtVcopyFunction · 0.85
dtSqrFunction · 0.85
dtTriArea2DFunction · 0.85
dtDistancePtSegSqr2DFunction · 0.85
dtVlerpFunction · 0.85
dtVdistFunction · 0.85
passFilterMethod · 0.80
getNodeAtIdxMethod · 0.80

Tested by

no test coverage detected