Recast Navigation
Navigation-mesh Toolset for Games
|
Provides the ability to perform pathfinding related queries against a navigation mesh. More...
#include <DetourNavMeshQuery.h>
Public Member Functions | |
dtNavMeshQuery () | |
~dtNavMeshQuery () | |
dtStatus | init (const dtNavMesh *nav, const int maxNodes) |
Initializes the query object. More... | |
Standard Pathfinding Functions | |
dtStatus | findPath (dtPolyRef startRef, dtPolyRef endRef, const float *startPos, const float *endPos, const dtQueryFilter *filter, dtPolyRef *path, int *pathCount, const int maxPath) const |
Finds a path from the start polygon to the end polygon. More... | |
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 |
Finds the straight path from the start to the end position within the polygon corridor. More... | |
Sliced Pathfinding Functions | |
Common use case:
| |
dtStatus | initSlicedFindPath (dtPolyRef startRef, dtPolyRef endRef, const float *startPos, const float *endPos, const dtQueryFilter *filter, const unsigned int options=0) |
Initializes a sliced path query. More... | |
dtStatus | updateSlicedFindPath (const int maxIter, int *doneIters) |
Updates an in-progress sliced path query. More... | |
dtStatus | finalizeSlicedFindPath (dtPolyRef *path, int *pathCount, const int maxPath) |
Finalizes and returns the results of a sliced path query. More... | |
dtStatus | finalizeSlicedFindPathPartial (const dtPolyRef *existing, const int existingSize, dtPolyRef *path, int *pathCount, const int maxPath) |
Finalizes and returns the results of an incomplete sliced path query, returning the path to the furthest polygon on the existing path that was visited during the search. More... | |
Dijkstra Search Functions | |
| |
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 |
Finds the polygons along the navigation graph that touch the specified circle. More... | |
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 |
Finds the polygons along the naviation graph that touch the specified convex polygon. More... | |
dtStatus | getPathFromDijkstraSearch (dtPolyRef endRef, dtPolyRef *path, int *pathCount, int maxPath) const |
Gets a path from the explored nodes in the previous search. More... | |
Local Query Functions | |
dtStatus | findNearestPoly (const float *center, const float *halfExtents, const dtQueryFilter *filter, dtPolyRef *nearestRef, float *nearestPt) const |
Finds the polygon nearest to the specified center point. More... | |
dtStatus | findNearestPoly (const float *center, const float *halfExtents, const dtQueryFilter *filter, dtPolyRef *nearestRef, float *nearestPt, bool *isOverPoly) const |
Finds the polygon nearest to the specified center point. More... | |
dtStatus | queryPolygons (const float *center, const float *halfExtents, const dtQueryFilter *filter, dtPolyRef *polys, int *polyCount, const int maxPolys) const |
Finds polygons that overlap the search box. More... | |
dtStatus | queryPolygons (const float *center, const float *halfExtents, const dtQueryFilter *filter, dtPolyQuery *query) const |
Finds polygons that overlap the search box. More... | |
dtStatus | findLocalNeighbourhood (dtPolyRef startRef, const float *centerPos, const float radius, const dtQueryFilter *filter, dtPolyRef *resultRef, dtPolyRef *resultParent, int *resultCount, const int maxResult) const |
Finds the non-overlapping navigation polygons in the local neighbourhood around the center position. More... | |
dtStatus | moveAlongSurface (dtPolyRef startRef, const float *startPos, const float *endPos, const dtQueryFilter *filter, float *resultPos, dtPolyRef *visited, int *visitedCount, const int maxVisitedSize) const |
Moves from the start to the end position constrained to the navigation mesh. More... | |
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 |
Casts a 'walkability' ray along the surface of the navigation mesh from the start position toward the end position. More... | |
dtStatus | raycast (dtPolyRef startRef, const float *startPos, const float *endPos, const dtQueryFilter *filter, const unsigned int options, dtRaycastHit *hit, dtPolyRef prevRef=0) const |
Casts a 'walkability' ray along the surface of the navigation mesh from the start position toward the end position. More... | |
dtStatus | findDistanceToWall (dtPolyRef startRef, const float *centerPos, const float maxRadius, const dtQueryFilter *filter, float *hitDist, float *hitPos, float *hitNormal) const |
Finds the distance from the specified position to the nearest polygon wall. More... | |
dtStatus | getPolyWallSegments (dtPolyRef ref, const dtQueryFilter *filter, float *segmentVerts, dtPolyRef *segmentRefs, int *segmentCount, const int maxSegments) const |
Returns the segments for the specified polygon, optionally including portals. More... | |
dtStatus | findRandomPoint (const dtQueryFilter *filter, float(*frand)(), dtPolyRef *randomRef, float *randomPt) const |
Returns random location on navmesh. More... | |
dtStatus | findRandomPointAroundCircle (dtPolyRef startRef, const float *centerPos, const float maxRadius, const dtQueryFilter *filter, float(*frand)(), dtPolyRef *randomRef, float *randomPt) const |
Returns random location on navmesh within the reach of specified location. More... | |
dtStatus | closestPointOnPoly (dtPolyRef ref, const float *pos, float *closest, bool *posOverPoly) const |
Finds the closest point on the specified polygon. More... | |
dtStatus | closestPointOnPolyBoundary (dtPolyRef ref, const float *pos, float *closest) const |
Returns a point on the boundary closest to the source point if the source point is outside the polygon's xz-bounds. More... | |
dtStatus | getPolyHeight (dtPolyRef ref, const float *pos, float *height) const |
Gets the height of the polygon at the provided position using the height detail. More... | |
Miscellaneous Functions | |
bool | isValidPolyRef (dtPolyRef ref, const dtQueryFilter *filter) const |
Returns true if the polygon reference is valid and passes the filter restrictions. More... | |
bool | isInClosedList (dtPolyRef ref) const |
Returns true if the polygon reference is in the closed list. More... | |
class dtNodePool * | getNodePool () const |
Gets the node pool. More... | |
const dtNavMesh * | getAttachedNavMesh () const |
Gets the navigation mesh the query object is using. More... | |
Provides the ability to perform pathfinding related queries against a navigation mesh.
For methods that support undersized buffers, if the buffer is too small to hold the entire result set the return status of the method will include the DT_BUFFER_TOO_SMALL flag.
Constant member functions can be used by multiple clients without side effects. (E.g. No change to the closed list. No impact on an in-progress sliced path query. Etc.)
Walls and portals: A wall is a polygon segment that is considered impassable. A portal is a passable segment between polygons. A portal may be treated as a wall based on the dtQueryFilter used for a query.
dtNavMeshQuery::dtNavMeshQuery | ( | ) |
dtNavMeshQuery::~dtNavMeshQuery | ( | ) |
dtStatus dtNavMeshQuery::closestPointOnPoly | ( | dtPolyRef | ref, |
const float * | pos, | ||
float * | closest, | ||
bool * | posOverPoly | ||
) | const |
Finds the closest point on the specified polygon.
[in] | ref | The reference id of the polygon. |
[in] | pos | The position to check. [(x, y, z)] |
[out] | closest | The closest point on the polygon. [(x, y, z)] |
[out] | posOverPoly | True of the position is over the polygon. |
Uses the detail polygons to find the surface height. (Most accurate.)
pos
does not have to be within the bounds of the polygon or navigation mesh.
See closestPointOnPolyBoundary() for a limited but faster option.
dtStatus dtNavMeshQuery::closestPointOnPolyBoundary | ( | dtPolyRef | ref, |
const float * | pos, | ||
float * | closest | ||
) | const |
Returns a point on the boundary closest to the source point if the source point is outside the polygon's xz-bounds.
[in] | ref | The reference id to the polygon. |
[in] | pos | The position to check. [(x, y, z)] |
[out] | closest | The closest point. [(x, y, z)] |
Much faster than closestPointOnPoly().
If the provided position lies within the polygon's xz-bounds (above or below), then pos
and closest
will be equal.
The height of closest
will be the polygon boundary. The height detail is not used.
pos
does not have to be within the bounds of the polybon or the navigation mesh.
dtStatus dtNavMeshQuery::finalizeSlicedFindPath | ( | dtPolyRef * | path, |
int * | pathCount, | ||
const int | maxPath | ||
) |
Finalizes and returns the results of a sliced path query.
[out] | path | An ordered list of polygon references representing the path. (Start to end.) [(polyRef) * pathCount ] |
[out] | pathCount | The number of polygons returned in the path array. |
[in] | maxPath | The max number of polygons the path array can hold. [Limit: >= 1] |
dtStatus dtNavMeshQuery::finalizeSlicedFindPathPartial | ( | const dtPolyRef * | existing, |
const int | existingSize, | ||
dtPolyRef * | path, | ||
int * | pathCount, | ||
const int | maxPath | ||
) |
Finalizes and returns the results of an incomplete sliced path query, returning the path to the furthest polygon on the existing path that was visited during the search.
[in] | existing | An array of polygon references for the existing path. |
[in] | existingSize | The number of polygon in the existing array. |
[out] | path | An ordered list of polygon references representing the path. (Start to end.) [(polyRef) * pathCount ] |
[out] | pathCount | The number of polygons returned in the path array. |
[in] | maxPath | The max number of polygons the path array can hold. [Limit: >= 1] |
dtStatus dtNavMeshQuery::findDistanceToWall | ( | dtPolyRef | startRef, |
const float * | centerPos, | ||
const float | maxRadius, | ||
const dtQueryFilter * | filter, | ||
float * | hitDist, | ||
float * | hitPos, | ||
float * | hitNormal | ||
) | const |
Finds the distance from the specified position to the nearest polygon wall.
[in] | startRef | The reference id of the polygon containing centerPos . |
[in] | centerPos | The center of the search circle. [(x, y, z)] |
[in] | maxRadius | The radius of the search circle. |
[in] | filter | The polygon filter to apply to the query. |
[out] | hitDist | The distance to the nearest wall from centerPos . |
[out] | hitPos | The nearest position on the wall that was hit. [(x, y, z)] |
[out] | hitNormal | The normalized ray formed from the wall point to the source point. [(x, y, z)] |
hitPos
is not adjusted using the height detail data.
hitDist
will equal the search radius if there is no wall within the radius. In this case the values of hitPos
and hitNormal
are undefined.
The normal will become unpredicable if hitDist
is a very small number.
dtStatus dtNavMeshQuery::findLocalNeighbourhood | ( | dtPolyRef | startRef, |
const float * | centerPos, | ||
const float | radius, | ||
const dtQueryFilter * | filter, | ||
dtPolyRef * | resultRef, | ||
dtPolyRef * | resultParent, | ||
int * | resultCount, | ||
const int | maxResult | ||
) | const |
Finds the non-overlapping navigation polygons in the local neighbourhood around the center position.
[in] | startRef | The reference id of the polygon where the search starts. |
[in] | centerPos | The center of the query circle. [(x, y, z)] |
[in] | radius | The radius of the query circle. |
[in] | filter | The polygon filter to apply to the query. |
[out] | resultRef | The reference ids of the polygons touched by the circle. |
[out] | resultParent | The reference ids of the parent polygons for each result. Zero if a result polygon has no parent. [opt] |
[out] | resultCount | The number of polygons found. |
[in] | maxResult | The maximum number of polygons the result arrays can hold. |
This method is optimized for a small search radius and small number of result polygons.
Candidate polygons are found by searching the navigation graph beginning at the start polygon.
The same intersection test restrictions that apply to the findPolysAroundCircle mehtod applies to this method.
The value of the center point is used as the start point for cost calculations. It is not projected onto the surface of the mesh, so its y-value will effect the costs.
Intersection tests occur in 2D. All polygons and the search circle are projected onto the xz-plane. So the y-value of the center point does not effect intersection tests.
If the result arrays are is too small to hold the entire result set, they will be filled to capacity.
dtStatus dtNavMeshQuery::findNearestPoly | ( | const float * | center, |
const float * | halfExtents, | ||
const dtQueryFilter * | filter, | ||
dtPolyRef * | nearestRef, | ||
float * | nearestPt | ||
) | const |
Finds the polygon nearest to the specified center point.
[opt] means the specified parameter can be a null pointer, in that case the output parameter will not be set.
[in] | center | The center of the search box. [(x, y, z)] |
[in] | halfExtents | The search distance along each axis. [(x, y, z)] |
[in] | filter | The polygon filter to apply to the query. |
[out] | nearestRef | The reference id of the nearest polygon. Will be set to 0 if no polygon is found. |
[out] | nearestPt | The nearest point on the polygon. Unchanged if no polygon is found. [opt] [(x, y, z)] |
nearestRef
will be zero. So if in doubt, check nearestRef
before using nearestPt
. dtStatus dtNavMeshQuery::findNearestPoly | ( | const float * | center, |
const float * | halfExtents, | ||
const dtQueryFilter * | filter, | ||
dtPolyRef * | nearestRef, | ||
float * | nearestPt, | ||
bool * | isOverPoly | ||
) | const |
Finds the polygon nearest to the specified center point.
[opt] means the specified parameter can be a null pointer, in that case the output parameter will not be set.
[in] | center | The center of the search box. [(x, y, z)] |
[in] | halfExtents | The search distance along each axis. [(x, y, z)] |
[in] | filter | The polygon filter to apply to the query. |
[out] | nearestRef | The reference id of the nearest polygon. Will be set to 0 if no polygon is found. |
[out] | nearestPt | The nearest point on the polygon. Unchanged if no polygon is found. [opt] [(x, y, z)] |
[out] | isOverPoly | Set to true if the point's X/Z coordinate lies inside the polygon, false otherwise. Unchanged if no polygon is found. [opt] |
dtStatus dtNavMeshQuery::findPath | ( | dtPolyRef | startRef, |
dtPolyRef | endRef, | ||
const float * | startPos, | ||
const float * | endPos, | ||
const dtQueryFilter * | filter, | ||
dtPolyRef * | path, | ||
int * | pathCount, | ||
const int | maxPath | ||
) | const |
Finds a path from the start polygon to the end polygon.
[in] | startRef | The reference id of the start polygon. |
[in] | endRef | The reference id of the end polygon. |
[in] | startPos | A position within the start polygon. [(x, y, z)] |
[in] | endPos | A position within the end polygon. [(x, y, z)] |
[in] | filter | The polygon filter to apply to the query. |
[out] | path | An ordered list of polygon references representing the path. (Start to end.) [(polyRef) * pathCount ] |
[out] | pathCount | The number of polygons returned in the path array. |
[in] | maxPath | The maximum number of polygons the path array can hold. [Limit: >= 1] |
If the end polygon cannot be reached through the navigation graph, the last polygon in the path will be the nearest the end polygon.
If the path array is to small to hold the full result, it will be filled as far as possible from the start polygon toward the end polygon.
The start and end positions are used to calculate traversal costs. (The y-values impact the result.)
dtStatus dtNavMeshQuery::findPolysAroundCircle | ( | dtPolyRef | startRef, |
const float * | centerPos, | ||
const float | radius, | ||
const dtQueryFilter * | filter, | ||
dtPolyRef * | resultRef, | ||
dtPolyRef * | resultParent, | ||
float * | resultCost, | ||
int * | resultCount, | ||
const int | maxResult | ||
) | const |
Finds the polygons along the navigation graph that touch the specified circle.
[in] | startRef | The reference id of the polygon where the search starts. |
[in] | centerPos | The center of the search circle. [(x, y, z)] |
[in] | radius | The radius of the search circle. |
[in] | filter | The polygon filter to apply to the query. |
[out] | resultRef | The reference ids of the polygons touched by the circle. [opt] |
[out] | resultParent | The reference ids of the parent polygons for each result. Zero if a result polygon has no parent. [opt] |
[out] | resultCost | The search cost from centerPos to the polygon. [opt] |
[out] | resultCount | The number of polygons found. [opt] |
[in] | maxResult | The maximum number of polygons the result arrays can hold. |
At least one result array must be provided.
The order of the result set is from least to highest cost to reach the polygon.
A common use case for this method is to perform Dijkstra searches. Candidate polygons are found by searching the graph beginning at the start polygon.
If a polygon is not found via the graph search, even if it intersects the search circle, it will not be included in the result set. For example:
polyA is the start polygon. polyB shares an edge with polyA. (Is adjacent.) polyC shares an edge with polyB, but not with polyA Even if the search circle overlaps polyC, it will not be included in the result set unless polyB is also in the set.
The value of the center point is used as the start position for cost calculations. It is not projected onto the surface of the mesh, so its y-value will effect the costs.
Intersection tests occur in 2D. All polygons and the search circle are projected onto the xz-plane. So the y-value of the center point does not effect intersection tests.
If the result arrays are to small to hold the entire result set, they will be filled to capacity.
dtStatus dtNavMeshQuery::findPolysAroundShape | ( | dtPolyRef | startRef, |
const float * | verts, | ||
const int | nverts, | ||
const dtQueryFilter * | filter, | ||
dtPolyRef * | resultRef, | ||
dtPolyRef * | resultParent, | ||
float * | resultCost, | ||
int * | resultCount, | ||
const int | maxResult | ||
) | const |
Finds the polygons along the naviation graph that touch the specified convex polygon.
[in] | startRef | The reference id of the polygon where the search starts. |
[in] | verts | The vertices describing the convex polygon. (CCW) [(x, y, z) * nverts ] |
[in] | nverts | The number of vertices in the polygon. |
[in] | filter | The polygon filter to apply to the query. |
[out] | resultRef | The reference ids of the polygons touched by the search polygon. [opt] |
[out] | resultParent | The reference ids of the parent polygons for each result. Zero if a result polygon has no parent. [opt] |
[out] | resultCost | The search cost from the centroid point to the polygon. [opt] |
[out] | resultCount | The number of polygons found. |
[in] | maxResult | The maximum number of polygons the result arrays can hold. |
The order of the result set is from least to highest cost.
At least one result array must be provided.
A common use case for this method is to perform Dijkstra searches. Candidate polygons are found by searching the graph beginning at the start polygon.
The same intersection test restrictions that apply to findPolysAroundCircle() method apply to this method.
The 3D centroid of the search polygon is used as the start position for cost calculations.
Intersection tests occur in 2D. All polygons are projected onto the xz-plane. So the y-values of the vertices do not effect intersection tests.
If the result arrays are is too small to hold the entire result set, they will be filled to capacity.
dtStatus dtNavMeshQuery::findRandomPoint | ( | const dtQueryFilter * | filter, |
float(*)() | frand, | ||
dtPolyRef * | randomRef, | ||
float * | randomPt | ||
) | const |
Returns random location on navmesh.
Polygons are chosen weighted by area. The search runs in linear related to number of polygon.
[in] | filter | The polygon filter to apply to the query. |
[in] | frand | Function returning a random number [0..1). |
[out] | randomRef | The reference id of the random location. |
[out] | randomPt | The random location. |
dtStatus dtNavMeshQuery::findRandomPointAroundCircle | ( | dtPolyRef | startRef, |
const float * | centerPos, | ||
const float | maxRadius, | ||
const dtQueryFilter * | filter, | ||
float(*)() | frand, | ||
dtPolyRef * | randomRef, | ||
float * | randomPt | ||
) | const |
Returns random location on navmesh within the reach of specified location.
Polygons are chosen weighted by area. The search runs in linear related to number of polygon. The location is not exactly constrained by the circle, but it limits the visited polygons.
[in] | startRef | The reference id of the polygon where the search starts. |
[in] | centerPos | The center of the search circle. [(x, y, z)] |
[in] | maxRadius | The radius of the search circle. [Units: wu] |
[in] | filter | The polygon filter to apply to the query. |
[in] | frand | Function returning a random number [0..1). |
[out] | randomRef | The reference id of the random location. |
[out] | randomPt | The random location. [(x, y, z)] |
dtStatus dtNavMeshQuery::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 |
Finds the straight path from the start to the end position within the polygon corridor.
[in] | startPos | Path start position. [(x, y, z)] |
[in] | endPos | Path end position. [(x, y, z)] |
[in] | path | An array of polygon references that represent the path corridor. |
[in] | pathSize | The number of polygons in the path array. |
[out] | straightPath | Points describing the straight path. [(x, y, z) * straightPathCount ]. |
[out] | straightPathFlags | Flags describing each point. (See: dtStraightPathFlags) [opt] |
[out] | straightPathRefs | The reference id of the polygon that is being entered at each point. [opt] |
[out] | straightPathCount | The number of points in the straight path. |
[in] | maxStraightPath | The maximum number of points the straight path arrays can hold. [Limit: > 0] |
[in] | options | Query options. (see: dtStraightPathOptions) |
This method peforms what is often called 'string pulling'.
The start position is clamped to the first polygon in the path, and the end position is clamped to the last. So the start and end positions should normally be within or very near the first and last polygons respectively.
The returned polygon references represent the reference id of the polygon that is entered at the associated path position. The reference id associated with the end point will always be zero. This allows, for example, matching off-mesh link points to their representative polygons.
If the provided result buffers are too small for the entire result set, they will be filled as far as possible from the start toward the end position.
|
inline |
Gets the navigation mesh the query object is using.
|
inline |
Gets the node pool.
dtStatus dtNavMeshQuery::getPathFromDijkstraSearch | ( | dtPolyRef | endRef, |
dtPolyRef * | path, | ||
int * | pathCount, | ||
int | maxPath | ||
) | const |
Gets a path from the explored nodes in the previous search.
[in] | endRef | The reference id of the end polygon. |
[out] | path | An ordered list of polygon references representing the path. (Start to end.) [(polyRef) * pathCount ] |
[out] | pathCount | The number of polygons returned in the path array. |
[in] | maxPath | The maximum number of polygons the path array can hold. [Limit: >= 0] |
endRef
was not explored in the previous search. Returns DT_SUCCESS | DT_BUFFER_TOO_SMALL if path
cannot contain the entire path. In this case it is filled to capacity with a partial path. Otherwise returns DT_SUCCESS. Gets the height of the polygon at the provided position using the height detail.
(Most accurate.)
[in] | ref | The reference id of the polygon. |
[in] | pos | A position within the xz-bounds of the polygon. [(x, y, z)] |
[out] | height | The height at the surface of the polygon. |
Will return DT_FAILURE | DT_INVALID_PARAM if the provided position is outside the xz-bounds of the polygon.
dtStatus dtNavMeshQuery::getPolyWallSegments | ( | dtPolyRef | ref, |
const dtQueryFilter * | filter, | ||
float * | segmentVerts, | ||
dtPolyRef * | segmentRefs, | ||
int * | segmentCount, | ||
const int | maxSegments | ||
) | const |
Returns the segments for the specified polygon, optionally including portals.
[in] | ref | The reference id of the polygon. |
[in] | filter | The polygon filter to apply to the query. |
[out] | segmentVerts | The segments. [(ax, ay, az, bx, by, bz) * segmentCount] |
[out] | segmentRefs | The reference ids of each segment's neighbor polygon. Or zero if the segment is a wall. [opt] [(parentRef) * segmentCount ] |
[out] | segmentCount | The number of segments returned. |
[in] | maxSegments | The maximum number of segments the result arrays can hold. |
If the segmentRefs
parameter is provided, then all polygon segments will be returned. Otherwise only the wall segments are returned.
A segment that is normally a portal will be included in the result set as a wall if the filter
results in the neighbor polygon becoomming impassable.
The segmentVerts
and segmentRefs
buffers should normally be sized for the maximum segments per polygon of the source navigation mesh.
Initializes the query object.
[in] | nav | Pointer to the dtNavMesh object to use for all queries. |
[in] | maxNodes | Maximum number of search nodes. [Limits: 0 < value <= 65535] |
Must be the first function called after construction, before other functions are used.
This function can be used multiple times.
dtStatus dtNavMeshQuery::initSlicedFindPath | ( | dtPolyRef | startRef, |
dtPolyRef | endRef, | ||
const float * | startPos, | ||
const float * | endPos, | ||
const dtQueryFilter * | filter, | ||
const unsigned int | options = 0 |
||
) |
Initializes a sliced path query.
[in] | startRef | The reference id of the start polygon. |
[in] | endRef | The reference id of the end polygon. |
[in] | startPos | A position within the start polygon. [(x, y, z)] |
[in] | endPos | A position within the end polygon. [(x, y, z)] |
[in] | filter | The polygon filter to apply to the query. |
[in] | options | query options (see: dtFindPathOptions) |
The filter
pointer is stored and used for the duration of the sliced path query.
bool dtNavMeshQuery::isInClosedList | ( | dtPolyRef | ref | ) | const |
Returns true if the polygon reference is in the closed list.
[in] | ref | The reference id of the polygon to check. |
The closed list is the list of polygons that were fully evaluated during the last navigation graph search. (A* or Dijkstra)
bool dtNavMeshQuery::isValidPolyRef | ( | dtPolyRef | ref, |
const dtQueryFilter * | filter | ||
) | const |
Returns true if the polygon reference is valid and passes the filter restrictions.
[in] | ref | The polygon reference to check. |
[in] | filter | The filter to apply. |
dtStatus dtNavMeshQuery::moveAlongSurface | ( | dtPolyRef | startRef, |
const float * | startPos, | ||
const float * | endPos, | ||
const dtQueryFilter * | filter, | ||
float * | resultPos, | ||
dtPolyRef * | visited, | ||
int * | visitedCount, | ||
const int | maxVisitedSize | ||
) | const |
Moves from the start to the end position constrained to the navigation mesh.
[in] | startRef | The reference id of the start polygon. |
[in] | startPos | A position of the mover within the start polygon. [(x, y, x)] |
[in] | endPos | The desired end position of the mover. [(x, y, z)] |
[in] | filter | The polygon filter to apply to the query. |
[out] | resultPos | The result position of the mover. [(x, y, z)] |
[out] | visited | The reference ids of the polygons visited during the move. |
[out] | visitedCount | The number of polygons visited during the move. |
[in] | maxVisitedSize | The maximum number of polygons the visited array can hold. |
This method is optimized for small delta movement and a small number of polygons. If used for too great a distance, the result set will form an incomplete path.
resultPos
will equal the endPos
if the end is reached. Otherwise the closest reachable position will be returned.
resultPos
is not projected onto the surface of the navigation mesh. Use getPolyHeight if this is needed.
This method treats the end position in the same manner as the raycast method. (As a 2D point.) See that method's documentation for details.
If the visited
array is too small to hold the entire result set, it will be filled as far as possible from the start position toward the end position.
dtStatus dtNavMeshQuery::queryPolygons | ( | const float * | center, |
const float * | halfExtents, | ||
const dtQueryFilter * | filter, | ||
dtPolyQuery * | query | ||
) | const |
Finds polygons that overlap the search box.
[in] | center | The center of the search box. [(x, y, z)] |
[in] | halfExtents | The search distance along each axis. [(x, y, z)] |
[in] | filter | The polygon filter to apply to the query. |
[in] | query | The query. Polygons found will be batched together and passed to this query. |
The query will be invoked with batches of polygons. Polygons passed to the query have bounding boxes that overlap with the center and halfExtents passed to this function. The dtPolyQuery::process function is invoked multiple times until all overlapping polygons have been processed.
dtStatus dtNavMeshQuery::queryPolygons | ( | const float * | center, |
const float * | halfExtents, | ||
const dtQueryFilter * | filter, | ||
dtPolyRef * | polys, | ||
int * | polyCount, | ||
const int | maxPolys | ||
) | const |
Finds polygons that overlap the search box.
[in] | center | The center of the search box. [(x, y, z)] |
[in] | halfExtents | The search distance along each axis. [(x, y, z)] |
[in] | filter | The polygon filter to apply to the query. |
[out] | polys | The reference ids of the polygons that overlap the query box. |
[out] | polyCount | The number of polygons in the search result. |
[in] | maxPolys | The maximum number of polygons the search result can hold. |
If no polygons are found, the function will return DT_SUCCESS with a polyCount
of zero.
If polys
is too small to hold the entire result set, then the array will be filled to capacity. The method of choosing which polygons from the full set are included in the partial result set is undefined.
dtStatus dtNavMeshQuery::raycast | ( | dtPolyRef | startRef, |
const float * | startPos, | ||
const float * | endPos, | ||
const dtQueryFilter * | filter, | ||
const unsigned int | options, | ||
dtRaycastHit * | hit, | ||
dtPolyRef | prevRef = 0 |
||
) | const |
Casts a 'walkability' ray along the surface of the navigation mesh from the start position toward the end position.
[in] | startRef | The reference id of the start polygon. |
[in] | startPos | A position within the start polygon representing the start of the ray. [(x, y, z)] |
[in] | endPos | The position to cast the ray toward. [(x, y, z)] |
[in] | filter | The polygon filter to apply to the query. |
[in] | options | govern how the raycast behaves. See dtRaycastOptions |
[out] | hit | Pointer to a raycast hit structure which will be filled by the results. |
[in] | prevRef | parent of start ref. Used during for cost calculation [opt] |
This method is meant to be used for quick, short distance checks.
If the path array is too small to hold the result, it will be filled as far as possible from the start postion toward the end position.
Using the Hit Parameter t of RaycastHit
If the hit parameter is a very high value (FLT_MAX), then the ray has hit the end position. In this case the path represents a valid corridor to the end position and the value of hitNormal
is undefined.
If the hit parameter is zero, then the start position is on the wall that was hit and the value of hitNormal
is undefined.
If 0 < t < 1.0 then the following applies:
Use Case Restriction
The raycast ignores the y-value of the end position. (2D check.) This places significant limits on how it can be used. For example:
Consider a scene where there is a main floor with a second floor balcony that hangs over the main floor. So the first floor mesh extends below the balcony mesh. The start position is somewhere on the first floor. The end position is on the balcony.
The raycast will search toward the end position along the first floor mesh. If it reaches the end position's xz-coordinates it will indicate FLT_MAX (no wall hit), meaning it reached the end position. This is one example of why this method is meant for short distance checks.
dtStatus dtNavMeshQuery::raycast | ( | dtPolyRef | startRef, |
const float * | startPos, | ||
const float * | endPos, | ||
const dtQueryFilter * | filter, | ||
float * | t, | ||
float * | hitNormal, | ||
dtPolyRef * | path, | ||
int * | pathCount, | ||
const int | maxPath | ||
) | const |
Casts a 'walkability' ray along the surface of the navigation mesh from the start position toward the end position.
[in] | startRef | The reference id of the start polygon. |
[in] | startPos | A position within the start polygon representing the start of the ray. [(x, y, z)] |
[in] | endPos | The position to cast the ray toward. [(x, y, z)] |
[in] | filter | The polygon filter to apply to the query. |
[out] | t | The hit parameter. (FLT_MAX if no wall hit.) |
[out] | hitNormal | The normal of the nearest wall hit. [(x, y, z)] |
[out] | path | The reference ids of the visited polygons. [opt] |
[out] | pathCount | The number of visited polygons. [opt] |
[in] | maxPath | The maximum number of polygons the path array can hold. |
This method is meant to be used for quick, short distance checks.
If the path array is too small to hold the result, it will be filled as far as possible from the start postion toward the end position.
Using the Hit Parameter (t)
If the hit parameter is a very high value (FLT_MAX), then the ray has hit the end position. In this case the path represents a valid corridor to the end position and the value of hitNormal
is undefined.
If the hit parameter is zero, then the start position is on the wall that was hit and the value of hitNormal
is undefined.
If 0 < t < 1.0 then the following applies:
Use Case Restriction
The raycast ignores the y-value of the end position. (2D check.) This places significant limits on how it can be used. For example:
Consider a scene where there is a main floor with a second floor balcony that hangs over the main floor. So the first floor mesh extends below the balcony mesh. The start position is somewhere on the first floor. The end position is on the balcony.
The raycast will search toward the end position along the first floor mesh. If it reaches the end position's xz-coordinates it will indicate FLT_MAX (no wall hit), meaning it reached the end position. This is one example of why this method is meant for short distance checks.
dtStatus dtNavMeshQuery::updateSlicedFindPath | ( | const int | maxIter, |
int * | doneIters | ||
) |
Updates an in-progress sliced path query.
[in] | maxIter | The maximum number of iterations to perform. |
[out] | doneIters | The actual number of iterations completed. [opt] |