Recast Navigation
Navigation-mesh Toolset for Games
rcCompactHeightfield Struct Reference

A compact, static heightfield representing unobstructed space. More...

#include <Recast.h>

Public Member Functions

 rcCompactHeightfield ()
 
 ~rcCompactHeightfield ()
 

Public Attributes

int width
 The width of the heightfield. (Along the x-axis in cell units.) More...
 
int height
 The height of the heightfield. (Along the z-axis in cell units.) More...
 
int spanCount
 The number of spans in the heightfield. More...
 
int walkableHeight
 The walkable height used during the build of the field. (See: rcConfig::walkableHeight) More...
 
int walkableClimb
 The walkable climb used during the build of the field. (See: rcConfig::walkableClimb) More...
 
int borderSize
 The AABB border size used during the build of the field. (See: rcConfig::borderSize) More...
 
unsigned short maxDistance
 The maximum distance value of any span within the field. More...
 
unsigned short maxRegions
 The maximum region id of any span within the field. More...
 
float bmin [3]
 The minimum bounds in world space. [(x, y, z)]. More...
 
float bmax [3]
 The maximum bounds in world space. [(x, y, z)]. More...
 
float cs
 The size of each cell. (On the xz-plane.) More...
 
float ch
 The height of each cell. (The minimum increment along the y-axis.) More...
 
rcCompactCellcells
 Array of cells. [Size: width*height]. More...
 
rcCompactSpanspans
 Array of spans. [Size: spanCount]. More...
 
unsigned short * dist
 Array containing border distance data. [Size: spanCount]. More...
 
unsigned char * areas
 Array containing area id data. [Size: spanCount]. More...
 

Description

A compact, static heightfield representing unobstructed space.

For this type of heightfield, the spans represent the open (unobstructed) space above the solid surfaces of a voxel field. It is usually created from a rcHeightfield object. Data is stored in a compact, efficient manner,
but the structure is not condusive to adding and removing spans.

The standard process for buidling a compact heightfield is to allocate it using rcAllocCompactHeightfield, build it using rcBuildCompactHeightfield, then run it through the various helper functions to generate neighbor and region data.

Connected neighbor spans form non-overlapping surfaces. When neighbor information is generated, spans will include data that can be used to locate axis-neighbors. Axis-neighbors are connected spans that are offset from the current cell column as follows:

Direction 0 = (-1, 0)
Direction 1 = (0, 1)
Direction 2 = (1, 0)
Direction 3 = (0, -1)

Example of iterating and inspecting spans, including connected neighbors:

// Where chf is an instance of a rcCompactHeightfield.
const float cs = chf.cs;
const float ch = chf.ch;
for (int y = 0; y < chf.height; ++y)
{
for (int x = 0; x < chf.width; ++x)
{
// Deriving the minimum corner of the grid location.
const float fx = chf.bmin[0] + x*cs;
const float fz = chf.bmin[2] + y*cs;
// Get the cell for the grid location then iterate
// up the column.
const rcCompactCell& c = chf.cells[x+y*chf.width];
for (unsigned i = c.index, ni = c.index+c.count; i < ni; ++i)
{
const rcCompactSpan& s = chf.spans[i];
Deriving the minimum (floor) of the span.
const float fy = chf.bmin[1] + (s.y+1)*ch;
// Testing the area assignment of the span.
if (chf.areas[i] == RC_WALKABLE_AREA)
{
// The span is in the default 'walkable area'.
}
else if (chf.areas[i] == RC_NULL_AREA)
{
// The surface is not considered walkable.
// E.g. It was filtered out during the build processes.
}
else
{
// Do something. (Only applicable for custom build
// build processes.)
}
// Iterating the connected axis-neighbor spans.
for (int dir = 0; dir < 4; ++dir)
{
if (rcGetCon(s, dir) != RC_NOT_CONNECTED)
{
// There is a neighbor in this direction.
const int nx = x + rcGetDirOffsetX(dir);
const int ny = y + rcGetDirOffsetY(dir);
const int ni = (int)chf.cells[nx+ny*w].index + rcGetCon(s, 0);
const rcCompactSpan& ns = chf.spans[ni];
// Do something with the neighbor span.
}
}
}
}
}
static const unsigned char RC_NULL_AREA
Represents the null area.
Definition: Recast.h:635
static const unsigned char RC_WALKABLE_AREA
The default area id used to indicate a walkable polygon.
Definition: Recast.h:640
static const int RC_NOT_CONNECTED
The value returned by rcGetCon if the specified direction is not connected to another span.
Definition: Recast.h:644
int rcGetDirOffsetY(int direction)
Gets the standard height (z-axis) offset for the specified direction.
Definition: Recast.h:1263
int rcGetDirOffsetX(int direction)
Gets the standard width (x-axis) offset for the specified direction.
Definition: Recast.h:1253
int rcGetCon(const rcCompactSpan &span, int direction)
Gets neighbor connection data for the specified direction.
Definition: Recast.h:1244
Provides information on the content of a cell column in a compact heightfield.
Definition: Recast.h:337
unsigned int count
Number of spans in the column.
Definition: Recast.h:339
unsigned int index
Index to the first span in the column.
Definition: Recast.h:338
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition: Recast.h:369
float cs
The size of each cell. (On the xz-plane.)
Definition: Recast.h:368
Represents a span of unobstructed space within a compact heightfield.
Definition: Recast.h:344
unsigned short y
The lower extent of the span. (Measured from the heightfield's base.)
Definition: Recast.h:345
See also
rcAllocCompactHeightfield, rcFreeCompactHeightfield, rcBuildCompactHeightfield

Constructor & Destructor Documentation

◆ rcCompactHeightfield()

rcCompactHeightfield::rcCompactHeightfield ( )

◆ ~rcCompactHeightfield()

rcCompactHeightfield::~rcCompactHeightfield ( )

Member Data Documentation

◆ areas

unsigned char* rcCompactHeightfield::areas

Array containing area id data. [Size: spanCount].

◆ bmax

float rcCompactHeightfield::bmax[3]

The maximum bounds in world space. [(x, y, z)].

◆ bmin

float rcCompactHeightfield::bmin[3]

The minimum bounds in world space. [(x, y, z)].

◆ borderSize

int rcCompactHeightfield::borderSize

The AABB border size used during the build of the field. (See: rcConfig::borderSize)

◆ cells

rcCompactCell* rcCompactHeightfield::cells

Array of cells. [Size: width*height].

◆ ch

float rcCompactHeightfield::ch

The height of each cell. (The minimum increment along the y-axis.)

◆ cs

float rcCompactHeightfield::cs

The size of each cell. (On the xz-plane.)

◆ dist

unsigned short* rcCompactHeightfield::dist

Array containing border distance data. [Size: spanCount].

◆ height

int rcCompactHeightfield::height

The height of the heightfield. (Along the z-axis in cell units.)

◆ maxDistance

unsigned short rcCompactHeightfield::maxDistance

The maximum distance value of any span within the field.

◆ maxRegions

unsigned short rcCompactHeightfield::maxRegions

The maximum region id of any span within the field.

◆ spanCount

int rcCompactHeightfield::spanCount

The number of spans in the heightfield.

◆ spans

rcCompactSpan* rcCompactHeightfield::spans

Array of spans. [Size: spanCount].

◆ walkableClimb

int rcCompactHeightfield::walkableClimb

The walkable climb used during the build of the field. (See: rcConfig::walkableClimb)

◆ walkableHeight

int rcCompactHeightfield::walkableHeight

The walkable height used during the build of the field. (See: rcConfig::walkableHeight)

◆ width

int rcCompactHeightfield::width

The width of the heightfield. (Along the x-axis in cell units.)


The documentation for this struct was generated from the following files: