@par Inaccurate locomotion or dynamic obstacle avoidance can force the argent position significantly outside the original corridor. Over time this can result in the formation of a non-optimal corridor. Non-optimal paths can also form near the corners of tiles. This function uses an efficient local visibility search to try to optimize the corridor between the current position and @p next. The
| 308 | This function is not suitable for long distance searches. |
| 309 | */ |
| 310 | void dtPathCorridor::optimizePathVisibility(const float* next, const float pathOptimizationRange, |
| 311 | dtNavMeshQuery* navquery, const dtQueryFilter* filter) |
| 312 | { |
| 313 | dtAssert(m_path); |
| 314 | |
| 315 | // Clamp the ray to max distance. |
| 316 | float goal[3]; |
| 317 | dtVcopy(goal, next); |
| 318 | float dist = dtVdist2D(m_pos, goal); |
| 319 | |
| 320 | // If too close to the goal, do not try to optimize. |
| 321 | if (dist < 0.01f) |
| 322 | return; |
| 323 | |
| 324 | // Overshoot a little. This helps to optimize open fields in tiled meshes. |
| 325 | dist = dtMin(dist+0.01f, pathOptimizationRange); |
| 326 | |
| 327 | // Adjust ray length. |
| 328 | float delta[3]; |
| 329 | dtVsub(delta, goal, m_pos); |
| 330 | dtVmad(goal, m_pos, delta, pathOptimizationRange/dist); |
| 331 | |
| 332 | static const int MAX_RES = 32; |
| 333 | dtPolyRef res[MAX_RES]; |
| 334 | float t, norm[3]; |
| 335 | int nres = 0; |
| 336 | navquery->raycast(m_path[0], m_pos, goal, filter, &t, norm, res, &nres, MAX_RES); |
| 337 | if (nres > 1 && t > 0.99f) |
| 338 | { |
| 339 | m_npath = dtMergeCorridorStartShortcut(m_path, m_npath, m_maxPath, res, nres); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | @par |