mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-15 00:28:21 +00:00
Recast navigation
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// 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 CHUNKYTRIMESH_H
|
||||
#define CHUNKYTRIMESH_H
|
||||
|
||||
struct rcChunkyTriMeshNode
|
||||
{
|
||||
float bmin[2];
|
||||
float bmax[2];
|
||||
int i;
|
||||
int n;
|
||||
};
|
||||
|
||||
struct rcChunkyTriMesh
|
||||
{
|
||||
inline rcChunkyTriMesh() : nodes(0), nnodes(0), tris(0), ntris(0), maxTrisPerChunk(0) {};
|
||||
inline ~rcChunkyTriMesh() { delete [] nodes; delete [] tris; }
|
||||
|
||||
rcChunkyTriMeshNode* nodes;
|
||||
int nnodes;
|
||||
int* tris;
|
||||
int ntris;
|
||||
int maxTrisPerChunk;
|
||||
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
rcChunkyTriMesh(const rcChunkyTriMesh&);
|
||||
rcChunkyTriMesh& operator=(const rcChunkyTriMesh&);
|
||||
};
|
||||
|
||||
/// Creates partitioned triangle mesh (AABB tree),
|
||||
/// where each node contains at max trisPerChunk triangles.
|
||||
bool rcCreateChunkyTriMesh(const float* verts, const int* tris, int ntris,
|
||||
int trisPerChunk, rcChunkyTriMesh* cm);
|
||||
|
||||
/// Returns the chunk indices which overlap the input rectable.
|
||||
int rcGetChunksOverlappingRect(const rcChunkyTriMesh* cm, float bmin[2], float bmax[2], int* ids, const int maxIds);
|
||||
|
||||
/// Returns the chunk indices which overlap the input segment.
|
||||
int rcGetChunksOverlappingSegment(const rcChunkyTriMesh* cm, float p[2], float q[2], int* ids, const int maxIds);
|
||||
|
||||
|
||||
#endif // CHUNKYTRIMESH_H
|
||||
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// 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 CONVEXVOLUMETOOL_H
|
||||
#define CONVEXVOLUMETOOL_H
|
||||
|
||||
#include "Sample.h"
|
||||
|
||||
// Tool to create convex volumess for InputGeom
|
||||
|
||||
class ConvexVolumeTool : public SampleTool
|
||||
{
|
||||
Sample* m_sample;
|
||||
int m_areaType;
|
||||
float m_polyOffset;
|
||||
float m_boxHeight;
|
||||
float m_boxDescent;
|
||||
|
||||
static const int MAX_PTS = 12;
|
||||
float m_pts[MAX_PTS*3];
|
||||
int m_npts;
|
||||
int m_hull[MAX_PTS];
|
||||
int m_nhull;
|
||||
|
||||
public:
|
||||
ConvexVolumeTool();
|
||||
|
||||
virtual int type() { return TOOL_CONVEX_VOLUME; }
|
||||
virtual void init(Sample* sample);
|
||||
virtual void reset();
|
||||
virtual void handleMenu();
|
||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
||||
virtual void handleToggle();
|
||||
virtual void handleStep();
|
||||
virtual void handleUpdate(const float dt);
|
||||
virtual void handleRender();
|
||||
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
||||
};
|
||||
|
||||
#endif // CONVEXVOLUMETOOL_H
|
||||
@@ -0,0 +1,144 @@
|
||||
//
|
||||
// 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 CROWDTOOL_H
|
||||
#define CROWDTOOL_H
|
||||
|
||||
#include "Sample.h"
|
||||
#include "DetourNavMesh.h"
|
||||
#include "DetourObstacleAvoidance.h"
|
||||
#include "ValueHistory.h"
|
||||
#include "DetourCrowd.h"
|
||||
|
||||
// Tool to create crowds.
|
||||
|
||||
struct CrowdToolParams
|
||||
{
|
||||
bool m_expandSelectedDebugDraw;
|
||||
bool m_showCorners;
|
||||
bool m_showCollisionSegments;
|
||||
bool m_showPath;
|
||||
bool m_showVO;
|
||||
bool m_showOpt;
|
||||
bool m_showNeis;
|
||||
|
||||
bool m_expandDebugDraw;
|
||||
bool m_showLabels;
|
||||
bool m_showGrid;
|
||||
bool m_showNodes;
|
||||
bool m_showPerfGraph;
|
||||
bool m_showDetailAll;
|
||||
|
||||
bool m_expandOptions;
|
||||
bool m_anticipateTurns;
|
||||
bool m_optimizeVis;
|
||||
bool m_optimizeTopo;
|
||||
bool m_obstacleAvoidance;
|
||||
float m_obstacleAvoidanceType;
|
||||
bool m_separation;
|
||||
float m_separationWeight;
|
||||
};
|
||||
|
||||
class CrowdToolState : public SampleToolState
|
||||
{
|
||||
Sample* m_sample;
|
||||
dtNavMesh* m_nav;
|
||||
dtCrowd* m_crowd;
|
||||
|
||||
float m_targetPos[3];
|
||||
dtPolyRef m_targetRef;
|
||||
|
||||
dtCrowdAgentDebugInfo m_agentDebug;
|
||||
dtObstacleAvoidanceDebugData* m_vod;
|
||||
|
||||
static const int AGENT_MAX_TRAIL = 64;
|
||||
static const int MAX_AGENTS = 128;
|
||||
struct AgentTrail
|
||||
{
|
||||
float trail[AGENT_MAX_TRAIL*3];
|
||||
int htrail;
|
||||
};
|
||||
AgentTrail m_trails[MAX_AGENTS];
|
||||
|
||||
ValueHistory m_crowdTotalTime;
|
||||
ValueHistory m_crowdSampleCount;
|
||||
|
||||
CrowdToolParams m_toolParams;
|
||||
|
||||
bool m_run;
|
||||
|
||||
public:
|
||||
CrowdToolState();
|
||||
virtual ~CrowdToolState();
|
||||
|
||||
virtual void init(class Sample* sample);
|
||||
virtual void reset();
|
||||
virtual void handleRender();
|
||||
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
||||
virtual void handleUpdate(const float dt);
|
||||
|
||||
inline bool isRunning() const { return m_run; }
|
||||
inline void setRunning(const bool s) { m_run = s; }
|
||||
|
||||
void addAgent(const float* pos);
|
||||
void removeAgent(const int idx);
|
||||
void hilightAgent(const int idx);
|
||||
void updateAgentParams();
|
||||
int hitTestAgents(const float* s, const float* p);
|
||||
void setMoveTarget(const float* p, bool adjust);
|
||||
void updateTick(const float dt);
|
||||
|
||||
inline CrowdToolParams* getToolParams() { return &m_toolParams; }
|
||||
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
CrowdToolState(const CrowdToolState&);
|
||||
CrowdToolState& operator=(const CrowdToolState&);
|
||||
};
|
||||
|
||||
|
||||
class CrowdTool : public SampleTool
|
||||
{
|
||||
Sample* m_sample;
|
||||
CrowdToolState* m_state;
|
||||
|
||||
enum ToolMode
|
||||
{
|
||||
TOOLMODE_CREATE,
|
||||
TOOLMODE_MOVE_TARGET,
|
||||
TOOLMODE_SELECT,
|
||||
TOOLMODE_TOGGLE_POLYS,
|
||||
};
|
||||
ToolMode m_mode;
|
||||
|
||||
public:
|
||||
CrowdTool();
|
||||
|
||||
virtual int type() { return TOOL_CROWD; }
|
||||
virtual void init(Sample* sample);
|
||||
virtual void reset();
|
||||
virtual void handleMenu();
|
||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
||||
virtual void handleToggle();
|
||||
virtual void handleStep();
|
||||
virtual void handleUpdate(const float dt);
|
||||
virtual void handleRender();
|
||||
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
||||
};
|
||||
|
||||
#endif // CROWDTOOL_H
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// 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 FILELIST_H
|
||||
#define FILELIST_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
void scanDirectoryAppend(const std::string& path, const std::string& ext, std::vector<std::string>& fileList);
|
||||
void scanDirectory(const std::string& path, const std::string& ext, std::vector<std::string>& fileList);
|
||||
|
||||
#endif // FILELIST_H
|
||||
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// 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 INPUTGEOM_H
|
||||
#define INPUTGEOM_H
|
||||
|
||||
#include "ChunkyTriMesh.h"
|
||||
#include "MeshLoaderObj.h"
|
||||
|
||||
static const int MAX_CONVEXVOL_PTS = 12;
|
||||
struct ConvexVolume
|
||||
{
|
||||
float verts[MAX_CONVEXVOL_PTS*3];
|
||||
float hmin, hmax;
|
||||
int nverts;
|
||||
int area;
|
||||
};
|
||||
|
||||
struct BuildSettings
|
||||
{
|
||||
// Cell size in world units
|
||||
float cellSize;
|
||||
// Cell height in world units
|
||||
float cellHeight;
|
||||
// Agent height in world units
|
||||
float agentHeight;
|
||||
// Agent radius in world units
|
||||
float agentRadius;
|
||||
// Agent max climb in world units
|
||||
float agentMaxClimb;
|
||||
// Agent max slope in degrees
|
||||
float agentMaxSlope;
|
||||
// Region minimum size in voxels.
|
||||
// regionMinSize = sqrt(regionMinArea)
|
||||
float regionMinSize;
|
||||
// Region merge size in voxels.
|
||||
// regionMergeSize = sqrt(regionMergeArea)
|
||||
float regionMergeSize;
|
||||
// Edge max length in world units
|
||||
float edgeMaxLen;
|
||||
// Edge max error in voxels
|
||||
float edgeMaxError;
|
||||
float vertsPerPoly;
|
||||
// Detail sample distance in voxels
|
||||
float detailSampleDist;
|
||||
// Detail sample max error in voxel heights.
|
||||
float detailSampleMaxError;
|
||||
// Partition type, see SamplePartitionType
|
||||
int partitionType;
|
||||
// Bounds of the area to mesh
|
||||
float navMeshBMin[3];
|
||||
float navMeshBMax[3];
|
||||
// Size of the tiles in voxels
|
||||
float tileSize;
|
||||
};
|
||||
|
||||
class InputGeom
|
||||
{
|
||||
rcChunkyTriMesh* m_chunkyMesh;
|
||||
rcMeshLoaderObj* m_mesh;
|
||||
float m_meshBMin[3], m_meshBMax[3];
|
||||
BuildSettings m_buildSettings;
|
||||
bool m_hasBuildSettings;
|
||||
|
||||
/// @name Off-Mesh connections.
|
||||
///@{
|
||||
static const int MAX_OFFMESH_CONNECTIONS = 256;
|
||||
float m_offMeshConVerts[MAX_OFFMESH_CONNECTIONS*3*2];
|
||||
float m_offMeshConRads[MAX_OFFMESH_CONNECTIONS];
|
||||
unsigned char m_offMeshConDirs[MAX_OFFMESH_CONNECTIONS];
|
||||
unsigned char m_offMeshConAreas[MAX_OFFMESH_CONNECTIONS];
|
||||
unsigned short m_offMeshConFlags[MAX_OFFMESH_CONNECTIONS];
|
||||
unsigned int m_offMeshConId[MAX_OFFMESH_CONNECTIONS];
|
||||
int m_offMeshConCount;
|
||||
///@}
|
||||
|
||||
/// @name Convex Volumes.
|
||||
///@{
|
||||
static const int MAX_VOLUMES = 256;
|
||||
ConvexVolume m_volumes[MAX_VOLUMES];
|
||||
int m_volumeCount;
|
||||
///@}
|
||||
|
||||
bool loadMesh(class rcContext* ctx, const std::string& filepath);
|
||||
bool loadGeomSet(class rcContext* ctx, const std::string& filepath);
|
||||
public:
|
||||
InputGeom();
|
||||
~InputGeom();
|
||||
|
||||
|
||||
bool load(class rcContext* ctx, const std::string& filepath);
|
||||
bool saveGeomSet(const BuildSettings* settings);
|
||||
|
||||
/// Method to return static mesh data.
|
||||
const rcMeshLoaderObj* getMesh() const { return m_mesh; }
|
||||
const float* getMeshBoundsMin() const { return m_meshBMin; }
|
||||
const float* getMeshBoundsMax() const { return m_meshBMax; }
|
||||
const float* getNavMeshBoundsMin() const { return m_hasBuildSettings ? m_buildSettings.navMeshBMin : m_meshBMin; }
|
||||
const float* getNavMeshBoundsMax() const { return m_hasBuildSettings ? m_buildSettings.navMeshBMax : m_meshBMax; }
|
||||
const rcChunkyTriMesh* getChunkyMesh() const { return m_chunkyMesh; }
|
||||
const BuildSettings* getBuildSettings() const { return m_hasBuildSettings ? &m_buildSettings : 0; }
|
||||
bool raycastMesh(float* src, float* dst, float& tmin);
|
||||
|
||||
/// @name Off-Mesh connections.
|
||||
///@{
|
||||
int getOffMeshConnectionCount() const { return m_offMeshConCount; }
|
||||
const float* getOffMeshConnectionVerts() const { return m_offMeshConVerts; }
|
||||
const float* getOffMeshConnectionRads() const { return m_offMeshConRads; }
|
||||
const unsigned char* getOffMeshConnectionDirs() const { return m_offMeshConDirs; }
|
||||
const unsigned char* getOffMeshConnectionAreas() const { return m_offMeshConAreas; }
|
||||
const unsigned short* getOffMeshConnectionFlags() const { return m_offMeshConFlags; }
|
||||
const unsigned int* getOffMeshConnectionId() const { return m_offMeshConId; }
|
||||
void addOffMeshConnection(const float* spos, const float* epos, const float rad,
|
||||
unsigned char bidir, unsigned char area, unsigned short flags);
|
||||
void deleteOffMeshConnection(int i);
|
||||
void drawOffMeshConnections(struct duDebugDraw* dd, bool hilight = false);
|
||||
///@}
|
||||
|
||||
/// @name Box Volumes.
|
||||
///@{
|
||||
int getConvexVolumeCount() const { return m_volumeCount; }
|
||||
const ConvexVolume* getConvexVolumes() const { return m_volumes; }
|
||||
void addConvexVolume(const float* verts, const int nverts,
|
||||
const float minh, const float maxh, unsigned char area);
|
||||
void deleteConvexVolume(int i);
|
||||
void drawConvexVolumes(struct duDebugDraw* dd, bool hilight = false);
|
||||
///@}
|
||||
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
InputGeom(const InputGeom&);
|
||||
InputGeom& operator=(const InputGeom&);
|
||||
};
|
||||
|
||||
#endif // INPUTGEOM_H
|
||||
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// 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 MESHLOADER_OBJ
|
||||
#define MESHLOADER_OBJ
|
||||
|
||||
#include <string>
|
||||
|
||||
class rcMeshLoaderObj
|
||||
{
|
||||
public:
|
||||
rcMeshLoaderObj();
|
||||
~rcMeshLoaderObj();
|
||||
|
||||
bool load(const std::string& fileName);
|
||||
|
||||
const float* getVerts() const { return m_verts; }
|
||||
const float* getNormals() const { return m_normals; }
|
||||
const int* getTris() const { return m_tris; }
|
||||
int getVertCount() const { return m_vertCount; }
|
||||
int getTriCount() const { return m_triCount; }
|
||||
const std::string& getFileName() const { return m_filename; }
|
||||
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
rcMeshLoaderObj(const rcMeshLoaderObj&);
|
||||
rcMeshLoaderObj& operator=(const rcMeshLoaderObj&);
|
||||
|
||||
void addVertex(float x, float y, float z, int& cap);
|
||||
void addTriangle(int a, int b, int c, int& cap);
|
||||
|
||||
std::string m_filename;
|
||||
float m_scale;
|
||||
float* m_verts;
|
||||
int* m_tris;
|
||||
float* m_normals;
|
||||
int m_vertCount;
|
||||
int m_triCount;
|
||||
};
|
||||
|
||||
#endif // MESHLOADER_OBJ
|
||||
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// 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 NAVMESHPRUNETOOL_H
|
||||
#define NAVMESHPRUNETOOL_H
|
||||
|
||||
#include "Sample.h"
|
||||
|
||||
// Prune navmesh to accessible locations from a point.
|
||||
|
||||
class NavMeshPruneTool : public SampleTool
|
||||
{
|
||||
Sample* m_sample;
|
||||
|
||||
class NavmeshFlags* m_flags;
|
||||
|
||||
float m_hitPos[3];
|
||||
bool m_hitPosSet;
|
||||
|
||||
public:
|
||||
NavMeshPruneTool();
|
||||
virtual ~NavMeshPruneTool();
|
||||
|
||||
virtual int type() { return TOOL_NAVMESH_PRUNE; }
|
||||
virtual void init(Sample* sample);
|
||||
virtual void reset();
|
||||
virtual void handleMenu();
|
||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
||||
virtual void handleToggle();
|
||||
virtual void handleStep();
|
||||
virtual void handleUpdate(const float dt);
|
||||
virtual void handleRender();
|
||||
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
||||
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
NavMeshPruneTool(const NavMeshPruneTool&);
|
||||
NavMeshPruneTool& operator=(const NavMeshPruneTool&);
|
||||
};
|
||||
|
||||
#endif // NAVMESHPRUNETOOL_H
|
||||
@@ -0,0 +1,113 @@
|
||||
//
|
||||
// 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 NAVMESHTESTERTOOL_H
|
||||
#define NAVMESHTESTERTOOL_H
|
||||
|
||||
#include "Sample.h"
|
||||
#include "DetourNavMesh.h"
|
||||
#include "DetourNavMeshQuery.h"
|
||||
|
||||
class NavMeshTesterTool : public SampleTool
|
||||
{
|
||||
Sample* m_sample;
|
||||
|
||||
dtNavMesh* m_navMesh;
|
||||
dtNavMeshQuery* m_navQuery;
|
||||
|
||||
dtQueryFilter m_filter;
|
||||
|
||||
dtStatus m_pathFindStatus;
|
||||
|
||||
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 m_toolMode;
|
||||
|
||||
int m_straightPathOptions;
|
||||
|
||||
static const int MAX_POLYS = 256;
|
||||
static const int MAX_SMOOTH = 2048;
|
||||
|
||||
dtPolyRef m_startRef;
|
||||
dtPolyRef m_endRef;
|
||||
dtPolyRef m_polys[MAX_POLYS];
|
||||
dtPolyRef m_parent[MAX_POLYS];
|
||||
int m_npolys;
|
||||
float m_straightPath[MAX_POLYS*3];
|
||||
unsigned char m_straightPathFlags[MAX_POLYS];
|
||||
dtPolyRef m_straightPathPolys[MAX_POLYS];
|
||||
int m_nstraightPath;
|
||||
float m_polyPickExt[3];
|
||||
float m_smoothPath[MAX_SMOOTH*3];
|
||||
int m_nsmoothPath;
|
||||
float m_queryPoly[4*3];
|
||||
|
||||
static const int MAX_RAND_POINTS = 64;
|
||||
float m_randPoints[MAX_RAND_POINTS*3];
|
||||
int m_nrandPoints;
|
||||
bool m_randPointsInCircle;
|
||||
|
||||
float m_spos[3];
|
||||
float m_epos[3];
|
||||
float m_hitPos[3];
|
||||
float m_hitNormal[3];
|
||||
bool m_hitResult;
|
||||
float m_distanceToWall;
|
||||
float m_neighbourhoodRadius;
|
||||
float m_randomRadius;
|
||||
bool m_sposSet;
|
||||
bool m_eposSet;
|
||||
|
||||
int m_pathIterNum;
|
||||
dtPolyRef m_pathIterPolys[MAX_POLYS];
|
||||
int m_pathIterPolyCount;
|
||||
float m_prevIterPos[3], m_iterPos[3], m_steerPos[3], m_targetPos[3];
|
||||
|
||||
static const int MAX_STEER_POINTS = 10;
|
||||
float m_steerPoints[MAX_STEER_POINTS*3];
|
||||
int m_steerPointCount;
|
||||
|
||||
public:
|
||||
NavMeshTesterTool();
|
||||
|
||||
virtual int type() { return TOOL_NAVMESH_TESTER; }
|
||||
virtual void init(Sample* sample);
|
||||
virtual void reset();
|
||||
virtual void handleMenu();
|
||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
||||
virtual void handleToggle();
|
||||
virtual void handleStep();
|
||||
virtual void handleUpdate(const float dt);
|
||||
virtual void handleRender();
|
||||
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
||||
|
||||
void recalc();
|
||||
void drawAgent(const float* pos, float r, float h, float c, const unsigned int col);
|
||||
};
|
||||
|
||||
#endif // NAVMESHTESTERTOOL_H
|
||||
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// 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 OFFMESHCONNECTIONTOOL_H
|
||||
#define OFFMESHCONNECTIONTOOL_H
|
||||
|
||||
#include "Sample.h"
|
||||
|
||||
// Tool to create off-mesh connection for InputGeom
|
||||
|
||||
class OffMeshConnectionTool : public SampleTool
|
||||
{
|
||||
Sample* m_sample;
|
||||
float m_hitPos[3];
|
||||
bool m_hitPosSet;
|
||||
bool m_bidir;
|
||||
unsigned char m_oldFlags;
|
||||
|
||||
public:
|
||||
OffMeshConnectionTool();
|
||||
~OffMeshConnectionTool();
|
||||
|
||||
virtual int type() { return TOOL_OFFMESH_CONNECTION; }
|
||||
virtual void init(Sample* sample);
|
||||
virtual void reset();
|
||||
virtual void handleMenu();
|
||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
||||
virtual void handleToggle();
|
||||
virtual void handleStep();
|
||||
virtual void handleUpdate(const float dt);
|
||||
virtual void handleRender();
|
||||
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
||||
};
|
||||
|
||||
#endif // OFFMESHCONNECTIONTOOL_H
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// 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 PERFTIMER_H
|
||||
#define PERFTIMER_H
|
||||
|
||||
#ifdef __GNUC__
|
||||
#include <stdint.h>
|
||||
typedef int64_t TimeVal;
|
||||
#else
|
||||
typedef __int64 TimeVal;
|
||||
#endif
|
||||
|
||||
TimeVal getPerfTime();
|
||||
int getPerfTimeUsec(const TimeVal duration);
|
||||
|
||||
#endif // PERFTIMER_H
|
||||
@@ -0,0 +1,190 @@
|
||||
//
|
||||
// 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 RECASTSAMPLE_H
|
||||
#define RECASTSAMPLE_H
|
||||
|
||||
#include "Recast.h"
|
||||
#include "SampleInterfaces.h"
|
||||
|
||||
|
||||
/// Tool types.
|
||||
enum SampleToolType
|
||||
{
|
||||
TOOL_NONE = 0,
|
||||
TOOL_TILE_EDIT,
|
||||
TOOL_TILE_HIGHLIGHT,
|
||||
TOOL_TEMP_OBSTACLE,
|
||||
TOOL_NAVMESH_TESTER,
|
||||
TOOL_NAVMESH_PRUNE,
|
||||
TOOL_OFFMESH_CONNECTION,
|
||||
TOOL_CONVEX_VOLUME,
|
||||
TOOL_CROWD,
|
||||
MAX_TOOLS
|
||||
};
|
||||
|
||||
/// These are just sample areas to use consistent values across the samples.
|
||||
/// The use should specify these base on his needs.
|
||||
enum SamplePolyAreas
|
||||
{
|
||||
SAMPLE_POLYAREA_GROUND,
|
||||
SAMPLE_POLYAREA_WATER,
|
||||
SAMPLE_POLYAREA_ROAD,
|
||||
SAMPLE_POLYAREA_DOOR,
|
||||
SAMPLE_POLYAREA_GRASS,
|
||||
SAMPLE_POLYAREA_JUMP,
|
||||
};
|
||||
enum SamplePolyFlags
|
||||
{
|
||||
SAMPLE_POLYFLAGS_WALK = 0x01, // Ability to walk (ground, grass, road)
|
||||
SAMPLE_POLYFLAGS_SWIM = 0x02, // Ability to swim (water).
|
||||
SAMPLE_POLYFLAGS_DOOR = 0x04, // Ability to move through doors.
|
||||
SAMPLE_POLYFLAGS_JUMP = 0x08, // Ability to jump.
|
||||
SAMPLE_POLYFLAGS_DISABLED = 0x10, // Disabled polygon
|
||||
SAMPLE_POLYFLAGS_ALL = 0xffff // All abilities.
|
||||
};
|
||||
|
||||
class SampleDebugDraw : public DebugDrawGL
|
||||
{
|
||||
public:
|
||||
virtual unsigned int areaToCol(unsigned int area);
|
||||
};
|
||||
|
||||
enum SamplePartitionType
|
||||
{
|
||||
SAMPLE_PARTITION_WATERSHED,
|
||||
SAMPLE_PARTITION_MONOTONE,
|
||||
SAMPLE_PARTITION_LAYERS,
|
||||
};
|
||||
|
||||
struct SampleTool
|
||||
{
|
||||
virtual ~SampleTool() {}
|
||||
virtual int type() = 0;
|
||||
virtual void init(class Sample* sample) = 0;
|
||||
virtual void reset() = 0;
|
||||
virtual void handleMenu() = 0;
|
||||
virtual void handleClick(const float* s, const float* p, bool shift) = 0;
|
||||
virtual void handleRender() = 0;
|
||||
virtual void handleRenderOverlay(double* proj, double* model, int* view) = 0;
|
||||
virtual void handleToggle() = 0;
|
||||
virtual void handleStep() = 0;
|
||||
virtual void handleUpdate(const float dt) = 0;
|
||||
};
|
||||
|
||||
struct SampleToolState {
|
||||
virtual ~SampleToolState() {}
|
||||
virtual void init(class Sample* sample) = 0;
|
||||
virtual void reset() = 0;
|
||||
virtual void handleRender() = 0;
|
||||
virtual void handleRenderOverlay(double* proj, double* model, int* view) = 0;
|
||||
virtual void handleUpdate(const float dt) = 0;
|
||||
};
|
||||
|
||||
class Sample
|
||||
{
|
||||
protected:
|
||||
class InputGeom* m_geom;
|
||||
class dtNavMesh* m_navMesh;
|
||||
class dtNavMeshQuery* m_navQuery;
|
||||
class dtCrowd* m_crowd;
|
||||
|
||||
unsigned char m_navMeshDrawFlags;
|
||||
|
||||
float m_cellSize;
|
||||
float m_cellHeight;
|
||||
float m_agentHeight;
|
||||
float m_agentRadius;
|
||||
float m_agentMaxClimb;
|
||||
float m_agentMaxSlope;
|
||||
float m_regionMinSize;
|
||||
float m_regionMergeSize;
|
||||
float m_edgeMaxLen;
|
||||
float m_edgeMaxError;
|
||||
float m_vertsPerPoly;
|
||||
float m_detailSampleDist;
|
||||
float m_detailSampleMaxError;
|
||||
int m_partitionType;
|
||||
|
||||
bool m_filterLowHangingObstacles;
|
||||
bool m_filterLedgeSpans;
|
||||
bool m_filterWalkableLowHeightSpans;
|
||||
|
||||
SampleTool* m_tool;
|
||||
SampleToolState* m_toolStates[MAX_TOOLS];
|
||||
|
||||
BuildContext* m_ctx;
|
||||
|
||||
SampleDebugDraw m_dd;
|
||||
|
||||
dtNavMesh* loadAll(const char* path);
|
||||
void saveAll(const char* path, const dtNavMesh* mesh);
|
||||
|
||||
public:
|
||||
Sample();
|
||||
virtual ~Sample();
|
||||
|
||||
void setContext(BuildContext* ctx) { m_ctx = ctx; }
|
||||
|
||||
void setTool(SampleTool* tool);
|
||||
SampleToolState* getToolState(int type) { return m_toolStates[type]; }
|
||||
void setToolState(int type, SampleToolState* s) { m_toolStates[type] = s; }
|
||||
|
||||
SampleDebugDraw& getDebugDraw() { return m_dd; }
|
||||
|
||||
virtual void handleSettings();
|
||||
virtual void handleTools();
|
||||
virtual void handleDebugMode();
|
||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
||||
virtual void handleToggle();
|
||||
virtual void handleStep();
|
||||
virtual void handleRender();
|
||||
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
||||
virtual void handleMeshChanged(class InputGeom* geom);
|
||||
virtual bool handleBuild();
|
||||
virtual void handleUpdate(const float dt);
|
||||
virtual void collectSettings(struct BuildSettings& settings);
|
||||
|
||||
virtual class InputGeom* getInputGeom() { return m_geom; }
|
||||
virtual class dtNavMesh* getNavMesh() { return m_navMesh; }
|
||||
virtual class dtNavMeshQuery* getNavMeshQuery() { return m_navQuery; }
|
||||
virtual class dtCrowd* getCrowd() { return m_crowd; }
|
||||
virtual float getAgentRadius() { return m_agentRadius; }
|
||||
virtual float getAgentHeight() { return m_agentHeight; }
|
||||
virtual float getAgentClimb() { return m_agentMaxClimb; }
|
||||
|
||||
unsigned char getNavMeshDrawFlags() const { return m_navMeshDrawFlags; }
|
||||
void setNavMeshDrawFlags(unsigned char flags) { m_navMeshDrawFlags = flags; }
|
||||
|
||||
void updateToolStates(const float dt);
|
||||
void initToolStates(Sample* sample);
|
||||
void resetToolStates();
|
||||
void renderToolStates();
|
||||
void renderOverlayToolStates(double* proj, double* model, int* view);
|
||||
|
||||
void resetCommonSettings();
|
||||
void handleCommonSettings();
|
||||
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
Sample(const Sample&);
|
||||
Sample& operator=(const Sample&);
|
||||
};
|
||||
|
||||
|
||||
#endif // RECASTSAMPLE_H
|
||||
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// 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 SAMPLEINTERFACES_H
|
||||
#define SAMPLEINTERFACES_H
|
||||
|
||||
#include "DebugDraw.h"
|
||||
#include "Recast.h"
|
||||
#include "RecastDump.h"
|
||||
#include "PerfTimer.h"
|
||||
|
||||
// These are example implementations of various interfaces used in Recast and Detour.
|
||||
|
||||
/// Recast build context.
|
||||
class BuildContext : public rcContext
|
||||
{
|
||||
TimeVal m_startTime[RC_MAX_TIMERS];
|
||||
TimeVal m_accTime[RC_MAX_TIMERS];
|
||||
|
||||
static const int MAX_MESSAGES = 1000;
|
||||
const char* m_messages[MAX_MESSAGES];
|
||||
int m_messageCount;
|
||||
static const int TEXT_POOL_SIZE = 8000;
|
||||
char m_textPool[TEXT_POOL_SIZE];
|
||||
int m_textPoolSize;
|
||||
|
||||
public:
|
||||
BuildContext();
|
||||
|
||||
/// Dumps the log to stdout.
|
||||
void dumpLog(const char* format, ...);
|
||||
/// Returns number of log messages.
|
||||
int getLogCount() const;
|
||||
/// Returns log message text.
|
||||
const char* getLogText(const int i) const;
|
||||
|
||||
protected:
|
||||
/// Virtual functions for custom implementations.
|
||||
///@{
|
||||
virtual void doResetLog();
|
||||
virtual void doLog(const rcLogCategory category, const char* msg, const int len);
|
||||
virtual void doResetTimers();
|
||||
virtual void doStartTimer(const rcTimerLabel label);
|
||||
virtual void doStopTimer(const rcTimerLabel label);
|
||||
virtual int doGetAccumulatedTime(const rcTimerLabel label) const;
|
||||
///@}
|
||||
};
|
||||
|
||||
/// OpenGL debug draw implementation.
|
||||
class DebugDrawGL : public duDebugDraw
|
||||
{
|
||||
public:
|
||||
virtual void depthMask(bool state);
|
||||
virtual void texture(bool state);
|
||||
virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f);
|
||||
virtual void vertex(const float* pos, unsigned int color);
|
||||
virtual void vertex(const float x, const float y, const float z, unsigned int color);
|
||||
virtual void vertex(const float* pos, unsigned int color, const float* uv);
|
||||
virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
/// stdio file implementation.
|
||||
class FileIO : public duFileIO
|
||||
{
|
||||
FILE* m_fp;
|
||||
int m_mode;
|
||||
public:
|
||||
FileIO();
|
||||
virtual ~FileIO();
|
||||
bool openForWrite(const char* path);
|
||||
bool openForRead(const char* path);
|
||||
virtual bool isWriting() const;
|
||||
virtual bool isReading() const;
|
||||
virtual bool write(const void* ptr, const size_t size);
|
||||
virtual bool read(void* ptr, const size_t size);
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
FileIO(const FileIO&);
|
||||
FileIO& operator=(const FileIO&);
|
||||
};
|
||||
|
||||
#endif // SAMPLEINTERFACES_H
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// 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 RECASTSAMPLEDEBUG_H
|
||||
#define RECASTSAMPLEDEBUG_H
|
||||
|
||||
#include "Sample.h"
|
||||
#include "DetourNavMesh.h"
|
||||
#include "Recast.h"
|
||||
|
||||
/// Sample used for random debugging.
|
||||
class Sample_Debug : public Sample
|
||||
{
|
||||
protected:
|
||||
rcCompactHeightfield* m_chf;
|
||||
rcContourSet* m_cset;
|
||||
rcPolyMesh* m_pmesh;
|
||||
|
||||
float m_halfExtents[3];
|
||||
float m_center[3];
|
||||
float m_bmin[3], m_bmax[3];
|
||||
dtPolyRef m_ref;
|
||||
|
||||
public:
|
||||
Sample_Debug();
|
||||
virtual ~Sample_Debug();
|
||||
|
||||
virtual void handleSettings();
|
||||
virtual void handleTools();
|
||||
virtual void handleDebugMode();
|
||||
virtual void handleClick(const float* s, const float* p, bool shift);
|
||||
virtual void handleToggle();
|
||||
virtual void handleRender();
|
||||
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
||||
virtual void handleMeshChanged(class InputGeom* geom);
|
||||
virtual bool handleBuild();
|
||||
|
||||
virtual const float* getBoundsMin();
|
||||
virtual const float* getBoundsMax();
|
||||
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
Sample_Debug(const Sample_Debug&);
|
||||
Sample_Debug& operator=(const Sample_Debug&);
|
||||
};
|
||||
|
||||
|
||||
#endif // RECASTSAMPLE_H
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// 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 RECASTSAMPLESOLOMESH_H
|
||||
#define RECASTSAMPLESOLOMESH_H
|
||||
|
||||
#include "Sample.h"
|
||||
#include "DetourNavMesh.h"
|
||||
#include "Recast.h"
|
||||
|
||||
class Sample_SoloMesh : public Sample
|
||||
{
|
||||
protected:
|
||||
bool m_keepInterResults;
|
||||
float m_totalBuildTimeMs;
|
||||
|
||||
unsigned char* m_triareas;
|
||||
rcHeightfield* m_solid;
|
||||
rcCompactHeightfield* m_chf;
|
||||
rcContourSet* m_cset;
|
||||
rcPolyMesh* m_pmesh;
|
||||
rcConfig m_cfg;
|
||||
rcPolyMeshDetail* m_dmesh;
|
||||
|
||||
enum DrawMode
|
||||
{
|
||||
DRAWMODE_NAVMESH,
|
||||
DRAWMODE_NAVMESH_TRANS,
|
||||
DRAWMODE_NAVMESH_BVTREE,
|
||||
DRAWMODE_NAVMESH_NODES,
|
||||
DRAWMODE_NAVMESH_INVIS,
|
||||
DRAWMODE_MESH,
|
||||
DRAWMODE_VOXELS,
|
||||
DRAWMODE_VOXELS_WALKABLE,
|
||||
DRAWMODE_COMPACT,
|
||||
DRAWMODE_COMPACT_DISTANCE,
|
||||
DRAWMODE_COMPACT_REGIONS,
|
||||
DRAWMODE_REGION_CONNECTIONS,
|
||||
DRAWMODE_RAW_CONTOURS,
|
||||
DRAWMODE_BOTH_CONTOURS,
|
||||
DRAWMODE_CONTOURS,
|
||||
DRAWMODE_POLYMESH,
|
||||
DRAWMODE_POLYMESH_DETAIL,
|
||||
MAX_DRAWMODE
|
||||
};
|
||||
|
||||
DrawMode m_drawMode;
|
||||
|
||||
void cleanup();
|
||||
|
||||
public:
|
||||
Sample_SoloMesh();
|
||||
virtual ~Sample_SoloMesh();
|
||||
|
||||
virtual void handleSettings();
|
||||
virtual void handleTools();
|
||||
virtual void handleDebugMode();
|
||||
|
||||
virtual void handleRender();
|
||||
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
||||
virtual void handleMeshChanged(class InputGeom* geom);
|
||||
virtual bool handleBuild();
|
||||
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
Sample_SoloMesh(const Sample_SoloMesh&);
|
||||
Sample_SoloMesh& operator=(const Sample_SoloMesh&);
|
||||
};
|
||||
|
||||
|
||||
#endif // RECASTSAMPLESOLOMESHSIMPLE_H
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// 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 RECASTSAMPLETEMPOBSTACLE_H
|
||||
#define RECASTSAMPLETEMPOBSTACLE_H
|
||||
|
||||
#include "Sample.h"
|
||||
#include "DetourNavMesh.h"
|
||||
#include "Recast.h"
|
||||
#include "ChunkyTriMesh.h"
|
||||
|
||||
|
||||
class Sample_TempObstacles : public Sample
|
||||
{
|
||||
protected:
|
||||
bool m_keepInterResults;
|
||||
|
||||
struct LinearAllocator* m_talloc;
|
||||
struct FastLZCompressor* m_tcomp;
|
||||
struct MeshProcess* m_tmproc;
|
||||
|
||||
class dtTileCache* m_tileCache;
|
||||
|
||||
float m_cacheBuildTimeMs;
|
||||
int m_cacheCompressedSize;
|
||||
int m_cacheRawSize;
|
||||
int m_cacheLayerCount;
|
||||
unsigned int m_cacheBuildMemUsage;
|
||||
|
||||
enum DrawMode
|
||||
{
|
||||
DRAWMODE_NAVMESH,
|
||||
DRAWMODE_NAVMESH_TRANS,
|
||||
DRAWMODE_NAVMESH_BVTREE,
|
||||
DRAWMODE_NAVMESH_NODES,
|
||||
DRAWMODE_NAVMESH_PORTALS,
|
||||
DRAWMODE_NAVMESH_INVIS,
|
||||
DRAWMODE_MESH,
|
||||
DRAWMODE_CACHE_BOUNDS,
|
||||
MAX_DRAWMODE
|
||||
};
|
||||
|
||||
DrawMode m_drawMode;
|
||||
|
||||
int m_maxTiles;
|
||||
int m_maxPolysPerTile;
|
||||
float m_tileSize;
|
||||
|
||||
public:
|
||||
Sample_TempObstacles();
|
||||
virtual ~Sample_TempObstacles();
|
||||
|
||||
virtual void handleSettings();
|
||||
virtual void handleTools();
|
||||
virtual void handleDebugMode();
|
||||
virtual void handleRender();
|
||||
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
||||
virtual void handleMeshChanged(class InputGeom* geom);
|
||||
virtual bool handleBuild();
|
||||
virtual void handleUpdate(const float dt);
|
||||
|
||||
void getTilePos(const float* pos, int& tx, int& ty);
|
||||
|
||||
void renderCachedTile(const int tx, const int ty, const int type);
|
||||
void renderCachedTileOverlay(const int tx, const int ty, double* proj, double* model, int* view);
|
||||
|
||||
void addTempObstacle(const float* pos);
|
||||
void removeTempObstacle(const float* sp, const float* sq);
|
||||
void clearAllTempObstacles();
|
||||
|
||||
void saveAll(const char* path);
|
||||
void loadAll(const char* path);
|
||||
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
Sample_TempObstacles(const Sample_TempObstacles&);
|
||||
Sample_TempObstacles& operator=(const Sample_TempObstacles&);
|
||||
|
||||
int rasterizeTileLayers(const int tx, const int ty, const rcConfig& cfg, struct TileCacheData* tiles, const int maxTiles);
|
||||
};
|
||||
|
||||
|
||||
#endif // RECASTSAMPLETEMPOBSTACLE_H
|
||||
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// 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 RECASTSAMPLETILEMESH_H
|
||||
#define RECASTSAMPLETILEMESH_H
|
||||
|
||||
#include "Sample.h"
|
||||
#include "DetourNavMesh.h"
|
||||
#include "Recast.h"
|
||||
#include "ChunkyTriMesh.h"
|
||||
|
||||
class Sample_TileMesh : public Sample
|
||||
{
|
||||
protected:
|
||||
bool m_keepInterResults;
|
||||
bool m_buildAll;
|
||||
float m_totalBuildTimeMs;
|
||||
|
||||
unsigned char* m_triareas;
|
||||
rcHeightfield* m_solid;
|
||||
rcCompactHeightfield* m_chf;
|
||||
rcContourSet* m_cset;
|
||||
rcPolyMesh* m_pmesh;
|
||||
rcPolyMeshDetail* m_dmesh;
|
||||
rcConfig m_cfg;
|
||||
|
||||
enum DrawMode
|
||||
{
|
||||
DRAWMODE_NAVMESH,
|
||||
DRAWMODE_NAVMESH_TRANS,
|
||||
DRAWMODE_NAVMESH_BVTREE,
|
||||
DRAWMODE_NAVMESH_NODES,
|
||||
DRAWMODE_NAVMESH_PORTALS,
|
||||
DRAWMODE_NAVMESH_INVIS,
|
||||
DRAWMODE_MESH,
|
||||
DRAWMODE_VOXELS,
|
||||
DRAWMODE_VOXELS_WALKABLE,
|
||||
DRAWMODE_COMPACT,
|
||||
DRAWMODE_COMPACT_DISTANCE,
|
||||
DRAWMODE_COMPACT_REGIONS,
|
||||
DRAWMODE_REGION_CONNECTIONS,
|
||||
DRAWMODE_RAW_CONTOURS,
|
||||
DRAWMODE_BOTH_CONTOURS,
|
||||
DRAWMODE_CONTOURS,
|
||||
DRAWMODE_POLYMESH,
|
||||
DRAWMODE_POLYMESH_DETAIL,
|
||||
MAX_DRAWMODE
|
||||
};
|
||||
|
||||
DrawMode m_drawMode;
|
||||
|
||||
int m_maxTiles;
|
||||
int m_maxPolysPerTile;
|
||||
float m_tileSize;
|
||||
|
||||
unsigned int m_tileCol;
|
||||
float m_lastBuiltTileBmin[3];
|
||||
float m_lastBuiltTileBmax[3];
|
||||
float m_tileBuildTime;
|
||||
float m_tileMemUsage;
|
||||
int m_tileTriCount;
|
||||
|
||||
unsigned char* buildTileMesh(const int tx, const int ty, const float* bmin, const float* bmax, int& dataSize);
|
||||
|
||||
void cleanup();
|
||||
|
||||
void saveAll(const char* path, const dtNavMesh* mesh);
|
||||
dtNavMesh* loadAll(const char* path);
|
||||
|
||||
public:
|
||||
Sample_TileMesh();
|
||||
virtual ~Sample_TileMesh();
|
||||
|
||||
virtual void handleSettings();
|
||||
virtual void handleTools();
|
||||
virtual void handleDebugMode();
|
||||
virtual void handleRender();
|
||||
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
||||
virtual void handleMeshChanged(class InputGeom* geom);
|
||||
virtual bool handleBuild();
|
||||
virtual void collectSettings(struct BuildSettings& settings);
|
||||
|
||||
void getTilePos(const float* pos, int& tx, int& ty);
|
||||
|
||||
void buildTile(const float* pos);
|
||||
void removeTile(const float* pos);
|
||||
void buildAllTiles();
|
||||
void removeAllTiles();
|
||||
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
Sample_TileMesh(const Sample_TileMesh&);
|
||||
Sample_TileMesh& operator=(const Sample_TileMesh&);
|
||||
};
|
||||
|
||||
|
||||
#endif // RECASTSAMPLETILEMESH_H
|
||||
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// 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 TESTCASE_H
|
||||
#define TESTCASE_H
|
||||
|
||||
#include <string>
|
||||
#include "DetourNavMesh.h"
|
||||
|
||||
class TestCase
|
||||
{
|
||||
enum TestType
|
||||
{
|
||||
TEST_PATHFIND,
|
||||
TEST_RAYCAST,
|
||||
};
|
||||
|
||||
struct Test
|
||||
{
|
||||
Test() :
|
||||
type(),
|
||||
radius(0),
|
||||
includeFlags(0),
|
||||
excludeFlags(0),
|
||||
expand(false),
|
||||
straight(0),
|
||||
nstraight(0),
|
||||
polys(0),
|
||||
npolys(0),
|
||||
findNearestPolyTime(0),
|
||||
findPathTime(0),
|
||||
findStraightPathTime(0),
|
||||
next(0)
|
||||
{
|
||||
}
|
||||
|
||||
~Test()
|
||||
{
|
||||
delete [] straight;
|
||||
delete [] polys;
|
||||
}
|
||||
|
||||
TestType type;
|
||||
float spos[3];
|
||||
float epos[3];
|
||||
float nspos[3];
|
||||
float nepos[3];
|
||||
float radius;
|
||||
unsigned short includeFlags;
|
||||
unsigned short excludeFlags;
|
||||
bool expand;
|
||||
|
||||
float* straight;
|
||||
int nstraight;
|
||||
dtPolyRef* polys;
|
||||
int npolys;
|
||||
|
||||
int findNearestPolyTime;
|
||||
int findPathTime;
|
||||
int findStraightPathTime;
|
||||
|
||||
Test* next;
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
Test(const Test&);
|
||||
Test& operator=(const Test&);
|
||||
};
|
||||
|
||||
std::string m_sampleName;
|
||||
std::string m_geomFileName;
|
||||
Test* m_tests;
|
||||
|
||||
void resetTimes();
|
||||
|
||||
public:
|
||||
TestCase();
|
||||
~TestCase();
|
||||
|
||||
bool load(const std::string& filePath);
|
||||
|
||||
const std::string& getSampleName() const { return m_sampleName; }
|
||||
const std::string& getGeomFileName() const { return m_geomFileName; }
|
||||
|
||||
void doTests(class dtNavMesh* navmesh, class dtNavMeshQuery* navquery);
|
||||
|
||||
void handleRender();
|
||||
bool handleRenderOverlay(double* proj, double* model, int* view);
|
||||
|
||||
private:
|
||||
// Explicitly disabled copy constructor and copy assignment operator.
|
||||
TestCase(const TestCase&);
|
||||
TestCase& operator=(const TestCase&);
|
||||
};
|
||||
|
||||
#endif // TESTCASE_H
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef VALUEHISTORY_H
|
||||
#define VALUEHISTORY_H
|
||||
|
||||
class ValueHistory
|
||||
{
|
||||
static const int MAX_HISTORY = 256;
|
||||
float m_samples[MAX_HISTORY];
|
||||
int m_hsamples;
|
||||
public:
|
||||
ValueHistory();
|
||||
|
||||
inline void addSample(const float val)
|
||||
{
|
||||
m_hsamples = (m_hsamples+MAX_HISTORY-1) % MAX_HISTORY;
|
||||
m_samples[m_hsamples] = val;
|
||||
}
|
||||
|
||||
inline int getSampleCount() const
|
||||
{
|
||||
return MAX_HISTORY;
|
||||
}
|
||||
|
||||
inline float getSample(const int i) const
|
||||
{
|
||||
return m_samples[(m_hsamples+i) % MAX_HISTORY];
|
||||
}
|
||||
|
||||
float getSampleMin() const;
|
||||
float getSampleMax() const;
|
||||
float getAverage() const;
|
||||
};
|
||||
|
||||
struct GraphParams
|
||||
{
|
||||
void setRect(int ix, int iy, int iw, int ih, int ipad);
|
||||
void setValueRange(float ivmin, float ivmax, int indiv, const char* iunits);
|
||||
|
||||
int x, y, w, h, pad;
|
||||
float vmin, vmax;
|
||||
int ndiv;
|
||||
char units[16];
|
||||
};
|
||||
|
||||
void drawGraphBackground(const GraphParams* p);
|
||||
|
||||
void drawGraph(const GraphParams* p, const ValueHistory* graph,
|
||||
int idx, const char* label, const unsigned int col);
|
||||
|
||||
|
||||
#endif // VALUEHISTORY_H
|
||||
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// 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 IMGUI_H
|
||||
#define IMGUI_H
|
||||
|
||||
enum imguiMouseButton
|
||||
{
|
||||
IMGUI_MBUT_LEFT = 0x01,
|
||||
IMGUI_MBUT_RIGHT = 0x02,
|
||||
};
|
||||
|
||||
enum imguiTextAlign
|
||||
{
|
||||
IMGUI_ALIGN_LEFT,
|
||||
IMGUI_ALIGN_CENTER,
|
||||
IMGUI_ALIGN_RIGHT,
|
||||
};
|
||||
|
||||
inline unsigned int imguiRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
|
||||
{
|
||||
return (r) | (g << 8) | (b << 16) | (a << 24);
|
||||
}
|
||||
|
||||
void imguiBeginFrame(int mx, int my, unsigned char mbut, int scroll);
|
||||
void imguiEndFrame();
|
||||
|
||||
bool imguiBeginScrollArea(const char* name, int x, int y, int w, int h, int* scroll);
|
||||
void imguiEndScrollArea();
|
||||
|
||||
void imguiIndent();
|
||||
void imguiUnindent();
|
||||
void imguiSeparator();
|
||||
void imguiSeparatorLine();
|
||||
|
||||
bool imguiButton(const char* text, bool enabled = true);
|
||||
bool imguiItem(const char* text, bool enabled = true);
|
||||
bool imguiCheck(const char* text, bool checked, bool enabled = true);
|
||||
bool imguiCollapse(const char* text, const char* subtext, bool checked, bool enabled = true);
|
||||
void imguiLabel(const char* text);
|
||||
void imguiValue(const char* text);
|
||||
bool imguiSlider(const char* text, float* val, float vmin, float vmax, float vinc, bool enabled = true);
|
||||
|
||||
void imguiDrawText(int x, int y, int align, const char* text, unsigned int color);
|
||||
void imguiDrawLine(float x0, float y0, float x1, float y1, float r, unsigned int color);
|
||||
void imguiDrawRoundedRect(float x, float y, float w, float h, float r, unsigned int color);
|
||||
void imguiDrawRect(float x, float y, float w, float h, unsigned int color);
|
||||
|
||||
// Pull render interface.
|
||||
enum imguiGfxCmdType
|
||||
{
|
||||
IMGUI_GFXCMD_RECT,
|
||||
IMGUI_GFXCMD_TRIANGLE,
|
||||
IMGUI_GFXCMD_LINE,
|
||||
IMGUI_GFXCMD_TEXT,
|
||||
IMGUI_GFXCMD_SCISSOR,
|
||||
};
|
||||
|
||||
struct imguiGfxRect
|
||||
{
|
||||
short x,y,w,h,r;
|
||||
};
|
||||
|
||||
struct imguiGfxText
|
||||
{
|
||||
short x,y,align;
|
||||
const char* text;
|
||||
};
|
||||
|
||||
struct imguiGfxLine
|
||||
{
|
||||
short x0,y0,x1,y1,r;
|
||||
};
|
||||
|
||||
struct imguiGfxCmd
|
||||
{
|
||||
char type;
|
||||
char flags;
|
||||
char pad[2];
|
||||
unsigned int col;
|
||||
union
|
||||
{
|
||||
imguiGfxLine line;
|
||||
imguiGfxRect rect;
|
||||
imguiGfxText text;
|
||||
};
|
||||
};
|
||||
|
||||
const imguiGfxCmd* imguiGetRenderQueue();
|
||||
int imguiGetRenderQueueSize();
|
||||
|
||||
|
||||
#endif // IMGUI_H
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// 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 IMGUI_RENDER_GL_H
|
||||
#define IMGUI_RENDER_GL_H
|
||||
|
||||
bool imguiRenderGLInit(const char* fontpath);
|
||||
void imguiRenderGLDestroy();
|
||||
void imguiRenderGLDraw();
|
||||
|
||||
#endif // IMGUI_RENDER_GL_H
|
||||
Reference in New Issue
Block a user