Missing DetourNavMeshQuery files, plus sliced findPath.

This commit is contained in:
Mikko Mononen 2010-08-17 17:46:19 +00:00
parent cbc47f4ddf
commit 785e9c68be
7 changed files with 4630 additions and 149 deletions

View File

@ -0,0 +1,339 @@
//
// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef DETOURNAVMESHQUERY_H
#define DETOURNAVMESHQUERY_H
#include "DetourAlloc.h"
#include "DetourNavMesh.h"
struct dtQueryFilter
{
dtQueryFilter() : includeFlags(0xffff), excludeFlags(0) {}
unsigned short includeFlags; // If any of the flags are set, the poly is included.
unsigned short excludeFlags; // If any of the flags are set, the poly is excluded.
};
enum dtQueryState
{
DT_QUERY_FAILED = 0, // Path find failed.
DT_QUERY_RUNNING, // Path find running.
DT_QUERY_READY, // Path find results ready.
};
class dtNavMeshQuery
{
public:
dtNavMeshQuery();
~dtNavMeshQuery();
// Initializes the nav mesh query.
// Params:
// nav - (in) pointer to navigation mesh data.
// maxNodes - (in) Maximum number of search nodes to use (max 65536).
// Returns: True if succeed, else false.
bool init(dtNavMesh* nav, const int maxNodes);
// Sets the pathfinding cost of the specified area.
// Params:
// area - (in) area ID (0-63).
// cost - (int) travel cost of the area.
void setAreaCost(const int area, float cost);
// Returns the pathfinding cost of the specified area.
// Params:
// area - (in) area ID (0-63).
float getAreaCost(const int area) const;
// Finds the nearest navigation polygon around the center location.
// Params:
// center[3] - (in) The center of the search box.
// extents[3] - (in) The extents of the search box.
// filter - (in) path polygon filter.
// nearestPt[3] - (out, opt) The nearest point on found polygon, null if not needed.
// Returns: Reference identifier for the polygon, or 0 if no polygons found.
dtPolyRef findNearestPoly(const float* center, const float* extents,
const dtQueryFilter* filter, float* nearestPt) const;
// Returns polygons which overlap the query box.
// Params:
// center[3] - (in) the center of the search box.
// extents[3] - (in) the extents of the search box.
// filter - (in) path polygon filter.
// polys - (out) array holding the search result.
// maxPolys - (in) The max number of polygons the polys array can hold.
// Returns: Number of polygons in search result array.
int queryPolygons(const float* center, const float* extents, const dtQueryFilter* filter,
dtPolyRef* polys, const int maxPolys) const;
// Finds path from start polygon to end polygon.
// If target polygon canno be reached through the navigation graph,
// the last node on the array is nearest node to the end polygon.
// Start end end positions are needed to calculate more accurate
// traversal cost at start end end polygons.
// Params:
// startRef - (in) ref to path start polygon.
// endRef - (in) ref to path end polygon.
// startPos[3] - (in) Path start location.
// endPos[3] - (in) Path end location.
// filter - (in) path polygon filter.
// path - (out) array holding the search result.
// maxPathSize - (in) The max number of polygons the path array can hold.
// Returns: Number of polygons in search result array.
int findPath(dtPolyRef startRef, dtPolyRef endRef,
const float* startPos, const float* endPos,
const dtQueryFilter* filter,
dtPolyRef* path, const int maxPathSize) const;
// Intializes sliced path find query.
// Note: calling any other dtNavMeshQuery method before calling findPathEnd()
// may results in corrupted data!
// Params:
// startRef - (in) ref to path start polygon.
// endRef - (in) ref to path end polygon.
// startPos[3] - (in) Path start location.
// endPos[3] - (in) Path end location.
// filter - (in) path polygon filter.
// Returns: Path query state.
dtQueryState initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef,
const float* startPos, const float* endPos,
const dtQueryFilter* filter);
// Updates sliced path find query.
// Params:
// maxIter - (in) max number of iterations to update.
// Returns: Path query state.
dtQueryState updateSlicedFindPath(const int maxIter);
// Finalizes sliced path find query.
// path - (out) array holding the search result.
// maxPathSize - (in) The max number of polygons the path array can hold.
// Returns: Number of polygons in search result array.
int finalizeSlicedFindPath(dtPolyRef* path, const int maxPathSize);
// Finds a straight path from start to end locations within the corridor
// described by the path polygons.
// Start and end locations will be clamped on the corridor.
// The returned polygon references are point to polygon which was entered when
// a path point was added. For the end point, zero will be returned. This allows
// to match for example off-mesh link points to their representative polygons.
// Params:
// startPos[3] - (in) Path start location.
// endPo[3] - (in) Path end location.
// path - (in) Array of connected polygons describing the corridor.
// pathSize - (in) Number of polygons in path array.
// straightPath - (out) Points describing the straight path.
// straightPathFlags - (out, opt) Flags describing each point type, see dtStraightPathFlags.
// straightPathRefs - (out, opt) References to polygons at point locations.
// maxStraightPathSize - (in) The max number of points the straight path array can hold.
// Returns: Number of points in the path.
int findStraightPath(const float* startPos, const float* endPos,
const dtPolyRef* path, const int pathSize,
float* straightPath, unsigned char* straightPathFlags, dtPolyRef* straightPathRefs,
const int maxStraightPathSize) const;
// Moves from startPos to endPos constrained to the navmesh.
// If the endPos is reachable, the resultPos will be endPos,
// or else the resultPos will be the nearest point in navmesh.
// Note: The resulting point is not projected to the ground, use getPolyHeight() to get height.
// Note: The algorithm is optimized for small delta movement and small number of polygons.
// Params:
// startRef - (in) ref to the polygon where startPos lies.
// startPos[3] - (in) start position of the mover.
// endPos[3] - (in) desired end position of the mover.
// filter - (in) path polygon filter.
// resultPos[3] - (out) new position of the mover.
// visited - (out) array of visited polygons.
// maxVisitedSize - (in) max number of polygons in the visited array.
// Returns: Number of entries in the visited array.
int moveAlongSurface(dtPolyRef startRef, const float* startPos, const float* endPos,
const dtQueryFilter* filter,
float* resultPos, dtPolyRef* visited, const int maxVisitedSize) const;
// Casts 'walkability' ray along the navmesh surface from startPos towards the endPos.
// Params:
// startRef - (in) ref to the polygon where the start lies.
// startPos[3] - (in) start position of the query.
// endPos[3] - (in) end position of the query.
// t - (out) hit parameter along the segment, FLT_MAX if no hit.
// hitNormal[3] - (out) normal of the nearest hit.
// filter - (in) path polygon filter.
// path - (out) visited path polygons.
// pathSize - (in) max number of polygons in the path array.
// Returns: Number of polygons visited or 0 if failed.
int raycast(dtPolyRef startRef, const float* startPos, const float* endPos, const dtQueryFilter* filter,
float& t, float* hitNormal, dtPolyRef* path, const int pathSize) const;
// Returns distance to nearest wall from the specified location.
// Params:
// centerRef - (in) ref to the polygon where the center lies.
// centerPos[3] - (in) center if the query circle.
// maxRadius - (in) max search radius.
// filter - (in) path polygon filter.
// hitPos[3] - (out) location of the nearest hit.
// hitNormal[3] - (out) normal of the nearest hit.
// Returns: Distance to nearest wall from the test location.
float findDistanceToWall(dtPolyRef centerRef, const float* centerPos, float maxRadius,
const dtQueryFilter* filter, float* hitPos, float* hitNormal) const;
// Finds polygons found along the navigation graph which touch the specified circle.
// Params:
// startRef - (in) ref to the polygon where the search starts.
// centerPos[3] - (in) center if the query circle.
// radius - (in) radius of the query circle.
// filter - (in) path polygon filter.
// resultRef - (out, opt) refs to the polygons touched by the circle.
// resultParent - (out, opt) parent of each result polygon.
// resultCost - (out, opt) search cost at each result polygon.
// maxResult - (int) maximum capacity of search results.
// Returns: Number of results.
int findPolysAroundCircle(dtPolyRef startRef, const float* centerPos, const float radius,
const dtQueryFilter* filter,
dtPolyRef* resultRef, dtPolyRef* resultParent, float* resultCost,
const int maxResult) const;
// Finds polygons found along the navigation graph which touch the convex polygon shape.
// Params:
// startRef - (in) ref to the polygon where the search starts.
// verts[3*n] - (in) vertices describing convex polygon shape (CCW).
// nverts - (in) number of vertices in the polygon.
// filter - (in) path polygon filter.
// resultRef - (out, opt) refs to the polygons touched by the circle.
// resultParent - (out, opt) parent of each result polygon.
// resultCost - (out, opt) search cost at each result polygon.
// maxResult - (int) maximum capacity of search results.
// Returns: Number of results.
int findPolysAroundShape(dtPolyRef startRef, const float* verts, const int nverts,
const dtQueryFilter* filter,
dtPolyRef* resultRef, dtPolyRef* resultParent, float* resultCost,
const int maxResult) const;
// Finds non-overlapping local neighbourhood around center location.
// Note: The algorithm is optimized for small query radius and small number of polygons.
// Params:
// startRef - (in) ref to the polygon where the search starts.
// centerPos[3] - (in) center if the query circle.
// radius - (in) radius of the query circle.
// filter - (in) path polygon filter.
// resultRef - (out) refs to the polygons touched by the circle.
// resultParent - (out, opt) parent of each result polygon.
// maxResult - (int) maximum capacity of search results.
// Returns: Number of results.
int findLocalNeighbourhood(dtPolyRef startRef, const float* centerPos, const float radius,
const dtQueryFilter* filter,
dtPolyRef* resultRef, dtPolyRef* resultParent, const int maxResult) const;
// Returns wall segments of specified polygon.
// Params:
// ref - (in) ref to the polygon.
// filter - (in) path polygon filter.
// segments[DT_VERTS_PER_POLYGON*3*2] - (out) wall segments.
// Returns: Number of wall segments.
int getPolyWallSegments(dtPolyRef ref, const dtQueryFilter* filter, float* segments);
// Returns closest point on navigation polygon.
// Uses detail polygons to find the closest point to the navigation polygon surface.
// Params:
// ref - (in) ref to the polygon.
// pos[3] - (in) the point to check.
// closest[3] - (out) closest point.
// Returns: true if closest point found.
bool closestPointOnPoly(dtPolyRef ref, const float* pos, float* closest) const;
// Returns closest point on navigation polygon boundary.
// Uses the navigation polygon boundary to snap the point to poly boundary
// if it is outside the polygon. Much faster than closestPointToPoly. Does not affect height.
// Params:
// ref - (in) ref to the polygon.
// pos[3] - (in) the point to check.
// closest[3] - (out) closest point.
// Returns: true if closest point found.
bool closestPointOnPolyBoundary(dtPolyRef ref, const float* pos, float* closest) const;
// Returns start and end location of an off-mesh link polygon.
// Params:
// prevRef - (in) ref to the polygon before the link (used to select direction).
// polyRef - (in) ref to the off-mesh link polygon.
// startPos[3] - (out) start point of the link.
// endPos[3] - (out) end point of the link.
// Returns: true if link is found.
bool getOffMeshConnectionPolyEndPoints(dtPolyRef prevRef, dtPolyRef polyRef, float* startPos, float* endPos) const;
// Returns height of the polygon at specified location.
// Params:
// ref - (in) ref to the polygon.
// pos[3] - (in) the point where to locate the height.
// height - (out) height at the location.
// Returns: true if over polygon.
bool getPolyHeight(dtPolyRef ref, const float* pos, float* height) const;
// Returns true if poly reference ins in closed list.
bool isInClosedList(dtPolyRef ref) const;
private:
// Returns neighbour tile based on side.
dtMeshTile* getNeighbourTileAt(int x, int y, int side) const;
// Queries polygons within a tile.
int queryPolygonsInTile(const dtMeshTile* tile, const float* qmin, const float* qmax, const dtQueryFilter* filter,
dtPolyRef* polys, const int maxPolys) const;
// Find nearest polygon within a tile.
dtPolyRef findNearestPolyInTile(const dtMeshTile* tile, const float* center, const float* extents,
const dtQueryFilter* filter, float* nearestPt) const;
// Returns closest point on polygon.
bool closestPointOnPolyInTile(const dtMeshTile* tile, const dtPoly* poly, const float* pos, float* closest) const;
// Returns portal points between two polygons.
bool getPortalPoints(dtPolyRef from, dtPolyRef to, float* left, float* right,
unsigned char& fromType, unsigned char& toType) const;
bool getPortalPoints(dtPolyRef from, const dtPoly* fromPoly, const dtMeshTile* fromTile,
dtPolyRef to, const dtPoly* toPoly, const dtMeshTile* toTile,
float* left, float* right) const;
// Returns edge mid point between two polygons.
bool getEdgeMidPoint(dtPolyRef from, dtPolyRef to, float* mid) const;
bool getEdgeMidPoint(dtPolyRef from, const dtPoly* fromPoly, const dtMeshTile* fromTile,
dtPolyRef to, const dtPoly* toPoly, const dtMeshTile* toTile,
float* mid) const;
dtNavMesh* m_nav; // Pointer to navmesh data.
struct dtQueryData
{
dtQueryState state;
struct dtNode* lastBestNode;
float lastBestNodeCost;
dtPolyRef startRef, endRef;
float startPos[3], endPos[3];
dtQueryFilter filter;
};
dtQueryData m_query; // Sliced query state.
float m_areaCost[DT_MAX_AREAS]; // Cost per area.
class dtNodePool* m_tinyNodePool; // Pointer to small node pool.
class dtNodePool* m_nodePool; // Pointer to node pool.
class dtNodeQueue* m_openList; // Pointer to open list queue.
};
// Helper function to allocate navmesh query class using Detour allocator.
dtNavMeshQuery* dtAllocNavMeshQuery();
void dtFreeNavMeshQuery(dtNavMeshQuery* query);
#endif // DETOURNAVMESHQUERY_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -290,7 +290,7 @@
</array>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
<string>{{0, 8}, {264, 660}}</string>
<string>{{0, 107}, {264, 660}}</string>
</dict>
<key>PBXTopSmartGroupGIDs</key>
<array/>
@ -337,7 +337,7 @@
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>6BAF428A121ADD46008CFCDF</string>
<string>6BAF434F121B00EF008CFCDF</string>
<key>history</key>
<array>
<string>6BBB4AA5115B4F3400CF791D</string>
@ -387,7 +387,6 @@
<string>6BAF40F212197F3D008CFCDF</string>
<string>6BAF40F312197F3D008CFCDF</string>
<string>6BAF40F412197F3D008CFCDF</string>
<string>6BAF416F1219811E008CFCDF</string>
<string>6BAF41701219811E008CFCDF</string>
<string>6BAF419E12198419008CFCDF</string>
<string>6BAF419F12198419008CFCDF</string>
@ -398,26 +397,26 @@
<string>6BAF41A612198419008CFCDF</string>
<string>6BAF41A812198419008CFCDF</string>
<string>6BAF41A912198419008CFCDF</string>
<string>6BAF41AA12198419008CFCDF</string>
<string>6BAF41AB12198419008CFCDF</string>
<string>6BAF41D0121A5AEE008CFCDF</string>
<string>6BAF41E3121ACD06008CFCDF</string>
<string>6BAF421F121ACE5E008CFCDF</string>
<string>6BAF4250121AD7D7008CFCDF</string>
<string>6BAF4251121AD7D7008CFCDF</string>
<string>6BAF4264121AD99B008CFCDF</string>
<string>6BAF4267121AD99B008CFCDF</string>
<string>6BAF4269121AD99B008CFCDF</string>
<string>6BAF427D121ADD46008CFCDF</string>
<string>6BAF427E121ADD46008CFCDF</string>
<string>6BAF427F121ADD46008CFCDF</string>
<string>6BAF4280121ADD46008CFCDF</string>
<string>6BAF4281121ADD46008CFCDF</string>
<string>6BAF4282121ADD46008CFCDF</string>
<string>6BAF42A6121AEFD9008CFCDF</string>
<string>6BAF42E2121AF3B8008CFCDF</string>
<string>6BAF4321121AF998008CFCDF</string>
<string>6BAF4322121AF998008CFCDF</string>
<string>6BAF4323121AF998008CFCDF</string>
<string>6BAF4325121AF998008CFCDF</string>
<string>6BAF4346121AFD0B008CFCDF</string>
<string>6BAF4347121AFD0B008CFCDF</string>
</array>
<key>prevStack</key>
<array>
<string>6BBB4AD3115B4F3400CF791D</string>
<string>6BBB4AE0115B4F3400CF791D</string>
<string>6BBB4AE6115B4F3400CF791D</string>
<string>6BBB4AE7115B4F3400CF791D</string>
@ -490,9 +489,7 @@
<string>6BAF410812197F3D008CFCDF</string>
<string>6BAF411712197F3D008CFCDF</string>
<string>6BAF411F12197F3D008CFCDF</string>
<string>6BAF412E12197F3D008CFCDF</string>
<string>6BAF412F12197F3D008CFCDF</string>
<string>6BAF414612197F3D008CFCDF</string>
<string>6BAF414812197F3D008CFCDF</string>
<string>6BAF414912197F3D008CFCDF</string>
<string>6BAF414A12197F3D008CFCDF</string>
@ -549,18 +546,10 @@
<string>6BAF41D3121A5AEE008CFCDF</string>
<string>6BAF41DA121A5D13008CFCDF</string>
<string>6BAF41DB121A5D13008CFCDF</string>
<string>6BAF41DF121A5D13008CFCDF</string>
<string>6BAF41E9121ACD06008CFCDF</string>
<string>6BAF41ED121ACD06008CFCDF</string>
<string>6BAF41EF121ACD06008CFCDF</string>
<string>6BAF41F0121ACD06008CFCDF</string>
<string>6BAF41FD121ACD06008CFCDF</string>
<string>6BAF4222121ACE5E008CFCDF</string>
<string>6BAF4223121ACE5E008CFCDF</string>
<string>6BAF4238121AD4A8008CFCDF</string>
<string>6BAF4243121AD679008CFCDF</string>
<string>6BAF4245121AD679008CFCDF</string>
<string>6BAF4247121AD679008CFCDF</string>
<string>6BAF4254121AD7D7008CFCDF</string>
<string>6BAF4255121AD7D7008CFCDF</string>
<string>6BAF4256121AD7D7008CFCDF</string>
@ -569,15 +558,94 @@
<string>6BAF426D121AD99B008CFCDF</string>
<string>6BAF426F121AD99B008CFCDF</string>
<string>6BAF4270121AD99B008CFCDF</string>
<string>6BAF4271121AD99B008CFCDF</string>
<string>6BAF4272121AD99B008CFCDF</string>
<string>6BAF4283121ADD46008CFCDF</string>
<string>6BAF4284121ADD46008CFCDF</string>
<string>6BAF4285121ADD46008CFCDF</string>
<string>6BAF4286121ADD46008CFCDF</string>
<string>6BAF4287121ADD46008CFCDF</string>
<string>6BAF4288121ADD46008CFCDF</string>
<string>6BAF4289121ADD46008CFCDF</string>
<string>6BAF4290121AEBDF008CFCDF</string>
<string>6BAF4291121AEBDF008CFCDF</string>
<string>6BAF4293121AEBDF008CFCDF</string>
<string>6BAF4298121AEC2A008CFCDF</string>
<string>6BAF429D121AED31008CFCDF</string>
<string>6BAF429F121AED31008CFCDF</string>
<string>6BAF42A1121AED31008CFCDF</string>
<string>6BAF42A3121AED31008CFCDF</string>
<string>6BAF42A9121AEFD9008CFCDF</string>
<string>6BAF42B5121AF141008CFCDF</string>
<string>6BAF42B6121AF141008CFCDF</string>
<string>6BAF42B7121AF141008CFCDF</string>
<string>6BAF42B8121AF141008CFCDF</string>
<string>6BAF42B9121AF141008CFCDF</string>
<string>6BAF42BA121AF141008CFCDF</string>
<string>6BAF42BB121AF141008CFCDF</string>
<string>6BAF42BC121AF141008CFCDF</string>
<string>6BAF42BD121AF141008CFCDF</string>
<string>6BAF42BE121AF141008CFCDF</string>
<string>6BAF42BF121AF141008CFCDF</string>
<string>6BAF42C0121AF141008CFCDF</string>
<string>6BAF42C7121AF27C008CFCDF</string>
<string>6BAF42C8121AF27C008CFCDF</string>
<string>6BAF42C9121AF27C008CFCDF</string>
<string>6BAF42CA121AF27C008CFCDF</string>
<string>6BAF42CB121AF27C008CFCDF</string>
<string>6BAF42CC121AF27C008CFCDF</string>
<string>6BAF42CD121AF27C008CFCDF</string>
<string>6BAF42CE121AF27C008CFCDF</string>
<string>6BAF42CF121AF27C008CFCDF</string>
<string>6BBB4AD3115B4F3400CF791D</string>
<string>6BAF42E4121AF3B8008CFCDF</string>
<string>6BAF42E5121AF3B8008CFCDF</string>
<string>6BAF42E6121AF3B8008CFCDF</string>
<string>6BAF42E7121AF3B8008CFCDF</string>
<string>6BAF42E8121AF3B8008CFCDF</string>
<string>6BAF42FC121AF514008CFCDF</string>
<string>6BAF42FD121AF514008CFCDF</string>
<string>6BAF42FE121AF514008CFCDF</string>
<string>6BAF42FF121AF514008CFCDF</string>
<string>6BAF4300121AF514008CFCDF</string>
<string>6BAF4301121AF514008CFCDF</string>
<string>6BAF4302121AF514008CFCDF</string>
<string>6BAF4303121AF514008CFCDF</string>
<string>6BAF4304121AF514008CFCDF</string>
<string>6BAF4309121AF6E0008CFCDF</string>
<string>6BAF430E121AF7CD008CFCDF</string>
<string>6BAF430F121AF7CD008CFCDF</string>
<string>6BAF4310121AF7CD008CFCDF</string>
<string>6BAF4311121AF7CD008CFCDF</string>
<string>6BAF4312121AF7CD008CFCDF</string>
<string>6BAF4313121AF7CD008CFCDF</string>
<string>6BAF4314121AF7CD008CFCDF</string>
<string>6BAF4327121AF998008CFCDF</string>
<string>6BAF4328121AF998008CFCDF</string>
<string>6BAF4329121AF998008CFCDF</string>
<string>6BAF432A121AF998008CFCDF</string>
<string>6BAF432B121AF998008CFCDF</string>
<string>6BAF432C121AF998008CFCDF</string>
<string>6BAF432D121AF998008CFCDF</string>
<string>6BAF432E121AF998008CFCDF</string>
<string>6BAF432F121AF998008CFCDF</string>
<string>6BAF4330121AF998008CFCDF</string>
<string>6BAF4331121AF998008CFCDF</string>
<string>6BAF4332121AF998008CFCDF</string>
<string>6BAF4333121AF998008CFCDF</string>
<string>6BAF4334121AF998008CFCDF</string>
<string>6BAF4335121AF998008CFCDF</string>
<string>6BAF4336121AF998008CFCDF</string>
<string>6BAF4337121AF998008CFCDF</string>
<string>6BAF4338121AF998008CFCDF</string>
<string>6BAF4339121AF998008CFCDF</string>
<string>6BAF433A121AF998008CFCDF</string>
<string>6BAF433B121AF998008CFCDF</string>
<string>6BAF433C121AF998008CFCDF</string>
<string>6BAF433D121AF998008CFCDF</string>
<string>6BAF433E121AF998008CFCDF</string>
<string>6BAF433F121AF998008CFCDF</string>
<string>6BAF4340121AF998008CFCDF</string>
<string>6BAF4341121AF998008CFCDF</string>
<string>6BAF4342121AF998008CFCDF</string>
<string>6BAF4348121AFD0B008CFCDF</string>
</array>
</dict>
<key>SplitCount</key>
@ -591,18 +659,18 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 0}, {994, 505}}</string>
<string>{{0, 0}, {994, 559}}</string>
<key>RubberWindowFrame</key>
<string>0 59 1280 719 0 0 1280 778 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
<key>Proportion</key>
<string>505pt</string>
<string>559pt</string>
</dict>
<dict>
<key>Proportion</key>
<string>168pt</string>
<string>114pt</string>
<key>Tabs</key>
<array>
<dict>
@ -670,7 +738,7 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{10, 27}, {994, 141}}</string>
<string>{{10, 27}, {994, 87}}</string>
<key>RubberWindowFrame</key>
<string>0 59 1280 719 0 0 1280 778 </string>
</dict>
@ -892,6 +960,8 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
<string>6BAF42D9121AF2AF008CFCDF</string>
<string>6BAF42DA121AF2AF008CFCDF</string>
<string>/Users/memon/Code/recastnavigation/RecastDemo/Build/Xcode/Recast.xcodeproj</string>
</array>
<key>WindowString</key>

View File

@ -32,10 +32,13 @@ class NavMeshTesterTool : public SampleTool
dtQueryFilter m_filter;
dtQueryState m_pathFindState;
enum ToolMode
{
TOOLMODE_PATHFIND_ITER,
TOOLMODE_PATHFIND_FOLLOW,
TOOLMODE_PATHFIND_STRAIGHT,
TOOLMODE_PATHFIND_SLICED,
TOOLMODE_RAYCAST,
TOOLMODE_DISTANCE_TO_WALL,
TOOLMODE_FIND_POLYS_IN_CIRCLE,

View File

@ -145,7 +145,8 @@ NavMeshTesterTool::NavMeshTesterTool() :
m_sample(0),
m_navMesh(0),
m_navQuery(0),
m_toolMode(TOOLMODE_PATHFIND_ITER),
m_pathFindState(DT_QUERY_FAILED),
m_toolMode(TOOLMODE_PATHFIND_FOLLOW),
m_startRef(0),
m_endRef(0),
m_npolys(0),
@ -197,7 +198,9 @@ void NavMeshTesterTool::init(Sample* sample)
m_navQuery->setAreaCost(SAMPLE_POLYAREA_JUMP, 1.5f);
}
if (m_toolMode == TOOLMODE_PATHFIND_ITER || m_toolMode == TOOLMODE_PATHFIND_STRAIGHT)
if (m_toolMode == TOOLMODE_PATHFIND_FOLLOW ||
m_toolMode == TOOLMODE_PATHFIND_STRAIGHT ||
m_toolMode == TOOLMODE_PATHFIND_SLICED)
{
unsigned char flags = 0;
if (m_navMesh)
@ -210,9 +213,9 @@ void NavMeshTesterTool::init(Sample* sample)
void NavMeshTesterTool::handleMenu()
{
if (imguiCheck("Pathfind Iter", m_toolMode == TOOLMODE_PATHFIND_ITER))
if (imguiCheck("Pathfind Follow", m_toolMode == TOOLMODE_PATHFIND_FOLLOW))
{
m_toolMode = TOOLMODE_PATHFIND_ITER;
m_toolMode = TOOLMODE_PATHFIND_FOLLOW;
recalc();
}
if (imguiCheck("Pathfind Straight", m_toolMode == TOOLMODE_PATHFIND_STRAIGHT))
@ -220,6 +223,11 @@ void NavMeshTesterTool::handleMenu()
m_toolMode = TOOLMODE_PATHFIND_STRAIGHT;
recalc();
}
if (imguiCheck("Pathfind Sliced", m_toolMode == TOOLMODE_PATHFIND_SLICED))
{
m_toolMode = TOOLMODE_PATHFIND_SLICED;
recalc();
}
if (imguiCheck("Distance to Wall", m_toolMode == TOOLMODE_DISTANCE_TO_WALL))
{
m_toolMode = TOOLMODE_DISTANCE_TO_WALL;
@ -301,7 +309,7 @@ void NavMeshTesterTool::handleMenu()
imguiSeparator();
if (m_toolMode == TOOLMODE_PATHFIND_ITER || m_toolMode == TOOLMODE_PATHFIND_STRAIGHT)
if (m_toolMode == TOOLMODE_PATHFIND_FOLLOW || m_toolMode == TOOLMODE_PATHFIND_STRAIGHT)
{
unsigned char flags = 0;
if (m_navMesh)
@ -335,7 +343,7 @@ void NavMeshTesterTool::handleClick(const float* s, const float* p, bool shift)
void NavMeshTesterTool::handleStep()
{
// TODO: merge separate to a path iterator. Use same code in recalc() too.
if (m_toolMode != TOOLMODE_PATHFIND_ITER)
if (m_toolMode != TOOLMODE_PATHFIND_FOLLOW)
return;
if (!m_sposSet || !m_eposSet || !m_startRef || !m_endRef)
@ -481,6 +489,34 @@ void NavMeshTesterTool::handleStep()
void NavMeshTesterTool::handleUpdate(const float dt)
{
if (m_pathFindState == DT_QUERY_RUNNING)
{
m_pathFindState = m_navQuery->updateSlicedFindPath(1);
}
if (m_pathFindState == DT_QUERY_READY)
{
m_npolys = m_navQuery->finalizeSlicedFindPath(m_polys, MAX_POLYS);
m_nstraightPath = 0;
if (m_npolys)
{
// In case of partial path, make sure the end point is clamped to the last polygon.
float epos[3];
dtVcopy(epos, m_epos);
if (m_polys[m_npolys-1] != m_endRef)
m_navQuery->closestPointOnPoly(m_polys[m_npolys-1], m_epos, epos);
m_nstraightPath = m_navQuery->findStraightPath(m_spos, epos, m_polys, m_npolys,
m_straightPath, m_straightPathFlags,
m_straightPathPolys, MAX_POLYS);
}
m_pathFindState = DT_QUERY_FAILED;
}
}
void NavMeshTesterTool::reset()
@ -511,7 +547,9 @@ void NavMeshTesterTool::recalc()
else
m_endRef = 0;
if (m_toolMode == TOOLMODE_PATHFIND_ITER)
m_pathFindState = DT_QUERY_FAILED;
if (m_toolMode == TOOLMODE_PATHFIND_FOLLOW)
{
m_pathIterNum = 0;
if (m_sposSet && m_eposSet && m_startRef && m_endRef)
@ -684,6 +722,26 @@ void NavMeshTesterTool::recalc()
m_nstraightPath = 0;
}
}
else if (m_toolMode == TOOLMODE_PATHFIND_SLICED)
{
if (m_sposSet && m_eposSet && m_startRef && m_endRef)
{
#ifdef DUMP_REQS
printf("ps %f %f %f %f %f %f 0x%x 0x%x\n",
m_spos[0],m_spos[1],m_spos[2], m_epos[0],m_epos[1],m_epos[2],
m_filter.includeFlags, m_filter.excludeFlags);
#endif
m_npolys = 0;
m_nstraightPath = 0;
m_pathFindState = m_navQuery->initSlicedFindPath(m_startRef, m_endRef, m_spos, m_epos, &m_filter);
}
else
{
m_npolys = 0;
m_nstraightPath = 0;
}
}
else if (m_toolMode == TOOLMODE_RAYCAST)
{
m_nstraightPath = 0;
@ -855,7 +913,7 @@ void NavMeshTesterTool::handleRender()
return;
}
if (m_toolMode == TOOLMODE_PATHFIND_ITER)
if (m_toolMode == TOOLMODE_PATHFIND_FOLLOW)
{
duDebugDrawNavMeshPoly(&dd, *m_navMesh, m_startRef, startCol);
duDebugDrawNavMeshPoly(&dd, *m_navMesh, m_endRef, endCol);
@ -910,7 +968,7 @@ void NavMeshTesterTool::handleRender()
dd.depthMask(true);
}
}
else if (m_toolMode == TOOLMODE_PATHFIND_STRAIGHT)
else if (m_toolMode == TOOLMODE_PATHFIND_STRAIGHT || m_toolMode == TOOLMODE_PATHFIND_SLICED)
{
duDebugDrawNavMeshPoly(&dd, *m_navMesh, m_startRef, startCol);
duDebugDrawNavMeshPoly(&dd, *m_navMesh, m_endRef, endCol);