Debian Codegraph @

DetourCrowd/Include/DetourPathCorridor.h

raw symbols SCIP
1 //
2 // Copyright (c) 2009-2010 Mikko Mononen [email protected]
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
10 // 1. The origin of this software must not be misrepresented; you must not
11 // claim that you wrote the original software. If you use this software
12 // in a product, an acknowledgment in the product documentation would be
13 // appreciated but is not required.
14 // 2. Altered source versions must be plainly marked as such, and must not be
15 // misrepresented as being the original software.
16 // 3. This notice may not be removed or altered from any source distribution.
17 //
18
19 #ifndef DETOUTPATHCORRIDOR_H
20 #define DETOUTPATHCORRIDOR_H
21
22 #include "DetourNavMeshQuery.h"
23
24 /// Represents a dynamic polygon corridor used to plan agent movement.
25 /// @ingroup crowd, detour
26 class dtPathCorridor
27 {
28 float m_pos[3];
29 float m_target[3];
30
31 dtPolyRef* m_path;
32 int m_npath;
33 int m_maxPath;
34
35 public:
36 dtPathCorridor();
37 ~dtPathCorridor();
38
39 /// Allocates the corridor's path buffer.
40 /// @param[in] maxPath The maximum path size the corridor can handle.
41 /// @return True if the initialization succeeded.
42 bool init(const int maxPath);
43
44 /// Resets the path corridor to the specified position.
45 /// @param[in] ref The polygon reference containing the position.
46 /// @param[in] pos The new position in the corridor. [(x, y, z)]
47 void reset(dtPolyRef ref, const float* pos);
48
49 /// Finds the corners in the corridor from the position toward the target. (The straightened path.)
50 /// @param[out] cornerVerts The corner vertices. [(x, y, z) * cornerCount] [Size: <= maxCorners]
51 /// @param[out] cornerFlags The flag for each corner. [(flag) * cornerCount] [Size: <= maxCorners]
52 /// @param[out] cornerPolys The polygon reference for each corner. [(polyRef) * cornerCount]
53 /// [Size: <= @p maxCorners]
54 /// @param[in] maxCorners The maximum number of corners the buffers can hold.
55 /// @param[in] navquery The query object used to build the corridor.
56 /// @param[in] filter The filter to apply to the operation.
57 /// @return The number of corners returned in the corner buffers. [0 <= value <= @p maxCorners]
58 int findCorners(float* cornerVerts, unsigned char* cornerFlags,
59 dtPolyRef* cornerPolys, const int maxCorners,
60 dtNavMeshQuery* navquery, const dtQueryFilter* filter);
61
62 /// Attempts to optimize the path if the specified point is visible from the current position.
63 /// @param[in] next The point to search toward. [(x, y, z])
64 /// @param[in] pathOptimizationRange The maximum range to search. [Limit: > 0]
65 /// @param[in] navquery The query object used to build the corridor.
66 /// @param[in] filter The filter to apply to the operation.
67 void optimizePathVisibility(const float* next, const float pathOptimizationRange,
68 dtNavMeshQuery* navquery, const dtQueryFilter* filter);
69
70 /// Attempts to optimize the path using a local area search. (Partial replanning.)
71 /// @param[in] navquery The query object used to build the corridor.
72 /// @param[in] filter The filter to apply to the operation.
73 bool optimizePathTopology(dtNavMeshQuery* navquery, const dtQueryFilter* filter);
74
75 bool moveOverOffmeshConnection(dtPolyRef offMeshConRef, dtPolyRef* refs,
76 float* startPos, float* endPos,
77 dtNavMeshQuery* navquery);
78
79 bool fixPathStart(dtPolyRef safeRef, const float* safePos);
80
81 bool trimInvalidPath(dtPolyRef safeRef, const float* safePos,
82 dtNavMeshQuery* navquery, const dtQueryFilter* filter);
83
84 /// Checks the current corridor path to see if its polygon references remain valid.
85 /// @param[in] maxLookAhead The number of polygons from the beginning of the corridor to search.
86 /// @param[in] navquery The query object used to build the corridor.
87 /// @param[in] filter The filter to apply to the operation.
88 bool isValid(const int maxLookAhead, dtNavMeshQuery* navquery, const dtQueryFilter* filter);
89
90 /// Moves the position from the current location to the desired location, adjusting the corridor
91 /// as needed to reflect the change.
92 /// @param[in] npos The desired new position. [(x, y, z)]
93 /// @param[in] navquery The query object used to build the corridor.
94 /// @param[in] filter The filter to apply to the operation.
95 /// @return Returns true if move succeeded.
96 bool movePosition(const float* npos, dtNavMeshQuery* navquery, const dtQueryFilter* filter);
97
98 /// Moves the target from the curent location to the desired location, adjusting the corridor
99 /// as needed to reflect the change.
100 /// @param[in] npos The desired new target position. [(x, y, z)]
101 /// @param[in] navquery The query object used to build the corridor.
102 /// @param[in] filter The filter to apply to the operation.
103 /// @return Returns true if move succeeded.
104 bool moveTargetPosition(const float* npos, dtNavMeshQuery* navquery, const dtQueryFilter* filter);
105
106 /// Loads a new path and target into the corridor.
107 /// @param[in] target The target location within the last polygon of the path. [(x, y, z)]
108 /// @param[in] path The path corridor. [(polyRef) * @p npolys]
109 /// @param[in] npath The number of polygons in the path.
110 void setCorridor(const float* target, const dtPolyRef* polys, const int npath);
111
112 /// Gets the current position within the corridor. (In the first polygon.)
113 /// @return The current position within the corridor.
114 inline const float* getPos() const { return m_pos; }
115
116 /// Gets the current target within the corridor. (In the last polygon.)
117 /// @return The current target within the corridor.
118 inline const float* getTarget() const { return m_target; }
119
120 /// The polygon reference id of the first polygon in the corridor, the polygon containing the position.
121 /// @return The polygon reference id of the first polygon in the corridor. (Or zero if there is no path.)
122 inline dtPolyRef getFirstPoly() const { return m_npath ? m_path[0] : 0; }
123
124 /// The polygon reference id of the last polygon in the corridor, the polygon containing the target.
125 /// @return The polygon reference id of the last polygon in the corridor. (Or zero if there is no path.)
126 inline dtPolyRef getLastPoly() const { return m_npath ? m_path[m_npath-1] : 0; }
127
128 /// The corridor's path.
129 /// @return The corridor's path. [(polyRef) * #getPathCount()]
130 inline const dtPolyRef* getPath() const { return m_path; }
131
132 /// The number of polygons in the current corridor path.
133 /// @return The number of polygons in the current corridor path.
134 inline int getPathCount() const { return m_npath; }
135
136 private:
137 // Explicitly disabled copy constructor and copy assignment operator.
138 dtPathCorridor(const dtPathCorridor&);
139 dtPathCorridor& operator=(const dtPathCorridor&);
140 };
141
142 int dtMergeCorridorStartMoved(dtPolyRef* path, const int npath, const int maxPath,
143 const dtPolyRef* visited, const int nvisited);
144
145 int dtMergeCorridorEndMoved(dtPolyRef* path, const int npath, const int maxPath,
146 const dtPolyRef* visited, const int nvisited);
147
148 int dtMergeCorridorStartShortcut(dtPolyRef* path, const int npath, const int maxPath,
149 const dtPolyRef* visited, const int nvisited);
150
151 #endif // DETOUTPATHCORRIDOR_H