mirror of
https://github.com/recastnavigation/recastnavigation.git
synced 2026-08-16 16:19:55 +00:00
113 lines
3.2 KiB
C++
113 lines
3.2 KiB
C++
//
|
|
// 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.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include "DetourNavMesh.h"
|
|
#include "DetourNavMeshQuery.h"
|
|
#include "Sample.h"
|
|
|
|
class NavMeshTesterTool : public SampleTool
|
|
{
|
|
Sample* sample = nullptr;
|
|
|
|
dtNavMesh* navMesh = nullptr;
|
|
dtNavMeshQuery* navmeshQuery = nullptr;
|
|
|
|
dtQueryFilter filter;
|
|
|
|
dtStatus pathFindStatus = DT_FAILURE;
|
|
|
|
enum ToolMode
|
|
{
|
|
TOOLMODE_PATHFIND_FOLLOW,
|
|
TOOLMODE_PATHFIND_STRAIGHT,
|
|
TOOLMODE_PATHFIND_SLICED,
|
|
TOOLMODE_RAYCAST,
|
|
TOOLMODE_DISTANCE_TO_WALL,
|
|
TOOLMODE_FIND_POLYS_IN_CIRCLE,
|
|
TOOLMODE_FIND_POLYS_IN_SHAPE,
|
|
TOOLMODE_FIND_LOCAL_NEIGHBOURHOOD
|
|
};
|
|
ToolMode toolMode = TOOLMODE_PATHFIND_FOLLOW;
|
|
|
|
int straightPathOptions = 0;
|
|
|
|
static constexpr int MAX_POLYS = 256;
|
|
static constexpr int MAX_SMOOTH = 2048;
|
|
|
|
dtPolyRef startRef = 0;
|
|
dtPolyRef endRef = 0;
|
|
dtPolyRef polys[MAX_POLYS];
|
|
dtPolyRef parent[MAX_POLYS];
|
|
int npolys = 0;
|
|
float straightPath[MAX_POLYS * 3];
|
|
unsigned char straightPathFlags[MAX_POLYS];
|
|
dtPolyRef straightPathPolys[MAX_POLYS];
|
|
int nstraightPath = 0;
|
|
float polyPickExt[3] = {2, 4, 2};
|
|
float smoothPath[MAX_SMOOTH * 3];
|
|
int nsmoothPath = 0;
|
|
float queryPoly[4 * 3];
|
|
|
|
static constexpr int MAX_RAND_POINTS = 64;
|
|
float randPoints[MAX_RAND_POINTS * 3];
|
|
int nrandPoints = 0;
|
|
bool randPointsInCircle = false;
|
|
|
|
float spos[3];
|
|
float epos[3];
|
|
float hitPos[3];
|
|
float hitNormal[3];
|
|
bool hitResult = false;
|
|
float distanceToWall = 0;
|
|
float neighbourhoodRadius = 2.5f;
|
|
float randomRadius = 5.0f;
|
|
bool sposSet = false;
|
|
bool eposSet = false;
|
|
|
|
int pathIterNum = 0;
|
|
dtPolyRef pathIterPolys[MAX_POLYS];
|
|
int pathIterPolyCount = 0;
|
|
float prevIterPos[3];
|
|
float iterPos[3];
|
|
float steerPos[3];
|
|
float targetPos[3];
|
|
|
|
static constexpr int MAX_STEER_POINTS = 10;
|
|
float steerPoints[MAX_STEER_POINTS * 3];
|
|
int steerPointCount = 0;
|
|
|
|
public:
|
|
NavMeshTesterTool();
|
|
|
|
SampleToolType type() override { return SampleToolType::NAVMESH_TESTER; }
|
|
void init(Sample* newSample) override;
|
|
void reset() override;
|
|
void handleMenu() override;
|
|
void handleClick(const float* s, const float* p, bool shift) override;
|
|
void handleToggle() override;
|
|
void handleStep() override;
|
|
void handleUpdate(const float dt) override;
|
|
void handleRender() override;
|
|
void handleRenderOverlay(double* proj, double* model, int* view) override;
|
|
|
|
void recalc();
|
|
void drawAgent(const float* pos, float r, float h, float c, const unsigned int col);
|
|
};
|