19 #ifndef DETOURNAVMESHQUERY_H
20 #define DETOURNAVMESHQUERY_H
22 #include <AtomsUtils/Globals.h>
23 #include <AtomsUtils/NavigationMesh/Detour/DetourAlloc.h>
24 #include <AtomsUtils/NavigationMesh/Detour/DetourNavMesh.h>
25 #include <AtomsUtils/NavigationMesh/Detour/DetourCommon.h>
30 #define WITH_FIXED_AREA_ENTERING_COST 1
32 #define DT_UNWALKABLE_POLY_COST FLT_MAX
59 float m_areaCost[DT_MAX_AREAS];
60 #if WITH_FIXED_AREA_ENTERING_COST
61 float m_areaFixedCost[DT_MAX_AREAS];
69 bool m_isBacktracking;
93 dtQueryFilter(
bool inIsVirtual =
true) : isVirtual(inIsVirtual)
106 #
if WITH_FIXED_AREA_ENTERING_COST
117 return passInlineFilter(ref, tile, poly);
129 return !isVirtual ? passInlineFilter(ref, tile, poly) : passVirtualFilter(ref, tile, poly);
140 #if WITH_FIXED_AREA_ENTERING_COST
141 const float areaChangeCost = nextPoly != 0 && nextPoly->
getArea() != curPoly->
getArea()
156 return getInlineCost(pa, pb,
157 prevRef, prevTile, prevPoly,
158 curRef, curTile, curPoly,
159 nextRef, nextTile, nextPoly);
176 inline float getCost(
const float* pa,
const float* pb,
181 return !isVirtual ? getInlineCost(pa, pb, prevRef, prevTile, prevPoly, curRef, curTile, curPoly, nextRef, nextTile, nextPoly)
182 : getVirtualCost(pa, pb, prevRef, prevTile, prevPoly, curRef, curTile, curPoly, nextRef, nextTile, nextPoly);
196 inline void setAreaCost(
const int i,
const float cost) { data.
m_areaCost[i] = cost; data.lowestAreaCost =
dtMin(data.lowestAreaCost, cost); }
199 inline const float* getAllAreaCosts()
const {
return data.
m_areaCost; }
201 #if WITH_FIXED_AREA_ENTERING_COST
212 inline const float* getAllFixedAreaCosts()
const {
return data.
m_areaFixedCost; }
215 inline float getModifiedHeuristicScale()
const {
return data.
heuristicScale * ((data.lowestAreaCost > 0) ? data.lowestAreaCost : 1.0f); }
228 return (side & DT_LINK_FLAG_OFFMESH_CON) == 0 || (side & DT_LINK_FLAG_OFFMESH_CON_BIDIR) != 0
229 || (data.m_isBacktracking ? (side & DT_LINK_FLAG_OFFMESH_CON_BACKTRACKER) != 0
230 : (side & DT_LINK_FLAG_OFFMESH_CON_BACKTRACKER) == 0);
234 inline void setIsBacktracking(
const bool isBacktracking) { data.m_isBacktracking = isBacktracking; }
270 inline bool equals(
const dtQueryFilter& other)
const {
return data.equals(&(other.data)); }
274 inline void copyFrom(
const dtQueryFilter& other) { data.copyFrom(&(other.data)); }
291 inline void reserve(
int n) { data.resize(n); data.resize(0); }
292 inline int size()
const {
return data.size(); }
294 inline dtPolyRef getRef(
int idx)
const {
return data[idx].ref; }
295 inline float getCost(
int idx)
const {
return data[idx].cost; }
296 inline const float* getPos(
int idx)
const {
return data[idx].pos; }
297 inline unsigned int getFlag(
int idx)
const {
return data[idx].flag; }
298 void getPos(
int idx,
float* pos);
300 void copyRefs(
dtPolyRef* refs,
int nmax);
301 void copyCosts(
float* costs,
int nmax);
302 void copyPos(
float* pos,
int nmax);
303 void copyFlags(
unsigned char* flags,
int nmax);
304 void copyFlags(
unsigned int* flags,
int nmax);
311 inline void setRef(
int idx,
dtPolyRef ref) { data[idx].ref = ref; }
312 inline void setCost(
int idx,
float cost) { data[idx].cost = cost; }
313 inline void setFlag(
int idx,
unsigned int flag) { data[idx].flag = flag; }
314 void setPos(
int idx,
const float* pos);
351 const float* startPos,
const float* endPos,
const float costLimit,
370 const dtPolyRef* path,
const int pathSize,
390 const float* startPos,
const float* endPos,
const float costLimit,
417 dtPolyRef* path,
int* pathCount,
const int maxPath);
438 int* resultCount,
const int maxResult)
const;
456 int* resultCount,
const int maxResult)
const;
470 int* resultCount,
const int maxResult)
const;
486 dtPolyRef* nearestRef,
float* nearestPt,
const float* referencePt = 0)
const;
499 dtPolyRef* outProjectedRef,
float* outProjectedPt,
500 const float* referencePt = 0,
float tolerance = 0)
const;
511 dtPolyRef* nearestRef,
float* nearestPt)
const;
524 dtPolyRef* polys,
int* polyCount,
const int maxPolys)
const;
540 int* resultCount,
const int maxResult)
const;
545 dtPolyRef* neiRefs,
int* neiCount,
const int maxNei,
546 float* resultWalls,
dtPolyRef* resultRefs,
int* resultCount,
const int maxResult)
const;
560 float* resultPos,
dtPolyRef* visited,
int* visitedCount,
const int maxVisitedSize)
const;
578 float* t,
float* hitNormal,
dtPolyRef* path,
int* pathCount,
const int maxPath)
const;
592 float* hitDist,
float* hitPos,
float* hitNormal)
const;
604 float* segmentVerts,
dtPolyRef* segmentRefs,
int* segmentCount,
605 const int maxSegments)
const;
615 dtPolyRef* randomRef,
float* randomPt)
const;
629 dtPolyRef* randomRef,
float* randomPt)
const;
637 dtPolyRef* randomRef,
float* randomPt)
const;
710 void getCurrentBestResult(
struct dtNode*& bestNode,
float& bestCost)
const { bestNode = m_query.lastBestNode; bestCost = m_query.lastBestNodeCost; }
712 int getQueryNodes()
const {
return m_queryNodes; }
718 dtMeshTile* getNeighbourTileAt(
int x,
int y,
int side)
const;
721 int queryPolygonsInTile(
const dtMeshTile* tile,
const float* qmin,
const float* qmax,
const dtQueryFilter* filter,
722 dtPolyRef* polys,
const int maxPolys)
const;
724 dtPolyRef findNearestPolyInTile(
const dtMeshTile* tile,
const float* center,
const float* extents,
725 const dtQueryFilter* filter,
float* nearestPt)
const;
727 void closestPointOnPolyInTile(
const dtMeshTile* tile,
const dtPoly* poly,
const float* pos,
float* closest)
const;
730 dtStatus projectedPointOnPolyInTile(
const dtMeshTile* tile,
const dtPoly* poly,
const float* pos,
float* projected)
const;
737 unsigned char& fromType,
unsigned char& toType)
const;
740 float* left,
float* right)
const;
751 dtStatus appendVertex(
const float* pos,
const unsigned char flags,
const dtPolyRef ref,
755 dtStatus appendPortals(
const int startIdx,
const int endIdx,
const float* endPos,
const dtPolyRef* path,
760 return passLinkFilter(tile, m_nav->decodePolyIdPoly(ref));
763 inline bool passLinkFilter(
const dtMeshTile* tile,
const int polyIdx)
const
773 const dtNavMesh* m_nav;
774 dtQuerySpecialLinkFilter* m_linkFilter;
779 struct dtNode* lastBestNode;
780 float lastBestNodeCost;
782 float startPos[3], endPos[3];
784 const dtQueryFilter* filter;
788 class dtNodePool* m_tinyNodePool;
789 class dtNodePool* m_nodePool;
790 class dtNodeQueue* m_openList;
792 mutable int m_queryNodes;
A simple dynamic array of integers.
Definition: DetourAlloc.h:147
void push(T item)
Definition: DetourAlloc.h:168
int size() const
The current size of the integer array.
Definition: DetourAlloc.h:185
Definition: DetourNavMesh.h:427
Definition: DetourNavMeshQuery.h:323
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
dtStatus getPortalPoints(dtPolyRef from, dtPolyRef to, float *left, float *right, unsigned char &fromType, unsigned char &toType) const
Returns portal points between two polygons.
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
dtStatus isPointInsidePoly(dtPolyRef ref, const float *pos, bool &result) const
dtStatus getEdgeMidPoint(dtPolyRef from, dtPolyRef to, float *mid) const
Returns edge mid point between two polygons.
dtStatus finalizeSlicedFindPath(dtPolyRef *path, int *pathCount, const int maxPath)
dtStatus projectedPointOnPoly(dtPolyRef ref, const float *pos, float *projected) const
class dtNodePool * getNodePool() const
Definition: DetourNavMeshQuery.h:703
dtStatus findWallsInNeighbourhood(dtPolyRef startRef, const float *centerPos, const float radius, const dtQueryFilter *filter, dtPolyRef *neiRefs, int *neiCount, const int maxNei, float *resultWalls, dtPolyRef *resultRefs, int *resultCount, const int maxResult) const
Finds the wall segments in local neighbourhood.
dtStatus closestPointOnPolyBoundary(dtPolyRef ref, const float *pos, float *closest) const
dtStatus getPolyCluster(dtPolyRef polyRef, dtClusterRef &clusterRef) const
bool wasClusterLinkSearched(dtPolyRef cFrom, dtPolyRef cTo) const
bool isValidPolyRef(dtPolyRef ref, const dtQueryFilter *filter) const
dtStatus findRandomPointAroundCircle(dtPolyRef startRef, const float *centerPos, const float maxRadius, const dtQueryFilter *filter, int randomSeed, dtPolyRef *randomRef, float *randomPt) const
dtStatus moveAlongSurface(dtPolyRef startRef, const float *startPos, const float *endPos, const dtQueryFilter *filter, float *resultPos, dtPolyRef *visited, int *visitedCount, const int maxVisitedSize) const
dtStatus findDistanceToWall(dtPolyRef startRef, const float *centerPos, const float maxRadius, const dtQueryFilter *filter, float *hitDist, float *hitPos, float *hitNormal) const
dtStatus getPolyHeight(dtPolyRef ref, const float *pos, float *height) const
dtStatus findPath(dtPolyRef startRef, dtPolyRef endRef, const float *startPos, const float *endPos, const float costLimit, const dtQueryFilter *filter, dtQueryResult &result, float *totalCost) const
dtStatus getPolyWallSegments(dtPolyRef ref, const dtQueryFilter *filter, float *segmentVerts, dtPolyRef *segmentRefs, int *segmentCount, const int maxSegments) const
dtStatus findNearestPoly(const float *center, const float *extents, const dtQueryFilter *filter, dtPolyRef *nearestRef, float *nearestPt, const float *referencePt=0) const
dtStatus findRandomPoint(const dtQueryFilter *filter, int randomSeed, dtPolyRef *randomRef, float *randomPt) const
const dtNavMesh * getAttachedNavMesh() const
Definition: DetourNavMeshQuery.h:707
dtStatus closestPointOnPoly(dtPolyRef ref, const float *pos, float *closest) const
dtStatus init(const dtNavMesh *nav, const int maxNodes, dtQuerySpecialLinkFilter *linkFilter=0)
dtStatus updateSlicedFindPath(const int maxIter, int *doneIters)
dtStatus findNearestContainingPoly(const float *center, const float *extents, const dtQueryFilter *filter, dtPolyRef *nearestRef, float *nearestPt) const
void getCurrentBestResult(struct dtNode *&bestNode, float &bestCost) const
Gets best node ref and cost from sliced pathfinding data.
Definition: DetourNavMeshQuery.h:710
dtStatus queryPolygons(const float *center, const float *extents, const dtQueryFilter *filter, dtPolyRef *polys, int *polyCount, const int maxPolys) const
dtStatus finalizeSlicedFindPathPartial(const dtPolyRef *existing, const int existingSize, dtPolyRef *path, int *pathCount, const int maxPath)
dtStatus findStraightPath(const float *startPos, const float *endPos, const dtPolyRef *path, const int pathSize, dtQueryResult &result, const int options=0) const
dtStatus findNearestPoly2D(const float *center, const float *extents, const dtQueryFilter *filter, dtPolyRef *outProjectedRef, float *outProjectedPt, const float *referencePt=0, float tolerance=0) const
dtStatus findLocalNeighbourhood(dtPolyRef startRef, const float *centerPos, const float radius, const dtQueryFilter *filter, dtPolyRef *resultRef, dtPolyRef *resultParent, int *resultCount, const int maxResult) const
dtStatus findPolysInPathDistance(dtPolyRef startRef, const float *centerPos, const float pathDistance, const dtQueryFilter *filter, dtPolyRef *resultRef, int *resultCount, const int maxResult) const
bool isInClosedList(dtPolyRef ref) const
dtStatus testClusterPath(dtPolyRef startRef, dtPolyRef endRef) const
dtStatus initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef, const float *startPos, const float *endPos, const float costLimit, const dtQueryFilter *filter)
void updateLinkFilter(dtQuerySpecialLinkFilter *linkFilter)
updates special link filter for this query
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
dtStatus findRandomPointInCluster(dtClusterRef clusterRef, int randomSeed, dtPolyRef *randomRef, float *randomPt) const
Definition: DetourNode.h:48
Definition: DetourNavMeshQuery.h:87
void copyFrom(const dtQueryFilter *other)
Copy data values from source filter.
Definition: DetourNavMeshQuery.h:273
float getInlineCost(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
inlined scoring function.
Definition: DetourNavMeshQuery.h:135
void setExcludeFlags(const unsigned short flags)
Definition: DetourNavMeshQuery.h:264
float getAreaFixedCost(const int i) const
Definition: DetourNavMeshQuery.h:205
void setHeuristicScale(const float newScale)
Set euclidean distance heuristic scale.
Definition: DetourNavMeshQuery.h:222
bool getShouldIgnoreClosedNodes() const
Definition: DetourNavMeshQuery.h:245
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.h:176
unsigned short getExcludeFlags() const
Definition: DetourNavMeshQuery.h:260
void setShouldIgnoreClosedNodes(const bool shouldIgnore)
Instruct filter whether it can reopen nodes already on closed list.
Definition: DetourNavMeshQuery.h:241
void setIncludeFlags(const unsigned short flags)
Definition: DetourNavMeshQuery.h:255
void setAreaFixedCost(const int i, const float cost)
Definition: DetourNavMeshQuery.h:210
unsigned short getIncludeFlags() const
Definition: DetourNavMeshQuery.h:251
bool passFilter(const dtPolyRef ref, const dtMeshTile *tile, const dtPoly *poly) const
Definition: DetourNavMeshQuery.h:125
float getHeuristicScale() const
Definition: DetourNavMeshQuery.h:219
bool equals(const dtQueryFilter *other) const
Check if two filters have the same data values.
Definition: DetourNavMeshQuery.h:269
bool passInlineFilter(const dtPolyRef ref, const dtMeshTile *tile, const dtPoly *poly) const
inlined filter implementation.
Definition: DetourNavMeshQuery.h:100
virtual bool passVirtualFilter(const dtPolyRef ref, const dtMeshTile *tile, const dtPoly *poly) const
virtual filter implementation (defaults to passInlineFilter).
Definition: DetourNavMeshQuery.h:113
bool isValidLinkSide(const unsigned char side) const
Definition: DetourNavMeshQuery.h:226
void setAreaCost(const int i, const float cost)
Definition: DetourNavMeshQuery.h:196
bool getIsBacktracking() const
Definition: DetourNavMeshQuery.h:238
float getAreaCost(const int i) const
Definition: DetourNavMeshQuery.h:191
void setIsBacktracking(const bool isBacktracking)
Sets up filter for backtracking.
Definition: DetourNavMeshQuery.h:234
virtual float getVirtualCost(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
virtual scoring function implementation (defaults to getInlineCost).
Definition: DetourNavMeshQuery.h:151
ATOMSUTILS_EXPORT dtNavMeshQuery * dtAllocNavMeshQuery()
ATOMSUTILS_EXPORT void dtFreeNavMeshQuery(dtNavMeshQuery *query)
Type_uint64 dtPolyRef
Definition: DetourNavMesh.h:47
AtomsCore namespace.
Definition: Base64.h:13
Type_uint64 dtClusterRef
A handle to a cluster within a navigation mesh tile.
Definition: DetourNavMesh.h:54
ATOMSUTILS_EXPORT float dtVdist(const float *v1, const float *v2)
Definition: DetourCommon.h:221
T dtMin(T a, T b)
Definition: DetourCommon.h:50
Definition: DetourNavMesh.h:374
dtMeshHeader * header
The tile header.
Definition: DetourNavMesh.h:378
dtOffMeshConnection * offMeshCons
The tile off-mesh connections. [Size: dtMeshHeader::offMeshConCount].
Definition: DetourNavMesh.h:394
Definition: DetourNode.h:37
unsigned int userId
The id of the offmesh connection. (User assigned when the navigation mesh is built....
Definition: DetourNavMesh.h:293
Definition: DetourNavMesh.h:178
unsigned short flags
The user defined polygon flags.
Definition: DetourNavMesh.h:190
unsigned char getArea() const
Gets the user defined area id.
Definition: DetourNavMesh.h:206
Definition: DetourNavMeshQuery.h:58
float m_areaFixedCost[DT_MAX_AREAS]
Fixed cost for entering an area type (Used by default implementation.)
Definition: DetourNavMeshQuery.h:61
float heuristicScale
Search heuristic scale.
Definition: DetourNavMeshQuery.h:63
unsigned short m_includeFlags
Flags for polygons that can be visited. (Used by default implementation.)
Definition: DetourNavMeshQuery.h:66
bool m_shouldIgnoreClosedNodes
Definition: DetourNavMeshQuery.h:75
unsigned short m_excludeFlags
Flags for polygons that should not be visited. (Used by default implementation.)
Definition: DetourNavMeshQuery.h:67
float m_areaCost[DT_MAX_AREAS]
Cost per area type. (Used by default implementation.)
Definition: DetourNavMeshQuery.h:59
Definition: DetourNavMeshQuery.h:290
Definition: DetourNavMeshQuery.h:279
Definition: DetourNavMeshQuery.h:45
virtual void initialize()
Called before accessing in A* loop (can be called multiple time for updateSlicedFindPath)
Definition: DetourNavMeshQuery.h:53
virtual bool isLinkAllowed(const int UserId) const
Definition: DetourNavMeshQuery.h:50