TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Recast.cpp File Reference
#include <float.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include "Recast.h"
#include "RecastAlloc.h"
#include "RecastAssert.h"
+ Include dependency graph for Recast.cpp:

Macros

#define _USE_MATH_DEFINES
 

Functions

float rcSqrt (float x)
 
rcHeightfieldrcAllocHeightfield ()
 
void rcFreeHeightField (rcHeightfield *hf)
 
rcCompactHeightfieldrcAllocCompactHeightfield ()
 
void rcFreeCompactHeightfield (rcCompactHeightfield *chf)
 
rcHeightfieldLayerSetrcAllocHeightfieldLayerSet ()
 
void rcFreeHeightfieldLayerSet (rcHeightfieldLayerSet *lset)
 
rcContourSetrcAllocContourSet ()
 
void rcFreeContourSet (rcContourSet *cset)
 
rcPolyMeshrcAllocPolyMesh ()
 
void rcFreePolyMesh (rcPolyMesh *pmesh)
 
rcPolyMeshDetailrcAllocPolyMeshDetail ()
 
void rcFreePolyMeshDetail (rcPolyMeshDetail *dmesh)
 
void rcCalcBounds (const float *verts, int nv, float *bmin, float *bmax)
 
void rcCalcGridSize (const float *bmin, const float *bmax, float cs, int *w, int *h)
 
bool rcCreateHeightfield (rcContext *ctx, rcHeightfield &hf, int width, int height, const float *bmin, const float *bmax, float cs, float ch)
 
static void calcTriNormal (const float *v0, const float *v1, const float *v2, float *norm)
 
void rcMarkWalkableTriangles (rcContext *ctx, const float walkableSlopeAngle, const float *verts, int, const int *tris, int nt, unsigned char *areas)
 
void rcClearUnwalkableTriangles (rcContext *ctx, const float walkableSlopeAngle, const float *verts, int, const int *tris, int nt, unsigned char *areas)
 
int rcGetHeightFieldSpanCount (rcContext *ctx, rcHeightfield &hf)
 
bool rcBuildCompactHeightfield (rcContext *ctx, const int walkableHeight, const int walkableClimb, rcHeightfield &hf, rcCompactHeightfield &chf)
 

Macro Definition Documentation

#define _USE_MATH_DEFINES

Function Documentation

static void calcTriNormal ( const float *  v0,
const float *  v1,
const float *  v2,
float *  norm 
)
static
231 {
232  float e0[3], e1[3];
233  rcVsub(e0, v1, v0);
234  rcVsub(e1, v2, v0);
235  rcVcross(norm, e0, e1);
236  rcVnormalize(norm);
237 }
void rcVnormalize(float *v)
Definition: Recast.h:710
void rcVsub(float *dest, const float *v1, const float *v2)
Definition: Recast.h:647
void rcVcross(float *dest, const float *v1, const float *v2)
Definition: Recast.h:604

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

rcCompactHeightfield* rcAllocCompactHeightfield ( )

Allocates a compact heightfield object using the Recast allocator.

Returns
A compact heightfield that is ready for initialization, or null on failure.
See also
rcBuildCompactHeightfield, rcFreeCompactHeightfield
96 {
98  memset(chf, 0, sizeof(rcCompactHeightfield));
99  return chf;
100 }
Definition: Recast.h:305
void * rcAlloc(int size, rcAllocHint hint)
Definition: RecastAlloc.cpp:44
Memory will persist after a function call.
Definition: RecastAlloc.h:26

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

rcContourSet* rcAllocContourSet ( )

Allocates a contour set object using the Recast allocator.

Returns
A contour set that is ready for initialization, or null on failure.
See also
rcBuildContours, rcFreeContourSet
135 {
137  memset(cset, 0, sizeof(rcContourSet));
138  return cset;
139 }
Definition: Recast.h:368
void * rcAlloc(int size, rcAllocHint hint)
Definition: RecastAlloc.cpp:44
Memory will persist after a function call.
Definition: RecastAlloc.h:26

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

rcHeightfield* rcAllocHeightfield ( )

Allocates a heightfield object using the Recast allocator.

Returns
A heightfield that is ready for initialization, or null on failure.
See also
rcCreateHeightfield, rcFreeHeightField
74 {
76  memset(hf, 0, sizeof(rcHeightfield));
77  return hf;
78 }
Definition: Recast.h:274
void * rcAlloc(int size, rcAllocHint hint)
Definition: RecastAlloc.cpp:44
Memory will persist after a function call.
Definition: RecastAlloc.h:26

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

rcHeightfieldLayerSet* rcAllocHeightfieldLayerSet ( )

Allocates a heightfield layer set using the Recast allocator.

Returns
A heightfield layer set that is ready for initialization, or null on failure.
See also
rcBuildHeightfieldLayers, rcFreeHeightfieldLayerSet
114 {
116  memset(lset, 0, sizeof(rcHeightfieldLayerSet));
117  return lset;
118 }
Definition: Recast.h:349
void * rcAlloc(int size, rcAllocHint hint)
Definition: RecastAlloc.cpp:44
Memory will persist after a function call.
Definition: RecastAlloc.h:26

+ Here is the call graph for this function:

rcPolyMesh* rcAllocPolyMesh ( )

Allocates a polygon mesh object using the Recast allocator.

Returns
A polygon mesh that is ready for initialization, or null on failure.
See also
rcBuildPolyMesh, rcFreePolyMesh
154 {
156  memset(pmesh, 0, sizeof(rcPolyMesh));
157  return pmesh;
158 }
void * rcAlloc(int size, rcAllocHint hint)
Definition: RecastAlloc.cpp:44
Definition: Recast.h:383
Memory will persist after a function call.
Definition: RecastAlloc.h:26

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

rcPolyMeshDetail* rcAllocPolyMeshDetail ( )

Allocates a detail mesh object using the Recast allocator.

Returns
A detail mesh that is ready for initialization, or null on failure.
See also
rcBuildPolyMeshDetail, rcFreePolyMeshDetail
172 {
174  memset(dmesh, 0, sizeof(rcPolyMeshDetail));
175  return dmesh;
176 }
void * rcAlloc(int size, rcAllocHint hint)
Definition: RecastAlloc.cpp:44
Memory will persist after a function call.
Definition: RecastAlloc.h:26
Definition: Recast.h:404

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool rcBuildCompactHeightfield ( rcContext ctx,
const int  walkableHeight,
const int  walkableClimb,
rcHeightfield hf,
rcCompactHeightfield chf 
)

This is just the beginning of the process of fully building a compact heightfield. Various filters may be applied, then the distance field and regions built. E.g: rcBuildDistanceField and rcBuildRegions

See the rcConfig documentation for more information on the configuration parameters.

See also
rcAllocCompactHeightfield, rcHeightfield, rcCompactHeightfield, rcConfig
329 {
330  rcAssert(ctx);
331 
333 
334  const int w = hf.width;
335  const int h = hf.height;
336  const int spanCount = rcGetHeightFieldSpanCount(ctx, hf);
337 
338  // Fill in header.
339  chf.width = w;
340  chf.height = h;
341  chf.spanCount = spanCount;
342  chf.walkableHeight = walkableHeight;
343  chf.walkableClimb = walkableClimb;
344  chf.maxRegions = 0;
345  rcVcopy(chf.bmin, hf.bmin);
346  rcVcopy(chf.bmax, hf.bmax);
347  chf.bmax[1] += walkableHeight*hf.ch;
348  chf.cs = hf.cs;
349  chf.ch = hf.ch;
350  chf.cells = (rcCompactCell*)rcAlloc(sizeof(rcCompactCell)*w*h, RC_ALLOC_PERM);
351  if (!chf.cells)
352  {
353  ctx->log(RC_LOG_ERROR, "rcBuildCompactHeightfield: Out of memory 'chf.cells' (%d)", w*h);
354  return false;
355  }
356  memset(chf.cells, 0, sizeof(rcCompactCell)*w*h);
357  chf.spans = (rcCompactSpan*)rcAlloc(sizeof(rcCompactSpan)*spanCount, RC_ALLOC_PERM);
358  if (!chf.spans)
359  {
360  ctx->log(RC_LOG_ERROR, "rcBuildCompactHeightfield: Out of memory 'chf.spans' (%d)", spanCount);
361  return false;
362  }
363  memset(chf.spans, 0, sizeof(rcCompactSpan)*spanCount);
364  chf.areas = (unsigned char*)rcAlloc(sizeof(unsigned char)*spanCount, RC_ALLOC_PERM);
365  if (!chf.areas)
366  {
367  ctx->log(RC_LOG_ERROR, "rcBuildCompactHeightfield: Out of memory 'chf.areas' (%d)", spanCount);
368  return false;
369  }
370  memset(chf.areas, RC_NULL_AREA, sizeof(unsigned char)*spanCount);
371 
372  const int MAX_HEIGHT = 0xffff;
373 
374  // Fill in cells and spans.
375  int idx = 0;
376  for (int y = 0; y < h; ++y)
377  {
378  for (int x = 0; x < w; ++x)
379  {
380  const rcSpan* s = hf.spans[x + y*w];
381  // If there are no spans at this cell, just leave the data to index=0, count=0.
382  if (!s) continue;
383  rcCompactCell& c = chf.cells[x+y*w];
384  c.index = idx;
385  c.count = 0;
386  while (s)
387  {
388  if (s->area != RC_NULL_AREA)
389  {
390  const int bot = (int)s->smax;
391  const int top = s->next ? (int)s->next->smin : MAX_HEIGHT;
392  chf.spans[idx].y = (unsigned short)rcClamp(bot, 0, 0xffff);
393  chf.spans[idx].h = (unsigned char)rcClamp(top - bot, 0, 0xff);
394  chf.areas[idx] = s->area;
395  idx++;
396  c.count++;
397  }
398  s = s->next;
399  }
400  }
401  }
402 
403  // Find neighbour connections.
404  const int MAX_LAYERS = RC_NOT_CONNECTED-1;
405  int tooHighNeighbour = 0;
406  for (int y = 0; y < h; ++y)
407  {
408  for (int x = 0; x < w; ++x)
409  {
410  const rcCompactCell& c = chf.cells[x+y*w];
411  for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni; ++i)
412  {
413  rcCompactSpan& s = chf.spans[i];
414 
415  for (int dir = 0; dir < 4; ++dir)
416  {
417  rcSetCon(s, dir, RC_NOT_CONNECTED);
418  const int nx = x + rcGetDirOffsetX(dir);
419  const int ny = y + rcGetDirOffsetY(dir);
420  // First check that the neighbour cell is in bounds.
421  if (nx < 0 || ny < 0 || nx >= w || ny >= h)
422  continue;
423 
424  // Iterate over all neighbour spans and check if any of the is
425  // accessible from current cell.
426  const rcCompactCell& nc = chf.cells[nx+ny*w];
427  for (int k = (int)nc.index, nk = (int)(nc.index+nc.count); k < nk; ++k)
428  {
429  const rcCompactSpan& ns = chf.spans[k];
430  const int bot = rcMax(s.y, ns.y);
431  const int top = rcMin(s.y+s.h, ns.y+ns.h);
432 
433  // Check that the gap between the spans is walkable,
434  // and that the climb height between the gaps is not too high.
435  if ((top - bot) >= walkableHeight && rcAbs((int)ns.y - (int)s.y) <= walkableClimb)
436  {
437  // Mark direction as walkable.
438  const int lidx = k - (int)nc.index;
439  if (lidx < 0 || lidx > MAX_LAYERS)
440  {
441  tooHighNeighbour = rcMax(tooHighNeighbour, lidx);
442  continue;
443  }
444  rcSetCon(s, dir, lidx);
445  break;
446  }
447  }
448 
449  }
450  }
451  }
452  }
453 
454  if (tooHighNeighbour > MAX_LAYERS)
455  {
456  ctx->log(RC_LOG_ERROR, "rcBuildCompactHeightfield: Heightfield has too many layers %d (max: %d)",
457  tooHighNeighbour, MAX_LAYERS);
458  }
459 
461 
462  return true;
463 }
int height
The height of the heightfield. (Along the z-axis in cell units.)
Definition: Recast.h:308
#define rcAssert
Definition: RecastAssert.h:30
int width
The width of the heightfield. (Along the x-axis in cell units.)
Definition: Recast.h:276
T rcAbs(T a)
Definition: Recast.h:577
unsigned short maxRegions
The maximum region id of any span within the field.
Definition: Recast.h:314
Represents a span of unobstructed space within a compact heightfield.
Definition: Recast.h:295
static const int RC_NOT_CONNECTED
Definition: Recast.h:547
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition: Recast.h:281
unsigned char area
The area id assigned to the span.
Definition: Recast.h:260
rcCompactCell * cells
Array of cells. [Size: width*height].
Definition: Recast.h:319
int rcGetDirOffsetY(int dir)
Definition: Recast.h:1048
unsigned short y
The lower extent of the span. (Measured from the heightfield's base.)
Definition: Recast.h:297
rcCompactSpan * spans
Array of spans. [Size: spanCount].
Definition: Recast.h:320
T rcMin(T a, T b)
Definition: Recast.h:566
unsigned int h
The height of the span. (Measured from y.)
Definition: Recast.h:300
unsigned int index
Index to the first span in the column.
Definition: Recast.h:290
Definition: Recast.h:256
float bmax[3]
The maximum bounds in world space. [(x, y, z)].
Definition: Recast.h:279
Provides information on the content of a cell column in a compact heightfield.
Definition: Recast.h:288
void rcSetCon(rcCompactSpan &s, int dir, int i)
Definition: Recast.h:1016
unsigned int count
Number of spans in the column.
Definition: Recast.h:291
An error log entry.
Definition: Recast.h:31
void * rcAlloc(int size, rcAllocHint hint)
Definition: RecastAlloc.cpp:44
int rcGetDirOffsetX(int dir)
Definition: Recast.h:1038
float cs
The size of each cell. (On the xz-plane.)
Definition: Recast.h:280
unsigned char * areas
Array containing area id data. [Size: spanCount].
Definition: Recast.h:322
G3D::int16 y
Definition: Vector2int16.h:38
float bmax[3]
The maximum bounds in world space. [(x, y, z)].
Definition: Recast.h:316
int width
The width of the heightfield. (Along the x-axis in cell units.)
Definition: Recast.h:307
The time to build the compact heightfield. (See: rcBuildCompactHeightfield)
Definition: Recast.h:45
unsigned int smin
The lower limit of the span. [Limit: < smax].
Definition: Recast.h:258
void rcVcopy(float *dest, const float *v)
Definition: Recast.h:677
void startTimer(const rcTimerLabel label)
Definition: Recast.h:131
int spanCount
The number of spans in the heightfield.
Definition: Recast.h:309
int walkableHeight
The walkable height used during the build of the field. (See: rcConfig::walkableHeight) ...
Definition: Recast.h:310
Memory will persist after a function call.
Definition: RecastAlloc.h:26
T rcClamp(T v, T mn, T mx)
Definition: Recast.h:589
unsigned int smax
The upper limit of the span. [Limit: <= RC_SPAN_MAX_HEIGHT].
Definition: Recast.h:259
float cs
The size of each cell. (On the xz-plane.)
Definition: Recast.h:317
rcSpan * next
The next span higher up in column.
Definition: Recast.h:261
float bmin[3]
The minimum bounds in world space. [(x, y, z)].
Definition: Recast.h:278
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition: Recast.h:318
static const unsigned char RC_NULL_AREA
Definition: Recast.h:538
T rcMax(T a, T b)
Definition: Recast.h:572
void log(const rcLogCategory category, const char *format,...)
Definition: Recast.cpp:55
G3D::int16 x
Definition: Vector2int16.h:37
int height
The height of the heightfield. (Along the z-axis in cell units.)
Definition: Recast.h:277
void stopTimer(const rcTimerLabel label)
Definition: Recast.h:135
int walkableClimb
The walkable climb used during the build of the field. (See: rcConfig::walkableClimb) ...
Definition: Recast.h:311
#define MAX_HEIGHT
Definition: Map.h:247
rcSpan ** spans
Heightfield of spans (width*height).
Definition: Recast.h:282
float bmin[3]
The minimum bounds in world space. [(x, y, z)].
Definition: Recast.h:315
int rcGetHeightFieldSpanCount(rcContext *ctx, rcHeightfield &hf)
Definition: Recast.cpp:297

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void rcCalcBounds ( const float *  verts,
int  nv,
float *  bmin,
float *  bmax 
)

Calculates the bounding box of an array of vertices.

Parameters
[in]vertsAn array of vertices. [(x, y, z) * nv]
[in]nvThe number of vertices in the verts array.
[out]bminThe minimum bounds of the AABB. [(x, y, z)] [Units: wu]
[out]bmaxThe maximum bounds of the AABB. [(x, y, z)] [Units: wu]
188 {
189  // Calculate bounding box.
190  rcVcopy(bmin, verts);
191  rcVcopy(bmax, verts);
192  for (int i = 1; i < nv; ++i)
193  {
194  const float* v = &verts[i*3];
195  rcVmin(bmin, v);
196  rcVmax(bmax, v);
197  }
198 }
void rcVmin(float *mn, const float *v)
Definition: Recast.h:657
void rcVcopy(float *dest, const float *v)
Definition: Recast.h:677
void rcVmax(float *mx, const float *v)
Definition: Recast.h:667

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void rcCalcGridSize ( const float *  bmin,
const float *  bmax,
float  cs,
int *  w,
int *  h 
)

Calculates the grid size based on the bounding box and grid cell size.

Parameters
[in]bminThe minimum bounds of the AABB. [(x, y, z)] [Units: wu]
[in]bmaxThe maximum bounds of the AABB. [(x, y, z)] [Units: wu]
[in]csThe xz-plane cell size. [Limit: > 0] [Units: wu]
[out]wThe width along the x-axis. [Limit: >= 0] [Units: vx]
[out]hThe height along the z-axis. [Limit: >= 0] [Units: vx]
201 {
202  *w = (int)((bmax[0] - bmin[0])/cs+0.5f);
203  *h = (int)((bmax[2] - bmin[2])/cs+0.5f);
204 }

+ Here is the caller graph for this function:

void rcClearUnwalkableTriangles ( rcContext ctx,
const float  walkableSlopeAngle,
const float *  verts,
int  ,
const int *  tris,
int  nt,
unsigned char *  areas 
)

Only sets the area id's for the unwalkable triangles. Does not alter the area id's for walkable triangles.

See the rcConfig documentation for more information on the configuration parameters.

See also
rcHeightfield, rcClearUnwalkableTriangles, rcRasterizeTriangles
280 {
281  rcIgnoreUnused(ctx);
282 
283  const float walkableThr = cosf(walkableSlopeAngle/180.0f*RC_PI);
284 
285  float norm[3];
286 
287  for (int i = 0; i < nt; ++i)
288  {
289  const int* tri = &tris[i*3];
290  calcTriNormal(&verts[tri[0]*3], &verts[tri[1]*3], &verts[tri[2]*3], norm);
291  // Check if the face is walkable.
292  if (norm[1] <= walkableThr)
293  areas[i] = RC_NULL_AREA;
294  }
295 }
static void calcTriNormal(const float *v0, const float *v1, const float *v2, float *norm)
Definition: Recast.cpp:230
static const float RC_PI
The value of PI used by Recast.
Definition: Recast.h:23
static const unsigned char RC_NULL_AREA
Definition: Recast.h:538
void rcIgnoreUnused(const T &)
Definition: Recast.h:555

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool rcCreateHeightfield ( rcContext ctx,
rcHeightfield hf,
int  width,
int  height,
const float *  bmin,
const float *  bmax,
float  cs,
float  ch 
)

See the rcConfig documentation for more information on the configuration parameters.

See also
rcAllocHeightfield, rcHeightfield
214 {
215  rcIgnoreUnused(ctx);
216 
217  hf.width = width;
218  hf.height = height;
219  rcVcopy(hf.bmin, bmin);
220  rcVcopy(hf.bmax, bmax);
221  hf.cs = cs;
222  hf.ch = ch;
223  hf.spans = (rcSpan**)rcAlloc(sizeof(rcSpan*)*hf.width*hf.height, RC_ALLOC_PERM);
224  if (!hf.spans)
225  return false;
226  memset(hf.spans, 0, sizeof(rcSpan*)*hf.width*hf.height);
227  return true;
228 }
int width
The width of the heightfield. (Along the x-axis in cell units.)
Definition: Recast.h:276
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition: Recast.h:281
Definition: Recast.h:256
float bmax[3]
The maximum bounds in world space. [(x, y, z)].
Definition: Recast.h:279
void * rcAlloc(int size, rcAllocHint hint)
Definition: RecastAlloc.cpp:44
float cs
The size of each cell. (On the xz-plane.)
Definition: Recast.h:280
void rcVcopy(float *dest, const float *v)
Definition: Recast.h:677
Memory will persist after a function call.
Definition: RecastAlloc.h:26
float bmin[3]
The minimum bounds in world space. [(x, y, z)].
Definition: Recast.h:278
int height
The height of the heightfield. (Along the z-axis in cell units.)
Definition: Recast.h:277
void rcIgnoreUnused(const T &)
Definition: Recast.h:555
rcSpan ** spans
Heightfield of spans (width*height).
Definition: Recast.h:282

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void rcFreeCompactHeightfield ( rcCompactHeightfield chf)

Frees the specified compact heightfield object using the Recast allocator.

Parameters
[in]chfA compact heightfield allocated using rcAllocCompactHeightfield
See also
rcAllocCompactHeightfield
103 {
104  if (!chf) return;
105  rcFree(chf->cells);
106  rcFree(chf->spans);
107  rcFree(chf->dist);
108  rcFree(chf->areas);
109  rcFree(chf);
110 }
unsigned short * dist
Array containing border distance data. [Size: spanCount].
Definition: Recast.h:321
rcCompactCell * cells
Array of cells. [Size: width*height].
Definition: Recast.h:319
rcCompactSpan * spans
Array of spans. [Size: spanCount].
Definition: Recast.h:320
void rcFree(void *ptr)
Definition: RecastAlloc.cpp:55
unsigned char * areas
Array containing area id data. [Size: spanCount].
Definition: Recast.h:322

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void rcFreeContourSet ( rcContourSet cset)

Frees the specified contour set using the Recast allocator.

Parameters
[in]csetA contour set allocated using rcAllocContourSet
See also
rcAllocContourSet
142 {
143  if (!cset) return;
144  for (int i = 0; i < cset->nconts; ++i)
145  {
146  rcFree(cset->conts[i].verts);
147  rcFree(cset->conts[i].rverts);
148  }
149  rcFree(cset->conts);
150  rcFree(cset);
151 }
int * rverts
Raw contour vertex and connection data. [Size: 4 * nrverts].
Definition: Recast.h:360
rcContour * conts
An array of the contours in the set. [Size: nconts].
Definition: Recast.h:370
int nconts
The number of contours in the set.
Definition: Recast.h:371
int * verts
Simplified contour vertex and connection data. [Size: 4 * nverts].
Definition: Recast.h:358
void rcFree(void *ptr)
Definition: RecastAlloc.cpp:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void rcFreeHeightField ( rcHeightfield hf)

Frees the specified heightfield object using the Recast allocator.

Parameters
[in]hfA heightfield allocated using rcAllocHeightfield
See also
rcAllocHeightfield
81 {
82  if (!hf) return;
83  // Delete span array.
84  rcFree(hf->spans);
85  // Delete span pools.
86  while (hf->pools)
87  {
88  rcSpanPool* next = hf->pools->next;
89  rcFree(hf->pools);
90  hf->pools = next;
91  }
92  rcFree(hf);
93 }
int next(int i, int n)
Definition: RecastContour.cpp:469
void rcFree(void *ptr)
Definition: RecastAlloc.cpp:55
Definition: Recast.h:266
rcSpanPool * next
The next span pool.
Definition: Recast.h:268
rcSpanPool * pools
Linked list of span pools.
Definition: Recast.h:283
rcSpan ** spans
Heightfield of spans (width*height).
Definition: Recast.h:282

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void rcFreeHeightfieldLayerSet ( rcHeightfieldLayerSet lset)

Frees the specified heightfield layer set using the Recast allocator.

Parameters
[in]lsetA heightfield layer set allocated using rcAllocHeightfieldLayerSet
See also
rcAllocHeightfieldLayerSet
121 {
122  if (!lset) return;
123  for (int i = 0; i < lset->nlayers; ++i)
124  {
125  rcFree(lset->layers[i].heights);
126  rcFree(lset->layers[i].areas);
127  rcFree(lset->layers[i].cons);
128  }
129  rcFree(lset->layers);
130  rcFree(lset);
131 }
rcHeightfieldLayer * layers
The layers in the set. [Size: nlayers].
Definition: Recast.h:351
unsigned char * heights
The heightfield. [Size: width * height].
Definition: Recast.h:341
unsigned char * areas
Area ids. [Size: Same as heights].
Definition: Recast.h:342
void rcFree(void *ptr)
Definition: RecastAlloc.cpp:55
unsigned char * cons
Packed neighbor connection information. [Size: Same as heights].
Definition: Recast.h:343
int nlayers
The number of layers in the set.
Definition: Recast.h:352

+ Here is the call graph for this function:

void rcFreePolyMesh ( rcPolyMesh pmesh)

Frees the specified polygon mesh using the Recast allocator.

Parameters
[in]pmeshA polygon mesh allocated using rcAllocPolyMesh
See also
rcAllocPolyMesh
161 {
162  if (!pmesh) return;
163  rcFree(pmesh->verts);
164  rcFree(pmesh->polys);
165  rcFree(pmesh->regs);
166  rcFree(pmesh->flags);
167  rcFree(pmesh->areas);
168  rcFree(pmesh);
169 }
unsigned char * areas
The area id assigned to each polygon. [Length: maxpolys].
Definition: Recast.h:389
unsigned short * verts
The mesh vertices. [Form: (x, y, z) * nverts].
Definition: Recast.h:385
void rcFree(void *ptr)
Definition: RecastAlloc.cpp:55
unsigned short * flags
The user defined flags for each polygon. [Length: maxpolys].
Definition: Recast.h:388
unsigned short * regs
The region id assigned to each polygon. [Length: maxpolys].
Definition: Recast.h:387
unsigned short * polys
Polygon and neighbor data. [Length: maxpolys * 2 * nvp].
Definition: Recast.h:386

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void rcFreePolyMeshDetail ( rcPolyMeshDetail dmesh)

Frees the specified detail mesh using the Recast allocator.

Parameters
[in]dmeshA detail mesh allocated using rcAllocPolyMeshDetail
See also
rcAllocPolyMeshDetail
179 {
180  if (!dmesh) return;
181  rcFree(dmesh->meshes);
182  rcFree(dmesh->verts);
183  rcFree(dmesh->tris);
184  rcFree(dmesh);
185 }
float * verts
The mesh vertices. [Size: 3*nverts].
Definition: Recast.h:407
void rcFree(void *ptr)
Definition: RecastAlloc.cpp:55
unsigned char * tris
The mesh triangles. [Size: 4*ntris].
Definition: Recast.h:408
unsigned int * meshes
The sub-mesh data. [Size: 4*nmeshes].
Definition: Recast.h:406

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int rcGetHeightFieldSpanCount ( rcContext ctx,
rcHeightfield hf 
)

Returns the number of spans contained in the specified heightfield.

Parameters
[in,out]ctxThe build context to use during the operation.
[in]hfAn initialized heightfield.
Returns
The number of spans in the heightfield.
298 {
299  rcIgnoreUnused(ctx);
300 
301  const int w = hf.width;
302  const int h = hf.height;
303  int spanCount = 0;
304  for (int y = 0; y < h; ++y)
305  {
306  for (int x = 0; x < w; ++x)
307  {
308  for (rcSpan* s = hf.spans[x + y*w]; s; s = s->next)
309  {
310  if (s->area != RC_NULL_AREA)
311  spanCount++;
312  }
313  }
314  }
315  return spanCount;
316 }
int width
The width of the heightfield. (Along the x-axis in cell units.)
Definition: Recast.h:276
Definition: Recast.h:256
G3D::int16 y
Definition: Vector2int16.h:38
rcSpan * next
The next span higher up in column.
Definition: Recast.h:261
static const unsigned char RC_NULL_AREA
Definition: Recast.h:538
G3D::int16 x
Definition: Vector2int16.h:37
int height
The height of the heightfield. (Along the z-axis in cell units.)
Definition: Recast.h:277
void rcIgnoreUnused(const T &)
Definition: Recast.h:555
rcSpan ** spans
Heightfield of spans (width*height).
Definition: Recast.h:282

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void rcMarkWalkableTriangles ( rcContext ctx,
const float  walkableSlopeAngle,
const float *  verts,
int  ,
const int *  tris,
int  nt,
unsigned char *  areas 
)

Only sets the area id's for the walkable triangles. Does not alter the area id's for unwalkable triangles.

See the rcConfig documentation for more information on the configuration parameters.

See also
rcHeightfield, rcClearUnwalkableTriangles, rcRasterizeTriangles
251 {
252  rcIgnoreUnused(ctx);
253 
254  const float walkableThr = cosf(walkableSlopeAngle/180.0f*RC_PI);
255 
256  float norm[3];
257 
258  for (int i = 0; i < nt; ++i)
259  {
260  const int* tri = &tris[i*3];
261  calcTriNormal(&verts[tri[0]*3], &verts[tri[1]*3], &verts[tri[2]*3], norm);
262  // Check if the face is walkable.
263  if (norm[1] > walkableThr)
264  areas[i] = RC_WALKABLE_AREA;
265  }
266 }
static void calcTriNormal(const float *v0, const float *v1, const float *v2, float *norm)
Definition: Recast.cpp:230
static const unsigned char RC_WALKABLE_AREA
Definition: Recast.h:543
static const float RC_PI
The value of PI used by Recast.
Definition: Recast.h:23
void rcIgnoreUnused(const T &)
Definition: Recast.h:555

+ Here is the call graph for this function:

float rcSqrt ( float  x)

Returns the square root of the value.

Parameters
[in]xThe value.
Returns
The square root of the vlaue.
31 {
32  return sqrtf(x);
33 }
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function: