DetourNavMeshQuery.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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. #ifndef DETOURNAVMESHQUERY_H
  19. #define DETOURNAVMESHQUERY_H
  20. #include "DetourNavMesh.h"
  21. #include "DetourStatus.h"
  22. // Define DT_VIRTUAL_QUERYFILTER if you wish to derive a custom filter from dtQueryFilter.
  23. // On certain platforms indirect or virtual function call is expensive. The default
  24. // setting is to use non-virtual functions, the actual implementations of the functions
  25. // are declared as inline for maximum speed.
  26. //#define DT_VIRTUAL_QUERYFILTER 1
  27. /// Defines polygon filtering and traversal costs for navigation mesh query operations.
  28. /// @ingroup detour
  29. class dtQueryFilter
  30. {
  31. float m_areaCost[DT_MAX_AREAS]; ///< Cost per area type. (Used by default implementation.)
  32. unsigned short m_includeFlags; ///< Flags for polygons that can be visited. (Used by default implementation.)
  33. unsigned short m_excludeFlags; ///< Flags for polygons that should not be visted. (Used by default implementation.)
  34. public:
  35. dtQueryFilter();
  36. #ifdef DT_VIRTUAL_QUERYFILTER
  37. virtual ~dtQueryFilter() { }
  38. #endif
  39. /// Returns true if the polygon can be visited. (I.e. Is traversable.)
  40. /// @param[in] ref The reference id of the polygon test.
  41. /// @param[in] tile The tile containing the polygon.
  42. /// @param[in] poly The polygon to test.
  43. #ifdef DT_VIRTUAL_QUERYFILTER
  44. virtual bool passFilter(const dtPolyRef ref,
  45. const dtMeshTile* tile,
  46. const dtPoly* poly) const;
  47. #else
  48. bool passFilter(const dtPolyRef ref,
  49. const dtMeshTile* tile,
  50. const dtPoly* poly) const;
  51. #endif
  52. /// Returns cost to move from the beginning to the end of a line segment
  53. /// that is fully contained within a polygon.
  54. /// @param[in] pa The start position on the edge of the previous and current polygon. [(x, y, z)]
  55. /// @param[in] pb The end position on the edge of the current and next polygon. [(x, y, z)]
  56. /// @param[in] prevRef The reference id of the previous polygon. [opt]
  57. /// @param[in] prevTile The tile containing the previous polygon. [opt]
  58. /// @param[in] prevPoly The previous polygon. [opt]
  59. /// @param[in] curRef The reference id of the current polygon.
  60. /// @param[in] curTile The tile containing the current polygon.
  61. /// @param[in] curPoly The current polygon.
  62. /// @param[in] nextRef The refernece id of the next polygon. [opt]
  63. /// @param[in] nextTile The tile containing the next polygon. [opt]
  64. /// @param[in] nextPoly The next polygon. [opt]
  65. #ifdef DT_VIRTUAL_QUERYFILTER
  66. virtual float getCost(const float* pa, const float* pb,
  67. const dtPolyRef prevRef, const dtMeshTile* prevTile, const dtPoly* prevPoly,
  68. const dtPolyRef curRef, const dtMeshTile* curTile, const dtPoly* curPoly,
  69. const dtPolyRef nextRef, const dtMeshTile* nextTile, const dtPoly* nextPoly) const;
  70. #else
  71. float getCost(const float* pa, const float* pb,
  72. const dtPolyRef prevRef, const dtMeshTile* prevTile, const dtPoly* prevPoly,
  73. const dtPolyRef curRef, const dtMeshTile* curTile, const dtPoly* curPoly,
  74. const dtPolyRef nextRef, const dtMeshTile* nextTile, const dtPoly* nextPoly) const;
  75. #endif
  76. /// @name Getters and setters for the default implementation data.
  77. ///@{
  78. /// Returns the traversal cost of the area.
  79. /// @param[in] i The id of the area.
  80. /// @returns The traversal cost of the area.
  81. inline float getAreaCost(const int i) const { return m_areaCost[i]; }
  82. /// Sets the traversal cost of the area.
  83. /// @param[in] i The id of the area.
  84. /// @param[in] cost The new cost of traversing the area.
  85. inline void setAreaCost(const int i, const float cost) { m_areaCost[i] = cost; }
  86. /// Returns the include flags for the filter.
  87. /// Any polygons that include one or more of these flags will be
  88. /// included in the operation.
  89. inline unsigned short getIncludeFlags() const { return m_includeFlags; }
  90. /// Sets the include flags for the filter.
  91. /// @param[in] flags The new flags.
  92. inline void setIncludeFlags(const unsigned short flags) { m_includeFlags = flags; }
  93. /// Returns the exclude flags for the filter.
  94. /// Any polygons that include one ore more of these flags will be
  95. /// excluded from the operation.
  96. inline unsigned short getExcludeFlags() const { return m_excludeFlags; }
  97. /// Sets the exclude flags for the filter.
  98. /// @param[in] flags The new flags.
  99. inline void setExcludeFlags(const unsigned short flags) { m_excludeFlags = flags; }
  100. ///@}
  101. };
  102. /// Provides information about raycast hit
  103. /// filled by dtNavMeshQuery::raycast
  104. /// @ingroup detour
  105. struct dtRaycastHit
  106. {
  107. /// The hit parameter. (FLT_MAX if no wall hit.)
  108. float t;
  109. /// hitNormal The normal of the nearest wall hit. [(x, y, z)]
  110. float hitNormal[3];
  111. /// Pointer to an array of reference ids of the visited polygons. [opt]
  112. dtPolyRef* path;
  113. /// The number of visited polygons. [opt]
  114. int pathCount;
  115. /// The maximum number of polygons the @p path array can hold.
  116. int maxPath;
  117. /// The cost of the path until hit.
  118. float pathCost;
  119. };
  120. /// Provides the ability to perform pathfinding related queries against
  121. /// a navigation mesh.
  122. /// @ingroup detour
  123. class dtNavMeshQuery
  124. {
  125. public:
  126. dtNavMeshQuery();
  127. ~dtNavMeshQuery();
  128. /// Initializes the query object.
  129. /// @param[in] nav Pointer to the dtNavMesh object to use for all queries.
  130. /// @param[in] maxNodes Maximum number of search nodes. [Limits: 0 < value <= 65536]
  131. /// @returns The status flags for the query.
  132. dtStatus init(const dtNavMesh* nav, const int maxNodes);
  133. /// @name Standard Pathfinding Functions
  134. // /@{
  135. /// Finds a path from the start polygon to the end polygon.
  136. /// @param[in] startRef The refrence id of the start polygon.
  137. /// @param[in] endRef The reference id of the end polygon.
  138. /// @param[in] startPos A position within the start polygon. [(x, y, z)]
  139. /// @param[in] endPos A position within the end polygon. [(x, y, z)]
  140. /// @param[in] filter The polygon filter to apply to the query.
  141. /// @param[out] path An ordered list of polygon references representing the path. (Start to end.)
  142. /// [(polyRef) * @p pathCount]
  143. /// @param[out] pathCount The number of polygons returned in the @p path array.
  144. /// @param[in] maxPath The maximum number of polygons the @p path array can hold. [Limit: >= 1]
  145. dtStatus findPath(dtPolyRef startRef, dtPolyRef endRef,
  146. const float* startPos, const float* endPos,
  147. const dtQueryFilter* filter,
  148. dtPolyRef* path, int* pathCount, const int maxPath) const;
  149. /// Finds the straight path from the start to the end position within the polygon corridor.
  150. /// @param[in] startPos Path start position. [(x, y, z)]
  151. /// @param[in] endPos Path end position. [(x, y, z)]
  152. /// @param[in] path An array of polygon references that represent the path corridor.
  153. /// @param[in] pathSize The number of polygons in the @p path array.
  154. /// @param[out] straightPath Points describing the straight path. [(x, y, z) * @p straightPathCount].
  155. /// @param[out] straightPathFlags Flags describing each point. (See: #dtStraightPathFlags) [opt]
  156. /// @param[out] straightPathRefs The reference id of the polygon that is being entered at each point. [opt]
  157. /// @param[out] straightPathCount The number of points in the straight path.
  158. /// @param[in] maxStraightPath The maximum number of points the straight path arrays can hold. [Limit: > 0]
  159. /// @param[in] options Query options. (see: #dtStraightPathOptions)
  160. /// @returns The status flags for the query.
  161. dtStatus findStraightPath(const float* startPos, const float* endPos,
  162. const dtPolyRef* path, const int pathSize,
  163. float* straightPath, unsigned char* straightPathFlags, dtPolyRef* straightPathRefs,
  164. int* straightPathCount, const int maxStraightPath, const int options = 0) const;
  165. ///@}
  166. /// @name Sliced Pathfinding Functions
  167. /// Common use case:
  168. /// -# Call initSlicedFindPath() to initialize the sliced path query.
  169. /// -# Call updateSlicedFindPath() until it returns complete.
  170. /// -# Call finalizeSlicedFindPath() to get the path.
  171. ///@{
  172. /// Intializes a sliced path query.
  173. /// @param[in] startRef The refrence id of the start polygon.
  174. /// @param[in] endRef The reference id of the end polygon.
  175. /// @param[in] startPos A position within the start polygon. [(x, y, z)]
  176. /// @param[in] endPos A position within the end polygon. [(x, y, z)]
  177. /// @param[in] filter The polygon filter to apply to the query.
  178. /// @param[in] options query options (see: #dtFindPathOptions)
  179. /// @returns The status flags for the query.
  180. dtStatus initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef,
  181. const float* startPos, const float* endPos,
  182. const dtQueryFilter* filter, const unsigned int options = 0);
  183. /// Updates an in-progress sliced path query.
  184. /// @param[in] maxIter The maximum number of iterations to perform.
  185. /// @param[out] doneIters The actual number of iterations completed. [opt]
  186. /// @returns The status flags for the query.
  187. dtStatus updateSlicedFindPath(const int maxIter, int* doneIters);
  188. /// Finalizes and returns the results of a sliced path query.
  189. /// @param[out] path An ordered list of polygon references representing the path. (Start to end.)
  190. /// [(polyRef) * @p pathCount]
  191. /// @param[out] pathCount The number of polygons returned in the @p path array.
  192. /// @param[in] maxPath The max number of polygons the path array can hold. [Limit: >= 1]
  193. /// @returns The status flags for the query.
  194. dtStatus finalizeSlicedFindPath(dtPolyRef* path, int* pathCount, const int maxPath);
  195. /// Finalizes and returns the results of an incomplete sliced path query, returning the path to the furthest
  196. /// polygon on the existing path that was visited during the search.
  197. /// @param[in] existing An array of polygon references for the existing path.
  198. /// @param[in] existingSize The number of polygon in the @p existing array.
  199. /// @param[out] path An ordered list of polygon references representing the path. (Start to end.)
  200. /// [(polyRef) * @p pathCount]
  201. /// @param[out] pathCount The number of polygons returned in the @p path array.
  202. /// @param[in] maxPath The max number of polygons the @p path array can hold. [Limit: >= 1]
  203. /// @returns The status flags for the query.
  204. dtStatus finalizeSlicedFindPathPartial(const dtPolyRef* existing, const int existingSize,
  205. dtPolyRef* path, int* pathCount, const int maxPath);
  206. ///@}
  207. /// @name Dijkstra Search Functions
  208. /// @{
  209. /// Finds the polygons along the navigation graph that touch the specified circle.
  210. /// @param[in] startRef The reference id of the polygon where the search starts.
  211. /// @param[in] centerPos The center of the search circle. [(x, y, z)]
  212. /// @param[in] radius The radius of the search circle.
  213. /// @param[in] filter The polygon filter to apply to the query.
  214. /// @param[out] resultRef The reference ids of the polygons touched by the circle. [opt]
  215. /// @param[out] resultParent The reference ids of the parent polygons for each result.
  216. /// Zero if a result polygon has no parent. [opt]
  217. /// @param[out] resultCost The search cost from @p centerPos to the polygon. [opt]
  218. /// @param[out] resultCount The number of polygons found. [opt]
  219. /// @param[in] maxResult The maximum number of polygons the result arrays can hold.
  220. /// @returns The status flags for the query.
  221. dtStatus findPolysAroundCircle(dtPolyRef startRef, const float* centerPos, const float radius,
  222. const dtQueryFilter* filter,
  223. dtPolyRef* resultRef, dtPolyRef* resultParent, float* resultCost,
  224. int* resultCount, const int maxResult) const;
  225. /// Finds the polygons along the naviation graph that touch the specified convex polygon.
  226. /// @param[in] startRef The reference id of the polygon where the search starts.
  227. /// @param[in] verts The vertices describing the convex polygon. (CCW)
  228. /// [(x, y, z) * @p nverts]
  229. /// @param[in] nverts The number of vertices in the polygon.
  230. /// @param[in] filter The polygon filter to apply to the query.
  231. /// @param[out] resultRef The reference ids of the polygons touched by the search polygon. [opt]
  232. /// @param[out] resultParent The reference ids of the parent polygons for each result. Zero if a
  233. /// result polygon has no parent. [opt]
  234. /// @param[out] resultCost The search cost from the centroid point to the polygon. [opt]
  235. /// @param[out] resultCount The number of polygons found.
  236. /// @param[in] maxResult The maximum number of polygons the result arrays can hold.
  237. /// @returns The status flags for the query.
  238. dtStatus findPolysAroundShape(dtPolyRef startRef, const float* verts, const int nverts,
  239. const dtQueryFilter* filter,
  240. dtPolyRef* resultRef, dtPolyRef* resultParent, float* resultCost,
  241. int* resultCount, const int maxResult) const;
  242. /// @}
  243. /// @name Local Query Functions
  244. ///@{
  245. /// Finds the polygon nearest to the specified center point.
  246. /// @param[in] center The center of the search box. [(x, y, z)]
  247. /// @param[in] extents The search distance along each axis. [(x, y, z)]
  248. /// @param[in] filter The polygon filter to apply to the query.
  249. /// @param[out] nearestRef The reference id of the nearest polygon.
  250. /// @param[out] nearestPt The nearest point on the polygon. [opt] [(x, y, z)]
  251. /// @returns The status flags for the query.
  252. dtStatus findNearestPoly(const float* center, const float* extents,
  253. const dtQueryFilter* filter,
  254. dtPolyRef* nearestRef, float* nearestPt) const;
  255. /// Finds polygons that overlap the search box.
  256. /// @param[in] center The center of the search box. [(x, y, z)]
  257. /// @param[in] extents The search distance along each axis. [(x, y, z)]
  258. /// @param[in] filter The polygon filter to apply to the query.
  259. /// @param[out] polys The reference ids of the polygons that overlap the query box.
  260. /// @param[out] polyCount The number of polygons in the search result.
  261. /// @param[in] maxPolys The maximum number of polygons the search result can hold.
  262. /// @returns The status flags for the query.
  263. dtStatus queryPolygons(const float* center, const float* extents,
  264. const dtQueryFilter* filter,
  265. dtPolyRef* polys, int* polyCount, const int maxPolys) const;
  266. /// Finds the non-overlapping navigation polygons in the local neighbourhood around the center position.
  267. /// @param[in] startRef The reference id of the polygon where the search starts.
  268. /// @param[in] centerPos The center of the query circle. [(x, y, z)]
  269. /// @param[in] radius The radius of the query circle.
  270. /// @param[in] filter The polygon filter to apply to the query.
  271. /// @param[out] resultRef The reference ids of the polygons touched by the circle.
  272. /// @param[out] resultParent The reference ids of the parent polygons for each result.
  273. /// Zero if a result polygon has no parent. [opt]
  274. /// @param[out] resultCount The number of polygons found.
  275. /// @param[in] maxResult The maximum number of polygons the result arrays can hold.
  276. /// @returns The status flags for the query.
  277. dtStatus findLocalNeighbourhood(dtPolyRef startRef, const float* centerPos, const float radius,
  278. const dtQueryFilter* filter,
  279. dtPolyRef* resultRef, dtPolyRef* resultParent,
  280. int* resultCount, const int maxResult) const;
  281. /// Moves from the start to the end position constrained to the navigation mesh.
  282. /// @param[in] startRef The reference id of the start polygon.
  283. /// @param[in] startPos A position of the mover within the start polygon. [(x, y, x)]
  284. /// @param[in] endPos The desired end position of the mover. [(x, y, z)]
  285. /// @param[in] filter The polygon filter to apply to the query.
  286. /// @param[out] resultPos The result position of the mover. [(x, y, z)]
  287. /// @param[out] visited The reference ids of the polygons visited during the move.
  288. /// @param[out] visitedCount The number of polygons visited during the move.
  289. /// @param[in] maxVisitedSize The maximum number of polygons the @p visited array can hold.
  290. /// @returns The status flags for the query.
  291. dtStatus moveAlongSurface(dtPolyRef startRef, const float* startPos, const float* endPos,
  292. const dtQueryFilter* filter,
  293. float* resultPos, dtPolyRef* visited, int* visitedCount, const int maxVisitedSize) const;
  294. /// Casts a 'walkability' ray along the surface of the navigation mesh from
  295. /// the start position toward the end position.
  296. /// @note A wrapper around raycast(..., RaycastHit*). Retained for backward compatibility.
  297. /// @param[in] startRef The reference id of the start polygon.
  298. /// @param[in] startPos A position within the start polygon representing
  299. /// the start of the ray. [(x, y, z)]
  300. /// @param[in] endPos The position to cast the ray toward. [(x, y, z)]
  301. /// @param[out] t The hit parameter. (FLT_MAX if no wall hit.)
  302. /// @param[out] hitNormal The normal of the nearest wall hit. [(x, y, z)]
  303. /// @param[in] filter The polygon filter to apply to the query.
  304. /// @param[out] path The reference ids of the visited polygons. [opt]
  305. /// @param[out] pathCount The number of visited polygons. [opt]
  306. /// @param[in] maxPath The maximum number of polygons the @p path array can hold.
  307. /// @returns The status flags for the query.
  308. dtStatus raycast(dtPolyRef startRef, const float* startPos, const float* endPos,
  309. const dtQueryFilter* filter,
  310. float* t, float* hitNormal, dtPolyRef* path, int* pathCount, const int maxPath) const;
  311. /// Casts a 'walkability' ray along the surface of the navigation mesh from
  312. /// the start position toward the end position.
  313. /// @param[in] startRef The reference id of the start polygon.
  314. /// @param[in] startPos A position within the start polygon representing
  315. /// the start of the ray. [(x, y, z)]
  316. /// @param[in] endPos The position to cast the ray toward. [(x, y, z)]
  317. /// @param[in] filter The polygon filter to apply to the query.
  318. /// @param[in] flags govern how the raycast behaves. See dtRaycastOptions
  319. /// @param[out] hit Pointer to a raycast hit structure which will be filled by the results.
  320. /// @param[in] prevRef parent of start ref. Used during for cost calculation [opt]
  321. /// @returns The status flags for the query.
  322. dtStatus raycast(dtPolyRef startRef, const float* startPos, const float* endPos,
  323. const dtQueryFilter* filter, const unsigned int options,
  324. dtRaycastHit* hit, dtPolyRef prevRef = 0) const;
  325. /// Finds the distance from the specified position to the nearest polygon wall.
  326. /// @param[in] startRef The reference id of the polygon containing @p centerPos.
  327. /// @param[in] centerPos The center of the search circle. [(x, y, z)]
  328. /// @param[in] maxRadius The radius of the search circle.
  329. /// @param[in] filter The polygon filter to apply to the query.
  330. /// @param[out] hitDist The distance to the nearest wall from @p centerPos.
  331. /// @param[out] hitPos The nearest position on the wall that was hit. [(x, y, z)]
  332. /// @param[out] hitNormal The normalized ray formed from the wall point to the
  333. /// source point. [(x, y, z)]
  334. /// @returns The status flags for the query.
  335. dtStatus findDistanceToWall(dtPolyRef startRef, const float* centerPos, const float maxRadius,
  336. const dtQueryFilter* filter,
  337. float* hitDist, float* hitPos, float* hitNormal) const;
  338. /// Returns the segments for the specified polygon, optionally including portals.
  339. /// @param[in] ref The reference id of the polygon.
  340. /// @param[in] filter The polygon filter to apply to the query.
  341. /// @param[out] segmentVerts The segments. [(ax, ay, az, bx, by, bz) * segmentCount]
  342. /// @param[out] segmentRefs The reference ids of each segment's neighbor polygon.
  343. /// Or zero if the segment is a wall. [opt] [(parentRef) * @p segmentCount]
  344. /// @param[out] segmentCount The number of segments returned.
  345. /// @param[in] maxSegments The maximum number of segments the result arrays can hold.
  346. /// @returns The status flags for the query.
  347. dtStatus getPolyWallSegments(dtPolyRef ref, const dtQueryFilter* filter,
  348. float* segmentVerts, dtPolyRef* segmentRefs, int* segmentCount,
  349. const int maxSegments) const;
  350. /// Returns random location on navmesh.
  351. /// Polygons are chosen weighted by area. The search runs in linear related to number of polygon.
  352. /// @param[in] filter The polygon filter to apply to the query.
  353. /// @param[in] frand Function returning a random number [0..1).
  354. /// @param[out] randomRef The reference id of the random location.
  355. /// @param[out] randomPt The random location.
  356. /// @returns The status flags for the query.
  357. dtStatus findRandomPoint(const dtQueryFilter* filter, float (*frand)(),
  358. dtPolyRef* randomRef, float* randomPt) const;
  359. /// Returns random location on navmesh within the reach of specified location.
  360. /// Polygons are chosen weighted by area. The search runs in linear related to number of polygon.
  361. /// The location is not exactly constrained by the circle, but it limits the visited polygons.
  362. /// @param[in] startRef The reference id of the polygon where the search starts.
  363. /// @param[in] centerPos The center of the search circle. [(x, y, z)]
  364. /// @param[in] filter The polygon filter to apply to the query.
  365. /// @param[in] frand Function returning a random number [0..1).
  366. /// @param[out] randomRef The reference id of the random location.
  367. /// @param[out] randomPt The random location. [(x, y, z)]
  368. /// @returns The status flags for the query.
  369. dtStatus findRandomPointAroundCircle(dtPolyRef startRef, const float* centerPos, const float maxRadius,
  370. const dtQueryFilter* filter, float (*frand)(),
  371. dtPolyRef* randomRef, float* randomPt) const;
  372. /// Finds the closest point on the specified polygon.
  373. /// @param[in] ref The reference id of the polygon.
  374. /// @param[in] pos The position to check. [(x, y, z)]
  375. /// @param[out] closest The closest point on the polygon. [(x, y, z)]
  376. /// @param[out] posOverPoly True of the position is over the polygon.
  377. /// @returns The status flags for the query.
  378. dtStatus closestPointOnPoly(dtPolyRef ref, const float* pos, float* closest, bool* posOverPoly) const;
  379. /// Returns a point on the boundary closest to the source point if the source point is outside the
  380. /// polygon's xz-bounds.
  381. /// @param[in] ref The reference id to the polygon.
  382. /// @param[in] pos The position to check. [(x, y, z)]
  383. /// @param[out] closest The closest point. [(x, y, z)]
  384. /// @returns The status flags for the query.
  385. dtStatus closestPointOnPolyBoundary(dtPolyRef ref, const float* pos, float* closest) const;
  386. /// Gets the height of the polygon at the provided position using the height detail. (Most accurate.)
  387. /// @param[in] ref The reference id of the polygon.
  388. /// @param[in] pos A position within the xz-bounds of the polygon. [(x, y, z)]
  389. /// @param[out] height The height at the surface of the polygon.
  390. /// @returns The status flags for the query.
  391. dtStatus getPolyHeight(dtPolyRef ref, const float* pos, float* height) const;
  392. /// @}
  393. /// @name Miscellaneous Functions
  394. /// @{
  395. /// Returns true if the polygon reference is valid and passes the filter restrictions.
  396. /// @param[in] ref The polygon reference to check.
  397. /// @param[in] filter The filter to apply.
  398. bool isValidPolyRef(dtPolyRef ref, const dtQueryFilter* filter) const;
  399. /// Returns true if the polygon reference is in the closed list.
  400. /// @param[in] ref The reference id of the polygon to check.
  401. /// @returns True if the polygon is in closed list.
  402. bool isInClosedList(dtPolyRef ref) const;
  403. /// Gets the node pool.
  404. /// @returns The node pool.
  405. class dtNodePool* getNodePool() const { return m_nodePool; }
  406. /// Gets the navigation mesh the query object is using.
  407. /// @return The navigation mesh the query object is using.
  408. const dtNavMesh* getAttachedNavMesh() const { return m_nav; }
  409. /// @}
  410. private:
  411. /// Returns neighbour tile based on side.
  412. dtMeshTile* getNeighbourTileAt(int x, int y, int side) const;
  413. /// Queries polygons within a tile.
  414. int queryPolygonsInTile(const dtMeshTile* tile, const float* qmin, const float* qmax, const dtQueryFilter* filter,
  415. dtPolyRef* polys, const int maxPolys) const;
  416. /// Returns portal points between two polygons.
  417. dtStatus getPortalPoints(dtPolyRef from, dtPolyRef to, float* left, float* right,
  418. unsigned char& fromType, unsigned char& toType) const;
  419. dtStatus getPortalPoints(dtPolyRef from, const dtPoly* fromPoly, const dtMeshTile* fromTile,
  420. dtPolyRef to, const dtPoly* toPoly, const dtMeshTile* toTile,
  421. float* left, float* right) const;
  422. /// Returns edge mid point between two polygons.
  423. dtStatus getEdgeMidPoint(dtPolyRef from, dtPolyRef to, float* mid) const;
  424. dtStatus getEdgeMidPoint(dtPolyRef from, const dtPoly* fromPoly, const dtMeshTile* fromTile,
  425. dtPolyRef to, const dtPoly* toPoly, const dtMeshTile* toTile,
  426. float* mid) const;
  427. // Appends vertex to a straight path
  428. dtStatus appendVertex(const float* pos, const unsigned char flags, const dtPolyRef ref,
  429. float* straightPath, unsigned char* straightPathFlags, dtPolyRef* straightPathRefs,
  430. int* straightPathCount, const int maxStraightPath) const;
  431. // Appends intermediate portal points to a straight path.
  432. dtStatus appendPortals(const int startIdx, const int endIdx, const float* endPos, const dtPolyRef* path,
  433. float* straightPath, unsigned char* straightPathFlags, dtPolyRef* straightPathRefs,
  434. int* straightPathCount, const int maxStraightPath, const int options) const;
  435. const dtNavMesh* m_nav; ///< Pointer to navmesh data.
  436. struct dtQueryData
  437. {
  438. dtStatus status;
  439. struct dtNode* lastBestNode;
  440. float lastBestNodeCost;
  441. dtPolyRef startRef, endRef;
  442. float startPos[3], endPos[3];
  443. const dtQueryFilter* filter;
  444. unsigned int options;
  445. float raycastLimitSqr;
  446. };
  447. dtQueryData m_query; ///< Sliced query state.
  448. class dtNodePool* m_tinyNodePool; ///< Pointer to small node pool.
  449. class dtNodePool* m_nodePool; ///< Pointer to node pool.
  450. class dtNodeQueue* m_openList; ///< Pointer to open list queue.
  451. };
  452. /// Allocates a query object using the Detour allocator.
  453. /// @return An allocated query object, or null on failure.
  454. /// @ingroup detour
  455. dtNavMeshQuery* dtAllocNavMeshQuery();
  456. /// Frees the specified query object using the Detour allocator.
  457. /// @param[in] query A query object allocated using #dtAllocNavMeshQuery
  458. /// @ingroup detour
  459. void dtFreeNavMeshQuery(dtNavMeshQuery* query);
  460. #endif // DETOURNAVMESHQUERY_H