DetourNavMeshQuery.h 25 KB

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