RavEngine
Loading...
Searching...
No Matches
DetourNavMeshQuery.h
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
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{
37 float m_areaCost[DT_MAX_AREAS];
38 unsigned short m_includeFlags;
39 unsigned short m_excludeFlags;
40
41public:
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
126{
128 float t;
129
131 float hitNormal[3];
132
135
138
141
144
146 float pathCost;
147};
148
153{
154public:
155 virtual ~dtPolyQuery() { }
156
159 virtual void process(const dtMeshTile* tile, dtPoly** polys, dtPolyRef* refs, int count) = 0;
160};
161
166{
167public:
170
175 dtStatus init(const dtNavMesh* nav, const int maxNodes);
176
178 // /@{
179
190 dtStatus findPath(dtPolyRef startRef, dtPolyRef endRef,
191 const float* startPos, const float* endPos,
192 const dtQueryFilter* filter,
193 dtPolyRef* path, int* pathCount, const int maxPath) const;
194
207 dtStatus findStraightPath(const float* startPos, const float* endPos,
208 const dtPolyRef* path, const int pathSize,
209 float* straightPath, unsigned char* straightPathFlags, dtPolyRef* straightPathRefs,
210 int* straightPathCount, const int maxStraightPath, const int options = 0) const;
211
219
228 dtStatus initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef,
229 const float* startPos, const float* endPos,
230 const dtQueryFilter* filter, const unsigned int options = 0);
231
236 dtStatus updateSlicedFindPath(const int maxIter, int* doneIters);
237
244 dtStatus finalizeSlicedFindPath(dtPolyRef* path, int* pathCount, const int maxPath);
245
255 dtStatus finalizeSlicedFindPathPartial(const dtPolyRef* existing, const int existingSize,
256 dtPolyRef* path, int* pathCount, const int maxPath);
257
261
274 dtStatus findPolysAroundCircle(dtPolyRef startRef, const float* centerPos, const float radius,
275 const dtQueryFilter* filter,
276 dtPolyRef* resultRef, dtPolyRef* resultParent, float* resultCost,
277 int* resultCount, const int maxResult) const;
278
292 dtStatus findPolysAroundShape(dtPolyRef startRef, const float* verts, const int nverts,
293 const dtQueryFilter* filter,
294 dtPolyRef* resultRef, dtPolyRef* resultParent, float* resultCost,
295 int* resultCount, const int maxResult) const;
296
309 dtStatus getPathFromDijkstraSearch(dtPolyRef endRef, dtPolyRef* path, int* pathCount, int maxPath) const;
310
314
322 dtStatus findNearestPoly(const float* center, const float* halfExtents,
323 const dtQueryFilter* filter,
324 dtPolyRef* nearestRef, float* nearestPt) const;
325
334 dtStatus queryPolygons(const float* center, const float* halfExtents,
335 const dtQueryFilter* filter,
336 dtPolyRef* polys, int* polyCount, const int maxPolys) const;
337
343 dtStatus queryPolygons(const float* center, const float* halfExtents,
344 const dtQueryFilter* filter, dtPolyQuery* query) const;
345
357 dtStatus findLocalNeighbourhood(dtPolyRef startRef, const float* centerPos, const float radius,
358 const dtQueryFilter* filter,
359 dtPolyRef* resultRef, dtPolyRef* resultParent,
360 int* resultCount, const int maxResult) const;
361
372 dtStatus moveAlongSurface(dtPolyRef startRef, const float* startPos, const float* endPos,
373 const dtQueryFilter* filter,
374 float* resultPos, dtPolyRef* visited, int* visitedCount, const int maxVisitedSize) const;
375
390 dtStatus raycast(dtPolyRef startRef, const float* startPos, const float* endPos,
391 const dtQueryFilter* filter,
392 float* t, float* hitNormal, dtPolyRef* path, int* pathCount, const int maxPath) const;
393
405 dtStatus raycast(dtPolyRef startRef, const float* startPos, const float* endPos,
406 const dtQueryFilter* filter, const unsigned int options,
407 dtRaycastHit* hit, dtPolyRef prevRef = 0) const;
408
409
420 dtStatus findDistanceToWall(dtPolyRef startRef, const float* centerPos, const float maxRadius,
421 const dtQueryFilter* filter,
422 float* hitDist, float* hitPos, float* hitNormal) const;
423
433 dtStatus getPolyWallSegments(dtPolyRef ref, const dtQueryFilter* filter,
434 float* segmentVerts, dtPolyRef* segmentRefs, int* segmentCount,
435 const int maxSegments) const;
436
444 dtStatus findRandomPoint(const dtQueryFilter* filter, float (*frand)(),
445 dtPolyRef* randomRef, float* randomPt) const;
446
457 dtStatus findRandomPointAroundCircle(dtPolyRef startRef, const float* centerPos, const float maxRadius,
458 const dtQueryFilter* filter, float (*frand)(),
459 dtPolyRef* randomRef, float* randomPt) const;
460
467 dtStatus closestPointOnPoly(dtPolyRef ref, const float* pos, float* closest, bool* posOverPoly) const;
468
475 dtStatus closestPointOnPolyBoundary(dtPolyRef ref, const float* pos, float* closest) const;
476
482 dtStatus getPolyHeight(dtPolyRef ref, const float* pos, float* height) const;
483
487
491 bool isValidPolyRef(dtPolyRef ref, const dtQueryFilter* filter) const;
492
496 bool isInClosedList(dtPolyRef ref) const;
497
500 class dtNodePool* getNodePool() const { return m_nodePool; }
501
504 const dtNavMesh* getAttachedNavMesh() const { return m_nav; }
505
507
508private:
509 // Explicitly disabled copy constructor and copy assignment operator
511 dtNavMeshQuery& operator=(const dtNavMeshQuery&);
512
514 void queryPolygonsInTile(const dtMeshTile* tile, const float* qmin, const float* qmax,
515 const dtQueryFilter* filter, dtPolyQuery* query) const;
516
518 dtStatus getPortalPoints(dtPolyRef from, dtPolyRef to, float* left, float* right,
519 unsigned char& fromType, unsigned char& toType) const;
520 dtStatus getPortalPoints(dtPolyRef from, const dtPoly* fromPoly, const dtMeshTile* fromTile,
521 dtPolyRef to, const dtPoly* toPoly, const dtMeshTile* toTile,
522 float* left, float* right) const;
523
525 dtStatus getEdgeMidPoint(dtPolyRef from, dtPolyRef to, float* mid) const;
526 dtStatus getEdgeMidPoint(dtPolyRef from, const dtPoly* fromPoly, const dtMeshTile* fromTile,
527 dtPolyRef to, const dtPoly* toPoly, const dtMeshTile* toTile,
528 float* mid) const;
529
530 // Appends vertex to a straight path
531 dtStatus appendVertex(const float* pos, const unsigned char flags, const dtPolyRef ref,
532 float* straightPath, unsigned char* straightPathFlags, dtPolyRef* straightPathRefs,
533 int* straightPathCount, const int maxStraightPath) const;
534
535 // Appends intermediate portal points to a straight path.
536 dtStatus appendPortals(const int startIdx, const int endIdx, const float* endPos, const dtPolyRef* path,
537 float* straightPath, unsigned char* straightPathFlags, dtPolyRef* straightPathRefs,
538 int* straightPathCount, const int maxStraightPath, const int options) const;
539
540 // Gets the path leading to the specified end node.
541 dtStatus getPathToNode(struct dtNode* endNode, dtPolyRef* path, int* pathCount, int maxPath) const;
542
543 const dtNavMesh* m_nav;
544
545 struct dtQueryData
546 {
547 dtStatus status;
548 struct dtNode* lastBestNode;
549 float lastBestNodeCost;
550 dtPolyRef startRef, endRef;
551 float startPos[3], endPos[3];
552 const dtQueryFilter* filter;
553 unsigned int options;
554 float raycastLimitSqr;
555 };
556 dtQueryData m_query;
557
558 class dtNodePool* m_tinyNodePool;
559 class dtNodePool* m_nodePool;
560 class dtNodeQueue* m_openList;
561};
562
567
572
573#endif // DETOURNAVMESHQUERY_H
Definition DetourNavMeshQuery.h:166
dtStatus finalizeSlicedFindPathPartial(const dtPolyRef *existing, const int existingSize, dtPolyRef *path, int *pathCount, const int maxPath)
Definition DetourNavMeshQuery.cpp:1560
dtStatus queryPolygons(const float *center, const float *halfExtents, const dtQueryFilter *filter, dtPolyRef *polys, int *polyCount, const int maxPolys) const
Definition DetourNavMeshQuery.cpp:872
dtStatus closestPointOnPoly(dtPolyRef ref, const float *pos, float *closest, bool *posOverPoly) const
Definition DetourNavMeshQuery.cpp:514
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:2693
dtStatus findDistanceToWall(dtPolyRef startRef, const float *centerPos, const float maxRadius, const dtQueryFilter *filter, float *hitDist, float *hitPos, float *hitNormal) const
Definition DetourNavMeshQuery.cpp:3443
dtStatus getPolyWallSegments(dtPolyRef ref, const dtQueryFilter *filter, float *segmentVerts, dtPolyRef *segmentRefs, int *segmentCount, const int maxSegments) const
Definition DetourNavMeshQuery.cpp:3287
dtStatus findNearestPoly(const float *center, const float *halfExtents, const dtQueryFilter *filter, dtPolyRef *nearestRef, float *nearestPt) const
Definition DetourNavMeshQuery.cpp:686
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:2381
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:2017
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:3065
dtStatus finalizeSlicedFindPath(dtPolyRef *path, int *pathCount, const int maxPath)
Definition DetourNavMeshQuery.cpp:1470
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:946
dtStatus updateSlicedFindPath(const int maxIter, int *doneIters)
Definition DetourNavMeshQuery.cpp:1253
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:2867
dtStatus closestPointOnPolyBoundary(dtPolyRef ref, const float *pos, float *closest) const
Definition DetourNavMeshQuery.cpp:539
const dtNavMesh * getAttachedNavMesh() const
Definition DetourNavMeshQuery.h:504
dtStatus findRandomPointAroundCircle(dtPolyRef startRef, const float *centerPos, const float maxRadius, const dtQueryFilter *filter, float(*frand)(), dtPolyRef *randomRef, float *randomPt) const
Definition DetourNavMeshQuery.cpp:316
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:1766
class dtNodePool * getNodePool() const
Definition DetourNavMeshQuery.h:500
bool isValidPolyRef(dtPolyRef ref, const dtQueryFilter *filter) const
Definition DetourNavMeshQuery.cpp:3630
dtStatus init(const dtNavMesh *nav, const int maxNodes)
Definition DetourNavMeshQuery.cpp:166
bool isInClosedList(dtPolyRef ref) const
Definition DetourNavMeshQuery.cpp:3649
dtStatus initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef, const float *startPos, const float *endPos, const dtQueryFilter *filter, const unsigned int options=0)
Definition DetourNavMeshQuery.cpp:1189
dtStatus getPathFromDijkstraSearch(dtPolyRef endRef, dtPolyRef *path, int *pathCount, int maxPath) const
Definition DetourNavMeshQuery.cpp:3028
dtStatus getPolyHeight(dtPolyRef ref, const float *pos, float *height) const
Definition DetourNavMeshQuery.cpp:594
dtStatus findRandomPoint(const dtQueryFilter *filter, float(*frand)(), dtPolyRef *randomRef, float *randomPt) const
Definition DetourNavMeshQuery.cpp:221
Definition DetourNavMesh.h:339
Definition DetourNode.h:50
Definition DetourNode.h:109
Definition DetourNavMeshQuery.h:153
virtual void process(const dtMeshTile *tile, dtPoly **polys, dtPolyRef *refs, int count)=0
Definition DetourNavMeshQuery.h:36
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
void setExcludeFlags(const unsigned short flags)
Definition DetourNavMeshQuery.h:116
float getAreaCost(const int i) const
Definition DetourNavMeshQuery.h:93
void setAreaCost(const int i, const float cost)
Definition DetourNavMeshQuery.h:98
unsigned short getIncludeFlags() const
Definition DetourNavMeshQuery.h:103
bool passFilter(const dtPolyRef ref, const dtMeshTile *tile, const dtPoly *poly) const
Definition DetourNavMeshQuery.cpp:87
void setIncludeFlags(const unsigned short flags)
Definition DetourNavMeshQuery.h:107
unsigned short getExcludeFlags() const
Definition DetourNavMeshQuery.h:112
void dtFreeNavMeshQuery(dtNavMeshQuery *query)
Definition DetourNavMeshQuery.cpp:113
dtNavMeshQuery * dtAllocNavMeshQuery()
Definition DetourNavMeshQuery.cpp:106
unsigned int dtPolyRef
Definition DetourNavMesh.h:48
Definition DetourNavMesh.h:282
Definition DetourNode.h:37
Definition DetourNavMesh.h:156
Definition DetourNavMeshQuery.h:126
int hitEdgeIndex
The index of the edge on the final polygon where the wall was hit.
Definition DetourNavMeshQuery.h:134
float hitNormal[3]
hitNormal The normal of the nearest wall hit. [(x, y, z)]
Definition DetourNavMeshQuery.h:131
int maxPath
The maximum number of polygons the path array can hold.
Definition DetourNavMeshQuery.h:143
float t
The hit parameter. (FLT_MAX if no wall hit.)
Definition DetourNavMeshQuery.h:128
float pathCost
The cost of the path until hit.
Definition DetourNavMeshQuery.h:146
int pathCount
The number of visited polygons. [opt].
Definition DetourNavMeshQuery.h:140
dtPolyRef * path
Pointer to an array of reference ids of the visited polygons. [opt].
Definition DetourNavMeshQuery.h:137