Recast Navigation
Navigation-mesh Toolset for Games
RecastRasterization.cpp File Reference
#include <math.h>
#include "Recast.h"
#include "RecastAlloc.h"
#include "RecastAssert.h"

Enumerations

enum  rcAxis { RC_AXIS_X = 0 , RC_AXIS_Y = 1 , RC_AXIS_Z = 2 }
 

Functions

static bool overlapBounds (const float *aMin, const float *aMax, const float *bMin, const float *bMax)
 Check whether two bounding boxes overlap. More...
 
static rcSpanallocSpan (rcHeightfield &heightfield)
 Allocates a new span in the heightfield. More...
 
static void freeSpan (rcHeightfield &heightfield, rcSpan *span)
 Releases the memory used by the span back to the heightfield, so it can be re-used for new spans. More...
 
static bool addSpan (rcHeightfield &heightfield, const int x, const int z, const unsigned short min, const unsigned short max, const unsigned char areaID, const int flagMergeThreshold)
 Adds a span to the heightfield. More...
 
bool rcAddSpan (rcContext *context, rcHeightfield &heightfield, const int x, const int z, const unsigned short spanMin, const unsigned short spanMax, const unsigned char areaID, const int flagMergeThreshold)
 Adds a span to the specified heightfield. More...
 
static void dividePoly (const float *inVerts, int inVertsCount, float *outVerts1, int *outVerts1Count, float *outVerts2, int *outVerts2Count, float axisOffset, rcAxis axis)
 Divides a convex polygon of max 12 vertices into two convex polygons across a separating axis. More...
 
static bool rasterizeTri (const float *v0, const float *v1, const float *v2, const unsigned char areaID, rcHeightfield &heightfield, const float *heightfieldBBMin, const float *heightfieldBBMax, const float cellSize, const float inverseCellSize, const float inverseCellHeight, const int flagMergeThreshold)
 Rasterize a single triangle to the heightfield. More...
 
bool rcRasterizeTriangle (rcContext *context, const float *v0, const float *v1, const float *v2, const unsigned char areaID, rcHeightfield &heightfield, const int flagMergeThreshold)
 Rasterizes a single triangle into the specified heightfield. More...
 
bool rcRasterizeTriangles (rcContext *context, const float *verts, const int, const int *tris, const unsigned char *triAreaIDs, const int numTris, rcHeightfield &heightfield, const int flagMergeThreshold)
 Rasterizes an indexed triangle mesh into the specified heightfield. More...
 
bool rcRasterizeTriangles (rcContext *context, const float *verts, const int, const unsigned short *tris, const unsigned char *triAreaIDs, const int numTris, rcHeightfield &heightfield, const int flagMergeThreshold)
 Rasterizes an indexed triangle mesh into the specified heightfield. More...
 
bool rcRasterizeTriangles (rcContext *context, const float *verts, const unsigned char *triAreaIDs, const int numTris, rcHeightfield &heightfield, const int flagMergeThreshold)
 Rasterizes a triangle list into the specified heightfield. More...
 

Enumeration Type Documentation

◆ rcAxis

enum rcAxis
Enumerator
RC_AXIS_X 
RC_AXIS_Y 
RC_AXIS_Z 

Function Documentation

◆ addSpan()

static bool addSpan ( rcHeightfield heightfield,
const int  x,
const int  z,
const unsigned short  min,
const unsigned short  max,
const unsigned char  areaID,
const int  flagMergeThreshold 
)
static

Adds a span to the heightfield.

If the new span overlaps existing spans, it will merge the new span with the existing ones.

Parameters
[in]heightfieldHeightfield to add spans to
[in]xThe new span's column cell x index
[in]zThe new span's column cell z index
[in]minThe new span's minimum cell index
[in]maxThe new span's maximum cell index
[in]areaIDThe new span's area type ID
[in]flagMergeThresholdHow close two spans maximum extents need to be to merge area type IDs

◆ allocSpan()

static rcSpan* allocSpan ( rcHeightfield heightfield)
static

Allocates a new span in the heightfield.

Use a memory pool and free list to minimize actual allocations.

Parameters
[in]heightfieldThe heightfield
Returns
A pointer to the allocated or re-used span memory.

◆ dividePoly()

static void dividePoly ( const float *  inVerts,
int  inVertsCount,
float *  outVerts1,
int *  outVerts1Count,
float *  outVerts2,
int *  outVerts2Count,
float  axisOffset,
rcAxis  axis 
)
static

Divides a convex polygon of max 12 vertices into two convex polygons across a separating axis.

Parameters
[in]inVertsThe input polygon vertices
[in]inVertsCountThe number of input polygon vertices
[out]outVerts1Resulting polygon 1's vertices
[out]outVerts1CountThe number of resulting polygon 1 vertices
[out]outVerts2Resulting polygon 2's vertices
[out]outVerts2CountThe number of resulting polygon 2 vertices
[in]axisOffsetTHe offset along the specified axis
[in]axisThe separating axis

◆ freeSpan()

static void freeSpan ( rcHeightfield heightfield,
rcSpan span 
)
static

Releases the memory used by the span back to the heightfield, so it can be re-used for new spans.

Parameters
[in]heightfieldThe heightfield.
[in]spanA pointer to the span to free

◆ overlapBounds()

static bool overlapBounds ( const float *  aMin,
const float *  aMax,
const float *  bMin,
const float *  bMax 
)
static

Check whether two bounding boxes overlap.

Parameters
[in]aMinMin axis extents of bounding box A
[in]aMaxMax axis extents of bounding box A
[in]bMinMin axis extents of bounding box B
[in]bMaxMax axis extents of bounding box B
Returns
true if the two bounding boxes overlap. False otherwise.

◆ rasterizeTri()

static bool rasterizeTri ( const float *  v0,
const float *  v1,
const float *  v2,
const unsigned char  areaID,
rcHeightfield heightfield,
const float *  heightfieldBBMin,
const float *  heightfieldBBMax,
const float  cellSize,
const float  inverseCellSize,
const float  inverseCellHeight,
const int  flagMergeThreshold 
)
static

Rasterize a single triangle to the heightfield.

This code is extremely hot, so much care should be given to maintaining maximum perf here.

Parameters
[in]v0Triangle vertex 0
[in]v1Triangle vertex 1
[in]v2Triangle vertex 2
[in]areaIDThe area ID to assign to the rasterized spans
[in]heightfieldHeightfield to rasterize into
[in]heightfieldBBMinThe min extents of the heightfield bounding box
[in]heightfieldBBMaxThe max extents of the heightfield bounding box
[in]cellSizeThe x and z axis size of a voxel in the heightfield
[in]inverseCellSize1 / cellSize
[in]inverseCellHeight1 / cellHeight
[in]flagMergeThresholdThe threshold in which area flags will be merged
Returns
true if the operation completes successfully. false if there was an error adding spans to the heightfield.