TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DetourNavMeshQuery.h
Go to the documentation of this file.
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 
19 #ifndef DETOURNAVMESHQUERY_H
20 #define DETOURNAVMESHQUERY_H
21 
22 #include "DetourNavMesh.h"
23 #include "DetourStatus.h"
24 
25 
26 // Define DT_VIRTUAL_QUERYFILTER if you wish to derive a custom filter from dtQueryFilter.
27 // On certain platforms indirect or virtual function call is expensive. The default
28 // setting is to use non-virtual functions, the actual implementations of the functions
29 // are declared as inline for maximum speed.
30 
31 //#define DT_VIRTUAL_QUERYFILTER 1
32 
36 {
38  unsigned short m_includeFlags;
39  unsigned short m_excludeFlags;
40 
41 public:
42  dtQueryFilter();
43 
44 #ifdef DT_VIRTUAL_QUERYFILTER
45  virtual ~dtQueryFilter() { }
46 #endif
47 
52 #ifdef DT_VIRTUAL_QUERYFILTER
53  virtual bool passFilter(const dtPolyRef ref,
54  const dtMeshTile* tile,
55  const dtPoly* poly) const;
56 #else
57  bool passFilter(const dtPolyRef ref,
58  const dtMeshTile* tile,
59  const dtPoly* poly) const;
60 #endif
61 
75 #ifdef DT_VIRTUAL_QUERYFILTER
76  virtual float getCost(const float* pa, const float* pb,
77  const dtPolyRef prevRef, const dtMeshTile* prevTile, const dtPoly* prevPoly,
78  const dtPolyRef curRef, const dtMeshTile* curTile, const dtPoly* curPoly,
79  const dtPolyRef nextRef, const dtMeshTile* nextTile, const dtPoly* nextPoly) const;
80 #else
81  float getCost(const float* pa, const float* pb,
82  const dtPolyRef prevRef, const dtMeshTile* prevTile, const dtPoly* prevPoly,
83  const dtPolyRef curRef, const dtMeshTile* curTile, const dtPoly* curPoly,
84  const dtPolyRef nextRef, const dtMeshTile* nextTile, const dtPoly* nextPoly) const;
85 #endif
86 
89 
93  inline float getAreaCost(const int i) const { return m_areaCost[i]; }
94 
98  inline void setAreaCost(const int i, const float cost) { m_areaCost[i] = cost; }
99 
103  inline unsigned short getIncludeFlags() const { return m_includeFlags; }
104 
107  inline void setIncludeFlags(const unsigned short flags) { m_includeFlags = flags; }
108 
112  inline unsigned short getExcludeFlags() const { return m_excludeFlags; }
113 
116  inline void setExcludeFlags(const unsigned short flags) { m_excludeFlags = flags; }
117 
119 
120 };
121 
122 
123 
128 {
130  float t;
131 
133  float hitNormal[3];
134 
137 
140 
142  int maxPath;
143 
145  float pathCost;
146 };
147 
148 
149 
154 {
155 public:
156  dtNavMeshQuery();
157  ~dtNavMeshQuery();
158 
163  dtStatus init(const dtNavMesh* nav, const int maxNodes);
164 
166  // /@{
167 
178  dtStatus findPath(dtPolyRef startRef, dtPolyRef endRef,
179  const float* startPos, const float* endPos,
180  const dtQueryFilter* filter,
181  dtPolyRef* path, int* pathCount, const int maxPath) const;
182 
195  dtStatus findStraightPath(const float* startPos, const float* endPos,
196  const dtPolyRef* path, const int pathSize,
197  float* straightPath, unsigned char* straightPathFlags, dtPolyRef* straightPathRefs,
198  int* straightPathCount, const int maxStraightPath, const int options = 0) const;
199 
207 
217  const float* startPos, const float* endPos,
218  const dtQueryFilter* filter, const unsigned int options = 0);
219 
224  dtStatus updateSlicedFindPath(const int maxIter, int* doneIters);
225 
232  dtStatus finalizeSlicedFindPath(dtPolyRef* path, int* pathCount, const int maxPath);
233 
243  dtStatus finalizeSlicedFindPathPartial(const dtPolyRef* existing, const int existingSize,
244  dtPolyRef* path, int* pathCount, const int maxPath);
245 
249 
262  dtStatus findPolysAroundCircle(dtPolyRef startRef, const float* centerPos, const float radius,
263  const dtQueryFilter* filter,
264  dtPolyRef* resultRef, dtPolyRef* resultParent, float* resultCost,
265  int* resultCount, const int maxResult) const;
266 
280  dtStatus findPolysAroundShape(dtPolyRef startRef, const float* verts, const int nverts,
281  const dtQueryFilter* filter,
282  dtPolyRef* resultRef, dtPolyRef* resultParent, float* resultCost,
283  int* resultCount, const int maxResult) const;
284 
288 
296  dtStatus findNearestPoly(const float* center, const float* extents,
297  const dtQueryFilter* filter,
298  dtPolyRef* nearestRef, float* nearestPt) const;
299 
308  dtStatus queryPolygons(const float* center, const float* extents,
309  const dtQueryFilter* filter,
310  dtPolyRef* polys, int* polyCount, const int maxPolys) const;
311 
323  dtStatus findLocalNeighbourhood(dtPolyRef startRef, const float* centerPos, const float radius,
324  const dtQueryFilter* filter,
325  dtPolyRef* resultRef, dtPolyRef* resultParent,
326  int* resultCount, const int maxResult) const;
327 
338  dtStatus moveAlongSurface(dtPolyRef startRef, const float* startPos, const float* endPos,
339  const dtQueryFilter* filter,
340  float* resultPos, dtPolyRef* visited, int* visitedCount, const int maxVisitedSize) const;
341 
356  dtStatus raycast(dtPolyRef startRef, const float* startPos, const float* endPos,
357  const dtQueryFilter* filter,
358  float* t, float* hitNormal, dtPolyRef* path, int* pathCount, const int maxPath) const;
359 
371  dtStatus raycast(dtPolyRef startRef, const float* startPos, const float* endPos,
372  const dtQueryFilter* filter, const unsigned int options,
373  dtRaycastHit* hit, dtPolyRef prevRef = 0) const;
374 
375 
386  dtStatus findDistanceToWall(dtPolyRef startRef, const float* centerPos, const float maxRadius,
387  const dtQueryFilter* filter,
388  float* hitDist, float* hitPos, float* hitNormal) const;
389 
400  float* segmentVerts, dtPolyRef* segmentRefs, int* segmentCount,
401  const int maxSegments) const;
402 
410  dtStatus findRandomPoint(const dtQueryFilter* filter, float (*frand)(),
411  dtPolyRef* randomRef, float* randomPt) const;
412 
423  dtStatus findRandomPointAroundCircle(dtPolyRef startRef, const float* centerPos, const float maxRadius,
424  const dtQueryFilter* filter, float (*frand)(),
425  dtPolyRef* randomRef, float* randomPt) const;
426 
433  dtStatus closestPointOnPoly(dtPolyRef ref, const float* pos, float* closest, bool* posOverPoly) const;
434 
441  dtStatus closestPointOnPolyBoundary(dtPolyRef ref, const float* pos, float* closest) const;
442 
448  dtStatus getPolyHeight(dtPolyRef ref, const float* pos, float* height) const;
449 
453 
457  bool isValidPolyRef(dtPolyRef ref, const dtQueryFilter* filter) const;
458 
462  bool isInClosedList(dtPolyRef ref) const;
463 
466  class dtNodePool* getNodePool() const { return m_nodePool; }
467 
470  const dtNavMesh* getAttachedNavMesh() const { return m_nav; }
471 
473 
474 private:
475 
477  dtMeshTile* getNeighbourTileAt(int x, int y, int side) const;
478 
480  int queryPolygonsInTile(const dtMeshTile* tile, const float* qmin, const float* qmax, const dtQueryFilter* filter,
481  dtPolyRef* polys, const int maxPolys) const;
482 
484  dtStatus getPortalPoints(dtPolyRef from, dtPolyRef to, float* left, float* right,
485  unsigned char& fromType, unsigned char& toType) const;
486  dtStatus getPortalPoints(dtPolyRef from, const dtPoly* fromPoly, const dtMeshTile* fromTile,
487  dtPolyRef to, const dtPoly* toPoly, const dtMeshTile* toTile,
488  float* left, float* right) const;
489 
491  dtStatus getEdgeMidPoint(dtPolyRef from, dtPolyRef to, float* mid) const;
492  dtStatus getEdgeMidPoint(dtPolyRef from, const dtPoly* fromPoly, const dtMeshTile* fromTile,
493  dtPolyRef to, const dtPoly* toPoly, const dtMeshTile* toTile,
494  float* mid) const;
495 
496  // Appends vertex to a straight path
497  dtStatus appendVertex(const float* pos, const unsigned char flags, const dtPolyRef ref,
498  float* straightPath, unsigned char* straightPathFlags, dtPolyRef* straightPathRefs,
499  int* straightPathCount, const int maxStraightPath) const;
500 
501  // Appends intermediate portal points to a straight path.
502  dtStatus appendPortals(const int startIdx, const int endIdx, const float* endPos, const dtPolyRef* path,
503  float* straightPath, unsigned char* straightPathFlags, dtPolyRef* straightPathRefs,
504  int* straightPathCount, const int maxStraightPath, const int options) const;
505 
506  const dtNavMesh* m_nav;
507 
508  struct dtQueryData
509  {
514  float startPos[3], endPos[3];
516  unsigned int options;
518  };
520 
524 };
525 
530 
535 
536 #endif // DETOURNAVMESHQUERY_H
dtStatus queryPolygons(const float *center, const float *extents, const dtQueryFilter *filter, dtPolyRef *polys, int *polyCount, const int maxPolys) const
Definition: DetourNavMeshQuery.cpp:872
bool isInClosedList(dtPolyRef ref) const
Definition: DetourNavMeshQuery.cpp:3529
void setIncludeFlags(const unsigned short flags)
Definition: DetourNavMeshQuery.h:107
float t
The hit parameter. (FLT_MAX if no wall hit.)
Definition: DetourNavMeshQuery.h:130
dtStatus findRandomPointAroundCircle(dtPolyRef startRef, const float *centerPos, const float maxRadius, const dtQueryFilter *filter, float(*frand)(), dtPolyRef *randomRef, float *randomPt) const
Definition: DetourNavMeshQuery.cpp:312
uint64_d dtPolyRef
Definition: DetourNavMesh.h:49
dtStatus findPolysAroundCircle(dtPolyRef startRef, const float *centerPos, const float radius, const dtQueryFilter *filter, dtPolyRef *resultRef, dtPolyRef *resultParent, float *resultCost, int *resultCount, const int maxResult) const
Definition: DetourNavMeshQuery.cpp:2608
float pathCost
The cost of the path until hit.
Definition: DetourNavMeshQuery.h:145
const dtNavMesh * getAttachedNavMesh() const
Definition: DetourNavMeshQuery.h:470
class dtNodeQueue * m_openList
Pointer to open list queue.
Definition: DetourNavMeshQuery.h:523
Definition: DetourNode.h:34
Position const centerPos
Definition: boss_blood_queen_lana_thel.cpp:125
float m_areaCost[DT_MAX_AREAS]
Cost per area type. (Used by default implementation.)
Definition: DetourNavMeshQuery.h:37
double frand()
Definition: Vector3.cpp:170
dtStatus appendVertex(const float *pos, const unsigned char flags, const dtPolyRef ref, float *straightPath, unsigned char *straightPathFlags, dtPolyRef *straightPathRefs, int *straightPathCount, const int maxStraightPath) const
Definition: DetourNavMeshQuery.cpp:1610
dtStatus getPortalPoints(dtPolyRef from, dtPolyRef to, float *left, float *right, unsigned char &fromType, unsigned char &toType) const
Returns portal points between two polygons.
Definition: DetourNavMeshQuery.cpp:2146
dtQueryFilter()
Definition: DetourNavMeshQuery.cpp:63
Definition: DetourNavMeshQuery.h:508
dtStatus findStraightPath(const float *startPos, const float *endPos, const dtPolyRef *path, const int pathSize, float *straightPath, unsigned char *straightPathFlags, dtPolyRef *straightPathRefs, int *straightPathCount, const int maxStraightPath, const int options=0) const
Definition: DetourNavMeshQuery.cpp:1707
dtStatus raycast(dtPolyRef startRef, const float *startPos, const float *endPos, const dtQueryFilter *filter, float *t, float *hitNormal, dtPolyRef *path, int *pathCount, const int maxPath) const
Definition: DetourNavMeshQuery.cpp:2306
Definition: BnetFileGenerator.h:49
Definition: DetourNavMeshQuery.h:127
char * query(struct soap *soap)
Definition: httpget.cpp:244
struct dtNode * lastBestNode
Definition: DetourNavMeshQuery.h:511
Definition: DetourNavMeshQuery.h:35
class dtNodePool * m_nodePool
Pointer to node pool.
Definition: DetourNavMeshQuery.h:522
unsigned int dtStatus
Definition: DetourStatus.h:22
dtStatus closestPointOnPolyBoundary(dtPolyRef ref, const float *pos, float *closest) const
Definition: DetourNavMeshQuery.cpp:601
Definition: DetourNode.h:107
Definition: DetourNavMesh.h:323
dtStatus findPath(dtPolyRef startRef, dtPolyRef endRef, const float *startPos, const float *endPos, const dtQueryFilter *filter, dtPolyRef *path, int *pathCount, const int maxPath) const
Definition: DetourNavMeshQuery.cpp:923
float getCost(const float *pa, const float *pb, const dtPolyRef prevRef, const dtMeshTile *prevTile, const dtPoly *prevPoly, const dtPolyRef curRef, const dtMeshTile *curTile, const dtPoly *curPoly, const dtPolyRef nextRef, const dtMeshTile *nextTile, const dtPoly *nextPoly) const
Definition: DetourNavMeshQuery.cpp:94
dtPolyRef * path
Pointer to an array of reference ids of the visited polygons. [opt].
Definition: DetourNavMeshQuery.h:136
static const int DT_MAX_AREAS
Definition: DetourNavMesh.h:91
dtStatus finalizeSlicedFindPath(dtPolyRef *path, int *pathCount, const int maxPath)
Definition: DetourNavMeshQuery.cpp:1425
unsigned short getIncludeFlags() const
Definition: DetourNavMeshQuery.h:103
dtNavMeshQuery()
Definition: DetourNavMeshQuery.cpp:139
dtStatus status
Definition: DetourNavMeshQuery.h:510
int maxPath
The maximum number of polygons the path array can hold.
Definition: DetourNavMeshQuery.h:142
Definition: DetourNavMesh.h:153
int pathCount
The number of visited polygons. [opt].
Definition: DetourNavMeshQuery.h:139
dtStatus initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef, const float *startPos, const float *endPos, const dtQueryFilter *filter, const unsigned int options=0)
Definition: DetourNavMeshQuery.cpp:1147
dtStatus finalizeSlicedFindPathPartial(const dtPolyRef *existing, const int existingSize, dtPolyRef *path, int *pathCount, const int maxPath)
Definition: DetourNavMeshQuery.cpp:1509
float hitNormal[3]
hitNormal The normal of the nearest wall hit. [(x, y, z)]
Definition: DetourNavMeshQuery.h:133
unsigned short getExcludeFlags() const
Definition: DetourNavMeshQuery.h:112
dtStatus findLocalNeighbourhood(dtPolyRef startRef, const float *centerPos, const float radius, const dtQueryFilter *filter, dtPolyRef *resultRef, dtPolyRef *resultParent, int *resultCount, const int maxResult) const
Definition: DetourNavMeshQuery.cpp:2963
~dtNavMeshQuery()
Definition: DetourNavMeshQuery.cpp:148
dtMeshTile * getNeighbourTileAt(int x, int y, int side) const
Returns neighbour tile based on side.
bool isValidPolyRef(dtPolyRef ref, const dtQueryFilter *filter) const
Definition: DetourNavMeshQuery.cpp:3510
float getAreaCost(const int i) const
Definition: DetourNavMeshQuery.h:93
G3D::int16 y
Definition: Vector2int16.h:38
int queryPolygonsInTile(const dtMeshTile *tile, const float *qmin, const float *qmax, const dtQueryFilter *filter, dtPolyRef *polys, const int maxPolys) const
Queries polygons within a tile.
Definition: DetourNavMeshQuery.cpp:768
float lastBestNodeCost
Definition: DetourNavMeshQuery.h:512
unsigned short m_includeFlags
Flags for polygons that can be visited. (Used by default implementation.)
Definition: DetourNavMeshQuery.h:38
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487
dtStatus getPolyHeight(dtPolyRef ref, const float *pos, float *height) const
Definition: DetourNavMeshQuery.cpp:653
dtPolyRef startRef
Definition: DetourNavMeshQuery.h:513
dtStatus findPolysAroundShape(dtPolyRef startRef, const float *verts, const int nverts, const dtQueryFilter *filter, dtPolyRef *resultRef, dtPolyRef *resultParent, float *resultCost, int *resultCount, const int maxResult) const
Definition: DetourNavMeshQuery.cpp:2783
dtStatus findNearestPoly(const float *center, const float *extents, const dtQueryFilter *filter, dtPolyRef *nearestRef, float *nearestPt) const
Definition: DetourNavMeshQuery.cpp:710
class dtNodePool * getNodePool() const
Definition: DetourNavMeshQuery.h:466
dtPolyRef endRef
Definition: DetourNavMeshQuery.h:513
Definition: DetourNode.h:50
unsigned short m_excludeFlags
Flags for polygons that should not be visted. (Used by default implementation.)
Definition: DetourNavMeshQuery.h:39
class dtNodePool * m_tinyNodePool
Pointer to small node pool.
Definition: DetourNavMeshQuery.h:521
const dtNavMesh * m_nav
Pointer to navmesh data.
Definition: DetourNavMeshQuery.h:506
dtStatus getEdgeMidPoint(dtPolyRef from, dtPolyRef to, float *mid) const
Returns edge mid point between two polygons.
Definition: DetourNavMeshQuery.cpp:2241
dtNavMeshQuery * dtAllocNavMeshQuery()
Definition: DetourNavMeshQuery.cpp:107
dtStatus updateSlicedFindPath(const int maxIter, int *doneIters)
Definition: DetourNavMeshQuery.cpp:1208
void setAreaCost(const int i, const float cost)
Definition: DetourNavMeshQuery.h:98
dtStatus init(const dtNavMesh *nav, const int maxNodes)
Definition: DetourNavMeshQuery.cpp:167
dtStatus findDistanceToWall(dtPolyRef startRef, const float *centerPos, const float maxRadius, const dtQueryFilter *filter, float *hitDist, float *hitPos, float *hitNormal) const
Definition: DetourNavMeshQuery.cpp:3328
dtStatus findRandomPoint(const dtQueryFilter *filter, float(*frand)(), dtPolyRef *randomRef, float *randomPt) const
Definition: DetourNavMeshQuery.cpp:220
unsigned int options
Definition: DetourNavMeshQuery.h:516
void dtFreeNavMeshQuery(dtNavMeshQuery *query)
Definition: DetourNavMeshQuery.cpp:114
dtQueryData m_query
Sliced query state.
Definition: DetourNavMeshQuery.h:519
void setExcludeFlags(const unsigned short flags)
Definition: DetourNavMeshQuery.h:116
const dtQueryFilter * filter
Definition: DetourNavMeshQuery.h:515
uint8 flags
Definition: DisableMgr.cpp:44
G3D::int16 x
Definition: Vector2int16.h:37
Definition: DetourNavMesh.h:279
Definition: DetourNavMeshQuery.h:153
bool passFilter(const dtPolyRef ref, const dtMeshTile *tile, const dtPoly *poly) const
Definition: DetourNavMeshQuery.cpp:87
float raycastLimitSqr
Definition: DetourNavMeshQuery.h:517
dtStatus getPolyWallSegments(dtPolyRef ref, const dtQueryFilter *filter, float *segmentVerts, dtPolyRef *segmentRefs, int *segmentCount, const int maxSegments) const
Definition: DetourNavMeshQuery.cpp:3178
dtStatus appendPortals(const int startIdx, const int endIdx, const float *endPos, const dtPolyRef *path, float *straightPath, unsigned char *straightPathFlags, dtPolyRef *straightPathRefs, int *straightPathCount, const int maxStraightPath, const int options) const
Definition: DetourNavMeshQuery.cpp:1640
dtStatus moveAlongSurface(dtPolyRef startRef, const float *startPos, const float *endPos, const dtQueryFilter *filter, float *resultPos, dtPolyRef *visited, int *visitedCount, const int maxVisitedSize) const
Definition: DetourNavMeshQuery.cpp:1948
dtStatus closestPointOnPoly(dtPolyRef ref, const float *pos, float *closest, bool *posOverPoly) const
Definition: DetourNavMeshQuery.cpp:505