Changed header comments to use Doxygen format and added configuration Doxyfile.

This commit is contained in:
Cameron hart 2011-05-06 23:22:08 +00:00
parent 69f00ef893
commit d5729c678b
20 changed files with 2567 additions and 896 deletions

View File

@ -30,7 +30,7 @@ enum duDebugDrawPrimitives
DU_DRAW_QUADS,
};
// Abstrace debug draw interface.
/// Abstract debug draw interface.
struct duDebugDraw
{
virtual ~duDebugDraw() = 0;
@ -39,38 +39,32 @@ struct duDebugDraw
virtual void texture(bool state) = 0;
// Begin drawing primitives.
// Params:
// prim - (in) primitive type to draw, one of rcDebugDrawPrimitives.
// nverts - (in) number of vertices to be submitted.
// size - (in) size of a primitive, applies to point size and line width only.
/// Begin drawing primitives.
/// @param prim [in] primitive type to draw, one of rcDebugDrawPrimitives.
/// @param size [in] size of a primitive, applies to point size and line width only.
virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f) = 0;
// Submit a vertex
// Params:
// pos - (in) position of the verts.
// color - (in) color of the verts.
/// Submit a vertex
/// @param pos [in] position of the verts.
/// @param color [in] color of the verts.
virtual void vertex(const float* pos, unsigned int color) = 0;
// Submit a vertex
// Params:
// x,y,z - (in) position of the verts.
// color - (in) color of the verts.
/// Submit a vertex
/// @param x,y,z [in] position of the verts.
/// @param color [in] color of the verts.
virtual void vertex(const float x, const float y, const float z, unsigned int color) = 0;
// Submit a vertex
// Params:
// pos - (in) position of the verts.
// color - (in) color of the verts.
/// Submit a vertex
/// @param pos [in] position of the verts.
/// @param color [in] color of the verts.
virtual void vertex(const float* pos, unsigned int color, const float* uv) = 0;
// Submit a vertex
// Params:
// x,y,z - (in) position of the verts.
// color - (in) color of the verts.
/// Submit a vertex
/// @param x,y,z [in] position of the verts.
/// @param color [in] color of the verts.
virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v) = 0;
// End drawing primitives.
/// End drawing primitives.
virtual void end() = 0;
};

View File

@ -21,8 +21,8 @@
enum dtAllocHint
{
DT_ALLOC_PERM, // Memory persist after a function call.
DT_ALLOC_TEMP // Memory used temporarily within a function.
DT_ALLOC_PERM, ///< Memory persist after a function call.
DT_ALLOC_TEMP ///< Memory used temporarily within a function.
};
typedef void* (dtAllocFunc)(int size, dtAllocHint hint);

View File

@ -26,19 +26,19 @@
// Note: If you want to use 64-bit refs, change the types of both dtPolyRef & dtTileRef.
// It is also recommended to change dtHashRef() to proper 64-bit hash too.
// Reference to navigation polygon.
/// Reference to navigation polygon.
typedef unsigned int dtPolyRef;
// Reference to navigation mesh tile.
/// Reference to navigation mesh tile.
typedef unsigned int dtTileRef;
// Maximum number of vertices per navigation polygon.
/// Maximum number of vertices per navigation polygon.
static const int DT_VERTS_PER_POLYGON = 6;
static const int DT_NAVMESH_MAGIC = 'D'<<24 | 'N'<<16 | 'A'<<8 | 'V'; //'DNAV';
static const int DT_NAVMESH_MAGIC = 'D'<<24 | 'N'<<16 | 'A'<<8 | 'V'; ///< 'DNAV'
static const int DT_NAVMESH_VERSION = 7;
static const int DT_NAVMESH_STATE_MAGIC = 'D'<<24 | 'N'<<16 | 'M'<<8 | 'S'; //'DNMS';
static const int DT_NAVMESH_STATE_MAGIC = 'D'<<24 | 'N'<<16 | 'M'<<8 | 'S'; ///< 'DNMS'
static const int DT_NAVMESH_STATE_VERSION = 1;
static const unsigned short DT_EXT_LINK = 0x8000;
@ -47,127 +47,127 @@ static const unsigned int DT_OFFMESH_CON_BIDIR = 1;
static const int DT_MAX_AREAS = 64;
// Flags for addTile
/// Flags for addTile
enum dtTileFlags
{
DT_TILE_FREE_DATA = 0x01, // Navmesh owns the tile memory and should free it.
DT_TILE_FREE_DATA = 0x01, ///< Navmesh owns the tile memory and should free it.
};
// Flags returned by findStraightPath().
/// Flags returned by findStraightPath().
enum dtStraightPathFlags
{
DT_STRAIGHTPATH_START = 0x01, // The vertex is the start position.
DT_STRAIGHTPATH_END = 0x02, // The vertex is the end position.
DT_STRAIGHTPATH_OFFMESH_CONNECTION = 0x04, // The vertex is start of an off-mesh link.
DT_STRAIGHTPATH_START = 0x01, ///< The vertex is the start position.
DT_STRAIGHTPATH_END = 0x02, ///< The vertex is the end position.
DT_STRAIGHTPATH_OFFMESH_CONNECTION = 0x04, ///< The vertex is start of an off-mesh link.
};
// Flags describing polygon properties.
/// Flags describing polygon properties.
enum dtPolyTypes
{
DT_POLYTYPE_GROUND = 0, // Regular ground polygons.
DT_POLYTYPE_OFFMESH_CONNECTION = 1, // Off-mesh connections.
DT_POLYTYPE_GROUND = 0, ///< Regular ground polygons.
DT_POLYTYPE_OFFMESH_CONNECTION = 1, ///< Off-mesh connections.
};
// Structure describing the navigation polygon data.
/// Structure describing the navigation polygon data.
struct dtPoly
{
unsigned int firstLink; // Index to first link in linked list.
unsigned short verts[DT_VERTS_PER_POLYGON]; // Indices to vertices of the poly.
unsigned short neis[DT_VERTS_PER_POLYGON]; // Refs to neighbours of the poly.
unsigned short flags; // Flags (see dtPolyFlags).
unsigned char vertCount; // Number of vertices.
unsigned char areaAndtype; // Bit packed: Area ID of the polygon, and Polygon type, see dtPolyTypes..
unsigned int firstLink; ///< Index to first link in linked list.
unsigned short verts[DT_VERTS_PER_POLYGON]; ///< Indices to vertices of the poly.
unsigned short neis[DT_VERTS_PER_POLYGON]; ///< Refs to neighbours of the poly.
unsigned short flags; ///< Flags (see dtPolyFlags).
unsigned char vertCount; ///< Number of vertices.
unsigned char areaAndtype; ///< Bit packed: Area ID of the polygon, and Polygon type, see dtPolyTypes..
inline void setArea(unsigned char a) { areaAndtype = (areaAndtype & 0xc0) | (a & 0x3f); }
inline void setType(unsigned char t) { areaAndtype = (areaAndtype & 0x3f) | (t << 6); }
inline unsigned char getArea() const { return areaAndtype & 0x3f; }
inline unsigned char getType() const { return areaAndtype >> 6; }
};
// Stucture describing polygon detail triangles.
/// Stucture describing polygon detail triangles.
struct dtPolyDetail
{
unsigned int vertBase; // Offset to detail vertex array.
unsigned int triBase; // Offset to detail triangle array.
unsigned char vertCount; // Number of vertices in the detail mesh.
unsigned char triCount; // Number of triangles.
unsigned int vertBase; ///< Offset to detail vertex array.
unsigned int triBase; ///< Offset to detail triangle array.
unsigned char vertCount; ///< Number of vertices in the detail mesh.
unsigned char triCount; ///< Number of triangles.
};
// Stucture describing a link to another polygon.
/// Stucture describing a link to another polygon.
struct dtLink
{
dtPolyRef ref; // Neighbour reference.
unsigned int next; // Index to next link.
unsigned char edge; // Index to polygon edge which owns this link.
unsigned char side; // If boundary link, defines on which side the link is.
unsigned char bmin, bmax; // If boundary link, defines the sub edge area.
dtPolyRef ref; ///< Neighbour reference.
unsigned int next; ///< Index to next link.
unsigned char edge; ///< Index to polygon edge which owns this link.
unsigned char side; ///< If boundary link, defines on which side the link is.
unsigned char bmin, bmax; ///< If boundary link, defines the sub edge area.
};
struct dtBVNode
{
unsigned short bmin[3], bmax[3]; // BVnode bounds
int i; // Index to item or if negative, escape index.
unsigned short bmin[3], bmax[3]; ///< BVnode bounds
int i; ///< Index to item or if negative, escape index.
};
struct dtOffMeshConnection
{
float pos[6]; // Both end point locations.
float rad; // Link connection radius.
unsigned short poly; // Poly Id
unsigned char flags; // Link flags
unsigned char side; // End point side.
unsigned int userId; // User ID to identify this connection.
float pos[6]; ///< Both end point locations.
float rad; ///< Link connection radius.
unsigned short poly; ///< Poly Id
unsigned char flags; ///< Link flags
unsigned char side; ///< End point side.
unsigned int userId; ///< User ID to identify this connection.
};
struct dtMeshHeader
{
int magic; // Magic number, used to identify the data.
int version; // Data version number.
int x, y, layer; // Location of the tile on the grid.
unsigned int userId; // User ID of the tile.
int polyCount; // Number of polygons in the tile.
int vertCount; // Number of vertices in the tile.
int maxLinkCount; // Number of allocated links.
int detailMeshCount; // Number of detail meshes.
int detailVertCount; // Number of detail vertices.
int detailTriCount; // Number of detail triangles.
int bvNodeCount; // Number of BVtree nodes.
int offMeshConCount; // Number of Off-Mesh links.
int offMeshBase; // Index to first polygon which is Off-Mesh link.
float walkableHeight; // Height of the agent.
float walkableRadius; // Radius of the agent
float walkableClimb; // Max climb height of the agent.
float bmin[3], bmax[3]; // Bounding box of the tile.
float bvQuantFactor; // BVtree quantization factor (world to bvnode coords)
int magic; ///< Magic number, used to identify the data.
int version; ///< Data version number.
int x, y, layer; ///< Location of the tile on the grid.
unsigned int userId; ///< User ID of the tile.
int polyCount; ///< Number of polygons in the tile.
int vertCount; ///< Number of vertices in the tile.
int maxLinkCount; ///< Number of allocated links.
int detailMeshCount; ///< Number of detail meshes.
int detailVertCount; ///< Number of detail vertices.
int detailTriCount; ///< Number of detail triangles.
int bvNodeCount; ///< Number of BVtree nodes.
int offMeshConCount; ///< Number of Off-Mesh links.
int offMeshBase; ///< Index to first polygon which is Off-Mesh link.
float walkableHeight; ///< Height of the agent.
float walkableRadius; ///< Radius of the agent
float walkableClimb; ///< Max climb height of the agent.
float bmin[3], bmax[3]; ///< Bounding box of the tile.
float bvQuantFactor; ///< BVtree quantization factor (world to bvnode coords)
};
struct dtMeshTile
{
unsigned int salt; // Counter describing modifications to the tile.
unsigned int salt; ///< Counter describing modifications to the tile.
unsigned int linksFreeList; // Index to next free link.
dtMeshHeader* header; // Pointer to tile header.
dtPoly* polys; // Pointer to the polygons (will be updated when tile is added).
float* verts; // Pointer to the vertices (will be updated when tile added).
dtLink* links; // Pointer to the links (will be updated when tile added).
dtPolyDetail* detailMeshes; // Pointer to detail meshes (will be updated when tile added).
float* detailVerts; // Pointer to detail vertices (will be updated when tile added).
unsigned char* detailTris; // Pointer to detail triangles (will be updated when tile added).
dtBVNode* bvTree; // Pointer to BVtree nodes (will be updated when tile added).
dtOffMeshConnection* offMeshCons; // Pointer to Off-Mesh links. (will be updated when tile added).
unsigned int linksFreeList; ///< Index to next free link.
dtMeshHeader* header; ///< Pointer to tile header.
dtPoly* polys; ///< Pointer to the polygons (will be updated when tile is added).
float* verts; ///< Pointer to the vertices (will be updated when tile added).
dtLink* links; ///< Pointer to the links (will be updated when tile added).
dtPolyDetail* detailMeshes; ///< Pointer to detail meshes (will be updated when tile added).
float* detailVerts; ///< Pointer to detail vertices (will be updated when tile added).
unsigned char* detailTris; ///< Pointer to detail triangles (will be updated when tile added).
dtBVNode* bvTree; ///< Pointer to BVtree nodes (will be updated when tile added).
dtOffMeshConnection* offMeshCons; ///< Pointer to Off-Mesh links. (will be updated when tile added).
unsigned char* data; // Pointer to tile data.
int dataSize; // Size of the tile data.
int flags; // Tile flags, see dtTileFlags.
dtMeshTile* next; // Next free tile or, next tile in spatial grid.
unsigned char* data; ///< Pointer to tile data.
int dataSize; ///< Size of the tile data.
int flags; ///< Tile flags, see dtTileFlags.
dtMeshTile* next; ///< Next free tile or, next tile in spatial grid.
};
struct dtNavMeshParams
{
float orig[3]; // Origin of the nav mesh tile space.
float tileWidth, tileHeight; // Width and height of each tile.
int maxTiles; // Maximum number of tiles the navmesh can contain.
int maxPolys; // Maximum number of polygons each tile can contain.
float orig[3]; ///< Origin of the nav mesh tile space.
float tileWidth, tileHeight; ///< Width and height of each tile.
int maxTiles; ///< Maximum number of tiles the navmesh can contain.
int maxPolys; ///< Maximum number of polygons each tile can contain.
};
@ -177,142 +177,132 @@ public:
dtNavMesh();
~dtNavMesh();
// Initializes the nav mesh for tiled use.
// Params:
// params - (in) navmesh initialization params, see dtNavMeshParams.
// Returns: True if succeed, else false.
/// Initializes the nav mesh for tiled use.
/// @param params [in] navmesh initialization params, see dtNavMeshParams.
/// @return True if succeed, else false.
dtStatus init(const dtNavMeshParams* params);
// Initializes the nav mesh for single tile use.
// Params:
// data - (in) Data of the new tile mesh.
// dataSize - (in) Data size of the new tile mesh.
// flags - (in) Tile flags, see dtTileFlags.
// Returns: True if succeed, else false.
/// Initializes the nav mesh for single tile use.
/// @param data - [in] Data of the new tile mesh.
/// @param dataSize - [in] Data size of the new tile mesh.
/// @param flags - [in] Tile flags, see dtTileFlags.
/// @return True if succeed, else false.
dtStatus init(unsigned char* data, const int dataSize, const int flags);
// Returns pointer to navmesh initialization params.
/// Returns pointer to navmesh initialization params.
const dtNavMeshParams* getParams() const;
// Adds new tile into the navmesh.
// The add will fail if the data is in wrong format,
// there is not enough tiles left, or if there is a tile already at the location.
// Params:
// data - (in) Data of the new tile mesh.
// dataSize - (in) Data size of the new tile mesh.
// flags - (in) Tile flags, see dtTileFlags.
// lastRef - (in,optional) Last tile ref, the tile will be restored so that
// the reference (as well as poly references) will be the same. Default: 0.
// result - (out,optional) tile ref if the tile was succesfully added.
/// Adds new tile into the navmesh.
/// The add will fail if the data is in wrong format,
/// there is not enough tiles left, or if there is a tile already at the location.
/// @param data [in] Data of the new tile mesh.
/// @param dataSize [in] Data size of the new tile mesh.
/// @param flags [in] Tile flags, see dtTileFlags.
/// @param lastRef [in,optional] Last tile ref, the tile will be restored so that
/// the reference (as well as poly references) will be the same. Default: 0.
/// @param result [out,optional] tile ref if the tile was succesfully added.
dtStatus addTile(unsigned char* data, int dataSize, int flags, dtTileRef lastRef, dtTileRef* result);
// Removes specified tile.
// Params:
// ref - (in) Reference to the tile to remove.
// data - (out) Data associated with deleted tile.
// dataSize - (out) Size of the data associated with deleted tile.
/// Removes specified tile.
/// @param ref [in] Reference to the tile to remove.
/// @param data [out] Data associated with deleted tile.
/// @param dataSize [out] Size of the data associated with deleted tile.
dtStatus removeTile(dtTileRef ref, unsigned char** data, int* dataSize);
// Calculates tile location based in input world position.
// Params:
// pos - (in) world position of the query.
// tx - (out) tile x location.
// ty - (out) tile y location.
/// Calculates tile location based in input world position.
/// @param pos [in] world position of the query.
/// @param tx [out] tile x location.
/// @param ty [out] tile y location.
void calcTileLoc(const float* pos, int* tx, int* ty) const;
// Returns pointer to tile at specified location.
// Params:
// x,y - (in) Location of the tile to get.
// Returns: pointer to tile if tile exists or 0 tile does not exists.
/// Returns pointer to tile at specified location.
/// @param x,y [in] Location of the tile to get.
/// @returns pointer to tile if tile exists or 0 tile does not exists.
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;
// Returns reference to tile at specified location.
// Params:
// x,y - (in) Location of the tile to get.
// Returns: reference to tile if tile exists or 0 tile does not exists.
/// Returns reference to tile at specified location.
/// @param x,y [in] Location of the tile to get.
/// @returns reference to tile if tile exists or 0 tile does not exists.
dtTileRef getTileRefAt(int x, int y, int layer) const;
// Returns tile references of a tile based on tile pointer.
/// Returns tile references of a tile based on tile pointer.
dtTileRef getTileRef(const dtMeshTile* tile) const;
// Returns tile based on references.
/// Returns tile based on references.
const dtMeshTile* getTileByRef(dtTileRef ref) const;
// Returns max number of tiles.
/// Returns max number of tiles.
int getMaxTiles() const;
// Returns pointer to tile in the tile array.
// Params:
// i - (in) Index to the tile to retrieve, max index is getMaxTiles()-1.
// Returns: Pointer to specified tile.
/// Returns pointer to tile in the tile array.
/// @param i [in] Index to the tile to retrieve, max index is getMaxTiles()-1.
/// @returns Pointer to specified tile.
const dtMeshTile* getTile(int i) const;
// Returns pointer to tile and polygon pointed by the polygon reference.
// Params:
// ref - (in) reference to a polygon.
// tile - (out) pointer to the tile containing the polygon.
// poly - (out) pointer to the polygon.
/// Returns pointer to tile and polygon pointed by the polygon reference.
/// @param ref [in] reference to a polygon.
/// @param tile [out] pointer to the tile containing the polygon.
/// @param poly [out] pointer to the polygon.
dtStatus getTileAndPolyByRef(const dtPolyRef ref, const dtMeshTile** tile, const dtPoly** poly) const;
// Returns pointer to tile and polygon pointed by the polygon reference.
// Note: this function does not check if 'ref' s valid, and is thus faster. Use only with valid refs!
// Params:
// ref - (in) reference to a polygon.
// tile - (out) pointer to the tile containing the polygon.
// poly - (out) pointer to the polygon.
/// Returns pointer to tile and polygon pointed by the polygon reference.
/// Note: this function does not check if 'ref' s valid, and is thus faster. Use only with valid refs!
///
/// @param ref [in] reference to a polygon.
/// @param tile [out] pointer to the tile containing the polygon.
/// @param poly [out] pointer to the polygon.
void getTileAndPolyByRefUnsafe(const dtPolyRef ref, const dtMeshTile** tile, const dtPoly** poly) const;
// Returns true if polygon reference points to valid data.
/// Returns true if polygon reference points to valid data.
bool isValidPolyRef(dtPolyRef ref) const;
// Returns base poly id for specified tile, polygon refs can be deducted from this.
/// Returns base poly id for specified tile, polygon refs can be deducted from this.
dtPolyRef getPolyRefBase(const dtMeshTile* tile) const;
// Returns start and end location of an off-mesh link polygon.
// Params:
// prevRef - (in) ref to the polygon before the link (used to select direction).
// polyRef - (in) ref to the off-mesh link polygon.
// startPos[3] - (out) start point of the link.
// endPos[3] - (out) end point of the link.
// Returns: true if link is found.
/// Returns start and end location of an off-mesh link polygon.
/// @param prevRef [in] ref to the polygon before the link (used to select direction).
/// @param polyRef [in] ref to the off-mesh link polygon.
/// @param startPos[3] [out] start point of the link.
/// @param endPos[3] [out] end point of the link.
/// @returns true if link is found.
dtStatus getOffMeshConnectionPolyEndPoints(dtPolyRef prevRef, dtPolyRef polyRef, float* startPos, float* endPos) const;
// Returns pointer to off-mesh connection based on polyref, or null if ref not valid.
/// Returns pointer to off-mesh connection based on polyref, or null if ref not valid.
const dtOffMeshConnection* getOffMeshConnectionByRef(dtPolyRef ref) const;
// Sets polygon flags.
/// Sets polygon flags.
dtStatus setPolyFlags(dtPolyRef ref, unsigned short flags);
// Return polygon flags.
/// Return polygon flags.
dtStatus getPolyFlags(dtPolyRef ref, unsigned short* resultFlags) const;
// Set polygon type.
/// Set polygon type.
dtStatus setPolyArea(dtPolyRef ref, unsigned char area);
// Return polygon area type.
/// Return polygon area type.
dtStatus getPolyArea(dtPolyRef ref, unsigned char* resultArea) const;
// Returns number of bytes required to store tile state.
/// Returns number of bytes required to store tile state.
int getTileStateSize(const dtMeshTile* tile) const;
// Stores tile state to buffer.
/// Stores tile state to buffer.
dtStatus storeTileState(const dtMeshTile* tile, unsigned char* data, const int maxDataSize) const;
// Restores tile state.
/// Restores tile state.
dtStatus restoreTileState(dtMeshTile* tile, const unsigned char* data, const int maxDataSize);
// Encodes a tile id.
/// Encodes a tile id.
inline dtPolyRef encodePolyId(unsigned int salt, unsigned int it, unsigned int ip) const
{
return ((dtPolyRef)salt << (m_polyBits+m_tileBits)) | ((dtPolyRef)it << m_polyBits) | (dtPolyRef)ip;
}
// Decodes a tile id.
/// Decodes a tile id.
inline void decodePolyId(dtPolyRef ref, unsigned int& salt, unsigned int& it, unsigned int& ip) const
{
const dtPolyRef saltMask = ((dtPolyRef)1<<m_saltBits)-1;
@ -323,21 +313,21 @@ public:
ip = (unsigned int)(ref & polyMask);
}
// Decodes a tile salt.
/// Decodes a tile salt.
inline unsigned int decodePolyIdSalt(dtPolyRef ref) const
{
const dtPolyRef saltMask = ((dtPolyRef)1<<m_saltBits)-1;
return (unsigned int)((ref >> (m_polyBits+m_tileBits)) & saltMask);
}
// Decodes a tile id.
/// Decodes a tile id.
inline unsigned int decodePolyIdTile(dtPolyRef ref) const
{
const dtPolyRef tileMask = ((dtPolyRef)1<<m_tileBits)-1;
return (unsigned int)((ref >> m_polyBits) & tileMask);
}
// Decodes a poly id.
/// Decodes a poly id.
inline unsigned int decodePolyIdPoly(dtPolyRef ref) const
{
const dtPolyRef polyMask = ((dtPolyRef)1<<m_polyBits)-1;
@ -346,65 +336,65 @@ public:
private:
// Returns pointer to tile in the tile array.
/// Returns pointer to tile in the tile array.
dtMeshTile* getTile(int i);
// Returns neighbour tile based on side.
/// Returns neighbour tile based on side.
int getTilesAt(const int x, const int y,
dtMeshTile** tiles, const int maxTiles) const;
// Returns neighbour tile based on side.
/// Returns neighbour tile based on side.
int getNeighbourTilesAt(const int x, const int y, const int side,
dtMeshTile** tiles, const int maxTiles) const;
// Returns all polygons in neighbour tile based on portal defined by the segment.
/// Returns all polygons in neighbour tile based on portal defined by the segment.
int findConnectingPolys(const float* va, const float* vb,
const dtMeshTile* tile, int side,
dtPolyRef* con, float* conarea, int maxcon) const;
// Builds internal polygons links for a tile.
/// Builds internal polygons links for a tile.
void connectIntLinks(dtMeshTile* tile);
// Builds internal polygons links for a tile.
/// Builds internal polygons links for a tile.
void connectIntOffMeshLinks(dtMeshTile* tile);
// Builds external polygon links for a tile.
/// Builds external polygon links for a tile.
void connectExtLinks(dtMeshTile* tile, dtMeshTile* target, int side);
// Builds external polygon links for a tile.
/// Builds external polygon links for a tile.
void connectExtOffMeshLinks(dtMeshTile* tile, dtMeshTile* target, int side);
// Removes external links at specified side.
/// Removes external links at specified side.
void unconnectExtLinks(dtMeshTile* tile, dtMeshTile* target);
// TODO: These methods are duplicates from dtNavMeshQuery, but are needed for off-mesh connection finding.
// Queries polygons within a tile.
/// Queries polygons within a tile.
int queryPolygonsInTile(const dtMeshTile* tile, const float* qmin, const float* qmax,
dtPolyRef* polys, const int maxPolys) const;
// Find nearest polygon within a tile.
/// Find nearest polygon within a tile.
dtPolyRef findNearestPolyInTile(const dtMeshTile* tile, const float* center,
const float* extents, float* nearestPt) const;
// Returns closest point on polygon.
/// Returns closest point on polygon.
void closestPointOnPolyInTile(const dtMeshTile* tile, unsigned int ip,
const float* pos, float* closest) const;
dtNavMeshParams m_params; // Current initialization params. TODO: do not store this info twice.
float m_orig[3]; // Origin of the tile (0,0)
float m_tileWidth, m_tileHeight; // Dimensions of each tile.
int m_maxTiles; // Max number of tiles.
int m_tileLutSize; // Tile hash lookup size (must be pot).
int m_tileLutMask; // Tile hash lookup mask.
dtNavMeshParams m_params; ///< Current initialization params. TODO: do not store this info twice.
float m_orig[3]; ///< Origin of the tile (0,0)
float m_tileWidth, m_tileHeight; ///< Dimensions of each tile.
int m_maxTiles; ///< Max number of tiles.
int m_tileLutSize; ///< Tile hash lookup size (must be pot).
int m_tileLutMask; ///< Tile hash lookup mask.
dtMeshTile** m_posLookup; // Tile hash lookup.
dtMeshTile* m_nextFree; // Freelist of tiles.
dtMeshTile* m_tiles; // List of tiles.
dtMeshTile** m_posLookup; ///< Tile hash lookup.
dtMeshTile* m_nextFree; ///< Freelist of tiles.
dtMeshTile* m_tiles; ///< List of tiles.
unsigned int m_saltBits; // Number of salt bits in the tile ID.
unsigned int m_tileBits; // Number of tile bits in the tile ID.
unsigned int m_polyBits; // Number of poly bits in the tile ID.
unsigned int m_saltBits; ///< Number of salt bits in the tile ID.
unsigned int m_tileBits; ///< Number of tile bits in the tile ID.
unsigned int m_polyBits; ///< Number of poly bits in the tile ID.
};
// Helper function to allocate navmesh class using Detour allocator.
/// Helper function to allocate navmesh class using Detour allocator.
dtNavMesh* dtAllocNavMesh();
void dtFreeNavMesh(dtNavMesh* navmesh);

View File

@ -22,56 +22,73 @@
#include "DetourAlloc.h"
// The units of the parameters are specified in parenthesis as follows:
// (vx) voxels, (wu) world units
/// The units of the parameters are specified in parenthesis as follows:
/// (vx) voxels, (wu) world units
struct dtNavMeshCreateParams
{
// Navmesh vertices.
const unsigned short* verts; // Array of vertices, each vertex has 3 components. (vx).
int vertCount; // Vertex count
// Navmesh polygons
const unsigned short* polys; // Array of polygons, uses same format as rcPolyMesh.
const unsigned short* polyFlags; // Array of flags per polygon.
const unsigned char* polyAreas; // Array of area ids per polygon.
int polyCount; // Number of polygons
int nvp; // Number of verts per polygon.
// Navmesh Detail (optional)
const unsigned int* detailMeshes; // Detail meshes, uses same format as rcPolyMeshDetail.
const float* detailVerts; // Detail mesh vertices, uses same format as rcPolyMeshDetail (wu).
int detailVertsCount; // Total number of detail vertices
const unsigned char* detailTris; // Array of detail tris per detail mesh.
int detailTriCount; // Total number of detail triangles.
// Off-Mesh Connections.
const float* offMeshConVerts; // Off-mesh connection vertices (wu).
const float* offMeshConRad; // Off-mesh connection radii (wu).
const unsigned short* offMeshConFlags; // Off-mesh connection flags.
const unsigned char* offMeshConAreas; // Off-mesh connection area ids.
const unsigned char* offMeshConDir; // Off-mesh connection direction flags (1 = bidir, 0 = oneway).
const unsigned int* offMeshConUserID; // Off-mesh connection user id (optional).
int offMeshConCount; // Number of off-mesh connections
// Tile location
unsigned int userId; // User ID bound to the tile.
int tileX, tileY, tileLayer; // Tile location (tile coords).
float bmin[3], bmax[3]; // Tile bounds (wu).
// Settings
float walkableHeight; // Agent height (wu).
float walkableRadius; // Agent radius (wu).
float walkableClimb; // Agent max climb (wu).
float cs; // Cell size (xz) (wu).
float ch; // Cell height (y) (wu).
bool buildBvTree; // Flag indicating if BVTree for polygon query should be build.
/// @name Navmesh vertices.
///@{
const unsigned short* verts; ///< Array of vertices, each vertex has 3 components. (vx).
int vertCount; ///< Vertex count
///@{
/// @name Navmesh polygons
///@{
const unsigned short* polys; ///< Array of polygons, uses same format as rcPolyMesh.
const unsigned short* polyFlags; ///< Array of flags per polygon.
const unsigned char* polyAreas; ///< Array of area ids per polygon.
int polyCount; ///< Number of polygons
int nvp; ///< Number of verts per polygon.
///@}
/// @name Navmesh Detail (optional)
///@{
const unsigned int* detailMeshes; ///< Detail meshes, uses same format as rcPolyMeshDetail.
const float* detailVerts; ///< Detail mesh vertices, uses same format as rcPolyMeshDetail (wu).
int detailVertsCount; ///< Total number of detail vertices
const unsigned char* detailTris; ///< Array of detail tris per detail mesh.
int detailTriCount; ///< Total number of detail triangles.
///@}
/// @name Off-Mesh Connections.
///@{
const float* offMeshConVerts; ///< Off-mesh connection vertices (wu).
const float* offMeshConRad; ///< Off-mesh connection radii (wu).
const unsigned short* offMeshConFlags; ///< Off-mesh connection flags.
const unsigned char* offMeshConAreas; ///< Off-mesh connection area ids.
const unsigned char* offMeshConDir; ///< Off-mesh connection direction flags (1 = bidir, 0 = oneway).
const unsigned int* offMeshConUserID; ///< Off-mesh connection user id (optional).
int offMeshConCount; ///< Number of off-mesh connections
///@}
/// @name Tile location
///@{
unsigned int userId; ///< User ID bound to the tile.
int tileX, tileY, tileLayer; ///< Tile location (tile coords).
float bmin[3], bmax[3]; ///< Tile bounds (wu).
///@}
/// @name Settings
///@{
float walkableHeight; ///< Agent height (wu).
float walkableRadius; ///< Agent radius (wu).
float walkableClimb; ///< Agent max climb (wu).
float cs; ///< Cell size (xz) (wu).
float ch; ///< Cell height (y) (wu).
bool buildBvTree; ///< Flag indicating if BVTree for polygon query should be build.
///@}
};
// Build navmesh data from given input data.
/// Build navmesh data from given input data.
bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData, int* outDataSize);
// Swaps endianess of navmesh header.
/// Swaps endianess of navmesh header.
bool dtNavMeshHeaderSwapEndian(unsigned char* data, const int dataSize);
// Swaps endianess of the navmesh data. This function assumes that the header is in correct
// endianess already. Call dtNavMeshHeaderSwapEndian() first on the data if the data is
// assumed to be in wrong endianess to start with. If converting from native endianess to foreign,
// call dtNavMeshHeaderSwapEndian() after the data has been swapped.
/// Swaps endianess of the navmesh data. This function assumes that the header is in correct
/// endianess already. Call dtNavMeshHeaderSwapEndian() first on the data if the data is
/// assumed to be in wrong endianess to start with. If converting from native endianess to foreign,
/// call dtNavMeshHeaderSwapEndian() after the data has been swapped.
bool dtNavMeshDataSwapEndian(unsigned char* data, const int dataSize);
#endif // DETOURNAVMESHBUILDER_H

View File

@ -30,30 +30,29 @@
//#define DT_VIRTUAL_QUERYFILTER 1
// Class for polygon filtering and cost calculation during query operations.
// - It is possible to derive a custom query filter from dtQueryFilter by overriding
// the virtual functions passFilter() and getCost().
// - Both functions should be as fast as possible. Use cached local copy of data
// instead of accessing your own objects where possible.
// - You do not need to adhere to the flags and cost logic provided by the default
// implementation.
// - In order for the A* to work properly, the cost should be proportional to
// the travel distance. Using cost modifier less than 1.0 is likely to lead
// to problems during pathfinding.
/// Class for polygon filtering and cost calculation during query operations.
/// - It is possible to derive a custom query filter from dtQueryFilter by overriding
/// the virtual functions passFilter() and getCost().
/// - Both functions should be as fast as possible. Use cached local copy of data
/// instead of accessing your own objects where possible.
/// - You do not need to adhere to the flags and cost logic provided by the default
/// implementation.
/// - In order for the A* to work properly, the cost should be proportional to
/// the travel distance. Using cost modifier less than 1.0 is likely to lead
/// to problems during pathfinding.
class dtQueryFilter
{
float m_areaCost[DT_MAX_AREAS]; // Array storing cost per area type, used by default implementation.
unsigned short m_includeFlags; // Include poly flags, used by default implementation.
unsigned short m_excludeFlags; // Exclude poly flags, used by default implementation.
float m_areaCost[DT_MAX_AREAS]; ///< Array storing cost per area type, used by default implementation.
unsigned short m_includeFlags; ///< Include poly flags, used by default implementation.
unsigned short m_excludeFlags; ///< Exclude poly flags, used by default implementation.
public:
dtQueryFilter();
// Returns true if the polygon is can visited.
// Params:
// ref - (in) reference to the polygon test.
// tile - (in) pointer to the tile of the polygon test.
// poly - (in) pointer to the polygon test.
/// Returns true if the polygon is can visited.
/// @param ref [in] reference to the polygon test.
/// @param tile [in] pointer to the tile of the polygon test.
/// @param poly [in] pointer to the polygon test.
#ifdef DT_VIRTUAL_QUERYFILTER
virtual bool passFilter(const dtPolyRef ref,
const dtMeshTile* tile,
@ -64,16 +63,15 @@ public:
const dtPoly* poly) const;
#endif
// Returns cost to travel from 'pa' to 'pb'.'
// The segment is fully contained inside 'cur'.
// 'pa' lies on the edge between 'prev' and 'cur',
// 'pb' lies on the edge between 'cur' and 'next'.
// Params:
// pa - (in) segment start position.
// pb - (in) segment end position.
// prevRef, prevTile, prevPoly - (in) data describing the previous polygon, can be null.
// curRef, curTile, curPoly - (in) data describing the current polygon.
// nextRef, nextTile, nextPoly - (in) data describing the next polygon, can be null.
/// Returns cost to travel from 'pa' to 'pb'.'
/// The segment is fully contained inside 'cur'.
/// 'pa' lies on the edge between 'prev' and 'cur',
/// 'pb' lies on the edge between 'cur' and 'next'.
/// @param pa [in] segment start position.
/// @param pb [in] segment end position.
/// @param prevRef, prevTile, prevPoly [in] data describing the previous polygon, can be null.
/// @param curRef, curTile, curPoly [in] data describing the current polygon.
/// @param nextRef, nextTile, nextPoly [in] data describing the next polygon, can be null.
#ifdef DT_VIRTUAL_QUERYFILTER
virtual float getCost(const float* pa, const float* pb,
const dtPolyRef prevRef, const dtMeshTile* prevTile, const dtPoly* prevPoly,
@ -86,7 +84,8 @@ public:
const dtPolyRef nextRef, const dtMeshTile* nextTile, const dtPoly* nextPoly) const;
#endif
// Getters and setters for the default implementation data.
/// @name Getters and setters for the default implementation data.
///@{
inline float getAreaCost(const int i) const { return m_areaCost[i]; }
inline void setAreaCost(const int i, const float cost) { m_areaCost[i] = cost; }
@ -95,6 +94,7 @@ public:
inline unsigned short getExcludeFlags() const { return m_excludeFlags; }
inline void setExcludeFlags(const unsigned short flags) { m_excludeFlags = flags; }
///@}
};
class dtNavMeshQuery
@ -103,249 +103,232 @@ public:
dtNavMeshQuery();
~dtNavMeshQuery();
// Initializes the nav mesh query.
// Params:
// nav - (in) pointer to navigation mesh data.
// maxNodes - (in) Maximum number of search nodes to use (max 65536).
/// Initializes the nav mesh query.
/// @param nav [in] pointer to navigation mesh data.
/// @param maxNodes [in] Maximum number of search nodes to use (max 65536).
dtStatus init(const dtNavMesh* nav, const int maxNodes);
// Finds the nearest navigation polygon around the center location.
// Params:
// center[3] - (in) The center of the search box.
// extents[3] - (in) The extents of the search box.
// filter - (in) path polygon filter.
// nearestRef - (out) Reference to the nearest polygon.
// nearestPt[3] - (out, opt) The nearest point on found polygon, null if not needed.
/// Finds the nearest navigation polygon around the center location.
/// @param center[3] [in] The center of the search box.
/// @param extents[3] [in] The extents of the search box.
/// @param filter [in] path polygon filter.
/// @param nearestRef [out] Reference to the nearest polygon.
/// @param nearestPt[3] [out, opt] The nearest point on found polygon, null if not needed.
dtStatus findNearestPoly(const float* center, const float* extents,
const dtQueryFilter* filter,
dtPolyRef* nearestRef, float* nearestPt) const;
// Returns polygons which overlap the query box.
// Params:
// center[3] - (in) the center of the search box.
// extents[3] - (in) the extents of the search box.
// filter - (in) path polygon filter.
// polys - (out) array holding the search result.
// polyCount - (out) Number of polygons in search result array.
// maxPolys - (in) The max number of polygons the polys array can hold.
/// Returns polygons which overlap the query box.
/// @param center[3] [in] the center of the search box.
/// @param extents[3] [in] the extents of the search box.
/// @param filter [in] path polygon filter.
/// @param polys [out] array holding the search result.
/// @param polyCount [out] Number of polygons in search result array.
/// @param maxPolys [in] The max number of polygons the polys array can hold.
dtStatus queryPolygons(const float* center, const float* extents,
const dtQueryFilter* filter,
dtPolyRef* polys, int* polyCount, const int maxPolys) const;
// Finds path from start polygon to end polygon.
// If target polygon canno be reached through the navigation graph,
// the last node on the array is nearest node to the end polygon.
// Start end end positions are needed to calculate more accurate
// traversal cost at start end end polygons.
// Params:
// startRef - (in) ref to path start polygon.
// endRef - (in) ref to path end polygon.
// startPos[3] - (in) Path start location.
// endPos[3] - (in) Path end location.
// filter - (in) path polygon filter.
// path - (out) array holding the search result.
// pathCount - (out) Number of polygons in search result array.
// maxPath - (in) The max number of polygons the path array can hold. Must be at least 1.
/// Finds path from start polygon to end polygon.
/// If target polygon canno be reached through the navigation graph,
/// the last node on the array is nearest node to the end polygon.
/// Start end end positions are needed to calculate more accurate
/// traversal cost at start end end polygons.
/// @param startRef [in] ref to path start polygon.
/// @param endRef [in] ref to path end polygon.
/// @param startPos[3] [in] Path start location.
/// @param endPos[3] [in] Path end location.
/// @param filter [in] path polygon filter.
/// @param path [out] array holding the search result.
/// @param pathCount [out] Number of polygons in search result array.
/// @param maxPath [in] The max number of polygons the path array can hold. Must be at least 1.
dtStatus findPath(dtPolyRef startRef, dtPolyRef endRef,
const float* startPos, const float* endPos,
const dtQueryFilter* filter,
dtPolyRef* path, int* pathCount, const int maxPath) const;
// Intializes sliced path find query.
// Note 1: calling any other dtNavMeshQuery method before calling findPathEnd()
// may results in corrupted data!
// Note 2: The pointer to filter is store, and used in subsequent
// calls to updateSlicedFindPath().
// Params:
// startRef - (in) ref to path start polygon.
// endRef - (in) ref to path end polygon.
// startPos[3] - (in) Path start location.
// endPos[3] - (in) Path end location.
// filter - (in) path polygon filter.
/// Intializes sliced path find query.
/// Note 1: calling any other dtNavMeshQuery method before calling findPathEnd()
/// may results in corrupted data!
/// Note 2: The pointer to filter is store, and used in subsequent
/// calls to updateSlicedFindPath().
/// @param startRef [in] ref to path start polygon.
/// @param endRef [in] ref to path end polygon.
/// @param startPos[3] [in] Path start location.
/// @param endPos[3] [in] Path end location.
/// @param filter [in] path polygon filter.
dtStatus initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef,
const float* startPos, const float* endPos,
const dtQueryFilter* filter);
// Updates sliced path find query.
// Params:
// maxIter - (in) Max number of iterations to update.
// doneIters - (out,opt) Number of iterations done during the update.
// Returns: Path query state.
/// Updates sliced path find query.
/// @param maxIter [in] Max number of iterations to update.
/// @param doneIters [out,opt] Number of iterations done during the update.
/// Returns: Path query state.
dtStatus updateSlicedFindPath(const int maxIter, int* doneIters);
// Finalizes sliced path find query and returns found path.
// path - (out) array holding the search result.
// pathCount - (out) Number of polygons in search result array.
// maxPath - (in) The max number of polygons the path array can hold.
/// Finalizes sliced path find query and returns found path.
/// @param path [out] array holding the search result.
/// @param pathCount [out] Number of polygons in search result array.
/// @param maxPath [in] The max number of polygons the path array can hold.
dtStatus finalizeSlicedFindPath(dtPolyRef* path, int* pathCount, const int maxPath);
// Finalizes partial sliced path find query and returns path to the furthest
// polygon on the existing path that was visited during the search.
// existing - (out) Array of polygons in the existing path.
// existingSize - (out) Number of polygons in existing path array.
// path - (out) array holding the search result.
// pathCount - (out) Number of polygons in search result array.
// maxPath - (in) The max number of polygons the path array can hold.
/// Finalizes partial sliced path find query and returns path to the furthest
/// polygon on the existing path that was visited during the search.
/// @param existing [out] Array of polygons in the existing path.
/// @param existingSize [out] Number of polygons in existing path array.
/// @param path [out] array holding the search result.
/// @param pathCount [out] Number of polygons in search result array.
/// @param maxPath [in] The max number of polygons the path array can hold.
dtStatus finalizeSlicedFindPathPartial(const dtPolyRef* existing, const int existingSize,
dtPolyRef* path, int* pathCount, const int maxPath);
// Finds a straight path from start to end locations within the corridor
// described by the path polygons.
// Start and end locations will be clamped on the corridor.
// The returned polygon references are point to polygon which was entered when
// a path point was added. For the end point, zero will be returned. This allows
// to match for example off-mesh link points to their representative polygons.
// Params:
// startPos[3] - (in) Path start location.
// endPo[3] - (in) Path end location.
// path - (in) Array of connected polygons describing the corridor.
// pathSize - (in) Number of polygons in path array.
// straightPath - (out) Points describing the straight path.
// straightPathFlags - (out, opt) Flags describing each point type, see dtStraightPathFlags.
// straightPathRefs - (out, opt) References to polygons at point locations.
// straightPathCount - (out) Number of points in the path.
// maxStraightPath - (in) The max number of points the straight path array can hold. Must be at least 1.
/// Finds a straight path from start to end locations within the corridor
/// described by the path polygons.
/// Start and end locations will be clamped on the corridor.
/// The returned polygon references are point to polygon which was entered when
/// a path point was added. For the end point, zero will be returned. This allows
/// to match for example off-mesh link points to their representative polygons.
/// @param startPos[3] [in] Path start location.
/// @param endPos[3] [in] Path end location.
/// @param path [in] Array of connected polygons describing the corridor.
/// @param pathSize [in] Number of polygons in path array.
/// @param straightPath [out] Points describing the straight path.
/// @param straightPathFlags [out, opt] Flags describing each point type, see dtStraightPathFlags.
/// @param straightPathRefs [out, opt] References to polygons at point locations.
/// @param straightPathCount [out] Number of points in the path.
/// @param maxStraightPath [in] The max number of points the straight path array can hold. Must be at least 1.
dtStatus findStraightPath(const float* startPos, const float* endPos,
const dtPolyRef* path, const int pathSize,
float* straightPath, unsigned char* straightPathFlags, dtPolyRef* straightPathRefs,
int* straightPathCount, const int maxStraightPath) const;
// Moves from startPos to endPos constrained to the navmesh.
// If the endPos is reachable, the resultPos will be endPos,
// or else the resultPos will be the nearest point in navmesh.
// Note: The resulting point is not projected to the ground, use getPolyHeight() to get height.
// Note: The algorithm is optimized for small delta movement and small number of polygons.
// Params:
// startRef - (in) ref to the polygon where startPos lies.
// startPos[3] - (in) start position of the mover.
// endPos[3] - (in) desired end position of the mover.
// filter - (in) path polygon filter.
// resultPos[3] - (out) new position of the mover.
// visited - (out) array of visited polygons.
// visitedCount - (out) Number of entries in the visited array.
// maxVisitedSize - (in) max number of polygons in the visited array.
/// Moves from startPos to endPos constrained to the navmesh.
/// If the endPos is reachable, the resultPos will be endPos,
/// or else the resultPos will be the nearest point in navmesh.
/// Note: The resulting point is not projected to the ground, use getPolyHeight() to get height.
/// Note: The algorithm is optimized for small delta movement and small number of polygons.
/// @param startRef [in] ref to the polygon where startPos lies.
/// @param startPos[3] [in] start position of the mover.
/// @param endPos[3] [in] desired end position of the mover.
/// @param filter [in] path polygon filter.
/// @param resultPos[3] [out] new position of the mover.
/// @param visited [out] array of visited polygons.
/// @param visitedCount [out] Number of entries in the visited array.
/// @param maxVisitedSize [in] max number of polygons in the visited array.
dtStatus moveAlongSurface(dtPolyRef startRef, const float* startPos, const float* endPos,
const dtQueryFilter* filter,
float* resultPos, dtPolyRef* visited, int* visitedCount, const int maxVisitedSize) const;
// Casts 'walkability' ray along the navmesh surface from startPos towards the endPos.
// Params:
// startRef - (in) ref to the polygon where the start lies.
// startPos[3] - (in) start position of the query.
// endPos[3] - (in) end position of the query.
// t - (out) hit parameter along the segment, FLT_MAX if no hit.
// hitNormal[3] - (out) normal of the nearest hit.
// filter - (in) path polygon filter.
// path - (out,opt) visited path polygons.
// pathCount - (out,opt) Number of polygons visited.
// maxPath - (in) max number of polygons in the path array.
/// Casts 'walkability' ray along the navmesh surface from startPos towards the endPos.
/// @param startRef [in] ref to the polygon where the start lies.
/// @param startPos[3] [in] start position of the query.
/// @param endPos[3] [in] end position of the query.
/// @param t [out] hit parameter along the segment, FLT_MAX if no hit.
/// @param hitNormal[3] [out] normal of the nearest hit.
/// @param filter [in] path polygon filter.
/// @param path [out,opt] visited path polygons.
/// @param pathCount [out,opt] Number of polygons visited.
/// @param maxPath [in] max number of polygons in the path array.
dtStatus raycast(dtPolyRef startRef, const float* startPos, const float* endPos,
const dtQueryFilter* filter,
float* t, float* hitNormal, dtPolyRef* path, int* pathCount, const int maxPath) const;
// Returns distance to nearest wall from the specified location.
// Params:
// startRef - (in) ref to the polygon where the center lies.
// centerPos[3] - (in) center if the query circle.
// maxRadius - (in) max search radius.
// filter - (in) path polygon filter.
// hitDist - (out) distance to nearest wall from the test location.
// hitPos[3] - (out) location of the nearest hit.
// hitNormal[3] - (out) normal of the nearest hit.
/// Returns distance to nearest wall from the specified location.
/// @param startRef [in] ref to the polygon where the center lies.
/// @param centerPos[3] [in] center if the query circle.
/// @param maxRadius [in] max search radius.
/// @param filter [in] path polygon filter.
/// @param hitDist [out] distance to nearest wall from the test location.
/// @param hitPos[3] [out] location of the nearest hit.
/// @param hitNormal[3] [out] normal of the nearest hit.
dtStatus findDistanceToWall(dtPolyRef startRef, const float* centerPos, const float maxRadius,
const dtQueryFilter* filter,
float* hitDist, float* hitPos, float* hitNormal) const;
// Finds polygons found along the navigation graph which touch the specified circle.
// Params:
// startRef - (in) ref to the polygon where the search starts.
// centerPos[3] - (in) center if the query circle.
// radius - (in) radius of the query circle.
// filter - (in) path polygon filter.
// resultRef - (out, opt) refs to the polygons touched by the circle.
// resultParent - (out, opt) parent of each result polygon.
// resultCost - (out, opt) search cost at each result polygon.
// resultCount - (out, opt) Number of results.
// maxResult - (int) maximum capacity of search results.
/// Finds polygons found along the navigation graph which touch the specified circle.
/// @param startRef [in] ref to the polygon where the search starts.
/// @param centerPos[3] [in] center if the query circle.
/// @param radius [in] radius of the query circle.
/// @param filter [in] path polygon filter.
/// @param resultRef [out, opt] refs to the polygons touched by the circle.
/// @param resultParent [out, opt] parent of each result polygon.
/// @param resultCost [out, opt] search cost at each result polygon.
/// @param resultCount [out, opt] Number of results.
/// @param maxResult [int] maximum capacity of search results.
dtStatus findPolysAroundCircle(dtPolyRef startRef, const float* centerPos, const float radius,
const dtQueryFilter* filter,
dtPolyRef* resultRef, dtPolyRef* resultParent, float* resultCost,
int* resultCount, const int maxResult) const;
// Finds polygons found along the navigation graph which touch the convex polygon shape.
// Params:
// startRef - (in) ref to the polygon where the search starts.
// verts[3*n] - (in) vertices describing convex polygon shape (CCW).
// nverts - (in) number of vertices in the polygon.
// filter - (in) path polygon filter.
// resultRef - (out, opt) refs to the polygons touched by the circle.
// resultParent - (out, opt) parent of each result polygon.
// resultCost - (out, opt) search cost at each result polygon.
// resultCount - (out) number of results.
// maxResult - (int) maximum capacity of search results.
/// Finds polygons found along the navigation graph which touch the convex polygon shape.
/// @param startRef [in] ref to the polygon where the search starts.
/// @param verts[3*n] [in] vertices describing convex polygon shape (CCW).
/// @param nverts [in] number of vertices in the polygon.
/// @param filter [in] path polygon filter.
/// @param resultRef [out, opt] refs to the polygons touched by the circle.
/// @param resultParent [out, opt] parent of each result polygon.
/// @param resultCost [out, opt] search cost at each result polygon.
/// @param resultCount [out] number of results.
/// @param maxResult [int] maximum capacity of search results.
dtStatus findPolysAroundShape(dtPolyRef startRef, const float* verts, const int nverts,
const dtQueryFilter* filter,
dtPolyRef* resultRef, dtPolyRef* resultParent, float* resultCost,
int* resultCount, const int maxResult) const;
// Finds non-overlapping local neighbourhood around center location.
// Note: The algorithm is optimized for small query radius and small number of polygons.
// Params:
// startRef - (in) ref to the polygon where the search starts.
// centerPos[3] - (in) center if the query circle.
// radius - (in) radius of the query circle.
// filter - (in) path polygon filter.
// resultRef - (out) refs to the polygons touched by the circle.
// resultParent - (out, opt) parent of each result polygon.
// resultCount - (out) number of results.
// maxResult - (int) maximum capacity of search results.
/// Finds non-overlapping local neighbourhood around center location.
/// Note: The algorithm is optimized for small query radius and small number of polygons.
/// @param startRef [in] ref to the polygon where the search starts.
/// @param centerPos[3] [in] center if the query circle.
/// @param radius [in] radius of the query circle.
/// @param filter [in] path polygon filter.
/// @param resultRef [out] refs to the polygons touched by the circle.
/// @param resultParent [out, opt] parent of each result polygon.
/// @param resultCount [out] number of results.
/// @param maxResult [int] maximum capacity of search results.
dtStatus findLocalNeighbourhood(dtPolyRef startRef, const float* centerPos, const float radius,
const dtQueryFilter* filter,
dtPolyRef* resultRef, dtPolyRef* resultParent,
int* resultCount, const int maxResult) const;
// Returns wall segments of specified polygon.
// If 'segmentRefs' is specified, both the wall and portal segments are returned.
// Wall segments will have null (0) polyref, and portal segments store the polygon they lead to.
// Params:
// ref - (in) ref to the polygon.
// filter - (in) path polygon filter.
// segmentVerts[6*maxSegments] - (out) wall segments (2 endpoints per segment).
// segmentRefs[maxSegments] - (out,opt) reference to a neighbour.
// segmentCount - (out) number of wall segments.
// maxSegments - (in) max number of segments that can be stored in 'segments'.
/// Returns wall segments of specified polygon.
/// If 'segmentRefs' is specified, both the wall and portal segments are returned.
/// Wall segments will have null (0) polyref, and portal segments store the polygon they lead to.
/// @param ref [in] ref to the polygon.
/// @param filter [in] path polygon filter.
/// @param segmentVerts[6*maxSegments] [out] wall segments (2 endpoints per segment).
/// @param segmentRefs[maxSegments] [out,opt] reference to a neighbour.
/// @param segmentCount [out] number of wall segments.
/// @param maxSegments [in] max number of segments that can be stored in 'segments'.
dtStatus getPolyWallSegments(dtPolyRef ref, const dtQueryFilter* filter,
float* segmentVerts, dtPolyRef* segmentRefs, int* segmentCount,
const int maxSegments) const;
// Returns closest point on navigation polygon.
// Uses detail polygons to find the closest point to the navigation polygon surface.
// Params:
// ref - (in) ref to the polygon.
// pos[3] - (in) the point to check.
// closest[3] - (out) closest point.
// Returns: true if closest point found.
/// Returns closest point on navigation polygon.
/// Uses detail polygons to find the closest point to the navigation polygon surface.
/// @param ref [in] ref to the polygon.
/// @param pos[3] [in] the point to check.
/// @param closest[3] [out] closest point.
/// @returns true if closest point found.
dtStatus closestPointOnPoly(dtPolyRef ref, const float* pos, float* closest) const;
// Returns closest point on navigation polygon boundary.
// Uses the navigation polygon boundary to snap the point to poly boundary
// if it is outside the polygon. Much faster than closestPointToPoly. Does not affect height.
// Params:
// ref - (in) ref to the polygon.
// pos[3] - (in) the point to check.
// closest[3] - (out) closest point.
// Returns: true if closest point found.
/// Returns closest point on navigation polygon boundary.
/// Uses the navigation polygon boundary to snap the point to poly boundary
/// if it is outside the polygon. Much faster than closestPointToPoly. Does not affect height.
/// @param ref [in] ref to the polygon.
/// @param pos[3] [in] the point to check.
/// @param closest[3] [out] closest point.
/// @returns true if closest point found.
dtStatus closestPointOnPolyBoundary(dtPolyRef ref, const float* pos, float* closest) const;
// Returns height of the polygon at specified location.
// Params:
// ref - (in) ref to the polygon.
// pos[3] - (in) the point where to locate the height.
// height - (out) height at the location.
// Returns: true if over polygon.
/// Returns height of the polygon at specified location.
/// @param ref [in] ref to the polygon.
/// @param pos[3] [in] the point where to locate the height.
/// @param height [out] height at the location.
/// @returns true if over polygon.
dtStatus getPolyHeight(dtPolyRef ref, const float* pos, float* height) const;
// Returns true if poly reference ins in closed list.
/// Returns true if poly reference ins in closed list.
bool isInClosedList(dtPolyRef ref) const;
class dtNodePool* getNodePool() const { return m_nodePool; }
@ -354,32 +337,32 @@ public:
private:
// Returns neighbour tile based on side.
/// Returns neighbour tile based on side.
dtMeshTile* getNeighbourTileAt(int x, int y, int side) const;
// Queries polygons within a tile.
/// Queries polygons within a tile.
int queryPolygonsInTile(const dtMeshTile* tile, const float* qmin, const float* qmax, const dtQueryFilter* filter,
dtPolyRef* polys, const int maxPolys) const;
// Find nearest polygon within a tile.
/// Find nearest polygon within a tile.
dtPolyRef findNearestPolyInTile(const dtMeshTile* tile, const float* center, const float* extents,
const dtQueryFilter* filter, float* nearestPt) const;
// Returns closest point on polygon.
/// Returns closest point on polygon.
void closestPointOnPolyInTile(const dtMeshTile* tile, const dtPoly* poly, const float* pos, float* closest) const;
// Returns portal points between two polygons.
/// Returns portal points between two polygons.
dtStatus getPortalPoints(dtPolyRef from, dtPolyRef to, float* left, float* right,
unsigned char& fromType, unsigned char& toType) const;
dtStatus getPortalPoints(dtPolyRef from, const dtPoly* fromPoly, const dtMeshTile* fromTile,
dtPolyRef to, const dtPoly* toPoly, const dtMeshTile* toTile,
float* left, float* right) const;
// Returns edge mid point between two polygons.
/// Returns edge mid point between two polygons.
dtStatus getEdgeMidPoint(dtPolyRef from, dtPolyRef to, float* mid) const;
dtStatus getEdgeMidPoint(dtPolyRef from, const dtPoly* fromPoly, const dtMeshTile* fromTile,
dtPolyRef to, const dtPoly* toPoly, const dtMeshTile* toTile,
float* mid) const;
const dtNavMesh* m_nav; // Pointer to navmesh data.
const dtNavMesh* m_nav; ///< Pointer to navmesh data.
struct dtQueryData
{
@ -390,14 +373,14 @@ private:
float startPos[3], endPos[3];
const dtQueryFilter* filter;
};
dtQueryData m_query; // Sliced query state.
dtQueryData m_query; ///< Sliced query state.
class dtNodePool* m_tinyNodePool; // Pointer to small node pool.
class dtNodePool* m_nodePool; // Pointer to node pool.
class dtNodeQueue* m_openList; // Pointer to open list queue.
class dtNodePool* m_tinyNodePool; ///< Pointer to small node pool.
class dtNodePool* m_nodePool; ///< Pointer to node pool.
class dtNodeQueue* m_openList; ///< Pointer to open list queue.
};
// Helper function to allocate navmesh query class using Detour allocator.
/// Helper function to allocate navmesh query class using Detour allocator.
dtNavMeshQuery* dtAllocNavMeshQuery();
void dtFreeNavMeshQuery(dtNavMeshQuery* query);

View File

@ -32,12 +32,12 @@ static const dtNodeIndex DT_NULL_IDX = (dtNodeIndex)~0;
struct dtNode
{
float pos[3]; // Position of the node.
float cost; // Cost from previous node to current node.
float total; // Cost up to the node.
unsigned int pidx : 30; // Index to parent node.
unsigned int flags : 2; // Node flags 0/open/closed.
dtPolyRef id; // Polygon ref the node corresponds to.
float pos[3]; ///< Position of the node.
float cost; ///< Cost from previous node to current node.
float total; ///< Cost up to the node.
unsigned int pidx : 30; ///< Index to parent node.
unsigned int flags : 2; ///< Node flags 0/open/closed.
dtPolyRef id; ///< Polygon ref the node corresponds to.
};

View File

@ -149,14 +149,14 @@ class dtCrowd
struct MoveRequest
{
unsigned char state; // State of the request
int idx; // Agent index
dtPolyRef ref; // Goal ref
float pos[3]; // Goal position
dtPathQueueRef pathqRef; // Path find query ref
dtPolyRef aref; // Goal adjustment ref
float apos[3]; // Goal adjustment pos
dtPolyRef temp[MAX_TEMP_PATH]; // Adjusted path to the goal
unsigned char state; ///< State of the request
int idx; ///< Agent index
dtPolyRef ref; ///< Goal ref
float pos[3]; ///< Goal position
dtPathQueueRef pathqRef; ///< Path find query ref
dtPolyRef aref; ///< Goal adjustment ref
float apos[3]; ///< Goal adjustment pos
dtPolyRef temp[MAX_TEMP_PATH]; ///< Adjusted path to the goal
int ntemp;
};
MoveRequest* m_moveRequests;

View File

@ -28,8 +28,8 @@ class dtLocalBoundary
struct Segment
{
float s[6]; // Segment start/end
float d; // Distance for pruning.
float s[6]; ///< Segment start/end
float d; ///< Distance for pruning.
};
float m_center[3];

View File

@ -21,16 +21,16 @@
struct dtObstacleCircle
{
float p[3]; // Position of the obstacle
float vel[3]; // Velocity of the obstacle
float dvel[3]; // Velocity of the obstacle
float rad; // Radius of the obstacle
float dp[3], np[3]; // Use for side selection during sampling.
float p[3]; ///< Position of the obstacle
float vel[3]; ///< Velocity of the obstacle
float dvel[3]; ///< Velocity of the obstacle
float rad; ///< Radius of the obstacle
float dp[3], np[3]; ///< Use for side selection during sampling.
};
struct dtObstacleSegment
{
float p[3], q[3]; // End points of the obstacle segment
float p[3], q[3]; ///< End points of the obstacle segment
bool touch;
};
@ -73,8 +73,8 @@ dtObstacleAvoidanceDebugData* dtAllocObstacleAvoidanceDebugData();
void dtFreeObstacleAvoidanceDebugData(dtObstacleAvoidanceDebugData* ptr);
static const int DT_MAX_PATTERN_DIVS = 32; // Max numver of adaptive divs.
static const int DT_MAX_PATTERN_RINGS = 4; // Max number of adaptive rings.
static const int DT_MAX_PATTERN_DIVS = 32; ///< Max numver of adaptive divs.
static const int DT_MAX_PATTERN_RINGS = 4; ///< Max number of adaptive rings.
struct dtObstacleAvoidanceParams
{
@ -84,10 +84,10 @@ struct dtObstacleAvoidanceParams
float weightSide;
float weightToi;
float horizTime;
unsigned char gridSize; // grid
unsigned char adaptiveDivs; // adaptive
unsigned char adaptiveRings; // adaptive
unsigned char adaptiveDepth; // adaptive
unsigned char gridSize; ///< grid
unsigned char adaptiveDivs; ///< adaptive
unsigned char adaptiveRings; ///< adaptive
unsigned char adaptiveDepth; ///< adaptive
};
class dtObstacleAvoidanceQuery

View File

@ -31,16 +31,16 @@ class dtPathQueue
struct PathQuery
{
dtPathQueueRef ref;
// Path find start and end location.
/// Path find start and end location.
float startPos[3], endPos[3];
dtPolyRef startRef, endRef;
// Result.
/// Result.
dtPolyRef* path;
int npath;
// State.
/// State.
dtStatus status;
int keepAlive;
const dtQueryFilter* filter; // TODO: This is potentially dangerous!
const dtQueryFilter* filter; ///< TODO: This is potentially dangerous!
};
static const int MAX_QUEUE = 8;

View File

@ -9,15 +9,15 @@ typedef unsigned int dtObstacleRef;
typedef unsigned int dtCompressedTileRef;
// Flags for addTile
/// Flags for addTile
enum dtCompressedTileFlags
{
DT_COMPRESSEDTILE_FREE_DATA = 0x01, // Navmesh owns the tile memory and should free it.
DT_COMPRESSEDTILE_FREE_DATA = 0x01, ///< Navmesh owns the tile memory and should free it.
};
struct dtCompressedTile
{
unsigned int salt; // Counter describing modifications to the tile.
unsigned int salt; ///< Counter describing modifications to the tile.
struct dtTileCacheLayerHeader* header;
unsigned char* compressed;
int compressedSize;
@ -108,40 +108,40 @@ public:
void getObstacleBounds(const struct dtTileCacheObstacle* ob, float* bmin, float* bmax) const;
// Encodes a tile id.
/// Encodes a tile id.
inline dtCompressedTileRef encodeTileId(unsigned int salt, unsigned int it) const
{
return ((dtCompressedTileRef)salt << m_tileBits) | (dtCompressedTileRef)it;
}
// Decodes a tile salt.
/// Decodes a tile salt.
inline unsigned int decodeTileIdSalt(dtCompressedTileRef ref) const
{
const dtCompressedTileRef saltMask = ((dtCompressedTileRef)1<<m_saltBits)-1;
return (unsigned int)((ref >> m_tileBits) & saltMask);
}
// Decodes a tile id.
/// Decodes a tile id.
inline unsigned int decodeTileIdTile(dtCompressedTileRef ref) const
{
const dtCompressedTileRef tileMask = ((dtCompressedTileRef)1<<m_tileBits)-1;
return (unsigned int)(ref & tileMask);
}
// Encodes an obstacle id.
/// Encodes an obstacle id.
inline dtObstacleRef encodeObstacleId(unsigned int salt, unsigned int it) const
{
return ((dtObstacleRef)salt << 16) | (dtObstacleRef)it;
}
// Decodes an obstacle salt.
/// Decodes an obstacle salt.
inline unsigned int decodeObstacleIdSalt(dtObstacleRef ref) const
{
const dtObstacleRef saltMask = ((dtObstacleRef)1<<16)-1;
return (unsigned int)((ref >> 16) & saltMask);
}
// Decodes an obstacle id.
/// Decodes an obstacle id.
inline unsigned int decodeObstacleIdObstacle(dtObstacleRef ref) const
{
const dtObstacleRef tileMask = ((dtObstacleRef)1<<16)-1;
@ -163,15 +163,15 @@ private:
dtObstacleRef ref;
};
int m_tileLutSize; // Tile hash lookup size (must be pot).
int m_tileLutMask; // Tile hash lookup mask.
int m_tileLutSize; ///< Tile hash lookup size (must be pot).
int m_tileLutMask; ///< Tile hash lookup mask.
dtCompressedTile** m_posLookup; // Tile hash lookup.
dtCompressedTile* m_nextFreeTile; // Freelist of tiles.
dtCompressedTile* m_tiles; // List of tiles.
dtCompressedTile** m_posLookup; ///< Tile hash lookup.
dtCompressedTile* m_nextFreeTile; ///< Freelist of tiles.
dtCompressedTile* m_tiles; ///< List of tiles.
unsigned int m_saltBits; // Number of salt bits in the tile ID.
unsigned int m_tileBits; // Number of tile bits in the tile ID.
unsigned int m_saltBits; ///< Number of salt bits in the tile ID.
unsigned int m_tileBits; ///< Number of tile bits in the tile ID.
dtTileCacheParams m_params;

View File

@ -22,7 +22,7 @@
#include "DetourAlloc.h"
#include "DetourStatus.h"
static const int DT_TILECACHE_MAGIC = 'D'<<24 | 'T'<<16 | 'L'<<8 | 'R'; //'DTLR';
static const int DT_TILECACHE_MAGIC = 'D'<<24 | 'T'<<16 | 'L'<<8 | 'R'; ///< 'DTLR';
static const int DT_TILECACHE_VERSION = 1;
static const unsigned char DT_TILECACHE_NULL_AREA = 0;
@ -30,19 +30,19 @@ static const unsigned char DT_TILECACHE_WALKABLE_AREA = 63;
struct dtTileCacheLayerHeader
{
int magic; // Data magic
int version; // Data version
int magic; ///< Data magic
int version; ///< Data version
int tx,ty,tlayer;
float bmin[3], bmax[3];
unsigned short hmin, hmax; // Height min/max range
unsigned char width, height; // Dimension of the layer.
unsigned char minx, maxx, miny, maxy; // Usable sub-region.
unsigned short hmin, hmax; ///< Height min/max range
unsigned char width, height; ///< Dimension of the layer.
unsigned char minx, maxx, miny, maxy; ///< Usable sub-region.
};
struct dtTileCacheLayer
{
dtTileCacheLayerHeader* header;
unsigned char regCount; // Region count.
unsigned char regCount; ///< Region count.
unsigned char* heights;
unsigned char* areas;
unsigned char* cons;
@ -65,12 +65,12 @@ struct dtTileCacheContourSet
struct dtTileCachePolyMesh
{
int nverts; // Number of vertices.
int npolys; // Number of polygons.
unsigned short* verts; // Vertices of the mesh, 3 elements per vertex.
unsigned short* polys; // Polygons of the mesh, nvp*2 elements per polygon.
unsigned short* flags; // Per polygon flags.
unsigned char* areas; // Area ID of polygons.
int nverts; ///< Number of vertices.
int npolys; ///< Number of polygons.
unsigned short* verts; ///< Vertices of the mesh, 3 elements per vertex.
unsigned short* polys; ///< Polygons of the mesh, nvp*2 elements per polygon.
unsigned short* flags; ///< Per polygon flags.
unsigned char* areas; ///< Area ID of polygons.
};

1699
Doxyfile Normal file

File diff suppressed because it is too large Load Diff

View File

@ -62,101 +62,104 @@ enum rcTimerLabel
RC_MAX_TIMERS
};
// Build context provides several optional utilities needed for the build process,
// such as timing, logging, and build time collecting.
/// Build context provides several optional utilities needed for the build process,
/// such as timing, logging, and build time collecting.
class rcContext
{
public:
inline rcContext(bool state = true) : m_logEnabled(state), m_timerEnabled(state) {}
virtual ~rcContext() {}
// Enables or disables logging.
/// Enables or disables logging.
inline void enableLog(bool state) { m_logEnabled = state; }
// Resets log.
/// Resets log.
inline void resetLog() { if (m_logEnabled) doResetLog(); }
// Logs a message.
/// Logs a message.
void log(const rcLogCategory category, const char* format, ...);
// Enables or disables timer.
/// Enables or disables timer.
inline void enableTimer(bool state) { m_timerEnabled = state; }
// Resets all timers.
/// Resets all timers.
inline void resetTimers() { if (m_timerEnabled) doResetTimers(); }
// Starts timer, used for performance timing.
/// Starts timer, used for performance timing.
inline void startTimer(const rcTimerLabel label) { if (m_timerEnabled) doStartTimer(label); }
// Stops timer, used for performance timing.
/// Stops timer, used for performance timing.
inline void stopTimer(const rcTimerLabel label) { if (m_timerEnabled) doStopTimer(label); }
// Returns time accumulated between timer start/stop.
/// Returns time accumulated between timer start/stop.
inline int getAccumulatedTime(const rcTimerLabel label) const { return m_timerEnabled ? doGetAccumulatedTime(label) : -1; }
protected:
// Virtual functions to override for custom implementations.
/// @name Virtual functions to override 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 { return -1; }
///@}
bool m_logEnabled;
bool m_timerEnabled;
};
// The units of the parameters are specified in parenthesis as follows:
// (vx) voxels, (wu) world units
/// The units of the parameters are specified in parenthesis as follows:
/// (vx) voxels, (wu) world units
struct rcConfig
{
int width, height; // Dimensions of the rasterized heightfield (vx)
int tileSize; // Width and Height of a tile (vx)
int borderSize; // Non-navigable Border around the heightfield (vx)
float cs, ch; // Grid cell size and height (wu)
float bmin[3], bmax[3]; // Grid bounds (wu)
float walkableSlopeAngle; // Maximum walkable slope angle in degrees.
int walkableHeight; // Minimum height where the agent can still walk (vx)
int walkableClimb; // Maximum height between grid cells the agent can climb (vx)
int walkableRadius; // Radius of the agent in cells (vx)
int maxEdgeLen; // Maximum contour edge length (vx)
float maxSimplificationError; // Maximum distance error from contour to cells (vx)
int minRegionArea; // Regions whose area is smaller than this threshold will be removed. (vx)
int mergeRegionArea; // Regions whose area is smaller than this threshold will be merged (vx)
int maxVertsPerPoly; // Max number of vertices per polygon
float detailSampleDist; // Detail mesh sample spacing.
float detailSampleMaxError; // Detail mesh simplification max sample error.
int width, height; ///< Dimensions of the rasterized heightfield (vx)
int tileSize; ///< Width and Height of a tile (vx)
int borderSize; ///< Non-navigable Border around the heightfield (vx)
float cs, ch; ///< Grid cell size and height (wu)
float bmin[3], bmax[3]; ///< Grid bounds (wu)
float walkableSlopeAngle; ///< Maximum walkable slope angle in degrees.
int walkableHeight; ///< Minimum height where the agent can still walk (vx)
int walkableClimb; ///< Maximum height between grid cells the agent can climb (vx)
int walkableRadius; ///< Radius of the agent in cells (vx)
int maxEdgeLen; ///< Maximum contour edge length (vx)
float maxSimplificationError; ///< Maximum distance error from contour to cells (vx)
int minRegionArea; ///< Regions whose area is smaller than this threshold will be removed. (vx)
int mergeRegionArea; ///< Regions whose area is smaller than this threshold will be merged (vx)
int maxVertsPerPoly; ///< Max number of vertices per polygon
float detailSampleDist; ///< Detail mesh sample spacing.
float detailSampleMaxError; ///< Detail mesh simplification max sample error.
};
// Define number of bits in the above structure for smin/smax.
// The max height is used for clamping rasterized values.
/// Define number of bits in the above structure for smin/smax.
static const int RC_SPAN_HEIGHT_BITS = 13;
/// The max height is used for clamping rasterized values.
static const int RC_SPAN_MAX_HEIGHT = (1<<RC_SPAN_HEIGHT_BITS)-1;
// Heightfield span.
/// Heightfield span.
struct rcSpan
{
unsigned int smin : 13; // Span min height.
unsigned int smax : 13; // Span max height.
unsigned int area : 6; // Span area type.
rcSpan* next; // Next span in column.
unsigned int smin : 13; ///< Span min height.
unsigned int smax : 13; ///< Span max height.
unsigned int area : 6; ///< Span area type.
rcSpan* next; ///< Next span in column.
};
// Number of spans allocated per pool.
/// Number of spans allocated per pool.
static const int RC_SPANS_PER_POOL = 2048;
// Memory pool used for quick span allocation.
/// Memory pool used for quick span allocation.
struct rcSpanPool
{
rcSpanPool* next; // Pointer to next pool.
rcSpan items[RC_SPANS_PER_POOL]; // Array of spans.
rcSpanPool* next; ///< Pointer to next pool.
rcSpan items[RC_SPANS_PER_POOL]; ///< Array of spans.
};
// Dynamic span-heightfield.
/// Dynamic span-heightfield.
struct rcHeightfield
{
int width, height; // Dimension of the heightfield.
float bmin[3], bmax[3]; // Bounding box of the heightfield
float cs, ch; // Cell size and height.
rcSpan** spans; // Heightfield of spans (width*height).
rcSpanPool* pools; // Linked list of span pools.
rcSpan* freelist; // Pointer to next free span.
int width, height; ///< Dimension of the heightfield.
float bmin[3], bmax[3]; ///< Bounding box of the heightfield
float cs, ch; ///< Cell size and height.
rcSpan** spans; ///< Heightfield of spans (width*height).
rcSpanPool* pools; ///< Linked list of span pools.
rcSpan* freelist; ///< Pointer to next free span.
};
rcHeightfield* rcAllocHeightfield();
@ -165,33 +168,33 @@ void rcFreeHeightField(rcHeightfield* hf);
struct rcCompactCell
{
unsigned int index : 24; // Index to first span in column.
unsigned int count : 8; // Number of spans in this column.
unsigned int index : 24; ///< Index to first span in column.
unsigned int count : 8; ///< Number of spans in this column.
};
struct rcCompactSpan
{
unsigned short y; // Bottom coordinate of the span.
unsigned short y; ///< Bottom coordinate of the span.
unsigned short reg;
unsigned int con : 24; // Connections to neighbour cells.
unsigned int h : 8; // Height of the span.
unsigned int con : 24; ///< Connections to neighbour cells.
unsigned int h : 8; ///< Height of the span.
};
// Compact static heightfield.
/// Compact static heightfield.
struct rcCompactHeightfield
{
int width, height; // Width and height of the heightfield.
int spanCount; // Number of spans in the heightfield.
int walkableHeight, walkableClimb; // Agent properties.
int borderSize; // Border size of the heighfield.
unsigned short maxDistance; // Maximum distance value stored in heightfield.
unsigned short maxRegions; // Maximum Region Id stored in heightfield.
float bmin[3], bmax[3]; // Bounding box of the heightfield.
float cs, ch; // Cell size and height.
rcCompactCell* cells; // Pointer to width*height cells.
rcCompactSpan* spans; // Pointer to spans.
unsigned short* dist; // Pointer to per span distance to border.
unsigned char* areas; // Pointer to per span area ID.
int width, height; ///< Width and height of the heightfield.
int spanCount; ///< Number of spans in the heightfield.
int walkableHeight, walkableClimb; ///< Agent properties.
int borderSize; ///< Border size of the heighfield.
unsigned short maxDistance; ///< Maximum distance value stored in heightfield.
unsigned short maxRegions; ///< Maximum Region Id stored in heightfield.
float bmin[3], bmax[3]; ///< Bounding box of the heightfield.
float cs, ch; ///< Cell size and height.
rcCompactCell* cells; ///< Pointer to width*height cells.
rcCompactSpan* spans; ///< Pointer to spans.
unsigned short* dist; ///< Pointer to per span distance to border.
unsigned char* areas; ///< Pointer to per span area ID.
};
rcCompactHeightfield* rcAllocCompactHeightfield();
@ -201,20 +204,20 @@ void rcFreeCompactHeightfield(rcCompactHeightfield* chf);
struct rcHeightfieldLayer
{
float bmin[3], bmax[3]; // Bounding box of the heightfield.
float cs, ch; // Cell size and height.
int width, height; // Width and height of the layer.
int minx,maxx,miny,maxy; // Bounding box of usable data.
int hmin, hmax; // Height min/max
unsigned char* heights; // Heighfield.
unsigned char* areas; // Area types.
unsigned char* cons; // Connections.
float bmin[3], bmax[3]; ///< Bounding box of the heightfield.
float cs, ch; ///< Cell size and height.
int width, height; ///< Width and height of the layer.
int minx,maxx,miny,maxy; ///< Bounding box of usable data.
int hmin, hmax; ///< Height min/max
unsigned char* heights; ///< Heighfield.
unsigned char* areas; ///< Area types.
unsigned char* cons; ///< Connections.
};
struct rcHeightfieldLayerSet
{
rcHeightfieldLayer* layers; // Pointer to layers.
int nlayers; // Number of layers.
rcHeightfieldLayer* layers; ///< Pointer to layers.
int nlayers; ///< Number of layers.
};
rcHeightfieldLayerSet* rcAllocHeightfieldLayerSet();
@ -224,117 +227,116 @@ void rcFreeHeightfieldLayerSet(rcHeightfieldLayerSet* lset);
struct rcContour
{
int* verts; // Vertex coordinates, each vertex contains 4 components.
int nverts; // Number of vertices.
int* rverts; // Raw vertex coordinates, each vertex contains 4 components.
int nrverts; // Number of raw vertices.
unsigned short reg; // Region ID of the contour.
unsigned char area; // Area ID of the contour.
int* verts; ///< Vertex coordinates, each vertex contains 4 components.
int nverts; ///< Number of vertices.
int* rverts; ///< Raw vertex coordinates, each vertex contains 4 components.
int nrverts; ///< Number of raw vertices.
unsigned short reg; ///< Region ID of the contour.
unsigned char area; ///< Area ID of the contour.
};
struct rcContourSet
{
rcContour* conts; // Pointer to all contours.
int nconts; // Number of contours.
float bmin[3], bmax[3]; // Bounding box of the heightfield.
float cs, ch; // Cell size and height.
int width, height; // Region where the contours were build.
int borderSize; // Border size of the heighfield where the contours were build from.
rcContour* conts; ///< Pointer to all contours.
int nconts; ///< Number of contours.
float bmin[3], bmax[3]; ///< Bounding box of the heightfield.
float cs, ch; ///< Cell size and height.
int width, height; ///< Region where the contours were build.
int borderSize; ///< Border size of the heighfield where the contours were build from.
};
rcContourSet* rcAllocContourSet();
void rcFreeContourSet(rcContourSet* cset);
// Polymesh store a connected mesh of polygons.
// The polygons are store in an array where each polygons takes
// 'nvp*2' elements. The first 'nvp' elements are indices to vertices
// and the second 'nvp' elements are indices to neighbour polygons.
// If a polygon has less than 'bvp' vertices, the remaining indices
// are set to RC_MESH_NULL_IDX. If an polygon edge does not have a neighbour
// the neighbour index is set to RC_MESH_NULL_IDX.
// Vertices can be transformed into world space as follows:
// x = bmin[0] + verts[i*3+0]*cs;
// y = bmin[1] + verts[i*3+1]*ch;
// z = bmin[2] + verts[i*3+2]*cs;
/// Polymesh store a connected mesh of polygons.
/// The polygons are store in an array where each polygons takes
/// 'nvp*2' elements. The first 'nvp' elements are indices to vertices
/// and the second 'nvp' elements are indices to neighbour polygons.
/// If a polygon has less than 'bvp' vertices, the remaining indices
/// are set to RC_MESH_NULL_IDX. If an polygon edge does not have a neighbour
/// the neighbour index is set to RC_MESH_NULL_IDX.
/// Vertices can be transformed into world space as follows:
/// x = bmin[0] + verts[i*3+0]*cs;
/// y = bmin[1] + verts[i*3+1]*ch;
/// z = bmin[2] + verts[i*3+2]*cs;
struct rcPolyMesh
{
unsigned short* verts; // Vertices of the mesh, 3 elements per vertex.
unsigned short* polys; // Polygons of the mesh, nvp*2 elements per polygon.
unsigned short* regs; // Region ID of the polygons.
unsigned short* flags; // Per polygon flags.
unsigned char* areas; // Area ID of polygons.
int nverts; // Number of vertices.
int npolys; // Number of polygons.
int maxpolys; // Number of allocated polygons.
int nvp; // Max number of vertices per polygon.
float bmin[3], bmax[3]; // Bounding box of the mesh.
float cs, ch; // Cell size and height.
int borderSize; // Border size of the heighfield where the mesh was build from.
unsigned short* verts; ///< Vertices of the mesh, 3 elements per vertex.
unsigned short* polys; ///< Polygons of the mesh, nvp*2 elements per polygon.
unsigned short* regs; ///< Region ID of the polygons.
unsigned short* flags; ///< Per polygon flags.
unsigned char* areas; ///< Area ID of polygons.
int nverts; ///< Number of vertices.
int npolys; ///< Number of polygons.
int maxpolys; ///< Number of allocated polygons.
int nvp; ///< Max number of vertices per polygon.
float bmin[3], bmax[3]; ///< Bounding box of the mesh.
float cs, ch; ///< Cell size and height.
int borderSize; ///< Border size of the heighfield where the mesh was build from.
};
rcPolyMesh* rcAllocPolyMesh();
void rcFreePolyMesh(rcPolyMesh* pmesh);
// Detail mesh generated from a rcPolyMesh.
// Each submesh represents a polygon in the polymesh and they are stored in
// exactly same order. Each submesh is described as 4 values:
// base vertex, vertex count, base triangle, triangle count. That is,
// const unsigned char* t = &dmesh.tris[(tbase+i)*4]; and
// const float* v = &dmesh.verts[(vbase+t[j])*3];
// If the input polygon has 'n' vertices, those vertices are first in the
// submesh vertex list. This allows to compres the mesh by not storing the
// first vertices and using the polymesh vertices instead.
// Max number of vertices per submesh is 127 and
// max number of triangles per submesh is 255.
/// Detail mesh generated from a rcPolyMesh.
/// Each submesh represents a polygon in the polymesh and they are stored in
/// exactly same order. Each submesh is described as 4 values:
/// base vertex, vertex count, base triangle, triangle count. That is,
/// const unsigned char* t = &dmesh.tris[(tbase+i)*4]; and
/// const float* v = &dmesh.verts[(vbase+t[j])*3];
/// If the input polygon has 'n' vertices, those vertices are first in the
/// submesh vertex list. This allows to compres the mesh by not storing the
/// first vertices and using the polymesh vertices instead.
/// Max number of vertices per submesh is 127 and
/// max number of triangles per submesh is 255.
struct rcPolyMeshDetail
{
unsigned int* meshes; // Pointer to all mesh data.
float* verts; // Pointer to all vertex data.
unsigned char* tris; // Pointer to all triangle data.
int nmeshes; // Number of meshes.
int nverts; // Number of total vertices.
int ntris; // Number of triangles.
unsigned int* meshes; ///< Pointer to all mesh data.
float* verts; ///< Pointer to all vertex data.
unsigned char* tris; ///< Pointer to all triangle data.
int nmeshes; ///< Number of meshes.
int nverts; ///< Number of total vertices.
int ntris; ///< Number of triangles.
};
rcPolyMeshDetail* rcAllocPolyMeshDetail();
void rcFreePolyMeshDetail(rcPolyMeshDetail* dmesh);
// If heightfield region ID has the following bit set, the region is on border area
// and excluded from many calculations.
/// If heightfield region ID has the following bit set, the region is on border area
/// and excluded from many calculations.
static const unsigned short RC_BORDER_REG = 0x8000;
// If contour region ID has the following bit set, the vertex will be later
// removed in order to match the segments and vertices at tile boundaries.
/// If contour region ID has the following bit set, the vertex will be later
/// removed in order to match the segments and vertices at tile boundaries.
static const int RC_BORDER_VERTEX = 0x10000;
static const int RC_AREA_BORDER = 0x20000;
enum rcBuildContoursFlags
{
RC_CONTOUR_TESS_WALL_EDGES = 0x01, // Tessellate wall edges
RC_CONTOUR_TESS_AREA_EDGES = 0x02, // Tessellate edges between areas.
RC_CONTOUR_TESS_WALL_EDGES = 0x01, ///< Tessellate wall edges
RC_CONTOUR_TESS_AREA_EDGES = 0x02, ///< Tessellate edges between areas.
};
// Mask used with contours to extract region id.
/// Mask used with contours to extract region id.
static const int RC_CONTOUR_REG_MASK = 0xffff;
// Null index which is used with meshes to mark unset or invalid indices.
/// Null index which is used with meshes to mark unset or invalid indices.
static const unsigned short RC_MESH_NULL_IDX = 0xffff;
// Area ID that is considered empty.
/// Area ID that is considered empty.
static const unsigned char RC_NULL_AREA = 0;
// Area ID that is considered generally walkable.
/// Area ID that is considered generally walkable.
static const unsigned char RC_WALKABLE_AREA = 63;
// Value returned by rcGetCon() if the direction is not connected.
/// Value returned by rcGetCon() if the direction is not connected.
static const int RC_NOT_CONNECTED = 0x3f;
// Compact span neighbour helpers.
/// Compact span neighbour helpers.
inline void rcSetCon(rcCompactSpan& s, int dir, int i)
{
const unsigned int shift = (unsigned int)dir*6;
@ -360,7 +362,8 @@ inline int rcGetDirOffsetY(int dir)
return offset[dir&0x03];
}
// Common helper functions
/// @name Common helper functions
///@{
template<class T> inline void rcSwap(T& a, T& b) { T t = a; a = b; b = t; }
template<class T> inline T rcMin(T a, T b) { return a < b ? a : b; }
template<class T> inline T rcMax(T a, T b) { return a > b ? a : b; }
@ -369,8 +372,10 @@ template<class T> inline T rcSqr(T a) { return a*a; }
template<class T> inline T rcClamp(T v, T mn, T mx) { return v < mn ? mn : (v > mx ? mx : v); }
float rcSqrt(float x);
inline int rcAlign4(int x) { return (x+3) & ~3; }
///@}
// Common vector helper functions.
/// @name Common vector helper functions.
///@{
inline void rcVcross(float* dest, const float* v1, const float* v2)
{
dest[0] = v1[1]*v2[2] - v1[2]*v2[1];
@ -455,283 +460,256 @@ inline bool rcVequal(const float* p0, const float* p1)
const float d = rcVdistSqr(p0, p1);
return d < thr;
}
///@}
// Calculated bounding box of array of vertices.
// Params:
// verts - (in) array of vertices
// nv - (in) vertex count
// bmin, bmax - (out) bounding box
/// Calculated bounding box of array of vertices.
/// @param verts [in] array of vertices
/// @param nv [in] vertex count
/// @param bmin,bmax [out] bounding box
void rcCalcBounds(const float* verts, int nv, float* bmin, float* bmax);
// Calculates grid size based on bounding box and grid cell size.
// Params:
// bmin, bmax - (in) bounding box
// cs - (in) grid cell size
// w - (out) grid width
// h - (out) grid height
/// Calculates grid size based on bounding box and grid cell size.
/// @param bmin,bmax [in] bounding box
/// @param cs [in] grid cell size
/// @param w [out] grid width
/// @param h [out] grid height
void rcCalcGridSize(const float* bmin, const float* bmax, float cs, int* w, int* h);
// Creates and initializes new heightfield.
// Params:
// hf - (in/out) heightfield to initialize.
// width - (in) width of the heightfield.
// height - (in) height of the heightfield.
// bmin, bmax - (in) bounding box of the heightfield
// cs - (in) grid cell size
// ch - (in) grid cell height
/// Creates and initializes new heightfield.
/// @param hf [in,out] heightfield to initialize.
/// @param width [in] width of the heightfield.
/// @param height [in] height of the heightfield.
/// @param bmin,bmax [in] bounding box of the heightfield
/// @param cs [in] grid cell size
/// @param ch [in] grid cell height
bool rcCreateHeightfield(rcContext* ctx, rcHeightfield& hf, int width, int height,
const float* bmin, const float* bmax,
float cs, float ch);
// Sets the RC_WALKABLE_AREA for every triangle whose slope is below
// the maximum walkable slope angle.
// Params:
// walkableSlopeAngle - (in) maximum slope angle in degrees.
// verts - (in) array of vertices
// nv - (in) vertex count
// tris - (in) array of triangle vertex indices
// nt - (in) triangle count
// areas - (out) array of triangle area types
/// Sets the RC_WALKABLE_AREA for every triangle whose slope is below
/// the maximum walkable slope angle.
/// @param walkableSlopeAngle [in] maximum slope angle in degrees.
/// @param verts [in] array of vertices
/// @param nv [in] vertex count
/// @param tris [in] array of triangle vertex indices
/// @param nt [in] triangle count
/// @param areas [out] array of triangle area types
void rcMarkWalkableTriangles(rcContext* ctx, const float walkableSlopeAngle, const float* verts, int nv,
const int* tris, int nt, unsigned char* areas);
// Sets the RC_NULL_AREA for every triangle whose slope is steeper than
// the maximum walkable slope angle.
// Params:
// walkableSlopeAngle - (in) maximum slope angle in degrees.
// verts - (in) array of vertices
// nv - (in) vertex count
// tris - (in) array of triangle vertex indices
// nt - (in) triangle count
// areas - (out) array of triangle are types
/// Sets the RC_NULL_AREA for every triangle whose slope is steeper than
/// the maximum walkable slope angle.
/// @param walkableSlopeAngle [in] maximum slope angle in degrees.
/// @param verts [in] array of vertices
/// @param nv [in] vertex count
/// @param tris [in] array of triangle vertex indices
/// @param nt [in] triangle count
/// @param areas [out] array of triangle are types
void rcClearUnwalkableTriangles(rcContext* ctx, const float walkableSlopeAngle, const float* verts, int nv,
const int* tris, int nt, unsigned char* areas);
// Adds span to heightfield.
// The span addition can set to favor flags. If the span is merged to
// another span and the new smax is within 'flagMergeThr' units away
// from the existing span the span flags are merged and stored.
// Params:
// solid - (in) heightfield where the spans is added to
// x,y - (in) location on the heightfield where the span is added
// smin,smax - (in) spans min/max height
// flags - (in) span flags (zero or WALKABLE)
// flagMergeThr - (in) merge threshold.
/// Adds span to heightfield.
/// The span addition can set to favor flags. If the span is merged to
/// another span and the new smax is within 'flagMergeThr' units away
/// from the existing span the span flags are merged and stored.
/// @param x,y [in] location on the heightfield where the span is added
/// @param smin,smax [in] spans min/max height
/// @param area
/// @param flagMergeThr [in] merge threshold.
void rcAddSpan(rcContext* ctx, rcHeightfield& hf, const int x, const int y,
const unsigned short smin, const unsigned short smax,
const unsigned char area, const int flagMergeThr);
// Rasterizes a triangle into heightfield spans.
// Params:
// v0,v1,v2 - (in) the vertices of the triangle.
// area - (in) area type of the triangle.
// solid - (in) heightfield where the triangle is rasterized
// flagMergeThr - (in) distance in voxel where walkable flag is favored over non-walkable.
/// Rasterizes a triangle into heightfield spans.
/// @param v0,v1,v2 [in] the vertices of the triangle.
/// @param area [in] area type of the triangle.
/// @param solid [in] heightfield where the triangle is rasterized
/// @param flagMergeThr [in] distance in voxel where walkable flag is favored over non-walkable.
void rcRasterizeTriangle(rcContext* ctx, const float* v0, const float* v1, const float* v2,
const unsigned char area, rcHeightfield& solid,
const int flagMergeThr = 1);
// Rasterizes indexed triangle mesh into heightfield spans.
// Params:
// verts - (in) array of vertices
// nv - (in) vertex count
// tris - (in) array of triangle vertex indices
// area - (in) array of triangle area types.
// nt - (in) triangle count
// solid - (in) heightfield where the triangles are rasterized
// flagMergeThr - (in) distance in voxel where walkable flag is favored over non-walkable.
/// Rasterizes indexed triangle mesh into heightfield spans.
/// @param verts [in] array of vertices
/// @param nv [in] vertex count
/// @param tris [in] array of triangle vertex indices
/// @param areas [in] array of triangle area types.
/// @param nt [in] triangle count
/// @param solid [in] heightfield where the triangles are rasterized
/// @param flagMergeThr [in] distance in voxel where walkable flag is favored over non-walkable.
void rcRasterizeTriangles(rcContext* ctx, const float* verts, const int nv,
const int* tris, const unsigned char* areas, const int nt,
rcHeightfield& solid, const int flagMergeThr = 1);
// Rasterizes indexed triangle mesh into heightfield spans.
// Params:
// verts - (in) array of vertices
// nv - (in) vertex count
// tris - (in) array of triangle vertex indices
// area - (in) array of triangle area types.
// nt - (in) triangle count
// solid - (in) heightfield where the triangles are rasterized
// flagMergeThr - (in) distance in voxel where walkable flag is favored over non-walkable.
/// Rasterizes indexed triangle mesh into heightfield spans.
/// @param verts [in] array of vertices
/// @param nv [in] vertex count
/// @param tris [in] array of triangle vertex indices
/// @param areas [in] array of triangle area types.
/// @param nt [in] triangle count
/// @param solid [in] heightfield where the triangles are rasterized
/// @param flagMergeThr [in] distance in voxel where walkable flag is favored over non-walkable.
void rcRasterizeTriangles(rcContext* ctx, const float* verts, const int nv,
const unsigned short* tris, const unsigned char* areas, const int nt,
rcHeightfield& solid, const int flagMergeThr = 1);
// Rasterizes the triangles into heightfield spans.
// Params:
// verts - (in) array of vertices
// area - (in) array of triangle area types.
// nt - (in) triangle count
// solid - (in) heightfield where the triangles are rasterized
/// Rasterizes the triangles into heightfield spans.
/// @param verts [in] array of vertices
/// @param areas [in] array of triangle area types.
/// @param nt [in] triangle count
/// @param solid [in] heightfield where the triangles are rasterized
void rcRasterizeTriangles(rcContext* ctx, const float* verts, const unsigned char* areas, const int nt,
rcHeightfield& solid, const int flagMergeThr = 1);
// Marks non-walkable low obstacles as walkable if they are closer than walkableClimb
// from a walkable surface. Applying this filter allows to step over low hanging
// low obstacles.
// Params:
// walkableHeight - (in) minimum height where the agent can still walk
// solid - (in/out) heightfield describing the solid space
// TODO: Missuses ledge flag, must be called before rcFilterLedgeSpans!
/// Marks non-walkable low obstacles as walkable if they are closer than walkableClimb
/// from a walkable surface. Applying this filter allows to step over low hanging
/// low obstacles.
/// @param walkableClimb [in] maximum height between grid cells the agent can climb
/// @param solid [in,out] heightfield describing the solid space
/// @warning TODO: Misses ledge flag, must be called before rcFilterLedgeSpans!
void rcFilterLowHangingWalkableObstacles(rcContext* ctx, const int walkableClimb, rcHeightfield& solid);
// Removes WALKABLE flag from all spans that are at ledges. This filtering
// removes possible overestimation of the conservative voxelization so that
// the resulting mesh will not have regions hanging in air over ledges.
// Params:
// walkableHeight - (in) minimum height where the agent can still walk
// walkableClimb - (in) maximum height between grid cells the agent can climb
// solid - (in/out) heightfield describing the solid space
/// Removes WALKABLE flag from all spans that are at ledges. This filtering
/// removes possible overestimation of the conservative voxelization so that
/// the resulting mesh will not have regions hanging in air over ledges.
/// @param walkableHeight [in] minimum height where the agent can still walk
/// @param walkableClimb [in] maximum height between grid cells the agent can climb
/// @param solid [in,out] heightfield describing the solid space
void rcFilterLedgeSpans(rcContext* ctx, const int walkableHeight,
const int walkableClimb, rcHeightfield& solid);
// Removes WALKABLE flag from all spans which have smaller than
// 'walkableHeight' clearance above them.
// Params:
// walkableHeight - (in) minimum height where the agent can still walk
// solid - (in/out) heightfield describing the solid space
/// Removes WALKABLE flag from all spans which have smaller than
/// 'walkableHeight' clearance above them.
/// @param walkableHeight [in] minimum height where the agent can still walk
/// @param solid [in,out] heightfield describing the solid space
void rcFilterWalkableLowHeightSpans(rcContext* ctx, int walkableHeight, rcHeightfield& solid);
// Returns number of spans contained in a heightfield.
// Params:
// hf - (in) heightfield to be compacted
// Returns number of spans.
/// Returns number of spans contained in a heightfield.
/// @param hf [in] heightfield to be compacted
/// @returns number of spans.
int rcGetHeightFieldSpanCount(rcContext* ctx, rcHeightfield& hf);
// Builds compact representation of the heightfield.
// Params:
// walkableHeight - (in) minimum height where the agent can still walk
// walkableClimb - (in) maximum height between grid cells the agent can climb
// hf - (in) heightfield to be compacted
// chf - (out) compact heightfield representing the open space.
// Returns false if operation ran out of memory.
/// Builds compact representation of the heightfield.
/// @param walkableHeight [in] minimum height where the agent can still walk
/// @param walkableClimb [in] maximum height between grid cells the agent can climb
/// @param hf [in] heightfield to be compacted
/// @param chf [out] compact heightfield representing the open space.
/// @returns false if operation ran out of memory.
bool rcBuildCompactHeightfield(rcContext* ctx, const int walkableHeight, const int walkableClimb,
rcHeightfield& hf, rcCompactHeightfield& chf);
// Erodes walkable area.
// Params:
// radius - (in) radius of erosion (max 255).
// chf - (in/out) compact heightfield to erode.
// Returns false if operation ran out of memory.
/// Erodes walkable area.
/// @param radius [in] radius of erosion (max 255).
/// @param chf [in,out] compact heightfield to erode.
/// @returns false if operation ran out of memory.
bool rcErodeWalkableArea(rcContext* ctx, int radius, rcCompactHeightfield& chf);
// Applies median filter to walkable area types, removing noise.
// Params:
// chf - (in/out) compact heightfield to erode.
// Returns false if operation ran out of memory.
/// Applies median filter to walkable area types, removing noise.
/// @param chf [in,out] compact heightfield to erode.
/// @returns false if operation ran out of memory.
bool rcMedianFilterWalkableArea(rcContext* ctx, rcCompactHeightfield& chf);
// Marks the area of the convex polygon into the area type of the compact heightfield.
// Params:
// bmin/bmax - (in) bounds of the axis aligned box.
// areaId - (in) area ID to mark.
// chf - (in/out) compact heightfield to mark.
/// Marks the area of the convex polygon into the area type of the compact heightfield.
/// @param bmin,bmax [in] bounds of the axis aligned box.
/// @param areaId [in] area ID to mark.
/// @param chf [in,out] compact heightfield to mark.
void rcMarkBoxArea(rcContext* ctx, const float* bmin, const float* bmax, unsigned char areaId,
rcCompactHeightfield& chf);
// Marks the area of the convex polygon into the area type of the compact heightfield.
// Params:
// verts - (in) vertices of the convex polygon.
// nverts - (in) number of vertices in the polygon.
// hmin/hmax - (in) min and max height of the polygon.
// areaId - (in) area ID to mark.
// chf - (in/out) compact heightfield to mark.
/// Marks the area of the convex polygon into the area type of the compact heightfield.
/// @param verts [in] vertices of the convex polygon.
/// @param nverts [in] number of vertices in the polygon.
/// @param hmin,hmax [in] min and max height of the polygon.
/// @param areaId [in] area ID to mark.
/// @param chf [in,out] compact heightfield to mark.
void rcMarkConvexPolyArea(rcContext* ctx, const float* verts, const int nverts,
const float hmin, const float hmax, unsigned char areaId,
rcCompactHeightfield& chf);
// Marks the area of the cylinder into the area type of the compact heightfield.
// Params:
// pos - (in) center bottom location of hte cylinder.
// r - (in) radius of the cylinder.
// h - (in) height of the cylinder.
// areaId - (in) area ID to mark.
// chf - (in/out) compact heightfield to mark.
/// Marks the area of the cylinder into the area type of the compact heightfield.
/// @param pos [in] center bottom location of hte cylinder.
/// @param r [in] radius of the cylinder.
/// @param h [in] height of the cylinder.
/// @param areaId [in] area ID to mark.
/// @param chf [in,out] compact heightfield to mark.
void rcMarkCylinderArea(rcContext* ctx, const float* pos,
const float r, const float h, unsigned char areaId,
rcCompactHeightfield& chf);
// Builds distance field and stores it into the combat heightfield.
// Params:
// chf - (in/out) compact heightfield representing the open space.
// Returns false if operation ran out of memory.
/// Builds distance field and stores it into the combat heightfield.
/// @param chf [in,out] compact heightfield representing the open space.
/// @returns false if operation ran out of memory.
bool rcBuildDistanceField(rcContext* ctx, rcCompactHeightfield& chf);
// Divides the walkable heighfied into simple regions using watershed partitioning.
// Each region has only one contour and no overlaps.
// The regions are stored in the compact heightfield 'reg' field.
// The process sometimes creates small regions. If the area of a regions is
// smaller than 'mergeRegionArea' then the region will be merged with a neighbour
// region if possible. If multiple regions form an area which is smaller than
// 'minRegionArea' all the regions belonging to that area will be removed.
// Here area means the count of spans in an area.
// Params:
// chf - (in/out) compact heightfield representing the open space.
// borderSize - (in) Non-navigable Border around the heightfield.
// minRegionArea - (in) the smallest allowed region area.
// maxMergeRegionArea - (in) the largest allowed region area which can be merged.
// Returns false if operation ran out of memory.
/// Divides the walkable heighfied into simple regions using watershed partitioning.
/// Each region has only one contour and no overlaps.
/// The regions are stored in the compact heightfield 'reg' field.
/// The process sometimes creates small regions. If the area of a regions is
/// smaller than 'mergeRegionArea' then the region will be merged with a neighbour
/// region if possible. If multiple regions form an area which is smaller than
/// 'minRegionArea' all the regions belonging to that area will be removed.
/// Here area means the count of spans in an area.
/// @param chf [in,out] compact heightfield representing the open space.
/// @param borderSize [in] Non-navigable Border around the heightfield.
/// @param minRegionArea [in] the smallest allowed region area.
/// @param maxMergeRegionArea [in] the largest allowed region area which can be merged.
/// @returns false if operation ran out of memory.
bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf,
const int borderSize, const int minRegionArea, const int mergeRegionArea);
// Divides the walkable heighfied into simple regions using simple monotone partitioning.
// Each region has only one contour and no overlaps.
// The regions are stored in the compact heightfield 'reg' field.
// The process sometimes creates small regions. If the area of a regions is
// smaller than 'mergeRegionArea' then the region will be merged with a neighbour
// region if possible. If multiple regions form an area which is smaller than
// 'minRegionArea' all the regions belonging to that area will be removed.
// Here area means the count of spans in an area.
// Params:
// chf - (in/out) compact heightfield representing the open space.
// borderSize - (in) Non-navigable Border around the heightfield.
// minRegionArea - (in) the smallest allowed regions size.
// maxMergeRegionArea - (in) the largest allowed regions size which can be merged.
// Returns false if operation ran out of memory.
/// Divides the walkable heighfied into simple regions using simple monotone partitioning.
/// Each region has only one contour and no overlaps.
/// The regions are stored in the compact heightfield 'reg' field.
/// The process sometimes creates small regions. If the area of a regions is
/// smaller than 'mergeRegionArea' then the region will be merged with a neighbour
/// region if possible. If multiple regions form an area which is smaller than
/// 'minRegionArea' all the regions belonging to that area will be removed.
/// Here area means the count of spans in an area.
/// @param chf [in,out] compact heightfield representing the open space.
/// @param borderSize [in] Non-navigable Border around the heightfield.
/// @param minRegionArea [in] the smallest allowed regions size.
/// @param maxMergeRegionArea [in] the largest allowed regions size which can be merged.
/// @returns false if operation ran out of memory.
bool rcBuildRegionsMonotone(rcContext* ctx, rcCompactHeightfield& chf,
const int borderSize, const int minRegionArea, const int mergeRegionArea);
// Builds 2D layer representation of a heighfield.
// Params:
// chf - (in) compact heightfield representing the open space.
// borderSize - (in) Non-navigable Border around the heightfield.
// walkableHeight - (in) minimum height where the agent can still walk.
// lset - (out) set of 2D heighfield layers.
// Returns false if operation ran out of memory.
/// Builds 2D layer representation of a heighfield.
/// @param chf [in] compact heightfield representing the open space.
/// @param borderSize [in] Non-navigable Border around the heightfield.
/// @param walkableHeight [in] minimum height where the agent can still walk.
/// @param lset [out] set of 2D heighfield layers.
/// @returns false if operation ran out of memory.
bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf,
const int borderSize, const int walkableHeight,
rcHeightfieldLayerSet& lset);
// Builds simplified contours from the regions outlines.
// Params:
// chf - (in) compact heightfield which has regions set.
// maxError - (in) maximum allowed distance between simplified contour and cells.
// maxEdgeLen - (in) maximum allowed contour edge length in cells.
// cset - (out) Resulting contour set.
// flags - (in) build flags, see rcBuildContoursFlags.
// Returns false if operation ran out of memory.
/// Builds simplified contours from the regions outlines.
/// @param chf [in] compact heightfield which has regions set.
/// @param maxError [in] maximum allowed distance between simplified contour and cells.
/// @param maxEdgeLen [in] maximum allowed contour edge length in cells.
/// @param cset [out] Resulting contour set.
/// @param flags [in] build flags, see rcBuildContoursFlags.
/// @returns false if operation ran out of memory.
bool rcBuildContours(rcContext* ctx, rcCompactHeightfield& chf,
const float maxError, const int maxEdgeLen,
rcContourSet& cset, const int flags = RC_CONTOUR_TESS_WALL_EDGES);
// Builds connected convex polygon mesh from contour polygons.
// Params:
// cset - (in) contour set.
// nvp - (in) maximum number of vertices per polygon.
// mesh - (out) poly mesh.
// Returns false if operation ran out of memory.
/// Builds connected convex polygon mesh from contour polygons.
/// @param cset [in] contour set.
/// @param nvp [in] maximum number of vertices per polygon.
/// @param mesh [out] poly mesh.
/// @returns false if operation ran out of memory.
bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMesh& mesh);
bool rcMergePolyMeshes(rcContext* ctx, rcPolyMesh** meshes, const int nmeshes, rcPolyMesh& mesh);
// Builds detail triangle mesh for each polygon in the poly mesh.
// Params:
// mesh - (in) poly mesh to detail.
// chf - (in) compact height field, used to query height for new vertices.
// sampleDist - (in) spacing between height samples used to generate more detail into mesh.
// sampleMaxError - (in) maximum allowed distance between simplified detail mesh and height sample.
// dmesh - (out) detail mesh.
// Returns false if operation ran out of memory.
/// Builds detail triangle mesh for each polygon in the poly mesh.
/// @param mesh [in] poly mesh to detail.
/// @param chf [in] compact height field, used to query height for new vertices.
/// @param sampleDist [in] spacing between height samples used to generate more detail into mesh.
/// @param sampleMaxError [in] maximum allowed distance between simplified detail mesh and height sample.
/// @param dmesh [out] detail mesh.
/// @returns false if operation ran out of memory.
bool rcBuildPolyMeshDetail(rcContext* ctx, const rcPolyMesh& mesh, const rcCompactHeightfield& chf,
const float sampleDist, const float sampleMaxError,
rcPolyMeshDetail& dmesh);

View File

@ -21,8 +21,8 @@
enum rcAllocHint
{
RC_ALLOC_PERM, // Memory persist after a function call.
RC_ALLOC_TEMP // Memory used temporarily within a function.
RC_ALLOC_PERM, ///< Memory persist after a function call.
RC_ALLOC_TEMP ///< Memory used temporarily within a function.
};
typedef void* (rcAllocFunc)(int size, rcAllocHint hint);
@ -35,7 +35,7 @@ void rcFree(void* ptr);
// Simple dynamic array ints.
/// Simple dynamic array ints.
class rcIntArray
{
int* m_data;
@ -54,7 +54,7 @@ public:
inline int size() const { return m_size; }
};
// Simple internal helper class to delete array in scope
/// Simple internal helper class to delete array in scope
template<class T> class rcScopedDelete
{
T* ptr;

View File

@ -37,15 +37,15 @@ struct rcChunkyTriMesh
int maxTrisPerChunk;
};
// Creates partitioned triangle mesh (AABB tree),
// where each node contains at max trisPerChunk triangles.
/// 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.
/// 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.
/// 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);

View File

@ -37,7 +37,8 @@ class InputGeom
rcMeshLoaderObj* m_mesh;
float m_meshBMin[3], m_meshBMax[3];
// Off-Mesh connections.
/// @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];
@ -46,11 +47,14 @@ class InputGeom
unsigned short m_offMeshConFlags[MAX_OFFMESH_CONNECTIONS];
unsigned int m_offMeshConId[MAX_OFFMESH_CONNECTIONS];
int m_offMeshConCount;
///@}
// Convex Volumes.
/// @name Convex Volumes.
///@{
static const int MAX_VOLUMES = 256;
ConvexVolume m_volumes[MAX_VOLUMES];
int m_volumeCount;
///@}
public:
InputGeom();
@ -61,14 +65,15 @@ public:
bool load(class rcContext* ctx, const char* filepath);
bool save(const char* filepath);
// Method to return static mesh data.
/// Method to return static mesh data.
inline const rcMeshLoaderObj* getMesh() const { return m_mesh; }
inline const float* getMeshBoundsMin() const { return m_meshBMin; }
inline const float* getMeshBoundsMax() const { return m_meshBMax; }
inline const rcChunkyTriMesh* getChunkyMesh() const { return m_chunkyMesh; }
bool raycastMesh(float* src, float* dst, float& tmin);
// Off-Mesh connections.
/// @name Off-Mesh connections.
///@{
int getOffMeshConnectionCount() const { return m_offMeshConCount; }
const float* getOffMeshConnectionVerts() const { return m_offMeshConVerts; }
const float* getOffMeshConnectionRads() const { return m_offMeshConRads; }
@ -80,14 +85,17 @@ public:
unsigned char bidir, unsigned char area, unsigned short flags);
void deleteOffMeshConnection(int i);
void drawOffMeshConnections(struct duDebugDraw* dd, bool hilight = false);
///@}
// Box Volumes.
/// @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);
///@}
};
#endif // INPUTGEOM_H

View File

@ -23,7 +23,7 @@
#include "SampleInterfaces.h"
// Tool types.
/// Tool types.
enum SampleToolType
{
TOOL_NONE = 0,
@ -36,8 +36,8 @@ enum SampleToolType
TOOL_CROWD,
};
// These are just sample areas to use consistent values across the samples.
// The use should specify these base on his needs.
/// 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,
@ -49,11 +49,11 @@ enum SamplePolyAreas
};
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_ALL = 0xffff // All abilities.
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_ALL = 0xffff ///< All abilities.
};
struct SampleTool

View File

@ -26,7 +26,7 @@
// These are example implementations of various interfaces used in Recast and Detour.
// Recast build context.
/// Recast build context.
class BuildContext : public rcContext
{
TimeVal m_startTime[RC_MAX_TIMERS];
@ -43,24 +43,26 @@ public:
BuildContext();
virtual ~BuildContext();
// Dumps the log to stdout.
/// Dumps the log to stdout.
void dumpLog(const char* format, ...);
// Returns number of log messages.
/// Returns number of log messages.
int getLogCount() const;
// Returns log message text.
/// Returns log message text.
const char* getLogText(const int i) const;
protected:
// Virtual functions for custom implementations.
/// 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.
/// OpenGL debug draw implementation.
class DebugDrawGL : public duDebugDraw
{
public:
@ -74,7 +76,7 @@ public:
virtual void end();
};
// stdio file implementation.
/// stdio file implementation.
class FileIO : public duFileIO
{
FILE* m_fp;

View File

@ -23,7 +23,7 @@
#include "DetourNavMesh.h"
#include "Recast.h"
// Sample used for random debugging.
/// Sample used for random debugging.
class Sample_Debug : public Sample
{
protected: