TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DetourCommon.h File Reference
#include "DetourMath.h"
+ Include dependency graph for DetourCommon.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

General helper functions
template<class T >
void dtIgnoreUnused (const T &)
 
template<class T >
void dtSwap (T &a, T &b)
 
template<class T >
dtMin (T a, T b)
 
template<class T >
dtMax (T a, T b)
 
template<class T >
dtAbs (T a)
 
template<class T >
dtSqr (T a)
 
template<class T >
dtClamp (T v, T mn, T mx)
 
Vector helper functions.
void dtVcross (float *dest, const float *v1, const float *v2)
 
float dtVdot (const float *v1, const float *v2)
 
void dtVmad (float *dest, const float *v1, const float *v2, const float s)
 
void dtVlerp (float *dest, const float *v1, const float *v2, const float t)
 
void dtVadd (float *dest, const float *v1, const float *v2)
 
void dtVsub (float *dest, const float *v1, const float *v2)
 
void dtVscale (float *dest, const float *v, const float t)
 
void dtVmin (float *mn, const float *v)
 
void dtVmax (float *mx, const float *v)
 
void dtVset (float *dest, const float x, const float y, const float z)
 
void dtVcopy (float *dest, const float *a)
 
float dtVlen (const float *v)
 
float dtVlenSqr (const float *v)
 
float dtVdist (const float *v1, const float *v2)
 
float dtVdistSqr (const float *v1, const float *v2)
 
float dtVdist2D (const float *v1, const float *v2)
 
float dtVdist2DSqr (const float *v1, const float *v2)
 
void dtVnormalize (float *v)
 
bool dtVequal (const float *p0, const float *p1)
 
float dtVdot2D (const float *u, const float *v)
 
float dtVperp2D (const float *u, const float *v)
 
Computational geometry helper functions.
float dtTriArea2D (const float *a, const float *b, const float *c)
 
bool dtOverlapQuantBounds (const unsigned short amin[3], const unsigned short amax[3], const unsigned short bmin[3], const unsigned short bmax[3])
 
bool dtOverlapBounds (const float *amin, const float *amax, const float *bmin, const float *bmax)
 
void dtClosestPtPointTriangle (float *closest, const float *p, const float *a, const float *b, const float *c)
 
bool dtClosestHeightPointTriangle (const float *p, const float *a, const float *b, const float *c, float &h)
 
bool dtIntersectSegmentPoly2D (const float *p0, const float *p1, const float *verts, int nverts, float &tmin, float &tmax, int &segMin, int &segMax)
 
bool dtIntersectSegSeg2D (const float *ap, const float *aq, const float *bp, const float *bq, float &s, float &t)
 
bool dtPointInPolygon (const float *pt, const float *verts, const int nverts)
 
bool dtDistancePtPolyEdgesSqr (const float *pt, const float *verts, const int nverts, float *ed, float *et)
 
float dtDistancePtSegSqr2D (const float *pt, const float *p, const float *q, float &t)
 
void dtCalcPolyCenter (float *tc, const unsigned short *idx, int nidx, const float *verts)
 
bool dtOverlapPolyPoly2D (const float *polya, const int npolya, const float *polyb, const int npolyb)
 
Miscellanious functions.
unsigned int dtNextPow2 (unsigned int v)
 
unsigned int dtIlog2 (unsigned int v)
 
int dtAlign4 (int x)
 
int dtOppositeTile (int side)
 
void dtSwapByte (unsigned char *a, unsigned char *b)
 
void dtSwapEndian (unsigned short *v)
 
void dtSwapEndian (short *v)
 
void dtSwapEndian (unsigned int *v)
 
void dtSwapEndian (int *v)
 
void dtSwapEndian (float *v)
 
void dtRandomPointInConvexPoly (const float *pts, const int npts, float *areas, const float s, const float t, float *out)
 

Function Documentation

template<class T >
T dtAbs ( a)
inline

Returns the absolute value.

Parameters
[in]aThe value.
Returns
The absolute value of the specified value.
62 { return a < 0 ? -a : a; }

+ Here is the caller graph for this function:

int dtAlign4 ( int  x)
inline
441 { return (x+3) & ~3; }
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

void dtCalcPolyCenter ( float *  tc,
const unsigned short *  idx,
int  nidx,
const float *  verts 
)

Derives the centroid of a convex polygon.

Parameters
[out]tcThe centroid of the polgyon. [(x, y, z)]
[in]idxThe polygon indices. [(vertIndex) * nidx]
[in]nidxThe number of indices in the polygon. [Limit: >= 3]
[in]vertsThe polygon vertices. [(x, y, z) * vertCount]
187 {
188  tc[0] = 0.0f;
189  tc[1] = 0.0f;
190  tc[2] = 0.0f;
191  for (int j = 0; j < nidx; ++j)
192  {
193  const float* v = &verts[idx[j]*3];
194  tc[0] += v[0];
195  tc[1] += v[1];
196  tc[2] += v[2];
197  }
198  const float s = 1.0f / nidx;
199  tc[0] *= s;
200  tc[1] *= s;
201  tc[2] *= s;
202 }
template<class T >
T dtClamp ( v,
mn,
mx 
)
inline

Clamps the value to the specified range.

Parameters
[in]vThe value to clamp.
[in]mnThe minimum permitted return value.
[in]mxThe maximum permitted return value.
Returns
The value, clamped to the specified range.
74 { return v < mn ? mn : (v > mx ? mx : v); }

+ Here is the caller graph for this function:

bool dtClosestHeightPointTriangle ( const float *  p,
const float *  a,
const float *  b,
const float *  c,
float &  h 
)

Derives the y-axis height of the closest point on the triangle from the specified reference point.

Parameters
[in]pThe reference point from which to test. [(x, y, z)]
[in]aVertex A of triangle ABC. [(x, y, z)]
[in]bVertex B of triangle ABC. [(x, y, z)]
[in]cVertex C of triangle ABC. [(x, y, z)]
[out]hThe resulting height.
205 {
206  float v0[3], v1[3], v2[3];
207  dtVsub(v0, c,a);
208  dtVsub(v1, b,a);
209  dtVsub(v2, p,a);
210 
211  const float dot00 = dtVdot2D(v0, v0);
212  const float dot01 = dtVdot2D(v0, v1);
213  const float dot02 = dtVdot2D(v0, v2);
214  const float dot11 = dtVdot2D(v1, v1);
215  const float dot12 = dtVdot2D(v1, v2);
216 
217  // Compute barycentric coordinates
218  const float invDenom = 1.0f / (dot00 * dot11 - dot01 * dot01);
219  const float u = (dot11 * dot02 - dot01 * dot12) * invDenom;
220  const float v = (dot00 * dot12 - dot01 * dot02) * invDenom;
221 
222  // The (sloppy) epsilon is needed to allow to get height of points which
223  // are interpolated along the edges of the triangles.
224  static const float EPS = 1e-4f;
225 
226  // If point lies inside the triangle, return interpolated ycoord.
227  if (u >= -EPS && v >= -EPS && (u+v) <= 1+EPS)
228  {
229  h = a[1] + v0[1]*u + v1[1]*v;
230  return true;
231  }
232 
233  return false;
234 }
void dtVsub(float *dest, const float *v1, const float *v2)
Definition: DetourCommon.h:139
float dtVdot2D(const float *u, const float *v)
Definition: DetourCommon.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void dtClosestPtPointTriangle ( float *  closest,
const float *  p,
const float *  a,
const float *  b,
const float *  c 
)

Derives the closest point on a triangle from the specified reference point.

Parameters
[out]closestThe closest point on the triangle.
[in]pThe reference point from which to test. [(x, y, z)]
[in]aVertex A of triangle ABC. [(x, y, z)]
[in]bVertex B of triangle ABC. [(x, y, z)]
[in]cVertex C of triangle ABC. [(x, y, z)]
26 {
27  // Check if P in vertex region outside A
28  float ab[3], ac[3], ap[3];
29  dtVsub(ab, b, a);
30  dtVsub(ac, c, a);
31  dtVsub(ap, p, a);
32  float d1 = dtVdot(ab, ap);
33  float d2 = dtVdot(ac, ap);
34  if (d1 <= 0.0f && d2 <= 0.0f)
35  {
36  // barycentric coordinates (1,0,0)
37  dtVcopy(closest, a);
38  return;
39  }
40 
41  // Check if P in vertex region outside B
42  float bp[3];
43  dtVsub(bp, p, b);
44  float d3 = dtVdot(ab, bp);
45  float d4 = dtVdot(ac, bp);
46  if (d3 >= 0.0f && d4 <= d3)
47  {
48  // barycentric coordinates (0,1,0)
49  dtVcopy(closest, b);
50  return;
51  }
52 
53  // Check if P in edge region of AB, if so return projection of P onto AB
54  float vc = d1*d4 - d3*d2;
55  if (vc <= 0.0f && d1 >= 0.0f && d3 <= 0.0f)
56  {
57  // barycentric coordinates (1-v,v,0)
58  float v = d1 / (d1 - d3);
59  closest[0] = a[0] + v * ab[0];
60  closest[1] = a[1] + v * ab[1];
61  closest[2] = a[2] + v * ab[2];
62  return;
63  }
64 
65  // Check if P in vertex region outside C
66  float cp[3];
67  dtVsub(cp, p, c);
68  float d5 = dtVdot(ab, cp);
69  float d6 = dtVdot(ac, cp);
70  if (d6 >= 0.0f && d5 <= d6)
71  {
72  // barycentric coordinates (0,0,1)
73  dtVcopy(closest, c);
74  return;
75  }
76 
77  // Check if P in edge region of AC, if so return projection of P onto AC
78  float vb = d5*d2 - d1*d6;
79  if (vb <= 0.0f && d2 >= 0.0f && d6 <= 0.0f)
80  {
81  // barycentric coordinates (1-w,0,w)
82  float w = d2 / (d2 - d6);
83  closest[0] = a[0] + w * ac[0];
84  closest[1] = a[1] + w * ac[1];
85  closest[2] = a[2] + w * ac[2];
86  return;
87  }
88 
89  // Check if P in edge region of BC, if so return projection of P onto BC
90  float va = d3*d6 - d5*d4;
91  if (va <= 0.0f && (d4 - d3) >= 0.0f && (d5 - d6) >= 0.0f)
92  {
93  // barycentric coordinates (0,1-w,w)
94  float w = (d4 - d3) / ((d4 - d3) + (d5 - d6));
95  closest[0] = b[0] + w * (c[0] - b[0]);
96  closest[1] = b[1] + w * (c[1] - b[1]);
97  closest[2] = b[2] + w * (c[2] - b[2]);
98  return;
99  }
100 
101  // P inside face region. Compute Q through its barycentric coordinates (u,v,w)
102  float denom = 1.0f / (va + vb + vc);
103  float v = vb * denom;
104  float w = vc * denom;
105  closest[0] = a[0] + ab[0] * v + ac[0] * w;
106  closest[1] = a[1] + ab[1] * v + ac[1] * w;
107  closest[2] = a[2] + ab[2] * v + ac[2] * w;
108 }
float dtVdot(const float *v1, const float *v2)
Definition: DetourCommon.h:95
void dtVcopy(float *dest, const float *a)
Definition: DetourCommon.h:190
void dtVsub(float *dest, const float *v1, const float *v2)
Definition: DetourCommon.h:139

+ Here is the call graph for this function:

bool dtDistancePtPolyEdgesSqr ( const float *  pt,
const float *  verts,
const int  nverts,
float *  ed,
float *  et 
)
257 {
258  // TODO: Replace pnpoly with triArea2D tests?
259  int i, j;
260  bool c = false;
261  for (i = 0, j = nverts-1; i < nverts; j = i++)
262  {
263  const float* vi = &verts[i*3];
264  const float* vj = &verts[j*3];
265  if (((vi[2] > pt[2]) != (vj[2] > pt[2])) &&
266  (pt[0] < (vj[0]-vi[0]) * (pt[2]-vi[2]) / (vj[2]-vi[2]) + vi[0]) )
267  c = !c;
268  ed[j] = dtDistancePtSegSqr2D(pt, vj, vi, et[j]);
269  }
270  return c;
271 }
float dtDistancePtSegSqr2D(const float *pt, const float *p, const float *q, float &t)
Definition: DetourCommon.cpp:170

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float dtDistancePtSegSqr2D ( const float *  pt,
const float *  p,
const float *  q,
float &  t 
)
171 {
172  float pqx = q[0] - p[0];
173  float pqz = q[2] - p[2];
174  float dx = pt[0] - p[0];
175  float dz = pt[2] - p[2];
176  float d = pqx*pqx + pqz*pqz;
177  t = pqx*dx + pqz*dz;
178  if (d > 0) t /= d;
179  if (t < 0) t = 0;
180  else if (t > 1) t = 1;
181  dx = p[0] + t*pqx - pt[0];
182  dz = p[2] + t*pqz - pt[2];
183  return dx*dx + dz*dz;
184 }

+ Here is the caller graph for this function:

template<class T >
void dtIgnoreUnused ( const T &  )

Used to ignore a function parameter. VS complains about unused parameters and this silences the warning.

Parameters
[in]_Unused parameter
40 { }
unsigned int dtIlog2 ( unsigned int  v)
inline
430 {
431  unsigned int r;
432  unsigned int shift;
433  r = (v > 0xffff) << 4; v >>= r;
434  shift = (v > 0xff) << 3; v >>= shift; r |= shift;
435  shift = (v > 0xf) << 2; v >>= shift; r |= shift;
436  shift = (v > 0x3) << 1; v >>= shift; r |= shift;
437  r |= (v >> 1);
438  return r;
439 }
bool dtIntersectSegmentPoly2D ( const float *  p0,
const float *  p1,
const float *  verts,
int  nverts,
float &  tmin,
float &  tmax,
int &  segMin,
int &  segMax 
)
114 {
115  static const float EPS = 0.00000001f;
116 
117  tmin = 0;
118  tmax = 1;
119  segMin = -1;
120  segMax = -1;
121 
122  float dir[3];
123  dtVsub(dir, p1, p0);
124 
125  for (int i = 0, j = nverts-1; i < nverts; j=i++)
126  {
127  float edge[3], diff[3];
128  dtVsub(edge, &verts[i*3], &verts[j*3]);
129  dtVsub(diff, p0, &verts[j*3]);
130  const float n = dtVperp2D(edge, diff);
131  const float d = dtVperp2D(dir, edge);
132  if (fabsf(d) < EPS)
133  {
134  // S is nearly parallel to this edge
135  if (n < 0)
136  return false;
137  else
138  continue;
139  }
140  const float t = n / d;
141  if (d < 0)
142  {
143  // segment S is entering across this edge
144  if (t > tmin)
145  {
146  tmin = t;
147  segMin = j;
148  // S enters after leaving polygon
149  if (tmin > tmax)
150  return false;
151  }
152  }
153  else
154  {
155  // segment S is leaving across this edge
156  if (t < tmax)
157  {
158  tmax = t;
159  segMax = j;
160  // S leaves before entering polygon
161  if (tmax < tmin)
162  return false;
163  }
164  }
165  }
166 
167  return true;
168 }
float dtVperp2D(const float *u, const float *v)
Definition: DetourCommon.h:302
void dtVsub(float *dest, const float *v1, const float *v2)
Definition: DetourCommon.h:139

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool dtIntersectSegSeg2D ( const float *  ap,
const float *  aq,
const float *  bp,
const float *  bq,
float &  s,
float &  t 
)
377 {
378  float u[3], v[3], w[3];
379  dtVsub(u,aq,ap);
380  dtVsub(v,bq,bp);
381  dtVsub(w,ap,bp);
382  float d = vperpXZ(u,v);
383  if (fabsf(d) < 1e-6f) return false;
384  s = vperpXZ(v,w) / d;
385  t = vperpXZ(u,w) / d;
386  return true;
387 }
float vperpXZ(const float *a, const float *b)
Definition: DetourCommon.cpp:372
void dtVsub(float *dest, const float *v1, const float *v2)
Definition: DetourCommon.h:139

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T >
T dtMax ( a,
b 
)
inline

Returns the maximum of two values.

Parameters
[in]aValue A
[in]bValue B
Returns
The maximum of the two values.
57 { return a > b ? a : b; }

+ Here is the caller graph for this function:

template<class T >
T dtMin ( a,
b 
)
inline

Returns the minimum of two values.

Parameters
[in]aValue A
[in]bValue B
Returns
The minimum of the two values.
51 { return a < b ? a : b; }

+ Here is the caller graph for this function:

unsigned int dtNextPow2 ( unsigned int  v)
inline
418 {
419  v--;
420  v |= v >> 1;
421  v |= v >> 2;
422  v |= v >> 4;
423  v |= v >> 8;
424  v |= v >> 16;
425  v++;
426  return v;
427 }

+ Here is the caller graph for this function:

int dtOppositeTile ( int  side)
inline
443 { return (side+4) & 0x7; }

+ Here is the caller graph for this function:

bool dtOverlapBounds ( const float *  amin,
const float *  amax,
const float *  bmin,
const float *  bmax 
)
inline

Determines if two axis-aligned bounding boxes overlap.

Parameters
[in]aminMinimum bounds of box A. [(x, y, z)]
[in]amaxMaximum bounds of box A. [(x, y, z)]
[in]bminMinimum bounds of box B. [(x, y, z)]
[in]bmaxMaximum bounds of box B. [(x, y, z)]
Returns
True if the two AABB's overlap.
See also
dtOverlapQuantBounds
351 {
352  bool overlap = true;
353  overlap = (amin[0] > bmax[0] || amax[0] < bmin[0]) ? false : overlap;
354  overlap = (amin[1] > bmax[1] || amax[1] < bmin[1]) ? false : overlap;
355  overlap = (amin[2] > bmax[2] || amax[2] < bmin[2]) ? false : overlap;
356  return overlap;
357 }

+ Here is the caller graph for this function:

bool dtOverlapPolyPoly2D ( const float *  polya,
const int  npolya,
const float *  polyb,
const int  npolyb 
)

Determines if the two convex polygons overlap on the xz-plane.

Parameters
[in]polyaPolygon A vertices. [(x, y, z) * npolya]
[in]npolyaThe number of vertices in polygon A.
[in]polybPolygon B vertices. [(x, y, z) * npolyb]
[in]npolybThe number of vertices in polygon B.
Returns
True if the two polygons overlap.

All vertices are projected onto the xz-plane, so the y-values are ignored.

297 {
298  const float eps = 1e-4f;
299 
300  for (int i = 0, j = npolya-1; i < npolya; j=i++)
301  {
302  const float* va = &polya[j*3];
303  const float* vb = &polya[i*3];
304  const float n[3] = { vb[2]-va[2], 0, -(vb[0]-va[0]) };
305  float amin,amax,bmin,bmax;
306  projectPoly(n, polya, npolya, amin,amax);
307  projectPoly(n, polyb, npolyb, bmin,bmax);
308  if (!overlapRange(amin,amax, bmin,bmax, eps))
309  {
310  // Found separating axis
311  return false;
312  }
313  }
314  for (int i = 0, j = npolyb-1; i < npolyb; j=i++)
315  {
316  const float* va = &polyb[j*3];
317  const float* vb = &polyb[i*3];
318  const float n[3] = { vb[2]-va[2], 0, -(vb[0]-va[0]) };
319  float amin,amax,bmin,bmax;
320  projectPoly(n, polya, npolya, amin,amax);
321  projectPoly(n, polyb, npolyb, bmin,bmax);
322  if (!overlapRange(amin,amax, bmin,bmax, eps))
323  {
324  // Found separating axis
325  return false;
326  }
327  }
328  return true;
329 }
bool overlapRange(const float amin, const float amax, const float bmin, const float bmax, const float eps)
Definition: DetourCommon.cpp:285
double eps(double a, double b)
Definition: g3dmath.h:824
static void projectPoly(const float *axis, const float *poly, const int npoly, float &rmin, float &rmax)
Definition: DetourCommon.cpp:273

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool dtOverlapQuantBounds ( const unsigned short  amin[3],
const unsigned short  amax[3],
const unsigned short  bmin[3],
const unsigned short  bmax[3] 
)
inline

Determines if two axis-aligned bounding boxes overlap.

Parameters
[in]aminMinimum bounds of box A. [(x, y, z)]
[in]amaxMaximum bounds of box A. [(x, y, z)]
[in]bminMinimum bounds of box B. [(x, y, z)]
[in]bmaxMaximum bounds of box B. [(x, y, z)]
Returns
True if the two AABB's overlap.
See also
dtOverlapBounds
334 {
335  bool overlap = true;
336  overlap = (amin[0] > bmax[0] || amax[0] < bmin[0]) ? false : overlap;
337  overlap = (amin[1] > bmax[1] || amax[1] < bmin[1]) ? false : overlap;
338  overlap = (amin[2] > bmax[2] || amax[2] < bmin[2]) ? false : overlap;
339  return overlap;
340 }

+ Here is the caller graph for this function:

bool dtPointInPolygon ( const float *  pt,
const float *  verts,
const int  nverts 
)

Determines if the specified point is inside the convex polygon on the xz-plane.

Parameters
[in]ptThe point to check. [(x, y, z)]
[in]vertsThe polygon vertices. [(x, y, z) * nverts]
[in]nvertsThe number of vertices. [Limit: >= 3]
Returns
True if the point is inside the polygon.

All points are projected onto the xz-plane, so the y-values are ignored.

240 {
241  // TODO: Replace pnpoly with triArea2D tests?
242  int i, j;
243  bool c = false;
244  for (i = 0, j = nverts-1; i < nverts; j = i++)
245  {
246  const float* vi = &verts[i*3];
247  const float* vj = &verts[j*3];
248  if (((vi[2] > pt[2]) != (vj[2] > pt[2])) &&
249  (pt[0] < (vj[0]-vi[0]) * (pt[2]-vi[2]) / (vj[2]-vi[2]) + vi[0]) )
250  c = !c;
251  }
252  return c;
253 }

+ Here is the caller graph for this function:

void dtRandomPointInConvexPoly ( const float *  pts,
const int  npts,
float *  areas,
const float  s,
const float  t,
float *  out 
)
335 {
336  // Calc triangle araes
337  float areasum = 0.0f;
338  for (int i = 2; i < npts; i++) {
339  areas[i] = dtTriArea2D(&pts[0], &pts[(i-1)*3], &pts[i*3]);
340  areasum += dtMax(0.001f, areas[i]);
341  }
342  // Find sub triangle weighted by area.
343  const float thr = s*areasum;
344  float acc = 0.0f;
345  float u = 0.0f;
346  int tri = 0;
347  for (int i = 2; i < npts; i++) {
348  const float dacc = areas[i];
349  if (thr >= acc && thr < (acc+dacc))
350  {
351  u = (thr - acc) / dacc;
352  tri = i;
353  break;
354  }
355  acc += dacc;
356  }
357 
358  float v = dtMathSqrtf(t);
359 
360  const float a = 1 - v;
361  const float b = (1 - u) * v;
362  const float c = u * v;
363  const float* pa = &pts[0];
364  const float* pb = &pts[(tri-1)*3];
365  const float* pc = &pts[tri*3];
366 
367  out[0] = a*pa[0] + b*pb[0] + c*pc[0];
368  out[1] = a*pa[1] + b*pb[1] + c*pc[1];
369  out[2] = a*pa[2] + b*pb[2] + c*pc[2];
370 }
float dtTriArea2D(const float *a, const float *b, const float *c)
Definition: DetourCommon.h:316
Definition: BnetFileGenerator.h:49
float dtMathSqrtf(float x)
Definition: DetourMath.h:13
T dtMax(T a, T b)
Definition: DetourCommon.h:57

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T >
T dtSqr ( a)
inline

Returns the square of the value.

Parameters
[in]aThe value.
Returns
The square of the value.
67 { return a*a; }

+ Here is the caller graph for this function:

template<class T >
void dtSwap ( T &  a,
T &  b 
)
inline

Swaps the values of the two parameters.

Parameters
[in,out]aValue A
[in,out]bValue B
45 { T t = a; a = b; b = t; }

+ Here is the caller graph for this function:

void dtSwapByte ( unsigned char *  a,
unsigned char *  b 
)
inline
446 {
447  unsigned char tmp = *a;
448  *a = *b;
449  *b = tmp;
450 }

+ Here is the caller graph for this function:

void dtSwapEndian ( unsigned short *  v)
inline
453 {
454  unsigned char* x = (unsigned char*)v;
455  dtSwapByte(x+0, x+1);
456 }
void dtSwapByte(unsigned char *a, unsigned char *b)
Definition: DetourCommon.h:445
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void dtSwapEndian ( short *  v)
inline
459 {
460  unsigned char* x = (unsigned char*)v;
461  dtSwapByte(x+0, x+1);
462 }
void dtSwapByte(unsigned char *a, unsigned char *b)
Definition: DetourCommon.h:445
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

void dtSwapEndian ( unsigned int *  v)
inline
465 {
466  unsigned char* x = (unsigned char*)v;
467  dtSwapByte(x+0, x+3); dtSwapByte(x+1, x+2);
468 }
void dtSwapByte(unsigned char *a, unsigned char *b)
Definition: DetourCommon.h:445
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

void dtSwapEndian ( int *  v)
inline
471 {
472  unsigned char* x = (unsigned char*)v;
473  dtSwapByte(x+0, x+3); dtSwapByte(x+1, x+2);
474 }
void dtSwapByte(unsigned char *a, unsigned char *b)
Definition: DetourCommon.h:445
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

void dtSwapEndian ( float *  v)
inline
477 {
478  unsigned char* x = (unsigned char*)v;
479  dtSwapByte(x+0, x+3); dtSwapByte(x+1, x+2);
480 }
void dtSwapByte(unsigned char *a, unsigned char *b)
Definition: DetourCommon.h:445
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

float dtTriArea2D ( const float *  a,
const float *  b,
const float *  c 
)
inline

Derives the signed xz-plane area of the triangle ABC, or the relationship of line AB to point C.

Parameters
[in]aVertex A. [(x, y, z)]
[in]bVertex B. [(x, y, z)]
[in]cVertex C. [(x, y, z)]
Returns
The signed xz-plane area of the triangle.

The vertices are projected onto the xz-plane, so the y-values are ignored.

This is a low cost function than can be used for various purposes. Its main purpose is for point/line relationship testing.

In all cases: A value of zero indicates that all vertices are collinear or represent the same point. (On the xz-plane.)

When used for point/line relationship tests, AB usually represents a line against which the C point is to be tested. In this case:

A positive value indicates that point C is to the left of line AB, looking from A toward B.
A negative value indicates that point C is to the right of lineAB, looking from A toward B.

When used for evaluating a triangle:

The absolute value of the return value is two times the area of the triangle when it is projected onto the xz-plane.

A positive return value indicates:

  • The vertices are wrapped in the normal Detour wrap direction.
  • The triangle's 3D face normal is in the general up direction.

A negative return value indicates:

  • The vertices are reverse wrapped. (Wrapped opposite the normal Detour wrap direction.)
  • The triangle's 3D face normal is in the general down direction.
317 {
318  const float abx = b[0] - a[0];
319  const float abz = b[2] - a[2];
320  const float acx = c[0] - a[0];
321  const float acz = c[2] - a[2];
322  return acx*abz - abx*acz;
323 }

+ Here is the caller graph for this function:

void dtVadd ( float *  dest,
const float *  v1,
const float *  v2 
)
inline

Performs a vector addition. (v1 + v2)

Parameters
[out]destThe result vector. [(x, y, z)]
[in]v1The base vector. [(x, y, z)]
[in]v2The vector to add to v1. [(x, y, z)]
129 {
130  dest[0] = v1[0]+v2[0];
131  dest[1] = v1[1]+v2[1];
132  dest[2] = v1[2]+v2[2];
133 }

+ Here is the caller graph for this function:

void dtVcopy ( float *  dest,
const float *  a 
)
inline

Performs a vector copy.

Parameters
[out]destThe result. [(x, y, z)]
[in]aThe vector to copy. [(x, y, z)]
191 {
192  dest[0] = a[0];
193  dest[1] = a[1];
194  dest[2] = a[2];
195 }

+ Here is the caller graph for this function:

void dtVcross ( float *  dest,
const float *  v1,
const float *  v2 
)
inline

Derives the cross product of two vectors. (v1 x v2)

Parameters
[out]destThe cross product. [(x, y, z)]
[in]v1A Vector [(x, y, z)]
[in]v2A vector [(x, y, z)]
85 {
86  dest[0] = v1[1]*v2[2] - v1[2]*v2[1];
87  dest[1] = v1[2]*v2[0] - v1[0]*v2[2];
88  dest[2] = v1[0]*v2[1] - v1[1]*v2[0];
89 }
float dtVdist ( const float *  v1,
const float *  v2 
)
inline

Returns the distance between two points.

Parameters
[in]v1A point. [(x, y, z)]
[in]v2A point. [(x, y, z)]
Returns
The distance between the two points.
218 {
219  const float dx = v2[0] - v1[0];
220  const float dy = v2[1] - v1[1];
221  const float dz = v2[2] - v1[2];
222  return dtMathSqrtf(dx*dx + dy*dy + dz*dz);
223 }
float dtMathSqrtf(float x)
Definition: DetourMath.h:13

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float dtVdist2D ( const float *  v1,
const float *  v2 
)
inline

Derives the distance between the specified points on the xz-plane.

Parameters
[in]v1A point. [(x, y, z)]
[in]v2A point. [(x, y, z)]
Returns
The distance between the point on the xz-plane.

The vectors are projected onto the xz-plane, so the y-values are ignored.

244 {
245  const float dx = v2[0] - v1[0];
246  const float dz = v2[2] - v1[2];
247  return dtMathSqrtf(dx*dx + dz*dz);
248 }
float dtMathSqrtf(float x)
Definition: DetourMath.h:13

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float dtVdist2DSqr ( const float *  v1,
const float *  v2 
)
inline

Derives the square of the distance between the specified points on the xz-plane.

Parameters
[in]v1A point. [(x, y, z)]
[in]v2A point. [(x, y, z)]
Returns
The square of the distance between the point on the xz-plane.
255 {
256  const float dx = v2[0] - v1[0];
257  const float dz = v2[2] - v1[2];
258  return dx*dx + dz*dz;
259 }

+ Here is the caller graph for this function:

float dtVdistSqr ( const float *  v1,
const float *  v2 
)
inline

Returns the square of the distance between two points.

Parameters
[in]v1A point. [(x, y, z)]
[in]v2A point. [(x, y, z)]
Returns
The square of the distance between the two points.
230 {
231  const float dx = v2[0] - v1[0];
232  const float dy = v2[1] - v1[1];
233  const float dz = v2[2] - v1[2];
234  return dx*dx + dy*dy + dz*dz;
235 }

+ Here is the caller graph for this function:

float dtVdot ( const float *  v1,
const float *  v2 
)
inline

Derives the dot product of two vectors. (v1 . v2)

Parameters
[in]v1A Vector [(x, y, z)]
[in]v2A vector [(x, y, z)]
Returns
The dot product.
96 {
97  return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
98 }

+ Here is the caller graph for this function:

float dtVdot2D ( const float *  u,
const float *  v 
)
inline

Derives the dot product of two vectors on the xz-plane. (u . v)

Parameters
[in]uA vector [(x, y, z)]
[in]vA vector [(x, y, z)]
Returns
The dot product on the xz-plane.

The vectors are projected onto the xz-plane, so the y-values are ignored.

292 {
293  return u[0]*v[0] + u[2]*v[2];
294 }

+ Here is the caller graph for this function:

bool dtVequal ( const float *  p0,
const float *  p1 
)
inline

Performs a 'sloppy' colocation check of the specified points.

Parameters
[in]p0A point. [(x, y, z)]
[in]p1A point. [(x, y, z)]
Returns
True if the points are considered to be at the same location.

Basically, this function will return true if the specified points are close enough to eachother to be considered colocated.

279 {
280  static const float thr = dtSqr(1.0f/16384.0f);
281  const float d = dtVdistSqr(p0, p1);
282  return d < thr;
283 }
float dtVdistSqr(const float *v1, const float *v2)
Definition: DetourCommon.h:229
T dtSqr(T a)
Definition: DetourCommon.h:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float dtVlen ( const float *  v)
inline

Derives the scalar length of the vector.

Parameters
[in]vThe vector. [(x, y, z)]
Returns
The scalar length of the vector.
201 {
202  return dtMathSqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
203 }
float dtMathSqrtf(float x)
Definition: DetourMath.h:13

+ Here is the call graph for this function:

float dtVlenSqr ( const float *  v)
inline

Derives the square of the scalar length of the vector. (len * len)

Parameters
[in]vThe vector. [(x, y, z)]
Returns
The square of the scalar length of the vector.
209 {
210  return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
211 }

+ Here is the caller graph for this function:

void dtVlerp ( float *  dest,
const float *  v1,
const float *  v2,
const float  t 
)
inline

Performs a linear interpolation between two vectors. (v1 toward v2)

Parameters
[out]destThe result vector. [(x, y, x)]
[in]v1The starting vector.
[in]v2The destination vector.
[in]tThe interpolation factor. [Limits: 0 <= value <= 1.0]
118 {
119  dest[0] = v1[0]+(v2[0]-v1[0])*t;
120  dest[1] = v1[1]+(v2[1]-v1[1])*t;
121  dest[2] = v1[2]+(v2[2]-v1[2])*t;
122 }

+ Here is the caller graph for this function:

void dtVmad ( float *  dest,
const float *  v1,
const float *  v2,
const float  s 
)
inline

Performs a scaled vector addition. (v1 + (v2 * s))

Parameters
[out]destThe result vector. [(x, y, z)]
[in]v1The base vector. [(x, y, z)]
[in]v2The vector to scale and add to v1. [(x, y, z)]
[in]sThe amount to scale v2 by before adding to v1.
106 {
107  dest[0] = v1[0]+v2[0]*s;
108  dest[1] = v1[1]+v2[1]*s;
109  dest[2] = v1[2]+v2[2]*s;
110 }

+ Here is the caller graph for this function:

void dtVmax ( float *  mx,
const float *  v 
)
inline

Selects the maximum value of each element from the specified vectors.

Parameters
[in,out]mxA vector. (Will be updated with the result.) [(x, y, z)]
[in]vA vector. [(x, y, z)]
171 {
172  mx[0] = dtMax(mx[0], v[0]);
173  mx[1] = dtMax(mx[1], v[1]);
174  mx[2] = dtMax(mx[2], v[2]);
175 }
T dtMax(T a, T b)
Definition: DetourCommon.h:57

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void dtVmin ( float *  mn,
const float *  v 
)
inline

Selects the minimum value of each element from the specified vectors.

Parameters
[in,out]mnA vector. (Will be updated with the result.) [(x, y, z)]
[in]vA vector. [(x, y, z)]
161 {
162  mn[0] = dtMin(mn[0], v[0]);
163  mn[1] = dtMin(mn[1], v[1]);
164  mn[2] = dtMin(mn[2], v[2]);
165 }
T dtMin(T a, T b)
Definition: DetourCommon.h:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void dtVnormalize ( float *  v)
inline

Normalizes the vector.

Parameters
[in,out]vThe vector to normalize. [(x, y, z)]
264 {
265  float d = 1.0f / dtMathSqrtf(dtSqr(v[0]) + dtSqr(v[1]) + dtSqr(v[2]));
266  v[0] *= d;
267  v[1] *= d;
268  v[2] *= d;
269 }
float dtMathSqrtf(float x)
Definition: DetourMath.h:13
T dtSqr(T a)
Definition: DetourCommon.h:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float dtVperp2D ( const float *  u,
const float *  v 
)
inline

Derives the xz-plane 2D perp product of the two vectors. (uz*vx - ux*vz)

Parameters
[in]uThe LHV vector [(x, y, z)]
[in]vThe RHV vector [(x, y, z)]
Returns
The dot product on the xz-plane.

The vectors are projected onto the xz-plane, so the y-values are ignored.

303 {
304  return u[2]*v[0] - u[0]*v[2];
305 }

+ Here is the caller graph for this function:

void dtVscale ( float *  dest,
const float *  v,
const float  t 
)
inline

Scales the vector by the specified value. (v * t)

Parameters
[out]destThe result vector. [(x, y, z)]
[in]vThe vector to scale. [(x, y, z)]
[in]tThe scaling factor.
151 {
152  dest[0] = v[0]*t;
153  dest[1] = v[1]*t;
154  dest[2] = v[2]*t;
155 }

+ Here is the caller graph for this function:

void dtVset ( float *  dest,
const float  x,
const float  y,
const float  z 
)
inline

Sets the vector elements to the specified values.

Parameters
[out]destThe result vector. [(x, y, z)]
[in]xThe x-value of the vector.
[in]yThe y-value of the vector.
[in]zThe z-value of the vector.
183 {
184  dest[0] = x; dest[1] = y; dest[2] = z;
185 }
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

void dtVsub ( float *  dest,
const float *  v1,
const float *  v2 
)
inline

Performs a vector subtraction. (v1 - v2)

Parameters
[out]destThe result vector. [(x, y, z)]
[in]v1The base vector. [(x, y, z)]
[in]v2The vector to subtract from v1. [(x, y, z)]
140 {
141  dest[0] = v1[0]-v2[0];
142  dest[1] = v1[1]-v2[1];
143  dest[2] = v1[2]-v2[2];
144 }

+ Here is the caller graph for this function: