Recast Navigation
Navigation-mesh Toolset for Games
|
A navigation mesh based on tiles of convex polygons. More...
#include <DetourNavMesh.h>
Public Member Functions | |
dtNavMesh () | |
~dtNavMesh () | |
Initialization and Tile Management | |
dtStatus | init (const dtNavMeshParams *params) |
Initializes the navigation mesh for tiled use. More... | |
dtStatus | init (unsigned char *data, const int dataSize, const int flags) |
Initializes the navigation mesh for single tile use. More... | |
const dtNavMeshParams * | getParams () const |
The navigation mesh initialization params. More... | |
dtStatus | addTile (unsigned char *data, int dataSize, int flags, dtTileRef lastRef, dtTileRef *result) |
Adds a tile to the navigation mesh. More... | |
dtStatus | removeTile (dtTileRef ref, unsigned char **data, int *dataSize) |
Removes the specified tile from the navigation mesh. More... | |
Query Functions | |
void | calcTileLoc (const float *pos, int *tx, int *ty) const |
Calculates the tile grid location for the specified world position. More... | |
const dtMeshTile * | getTileAt (const int x, const int y, const int layer) const |
Gets the tile at the specified grid location. More... | |
int | getTilesAt (const int x, const int y, dtMeshTile const **tiles, const int maxTiles) const |
Gets all tiles at the specified grid location. More... | |
dtTileRef | getTileRefAt (int x, int y, int layer) const |
Gets the tile reference for the tile at specified grid location. More... | |
dtTileRef | getTileRef (const dtMeshTile *tile) const |
Gets the tile reference for the specified tile. More... | |
const dtMeshTile * | getTileByRef (dtTileRef ref) const |
Gets the tile for the specified tile reference. More... | |
int | getMaxTiles () const |
The maximum number of tiles supported by the navigation mesh. More... | |
const dtMeshTile * | getTile (int i) const |
Gets the tile at the specified index. More... | |
dtStatus | getTileAndPolyByRef (const dtPolyRef ref, const dtMeshTile **tile, const dtPoly **poly) const |
Gets the tile and polygon for the specified polygon reference. More... | |
void | getTileAndPolyByRefUnsafe (const dtPolyRef ref, const dtMeshTile **tile, const dtPoly **poly) const |
Returns the tile and polygon for the specified polygon reference. More... | |
bool | isValidPolyRef (dtPolyRef ref) const |
Checks the validity of a polygon reference. More... | |
dtPolyRef | getPolyRefBase (const dtMeshTile *tile) const |
Gets the polygon reference for the tile's base polygon. More... | |
dtStatus | getOffMeshConnectionPolyEndPoints (dtPolyRef prevRef, dtPolyRef polyRef, float *startPos, float *endPos) const |
Gets the endpoints for an off-mesh connection, ordered by "direction of travel". More... | |
const dtOffMeshConnection * | getOffMeshConnectionByRef (dtPolyRef ref) const |
Gets the specified off-mesh connection. More... | |
State Management | |
dtStatus | setPolyFlags (dtPolyRef ref, unsigned short flags) |
Sets the user defined flags for the specified polygon. More... | |
dtStatus | getPolyFlags (dtPolyRef ref, unsigned short *resultFlags) const |
Gets the user defined flags for the specified polygon. More... | |
dtStatus | setPolyArea (dtPolyRef ref, unsigned char area) |
Sets the user defined area for the specified polygon. More... | |
dtStatus | getPolyArea (dtPolyRef ref, unsigned char *resultArea) const |
Gets the user defined area for the specified polygon. More... | |
int | getTileStateSize (const dtMeshTile *tile) const |
Gets the size of the buffer required by storeTileState to store the specified tile's state. More... | |
dtStatus | storeTileState (const dtMeshTile *tile, unsigned char *data, const int maxDataSize) const |
Stores the non-structural state of the tile in the specified buffer. More... | |
dtStatus | restoreTileState (dtMeshTile *tile, const unsigned char *data, const int maxDataSize) |
Restores the state of the tile. More... | |
Encoding and Decoding | |
These functions are generally meant for internal use only. | |
dtPolyRef | encodePolyId (unsigned int salt, unsigned int it, unsigned int ip) const |
Derives a standard polygon reference. More... | |
void | decodePolyId (dtPolyRef ref, unsigned int &salt, unsigned int &it, unsigned int &ip) const |
Decodes a standard polygon reference. More... | |
unsigned int | decodePolyIdSalt (dtPolyRef ref) const |
Extracts a tile's salt value from the specified polygon reference. More... | |
unsigned int | decodePolyIdTile (dtPolyRef ref) const |
Extracts the tile's index from the specified polygon reference. More... | |
unsigned int | decodePolyIdPoly (dtPolyRef ref) const |
Extracts the polygon's index (within its tile) from the specified polygon reference. More... | |
Friends | |
class | dtNavMeshQuery |
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.
The nav mesh assumes exclusive access to the data passed and will make changes to the dynamic portion of the data. For that reason the data should not be reused in other nav meshes until the tile has been successfully removed from this nav mesh.
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) |
|
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. |
int dtNavMesh::getMaxTiles | ( | ) | const |
The maximum number of tiles supported by the navigation mesh.
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()] |
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.
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. |
dtStatus dtNavMesh::init | ( | unsigned char * | data, |
const int | dataSize, | ||
const int | flags | ||
) |
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) |
bool dtNavMesh::isValidPolyRef | ( | dtPolyRef | ref | ) | const |
Checks the validity of a polygon reference.
[in] | ref | The polygon reference to check. |
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.
|
friend |