19#ifndef DETOURNAVMESH_H
20#define DETOURNAVMESH_H
22#include "DetourAlloc.h"
23#include "DetourStatus.h"
43static const unsigned int DT_SALT_BITS = 16;
44static const unsigned int DT_TILE_BITS = 28;
45static const unsigned int DT_POLY_BITS = 20;
61static const int DT_VERTS_PER_POLYGON = 6;
70static const int DT_NAVMESH_MAGIC =
'D'<<24 |
'N'<<16 |
'A'<<8 |
'V';
73static const int DT_NAVMESH_VERSION = 7;
76static const int DT_NAVMESH_STATE_MAGIC =
'D'<<24 |
'N'<<16 |
'M'<<8 |
'S';
79static const int DT_NAVMESH_STATE_VERSION = 1;
85static const unsigned short DT_EXT_LINK = 0x8000;
88static const unsigned int DT_NULL_LINK = 0xffffffff;
91static const unsigned int DT_OFFMESH_CON_BIDIR = 1;
95static const int DT_MAX_AREAS = 64;
102 DT_TILE_FREE_DATA = 0x01,
106enum dtStraightPathFlags
108 DT_STRAIGHTPATH_START = 0x01,
109 DT_STRAIGHTPATH_END = 0x02,
110 DT_STRAIGHTPATH_OFFMESH_CONNECTION = 0x04,
114enum dtStraightPathOptions
116 DT_STRAIGHTPATH_AREA_CROSSINGS = 0x01,
117 DT_STRAIGHTPATH_ALL_CROSSINGS = 0x02,
122enum dtFindPathOptions
124 DT_FINDPATH_ANY_ANGLE = 0x02,
130 DT_RAYCAST_USE_COSTS = 0x01,
133enum dtDetailTriEdgeFlags
135 DT_DETAIL_EDGE_BOUNDARY = 0x01,
141static const float DT_RAY_CAST_LIMIT_PROPORTIONS = 50.0f;
147 DT_POLYTYPE_GROUND = 0,
149 DT_POLYTYPE_OFFMESH_CONNECTION = 1,
162 unsigned short verts[DT_VERTS_PER_POLYGON];
165 unsigned short neis[DT_VERTS_PER_POLYGON];
318inline int dtGetDetailTriEdgeFlags(
unsigned char triFlags,
int edgeIndex)
320 return (triFlags >> (edgeIndex * 2)) & 0x3;
358 dtStatus
init(
unsigned char* data,
const int dataSize,
const int flags);
388 void calcTileLoc(
const float* pos,
int* tx,
int* ty)
const;
404 dtMeshTile const** tiles,
const int maxTiles)
const;
551 salt = (
unsigned int)((ref >> (DT_POLY_BITS+DT_TILE_BITS)) & saltMask);
552 it = (
unsigned int)((ref >> DT_POLY_BITS) & tileMask);
553 ip = (
unsigned int)(ref & polyMask);
558 salt = (
unsigned int)((ref >> (m_polyBits+m_tileBits)) & saltMask);
559 it = (
unsigned int)((ref >> m_polyBits) & tileMask);
560 ip = (
unsigned int)(ref & polyMask);
572 return (
unsigned int)((ref >> (DT_POLY_BITS+DT_TILE_BITS)) & saltMask);
575 return (
unsigned int)((ref >> (m_polyBits+m_tileBits)) & saltMask);
587 return (
unsigned int)((ref >> DT_POLY_BITS) & tileMask);
590 return (
unsigned int)((ref >> m_polyBits) & tileMask);
602 return (
unsigned int)(ref & polyMask);
605 return (
unsigned int)(ref & polyMask);
621 dtMeshTile** tiles,
const int maxTiles)
const;
624 int getNeighbourTilesAt(
const int x,
const int y,
const int side,
625 dtMeshTile** tiles,
const int maxTiles)
const;
628 int findConnectingPolys(
const float* va,
const float* vb,
630 dtPolyRef* con,
float* conarea,
int maxcon)
const;
649 int queryPolygonsInTile(
const dtMeshTile* tile,
const float* qmin,
const float* qmax,
650 dtPolyRef* polys,
const int maxPolys)
const;
653 const float* halfExtents,
float* nearestPt)
const;
655 bool getPolyHeight(
const dtMeshTile* tile,
const dtPoly* poly,
const float* pos,
float* height)
const;
657 void closestPointOnPoly(
dtPolyRef ref,
const float* pos,
float* closest,
bool* posOverPoly)
const;
661 float m_tileWidth, m_tileHeight;
671 unsigned int m_saltBits;
672 unsigned int m_tileBits;
673 unsigned int m_polyBits;
Definition DetourNavMeshQuery.h:166
Definition DetourNavMesh.h:339
dtStatus init(const dtNavMeshParams *params)
Definition DetourNavMesh.cpp:224
dtPolyRef getPolyRefBase(const dtMeshTile *tile) const
Definition DetourNavMesh.cpp:1356
dtStatus storeTileState(const dtMeshTile *tile, unsigned char *data, const int maxDataSize) const
Definition DetourNavMesh.cpp:1390
dtPolyRef encodePolyId(unsigned int salt, unsigned int it, unsigned int ip) const
Definition DetourNavMesh.h:529
int getMaxTiles() const
Definition DetourNavMesh.cpp:1176
int getTilesAt(const int x, const int y, dtMeshTile const **tiles, const int maxTiles) const
Definition DetourNavMesh.cpp:1120
const dtOffMeshConnection * getOffMeshConnectionByRef(dtPolyRef ref) const
Definition DetourNavMesh.cpp:1502
dtStatus getTileAndPolyByRef(const dtPolyRef ref, const dtMeshTile **tile, const dtPoly **poly) const
Definition DetourNavMesh.cpp:1197
const dtMeshTile * getTile(int i) const
Definition DetourNavMesh.cpp:1186
unsigned int decodePolyIdSalt(dtPolyRef ref) const
Definition DetourNavMesh.h:568
dtStatus addTile(unsigned char *data, int dataSize, int flags, dtTileRef lastRef, dtTileRef *result)
Definition DetourNavMesh.cpp:908
dtStatus removeTile(dtTileRef ref, unsigned char **data, int *dataSize)
Definition DetourNavMesh.cpp:1240
dtStatus getOffMeshConnectionPolyEndPoints(dtPolyRef prevRef, dtPolyRef polyRef, float *startPos, float *endPos) const
Definition DetourNavMesh.cpp:1459
dtTileRef getTileRef(const dtMeshTile *tile) const
Definition DetourNavMesh.cpp:1335
void calcTileLoc(const float *pos, int *tx, int *ty) const
Definition DetourNavMesh.cpp:1191
dtStatus setPolyArea(dtPolyRef ref, unsigned char area)
Definition DetourNavMesh.cpp:1560
bool isValidPolyRef(dtPolyRef ref) const
Definition DetourNavMesh.cpp:1223
dtTileRef getTileRefAt(int x, int y, int layer) const
Definition DetourNavMesh.cpp:1143
dtStatus getPolyFlags(dtPolyRef ref, unsigned short *resultFlags) const
Definition DetourNavMesh.cpp:1544
const dtNavMeshParams * getParams() const
The navigation mesh initialization params.
Definition DetourNavMesh.cpp:294
unsigned int decodePolyIdPoly(dtPolyRef ref) const
Definition DetourNavMesh.h:598
unsigned int decodePolyIdTile(dtPolyRef ref) const
Definition DetourNavMesh.h:583
dtStatus getPolyArea(dtPolyRef ref, unsigned char *resultArea) const
Definition DetourNavMesh.cpp:1576
int getTileStateSize(const dtMeshTile *tile) const
Definition DetourNavMesh.cpp:1377
void getTileAndPolyByRefUnsafe(const dtPolyRef ref, const dtMeshTile **tile, const dtPoly **poly) const
Definition DetourNavMesh.cpp:1215
const dtMeshTile * getTileByRef(dtTileRef ref) const
Definition DetourNavMesh.cpp:1162
const dtMeshTile * getTileAt(const int x, const int y, const int layer) const
Definition DetourNavMesh.cpp:1057
dtStatus restoreTileState(dtMeshTile *tile, const unsigned char *data, const int maxDataSize)
Definition DetourNavMesh.cpp:1422
dtStatus setPolyFlags(dtPolyRef ref, unsigned short flags)
Definition DetourNavMesh.cpp:1527
void decodePolyId(dtPolyRef ref, unsigned int &salt, unsigned int &it, unsigned int &ip) const
Definition DetourNavMesh.h:545
dtNavMesh * dtAllocNavMesh()
Definition DetourNavMesh.cpp:138
unsigned int dtTileRef
Definition DetourNavMesh.h:56
unsigned int dtPolyRef
Definition DetourNavMesh.h:48
void dtFreeNavMesh(dtNavMesh *navmesh)
Definition DetourNavMesh.cpp:149
uint64 uint64_t
Definition fwd.hpp:145
Definition DetourNavMesh.h:216
unsigned short bmin[3]
Minimum bounds of the node's AABB. [(x, y, z)].
Definition DetourNavMesh.h:217
int i
The node's index. (Negative for escape sequence.)
Definition DetourNavMesh.h:219
unsigned short bmax[3]
Maximum bounds of the node's AABB. [(x, y, z)].
Definition DetourNavMesh.h:218
Definition DetourNavMesh.h:203
unsigned char bmin
If a boundary link, defines the minimum sub-edge area.
Definition DetourNavMesh.h:208
unsigned char edge
Index of the polygon edge that owns this link.
Definition DetourNavMesh.h:206
dtPolyRef ref
Neighbour reference. (The neighbor that is linked to.)
Definition DetourNavMesh.h:204
unsigned int next
Index of the next link.
Definition DetourNavMesh.h:205
unsigned char side
If a boundary link, defines on which side the link is.
Definition DetourNavMesh.h:207
unsigned char bmax
If a boundary link, defines the maximum sub-edge area.
Definition DetourNavMesh.h:209
Definition DetourNavMesh.h:282
dtLink * links
The tile links. [Size: dtMeshHeader::maxLinkCount].
Definition DetourNavMesh.h:289
int dataSize
Size of the tile data.
Definition DetourNavMesh.h:306
dtBVNode * bvTree
Definition DetourNavMesh.h:301
unsigned int salt
Counter describing modifications to the tile.
Definition DetourNavMesh.h:283
unsigned char * detailTris
Definition DetourNavMesh.h:297
dtMeshTile * next
The next free tile, or the next tile in the spatial grid.
Definition DetourNavMesh.h:308
dtMeshHeader * header
The tile header.
Definition DetourNavMesh.h:286
float * detailVerts
The detail mesh's unique vertices. [(x, y, z) * dtMeshHeader::detailVertCount].
Definition DetourNavMesh.h:293
int flags
Tile flags. (See: dtTileFlags)
Definition DetourNavMesh.h:307
dtPolyDetail * detailMeshes
The tile's detail sub-meshes. [Size: dtMeshHeader::detailMeshCount].
Definition DetourNavMesh.h:290
dtOffMeshConnection * offMeshCons
The tile off-mesh connections. [Size: dtMeshHeader::offMeshConCount].
Definition DetourNavMesh.h:303
dtPoly * polys
The tile polygons. [Size: dtMeshHeader::polyCount].
Definition DetourNavMesh.h:287
float * verts
The tile vertices. [Size: dtMeshHeader::vertCount].
Definition DetourNavMesh.h:288
unsigned int linksFreeList
Index to the next free link.
Definition DetourNavMesh.h:285
unsigned char * data
The tile data. (Not directly accessed under normal situations.)
Definition DetourNavMesh.h:305
Definition DetourNavMesh.h:328
float orig[3]
The world space origin of the navigation mesh's tile space. [(x, y, z)].
Definition DetourNavMesh.h:329
int maxPolys
The maximum number of polygons each tile can contain. This and maxTiles are used to calculate how man...
Definition DetourNavMesh.h:333
float tileWidth
The width of each tile. (Along the x-axis.)
Definition DetourNavMesh.h:330
float tileHeight
The height of each tile. (Along the z-axis.)
Definition DetourNavMesh.h:331
int maxTiles
The maximum number of tiles the navigation mesh can contain. This and maxPolys are used to calculate ...
Definition DetourNavMesh.h:332
Definition DetourNavMesh.h:225
unsigned int userId
The id of the offmesh connection. (User assigned when the navigation mesh is built....
Definition DetourNavMesh.h:244
float pos[6]
The endpoints of the connection. [(ax, ay, az, bx, by, bz)].
Definition DetourNavMesh.h:227
unsigned short poly
The polygon reference of the connection within the tile.
Definition DetourNavMesh.h:233
unsigned char side
End point side.
Definition DetourNavMesh.h:241
unsigned char flags
Definition DetourNavMesh.h:238
float rad
The radius of the endpoints. [Limit: >= 0].
Definition DetourNavMesh.h:230
Defines the location of detail sub-mesh data within a dtMeshTile.
Definition DetourNavMesh.h:192
unsigned char vertCount
The number of vertices in the sub-mesh.
Definition DetourNavMesh.h:195
unsigned int triBase
The offset of the triangles in the dtMeshTile::detailTris array.
Definition DetourNavMesh.h:194
unsigned int vertBase
The offset of the vertices in the dtMeshTile::detailVerts array.
Definition DetourNavMesh.h:193
unsigned char triCount
The number of triangles in the sub-mesh.
Definition DetourNavMesh.h:196
Definition DetourNavMesh.h:156
unsigned char getType() const
Gets the polygon type. (See: dtPolyTypes)
Definition DetourNavMesh.h:187
unsigned short flags
The user defined polygon flags.
Definition DetourNavMesh.h:168
unsigned int firstLink
Index to first link in linked list. (Or DT_NULL_LINK if there is no link.)
Definition DetourNavMesh.h:158
void setArea(unsigned char a)
Sets the user defined area id. [Limit: < DT_MAX_AREAS].
Definition DetourNavMesh.h:178
unsigned char getArea() const
Gets the user defined area id.
Definition DetourNavMesh.h:184
unsigned short neis[DT_VERTS_PER_POLYGON]
Packed data representing neighbor polygons references and flags for each edge.
Definition DetourNavMesh.h:165
void setType(unsigned char t)
Sets the polygon type. (See: dtPolyTypes.)
Definition DetourNavMesh.h:181
unsigned short verts[DT_VERTS_PER_POLYGON]
Definition DetourNavMesh.h:162
unsigned char areaAndtype
Definition DetourNavMesh.h:175
unsigned char vertCount
The number of vertices in the polygon.
Definition DetourNavMesh.h:171