23static const float RC_PI = 3.14159265f;
43 RC_TIMER_RASTERIZE_TRIANGLES,
45 RC_TIMER_BUILD_COMPACTHEIGHTFIELD,
47 RC_TIMER_BUILD_CONTOURS,
49 RC_TIMER_BUILD_CONTOURS_TRACE,
51 RC_TIMER_BUILD_CONTOURS_SIMPLIFY,
53 RC_TIMER_FILTER_BORDER,
55 RC_TIMER_FILTER_WALKABLE,
59 RC_TIMER_FILTER_LOW_OBSTACLES,
61 RC_TIMER_BUILD_POLYMESH,
63 RC_TIMER_MERGE_POLYMESH,
67 RC_TIMER_MARK_BOX_AREA,
69 RC_TIMER_MARK_CYLINDER_AREA,
71 RC_TIMER_MARK_CONVEXPOLY_AREA,
73 RC_TIMER_BUILD_DISTANCEFIELD,
75 RC_TIMER_BUILD_DISTANCEFIELD_DIST,
77 RC_TIMER_BUILD_DISTANCEFIELD_BLUR,
79 RC_TIMER_BUILD_REGIONS,
81 RC_TIMER_BUILD_REGIONS_WATERSHED,
83 RC_TIMER_BUILD_REGIONS_EXPAND,
85 RC_TIMER_BUILD_REGIONS_FLOOD,
87 RC_TIMER_BUILD_REGIONS_FILTER,
89 RC_TIMER_BUILD_LAYERS,
91 RC_TIMER_BUILD_POLYMESHDETAIL,
93 RC_TIMER_MERGE_POLYMESHDETAIL,
120 void log(
const rcLogCategory category,
const char* format, ...);
151 virtual void doLog(
const rcLogCategory ,
const char* ,
const int ) {}
193 const rcTimerLabel m_label;
266static const int RC_SPAN_HEIGHT_BITS = 13;
268static const int RC_SPAN_MAX_HEIGHT = (1 << RC_SPAN_HEIGHT_BITS) - 1;
272static const int RC_SPANS_PER_POOL = 2048;
278 unsigned int smin : RC_SPAN_HEIGHT_BITS;
279 unsigned int smax : RC_SPAN_HEIGHT_BITS;
536static const unsigned short RC_BORDER_REG = 0x8000;
544static const unsigned short RC_MULTIPLE_REGS = 0;
553static const int RC_BORDER_VERTEX = 0x10000;
560static const int RC_AREA_BORDER = 0x20000;
564enum rcBuildContoursFlags
566 RC_CONTOUR_TESS_WALL_EDGES = 0x01,
567 RC_CONTOUR_TESS_AREA_EDGES = 0x02,
574static const int RC_CONTOUR_REG_MASK = 0xffff;
579static const unsigned short RC_MESH_NULL_IDX = 0xffff;
584static const unsigned char RC_NULL_AREA = 0;
589static const unsigned char RC_WALKABLE_AREA = 63;
593static const int RC_NOT_CONNECTED = 0x3f;
601template<
class T>
void rcIgnoreUnused(
const T&) { }
606template<
class T>
inline void rcSwap(T& a, T& b) { T t = a; a = b; b = t; }
612template<
class T>
inline T rcMin(T a, T b) {
return a < b ? a : b; }
618template<
class T>
inline T rcMax(T a, T b) {
return a > b ? a : b; }
623template<
class T>
inline T rcAbs(T a) {
return a < 0 ? -a : a; }
628template<
class T>
inline T rcSqr(T a) {
return a*a; }
635template<
class T>
inline T rcClamp(T v, T mn, T mx) {
return v < mn ? mn : (v > mx ? mx : v); }
640float rcSqrt(
float x);
650inline void rcVcross(
float* dest,
const float* v1,
const float* v2)
652 dest[0] = v1[1]*v2[2] - v1[2]*v2[1];
653 dest[1] = v1[2]*v2[0] - v1[0]*v2[2];
654 dest[2] = v1[0]*v2[1] - v1[1]*v2[0];
661inline float rcVdot(
const float* v1,
const float* v2)
663 return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
671inline void rcVmad(
float* dest,
const float* v1,
const float* v2,
const float s)
673 dest[0] = v1[0]+v2[0]*s;
674 dest[1] = v1[1]+v2[1]*s;
675 dest[2] = v1[2]+v2[2]*s;
682inline void rcVadd(
float* dest,
const float* v1,
const float* v2)
684 dest[0] = v1[0]+v2[0];
685 dest[1] = v1[1]+v2[1];
686 dest[2] = v1[2]+v2[2];
693inline void rcVsub(
float* dest,
const float* v1,
const float* v2)
695 dest[0] = v1[0]-v2[0];
696 dest[1] = v1[1]-v2[1];
697 dest[2] = v1[2]-v2[2];
703inline void rcVmin(
float* mn,
const float* v)
705 mn[0] = rcMin(mn[0], v[0]);
706 mn[1] = rcMin(mn[1], v[1]);
707 mn[2] = rcMin(mn[2], v[2]);
713inline void rcVmax(
float* mx,
const float* v)
715 mx[0] = rcMax(mx[0], v[0]);
716 mx[1] = rcMax(mx[1], v[1]);
717 mx[2] = rcMax(mx[2], v[2]);
723inline void rcVcopy(
float* dest,
const float* v)
734inline float rcVdist(
const float* v1,
const float* v2)
736 float dx = v2[0] - v1[0];
737 float dy = v2[1] - v1[1];
738 float dz = v2[2] - v1[2];
739 return rcSqrt(dx*dx + dy*dy + dz*dz);
746inline float rcVdistSqr(
const float* v1,
const float* v2)
748 float dx = v2[0] - v1[0];
749 float dy = v2[1] - v1[1];
750 float dz = v2[2] - v1[2];
751 return dx*dx + dy*dy + dz*dz;
756inline void rcVnormalize(
float* v)
758 float d = 1.0f / rcSqrt(rcSqr(v[0]) + rcSqr(v[1]) + rcSqr(v[2]));
775void rcCalcBounds(
const float* verts,
int nv,
float* bmin,
float* bmax);
784void rcCalcGridSize(
const float* bmin,
const float* bmax,
float cs,
int* w,
int* h);
798 const float* bmin,
const float* bmax,
812void rcMarkWalkableTriangles(
rcContext* ctx,
const float walkableSlopeAngle,
const float* verts,
int nv,
813 const int* tris,
int nt,
unsigned char* areas);
825void rcClearUnwalkableTriangles(
rcContext* ctx,
const float walkableSlopeAngle,
const float* verts,
int nv,
826 const int* tris,
int nt,
unsigned char* areas);
842 const unsigned short smin,
const unsigned short smax,
843 const unsigned char area,
const int flagMergeThr);
856bool rcRasterizeTriangle(
rcContext* ctx,
const float* v0,
const float* v1,
const float* v2,
858 const int flagMergeThr = 1);
872bool rcRasterizeTriangles(
rcContext* ctx,
const float* verts,
const int nv,
873 const int* tris,
const unsigned char* areas,
const int nt,
888bool rcRasterizeTriangles(
rcContext* ctx,
const float* verts,
const int nv,
889 const unsigned short* tris,
const unsigned char* areas,
const int nt,
902bool rcRasterizeTriangles(
rcContext* ctx,
const float* verts,
const unsigned char* areas,
const int nt,
921void rcFilterLedgeSpans(
rcContext* ctx,
const int walkableHeight,
954bool rcBuildCompactHeightfield(
rcContext* ctx,
const int walkableHeight,
const int walkableClimb,
979void rcMarkBoxArea(
rcContext* ctx,
const float* bmin,
const float* bmax,
unsigned char areaId,
991void rcMarkConvexPolyArea(
rcContext* ctx,
const float* verts,
const int nverts,
992 const float hmin,
const float hmax,
unsigned char areaId,
1002int rcOffsetPoly(
const float* verts,
const int nverts,
const float offset,
1003 float* outVerts,
const int maxOutVerts);
1013void rcMarkCylinderArea(
rcContext* ctx,
const float* pos,
1014 const float r,
const float h,
unsigned char areaId,
1036 const int borderSize,
const int minRegionArea,
const int mergeRegionArea);
1048 const int borderSize,
const int minRegionArea);
1062 const int borderSize,
const int minRegionArea,
const int mergeRegionArea);
1070 const unsigned int shift = (
unsigned int)dir*6;
1071 unsigned int con = s.con;
1072 s.con = (con & ~(0x3f << shift)) | (((
unsigned int)i & 0x3f) << shift);
1082 const unsigned int shift = (
unsigned int)dir*6;
1083 return (s.con >> shift) & 0x3f;
1090inline int rcGetDirOffsetX(
int dir)
1092 static const int offset[4] = { -1, 0, 1, 0, };
1093 return offset[dir&0x03];
1100inline int rcGetDirOffsetY(
int dir)
1102 static const int offset[4] = { 0, 1, 0, -1 };
1103 return offset[dir&0x03];
1110inline int rcGetDirForOffset(
int x,
int y)
1112 static const int dirs[5] = { 3, 0, -1, 2, 1 };
1113 return dirs[((y+1)<<1)+x];
1132 const int borderSize,
const int walkableHeight,
1147 const float maxError,
const int maxEdgeLen,
1148 rcContourSet& cset,
const int buildFlags = RC_CONTOUR_TESS_WALL_EDGES);
1180 const float sampleDist,
const float sampleMaxError,
void enableLog(bool state)
Definition Recast.h:112
int getAccumulatedTime(const rcTimerLabel label) const
Definition Recast.h:140
void resetTimers()
Clears all peformance timers. (Resets all to unused.)
Definition Recast.h:127
void startTimer(const rcTimerLabel label)
Definition Recast.h:131
void stopTimer(const rcTimerLabel label)
Definition Recast.h:135
virtual void doResetTimers()
Clears all timers. (Resets all to unused.)
Definition Recast.h:154
void resetLog()
Clears all log entries.
Definition Recast.h:115
virtual void doStopTimer(const rcTimerLabel)
Definition Recast.h:162
bool m_timerEnabled
True if the performance timers are enabled.
Definition Recast.h:173
virtual void doStartTimer(const rcTimerLabel)
Definition Recast.h:158
void enableTimer(bool state)
Definition Recast.h:124
virtual int doGetAccumulatedTime(const rcTimerLabel) const
Definition Recast.h:167
virtual void doLog(const rcLogCategory, const char *, const int)
Definition Recast.h:151
rcContext(bool state=true)
Definition Recast.h:107
virtual void doResetLog()
Clears all log entries.
Definition Recast.h:145
bool m_logEnabled
True if logging is enabled.
Definition Recast.h:170
rcScopedTimer(rcContext *ctx, const rcTimerLabel label)
Definition Recast.h:184
Provides information on the content of a cell column in a compact heightfield.
Definition Recast.h:317
unsigned int count
Number of spans in the column.
Definition Recast.h:319
unsigned int index
Index to the first span in the column.
Definition Recast.h:318
int walkableHeight
The walkable height used during the build of the field. (See: rcConfig::walkableHeight)
Definition Recast.h:340
rcCompactSpan * spans
Array of spans. [Size: spanCount].
Definition Recast.h:350
int height
The height of the heightfield. (Along the z-axis in cell units.)
Definition Recast.h:338
unsigned short maxDistance
The maximum distance value of any span within the field.
Definition Recast.h:343
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition Recast.h:348
float bmax[3]
The maximum bounds in world space. [(x, y, z)].
Definition Recast.h:346
int borderSize
The AABB border size used during the build of the field. (See: rcConfig::borderSize)
Definition Recast.h:342
unsigned short maxRegions
The maximum region id of any span within the field.
Definition Recast.h:344
int spanCount
The number of spans in the heightfield.
Definition Recast.h:339
float cs
The size of each cell. (On the xz-plane.)
Definition Recast.h:347
int width
The width of the heightfield. (Along the x-axis in cell units.)
Definition Recast.h:337
rcCompactCell * cells
Array of cells. [Size: width*height].
Definition Recast.h:349
unsigned char * areas
Array containing area id data. [Size: spanCount].
Definition Recast.h:352
int walkableClimb
The walkable climb used during the build of the field. (See: rcConfig::walkableClimb)
Definition Recast.h:341
float bmin[3]
The minimum bounds in world space. [(x, y, z)].
Definition Recast.h:345
unsigned short * dist
Array containing border distance data. [Size: spanCount].
Definition Recast.h:351
Represents a span of unobstructed space within a compact heightfield.
Definition Recast.h:324
unsigned short y
The lower extent of the span. (Measured from the heightfield's base.)
Definition Recast.h:325
unsigned int h
The height of the span. (Measured from y.)
Definition Recast.h:328
unsigned int con
Packed neighbor connection data.
Definition Recast.h:327
unsigned short reg
The id of the region the span belongs to. (Or zero if not in a region.)
Definition Recast.h:326
int minRegionArea
The minimum number of cells allowed to form isolated island areas. [Limit: >=0] [Units: vx].
Definition Recast.h:246
int maxVertsPerPoly
Definition Recast.h:254
int height
The height of the field along the z-axis. [Limit: >= 0] [Units: vx].
Definition Recast.h:204
int borderSize
The size of the non-navigable border around the heightfield. [Limit: >=0] [Units: vx].
Definition Recast.h:210
float cs
The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu].
Definition Recast.h:213
int tileSize
The width/height size of tile's on the xz-plane. [Limit: >= 0] [Units: vx].
Definition Recast.h:207
int walkableRadius
Definition Recast.h:236
int width
The width of the field along the x-axis. [Limit: >= 0] [Units: vx].
Definition Recast.h:201
float maxSimplificationError
Definition Recast.h:243
int mergeRegionArea
Definition Recast.h:250
float bmax[3]
The maximum bounds of the field's AABB. [(x, y, z)] [Units: wu].
Definition Recast.h:222
int walkableHeight
Definition Recast.h:229
float detailSampleDist
Definition Recast.h:258
int maxEdgeLen
The maximum allowed length for contour edges along the border of the mesh. [Limit: >=0] [Units: vx].
Definition Recast.h:239
float ch
The y-axis cell size to use for fields. [Limit: > 0] [Units: wu].
Definition Recast.h:216
int walkableClimb
Maximum ledge height that is considered to still be traversable. [Limit: >=0] [Units: vx].
Definition Recast.h:232
float walkableSlopeAngle
The maximum slope that is considered walkable. [Limits: 0 <= value < 90] [Units: Degrees].
Definition Recast.h:225
float detailSampleMaxError
Definition Recast.h:262
float bmin[3]
The minimum bounds of the field's AABB. [(x, y, z)] [Units: wu].
Definition Recast.h:219
int height
The height of the set. (Along the z-axis in cell units.)
Definition Recast.h:411
float cs
The size of each cell. (On the xz-plane.)
Definition Recast.h:408
float bmin[3]
The minimum bounds in world space. [(x, y, z)].
Definition Recast.h:406
int nconts
The number of contours in the set.
Definition Recast.h:405
rcContour * conts
An array of the contours in the set. [Size: nconts].
Definition Recast.h:404
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition Recast.h:409
int borderSize
The AABB border size used to generate the source data from which the contours were derived.
Definition Recast.h:412
float bmax[3]
The maximum bounds in world space. [(x, y, z)].
Definition Recast.h:407
int width
The width of the set. (Along the x-axis in cell units.)
Definition Recast.h:410
float maxError
The max edge error that this contour set was simplified with.
Definition Recast.h:413
Represents a simple, non-overlapping contour in field space.
Definition Recast.h:389
int nrverts
The number of vertices in the raw contour.
Definition Recast.h:393
unsigned char area
The area id of the contour.
Definition Recast.h:395
int * rverts
Raw contour vertex and connection data. [Size: 4 * nrverts].
Definition Recast.h:392
unsigned short reg
The region id of the contour.
Definition Recast.h:394
int * verts
Simplified contour vertex and connection data. [Size: 4 * nverts].
Definition Recast.h:390
int nverts
The number of vertices in the simplified contour.
Definition Recast.h:391
rcHeightfieldLayer * layers
The layers in the set. [Size: nlayers].
Definition Recast.h:383
int nlayers
The number of layers in the set.
Definition Recast.h:384
float bmax[3]
The maximum bounds in world space. [(x, y, z)].
Definition Recast.h:360
unsigned char * cons
Packed neighbor connection information. [Size: Same as heights].
Definition Recast.h:373
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition Recast.h:362
int height
The height of the heightfield. (Along the z-axis in cell units.)
Definition Recast.h:364
int width
The width of the heightfield. (Along the x-axis in cell units.)
Definition Recast.h:363
int hmin
The minimum height bounds of usable data. (Along the y-axis.)
Definition Recast.h:369
unsigned char * areas
Area ids. [Size: Same as heights].
Definition Recast.h:372
int hmax
The maximum height bounds of usable data. (Along the y-axis.)
Definition Recast.h:370
float bmin[3]
The minimum bounds in world space. [(x, y, z)].
Definition Recast.h:359
int maxx
The maximum x-bounds of usable data.
Definition Recast.h:366
unsigned char * heights
The heightfield. [Size: width * height].
Definition Recast.h:371
int maxy
The maximum y-bounds of usable data. (Along the z-axis.)
Definition Recast.h:368
int minx
The minimum x-bounds of usable data.
Definition Recast.h:365
float cs
The size of each cell. (On the xz-plane.)
Definition Recast.h:361
int miny
The minimum y-bounds of usable data. (Along the z-axis.)
Definition Recast.h:367
float bmin[3]
The minimum bounds in world space. [(x, y, z)].
Definition Recast.h:301
rcSpan * freelist
The next free span.
Definition Recast.h:307
rcSpan ** spans
Heightfield of spans (width*height).
Definition Recast.h:305
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition Recast.h:304
float cs
The size of each cell. (On the xz-plane.)
Definition Recast.h:303
float bmax[3]
The maximum bounds in world space. [(x, y, z)].
Definition Recast.h:302
int height
The height of the heightfield. (Along the z-axis in cell units.)
Definition Recast.h:300
rcSpanPool * pools
Linked list of span pools.
Definition Recast.h:306
int width
The width of the heightfield. (Along the x-axis in cell units.)
Definition Recast.h:299
unsigned char * tris
The mesh triangles. [Size: 4*ntris].
Definition Recast.h:446
float * verts
The mesh vertices. [Size: 3*nverts].
Definition Recast.h:445
int nverts
The number of vertices in verts.
Definition Recast.h:448
int ntris
The number of triangles in tris.
Definition Recast.h:449
unsigned int * meshes
The sub-mesh data. [Size: 4*nmeshes].
Definition Recast.h:444
int nmeshes
The number of sub-meshes defined by meshes.
Definition Recast.h:447
unsigned short * verts
The mesh vertices. [Form: (x, y, z) * nverts].
Definition Recast.h:422
float cs
The size of each cell. (On the xz-plane.)
Definition Recast.h:433
float bmin[3]
The minimum bounds in world space. [(x, y, z)].
Definition Recast.h:431
unsigned char * areas
The area id assigned to each polygon. [Length: maxpolys].
Definition Recast.h:426
unsigned short * regs
The region id assigned to each polygon. [Length: maxpolys].
Definition Recast.h:424
int borderSize
The AABB border size used to generate the source data from which the mesh was derived.
Definition Recast.h:435
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition Recast.h:434
float bmax[3]
The maximum bounds in world space. [(x, y, z)].
Definition Recast.h:432
int nvp
The maximum number of vertices per polygon.
Definition Recast.h:430
float maxEdgeError
The max error of the polygon edges in the mesh.
Definition Recast.h:436
unsigned short * polys
Polygon and neighbor data. [Length: maxpolys * 2 * nvp].
Definition Recast.h:423
unsigned short * flags
The user defined flags for each polygon. [Length: maxpolys].
Definition Recast.h:425
int npolys
The number of polygons.
Definition Recast.h:428
int nverts
The number of vertices.
Definition Recast.h:427
int maxpolys
The number of allocated polygons.
Definition Recast.h:429
rcSpan items[RC_SPANS_PER_POOL]
Array of spans in the pool.
Definition Recast.h:289
rcSpanPool * next
The next span pool.
Definition Recast.h:288
rcSpan * next
The next span higher up in column.
Definition Recast.h:281
unsigned int smax
The upper limit of the span. [Limit: <= RC_SPAN_MAX_HEIGHT].
Definition Recast.h:279
unsigned int area
The area id assigned to the span.
Definition Recast.h:280
unsigned int smin
The lower limit of the span. [Limit: < smax].
Definition Recast.h:278