TrinityCore
|
#include <DetourNavMesh.h>
Public Member Functions | |
dtNavMesh () | |
~dtNavMesh () | |
Initialization and Tile Management | |
dtStatus | init (const dtNavMeshParams *params) |
dtStatus | init (unsigned char *data, const int dataSize, const int flags) |
const dtNavMeshParams * | getParams () const |
The navigation mesh initialization params. More... | |
dtStatus | addTile (unsigned char *data, int dataSize, int flags, dtTileRef lastRef, dtTileRef *result) |
dtStatus | removeTile (dtTileRef ref, unsigned char **data, int *dataSize) |
Query Functions | |
void | calcTileLoc (const float *pos, int *tx, int *ty) const |
const dtMeshTile * | getTileAt (const int x, const int y, const int layer) const |
int | getTilesAt (const int x, const int y, dtMeshTile const **tiles, const int maxTiles) const |
dtTileRef | getTileRefAt (int x, int y, int layer) const |
dtTileRef | getTileRef (const dtMeshTile *tile) const |
const dtMeshTile * | getTileByRef (dtTileRef ref) const |
int | getMaxTiles () const |
const dtMeshTile * | getTile (int i) const |
dtStatus | getTileAndPolyByRef (const dtPolyRef ref, const dtMeshTile **tile, const dtPoly **poly) const |
void | getTileAndPolyByRefUnsafe (const dtPolyRef ref, const dtMeshTile **tile, const dtPoly **poly) const |
bool | isValidPolyRef (dtPolyRef ref) const |
dtPolyRef | getPolyRefBase (const dtMeshTile *tile) const |
dtStatus | getOffMeshConnectionPolyEndPoints (dtPolyRef prevRef, dtPolyRef polyRef, float *startPos, float *endPos) const |
const dtOffMeshConnection * | getOffMeshConnectionByRef (dtPolyRef ref) const |
State Management | |
dtStatus | setPolyFlags (dtPolyRef ref, unsigned short flags) |
dtStatus | getPolyFlags (dtPolyRef ref, unsigned short *resultFlags) const |
dtStatus | setPolyArea (dtPolyRef ref, unsigned char area) |
dtStatus | getPolyArea (dtPolyRef ref, unsigned char *resultArea) const |
int | getTileStateSize (const dtMeshTile *tile) const |
dtStatus | storeTileState (const dtMeshTile *tile, unsigned char *data, const int maxDataSize) const |
dtStatus | restoreTileState (dtMeshTile *tile, const unsigned char *data, const int maxDataSize) |
Encoding and Decoding | |
These functions are generally meant for internal use only. | |
dtPolyRef | encodePolyId (unsigned int salt, unsigned int it, unsigned int ip) const |
void | decodePolyId (dtPolyRef ref, unsigned int &salt, unsigned int &it, unsigned int &ip) const |
unsigned int | decodePolyIdSalt (dtPolyRef ref) const |
unsigned int | decodePolyIdTile (dtPolyRef ref) const |
unsigned int | decodePolyIdPoly (dtPolyRef ref) const |
Private Member Functions | |
dtMeshTile * | getTile (int i) |
Returns pointer to tile in the tile array. More... | |
int | getTilesAt (const int x, const int y, dtMeshTile **tiles, const int maxTiles) const |
Returns neighbour tile based on side. More... | |
int | getNeighbourTilesAt (const int x, const int y, const int side, dtMeshTile **tiles, const int maxTiles) const |
Returns neighbour tile based on side. More... | |
int | findConnectingPolys (const float *va, const float *vb, const dtMeshTile *tile, int side, dtPolyRef *con, float *conarea, int maxcon) const |
Returns all polygons in neighbour tile based on portal defined by the segment. More... | |
void | connectIntLinks (dtMeshTile *tile) |
Builds internal polygons links for a tile. More... | |
void | baseOffMeshLinks (dtMeshTile *tile) |
Builds internal polygons links for a tile. More... | |
void | connectExtLinks (dtMeshTile *tile, dtMeshTile *target, int side) |
Builds external polygon links for a tile. More... | |
void | connectExtOffMeshLinks (dtMeshTile *tile, dtMeshTile *target, int side) |
Builds external polygon links for a tile. More... | |
void | unconnectExtLinks (dtMeshTile *tile, dtMeshTile *target) |
Removes external links at specified side. More... | |
int | queryPolygonsInTile (const dtMeshTile *tile, const float *qmin, const float *qmax, dtPolyRef *polys, const int maxPolys) const |
Queries polygons within a tile. More... | |
dtPolyRef | findNearestPolyInTile (const dtMeshTile *tile, const float *center, const float *extents, float *nearestPt) const |
Find nearest polygon within a tile. More... | |
void | closestPointOnPoly (dtPolyRef ref, const float *pos, float *closest, bool *posOverPoly) const |
Returns closest point on polygon. More... | |
Private Attributes | |
dtNavMeshParams | m_params |
Current initialization params. TODO: do not store this info twice. More... | |
float | m_orig [3] |
Origin of the tile (0,0) More... | |
float | m_tileWidth |
float | m_tileHeight |
Dimensions of each tile. More... | |
int | m_maxTiles |
Max number of tiles. More... | |
int | m_tileLutSize |
Tile hash lookup size (must be pot). More... | |
int | m_tileLutMask |
Tile hash lookup mask. More... | |
dtMeshTile ** | m_posLookup |
Tile hash lookup. More... | |
dtMeshTile * | m_nextFree |
Freelist of tiles. More... | |
dtMeshTile * | m_tiles |
List of tiles. More... | |
unsigned int | m_saltBits |
Number of salt bits in the tile ID. More... | |
unsigned int | m_tileBits |
Number of tile bits in the tile ID. More... | |
unsigned int | m_polyBits |
Number of poly bits in the tile ID. More... | |
A navigation mesh based on tiles of convex polygons.
The navigation mesh consists of one or more tiles defining three primary types of structural data:
A polygon mesh which defines most of the navigation graph. (See rcPolyMesh for its structure.) A detail mesh used for determining surface height on the polygon mesh. (See rcPolyMeshDetail for its structure.) Off-mesh connections, which define custom point-to-point edges within the navigation graph.
The general build process is as follows:
Notes:
dtNavMesh::dtNavMesh | ( | ) |
dtNavMesh::~dtNavMesh | ( | ) |
dtStatus dtNavMesh::addTile | ( | unsigned char * | data, |
int | dataSize, | ||
int | flags, | ||
dtTileRef | lastRef, | ||
dtTileRef * | result | ||
) |
Adds a tile to the navigation mesh.
[in] | data | Data for the new tile mesh. (See: dtCreateNavMeshData) |
[in] | dataSize | Data size of the new tile mesh. |
[in] | flags | Tile flags. (See: dtTileFlags) |
[in] | lastRef | The desired reference for the tile. (When reloading a tile.) [opt] [Default: 0] |
[out] | result | The tile reference. (If the tile was succesfully added.) [opt] |
The add operation will fail if the data is in the wrong format, the allocated tile space is full, or there is a tile already at the specified reference.
The lastRef parameter is used to restore a tile with the same tile reference it had previously used. In this case the dtPolyRef's for the tile will be restored to the same values they were before the tile was removed.
|
private |
Builds internal polygons links for a tile.
void dtNavMesh::calcTileLoc | ( | const float * | pos, |
int * | tx, | ||
int * | ty | ||
) | const |
Calculates the tile grid location for the specified world position.
[in] | pos | The world position for the query. [(x, y, z)] |
[out] | tx | The tile's x-location. (x, y) |
[out] | ty | The tile's y-location. (x, y) |
|
private |
Returns closest point on polygon.
|
private |
Builds external polygon links for a tile.
|
private |
Builds external polygon links for a tile.
|
private |
Builds internal polygons links for a tile.
|
inline |
Decodes a standard polygon reference.
[in] | ref | The polygon reference to decode. |
[out] | salt | The tile's salt value. |
[out] | it | The index of the tile. |
[out] | ip | The index of the polygon within the tile. |
|
inline |
Extracts the polygon's index (within its tile) from the specified polygon reference.
[in] | ref | The polygon reference. |
|
inline |
Extracts a tile's salt value from the specified polygon reference.
[in] | ref | The polygon reference. |
|
inline |
Extracts the tile's index from the specified polygon reference.
[in] | ref | The polygon reference. |
|
inline |
Derives a standard polygon reference.
[in] | salt | The tile's salt value. |
[in] | it | The index of the tile. |
[in] | ip | The index of the polygon within the tile. |
|
private |
Returns all polygons in neighbour tile based on portal defined by the segment.
|
private |
Find nearest polygon within a tile.
int dtNavMesh::getMaxTiles | ( | ) | const |
The maximum number of tiles supported by the navigation mesh.
|
private |
Returns neighbour tile based on side.
const dtOffMeshConnection * dtNavMesh::getOffMeshConnectionByRef | ( | dtPolyRef | ref | ) | const |
Gets the specified off-mesh connection.
[in] | ref | The polygon reference of the off-mesh connection. |
dtStatus dtNavMesh::getOffMeshConnectionPolyEndPoints | ( | dtPolyRef | prevRef, |
dtPolyRef | polyRef, | ||
float * | startPos, | ||
float * | endPos | ||
) | const |
Gets the endpoints for an off-mesh connection, ordered by "direction of travel".
[in] | prevRef | The reference of the polygon before the connection. |
[in] | polyRef | The reference of the off-mesh connection polygon. |
[out] | startPos | The start position of the off-mesh connection. [(x, y, z)] |
[out] | endPos | The end position of the off-mesh connection. [(x, y, z)] |
Off-mesh connections are stored in the navigation mesh as special 2-vertex polygons with a single edge. At least one of the vertices is expected to be inside a normal polygon. So an off-mesh connection is "entered" from a normal polygon at one of its endpoints. This is the polygon identified by the prevRef parameter.
const dtNavMeshParams * dtNavMesh::getParams | ( | ) | const |
The navigation mesh initialization params.
Gets the user defined area for the specified polygon.
[in] | ref | The polygon reference. |
[out] | resultArea | The area id for the polygon. |
Gets the user defined flags for the specified polygon.
[in] | ref | The polygon reference. |
[out] | resultFlags | The polygon flags. |
dtPolyRef dtNavMesh::getPolyRefBase | ( | const dtMeshTile * | tile | ) | const |
Gets the polygon reference for the tile's base polygon.
[in] | tile | The tile. |
Example use case:
const dtMeshTile * dtNavMesh::getTile | ( | int | i | ) | const |
Gets the tile at the specified index.
[in] | i | The tile index. [Limit: 0 >= index < getMaxTiles()] |
|
private |
Returns pointer to tile in the tile array.
dtStatus dtNavMesh::getTileAndPolyByRef | ( | const dtPolyRef | ref, |
const dtMeshTile ** | tile, | ||
const dtPoly ** | poly | ||
) | const |
Gets the tile and polygon for the specified polygon reference.
[in] | ref | The reference for the a polygon. |
[out] | tile | The tile containing the polygon. |
[out] | poly | The polygon. |
void dtNavMesh::getTileAndPolyByRefUnsafe | ( | const dtPolyRef | ref, |
const dtMeshTile ** | tile, | ||
const dtPoly ** | poly | ||
) | const |
Returns the tile and polygon for the specified polygon reference.
[in] | ref | A known valid reference for a polygon. |
[out] | tile | The tile containing the polygon. |
[out] | poly | The polygon. |
const dtMeshTile * dtNavMesh::getTileAt | ( | const int | x, |
const int | y, | ||
const int | layer | ||
) | const |
Gets the tile at the specified grid location.
[in] | x | The tile's x-location. (x, y, layer) |
[in] | y | The tile's y-location. (x, y, layer) |
[in] | layer | The tile's layer. (x, y, layer) |
const dtMeshTile * dtNavMesh::getTileByRef | ( | dtTileRef | ref | ) | const |
Gets the tile for the specified tile reference.
[in] | ref | The tile reference of the tile to retrieve. |
dtTileRef dtNavMesh::getTileRef | ( | const dtMeshTile * | tile | ) | const |
Gets the tile reference for the specified tile.
[in] | tile | The tile. |
dtTileRef dtNavMesh::getTileRefAt | ( | int | x, |
int | y, | ||
int | layer | ||
) | const |
Gets the tile reference for the tile at specified grid location.
[in] | x | The tile's x-location. (x, y, layer) |
[in] | y | The tile's y-location. (x, y, layer) |
[in] | layer | The tile's layer. (x, y, layer) |
int dtNavMesh::getTilesAt | ( | const int | x, |
const int | y, | ||
dtMeshTile const ** | tiles, | ||
const int | maxTiles | ||
) | const |
Gets all tiles at the specified grid location. (All layers.)
[in] | x | The tile's x-location. (x, y) |
[in] | y | The tile's y-location. (x, y) |
[out] | tiles | A pointer to an array of tiles that will hold the result. |
[in] | maxTiles | The maximum tiles the tiles parameter can hold. |
This function will not fail if the tiles array is too small to hold the entire result set. It will simply fill the array to capacity.
|
private |
Returns neighbour tile based on side.
int dtNavMesh::getTileStateSize | ( | const dtMeshTile * | tile | ) | const |
Gets the size of the buffer required by storeTileState to store the specified tile's state.
[in] | tile | The tile. |
dtStatus dtNavMesh::init | ( | const dtNavMeshParams * | params | ) |
Initializes the navigation mesh for tiled use.
[in] | params | Initialization parameters. |
Initializes the navigation mesh for single tile use.
[in] | data | Data of the new tile. (See: dtCreateNavMeshData) |
[in] | dataSize | The data size of the new tile. |
[in] | flags | The tile flags. (See: dtTileFlags) |
Checks the validity of a polygon reference.
[in] | ref | The polygon reference to check. |
|
private |
Queries polygons within a tile.
Removes the specified tile from the navigation mesh.
[in] | ref | The reference of the tile to remove. |
[out] | data | Data associated with deleted tile. |
[out] | dataSize | Size of the data associated with deleted tile. |
This function returns the data for the tile so that, if desired, it can be added back to the navigation mesh at a later point.
dtStatus dtNavMesh::restoreTileState | ( | dtMeshTile * | tile, |
const unsigned char * | data, | ||
const int | maxDataSize | ||
) |
Restores the state of the tile.
[in] | tile | The tile. |
[in] | data | The new state. (Obtained from storeTileState.) |
[in] | maxDataSize | The size of the state within the data buffer. |
Tile state includes non-structural data such as polygon flags, area ids, etc.
Sets the user defined area for the specified polygon.
[in] | ref | The polygon reference. |
[in] | area | The new area id for the polygon. [Limit: < DT_MAX_AREAS] |
Sets the user defined flags for the specified polygon.
[in] | ref | The polygon reference. |
[in] | flags | The new flags for the polygon. |
dtStatus dtNavMesh::storeTileState | ( | const dtMeshTile * | tile, |
unsigned char * | data, | ||
const int | maxDataSize | ||
) | const |
Stores the non-structural state of the tile in the specified buffer. (Flags, area ids, etc.)
[in] | tile | The tile. |
[out] | data | The buffer to store the tile's state in. |
[in] | maxDataSize | The size of the data buffer. [Limit: >= getTileStateSize] |
Tile state includes non-structural data such as polygon flags, area ids, etc.
|
private |
Removes external links at specified side.
|
private |
Max number of tiles.
|
private |
Freelist of tiles.
|
private |
Origin of the tile (0,0)
|
private |
Current initialization params. TODO: do not store this info twice.
|
private |
Number of poly bits in the tile ID.
|
private |
Tile hash lookup.
|
private |
Number of salt bits in the tile ID.
|
private |
Number of tile bits in the tile ID.
|
private |
Dimensions of each tile.
|
private |
Tile hash lookup mask.
|
private |
Tile hash lookup size (must be pot).
|
private |
List of tiles.
|
private |