Planeshift

DetourCommon.h File Reference

Go to the source code of this file.

Functions

General helper functions
template<class T >
void dtSwap (T &a, T &b)
 Swaps the values of the two parameters.
template<class T >
dtMin (T a, T b)
 Returns the minimum of two values.
template<class T >
dtMax (T a, T b)
 Returns the maximum of two values.
template<class T >
dtAbs (T a)
 Returns the absolute value.
template<class T >
dtSqr (T a)
 Returns the square of the value.
template<class T >
dtClamp (T v, T mn, T mx)
 Clamps the value to the specified range.
float dtSqrt (float x)
 Returns the square root of the value.
Vector helper functions.
void dtVcross (float *dest, const float *v1, const float *v2)
 Derives the cross product of two vectors. (v1 x v2)
float dtVdot (const float *v1, const float *v2)
 Derives the dot product of two vectors. (v1 . v2)
void dtVmad (float *dest, const float *v1, const float *v2, const float s)
 Performs a scaled vector addition. (v1 + (v2 * s))
void dtVlerp (float *dest, const float *v1, const float *v2, const float t)
 Performs a linear interpolation between two vectors. (v1 toward v2)
void dtVadd (float *dest, const float *v1, const float *v2)
 Performs a vector addition. (v1 + v2)
void dtVsub (float *dest, const float *v1, const float *v2)
 Performs a vector subtraction. (v1 - v2)
void dtVscale (float *dest, const float *v, const float t)
 Scales the vector by the specified value. (v * t)
void dtVmin (float *mn, const float *v)
 Selects the minimum value of each element from the specified vectors.
void dtVmax (float *mx, const float *v)
 Selects the maximum value of each element from the specified vectors.
void dtVset (float *dest, const float x, const float y, const float z)
 Sets the vector elements to the specified values.
void dtVcopy (float *dest, const float *a)
 Performs a vector copy.
float dtVlen (const float *v)
 Derives the scalar length of the vector.
float dtVlenSqr (const float *v)
 Derives the square of the scalar length of the vector. (len * len)
float dtVdist (const float *v1, const float *v2)
 Returns the distance between two points.
float dtVdistSqr (const float *v1, const float *v2)
 Returns the square of the distance between two points.
float dtVdist2D (const float *v1, const float *v2)
 Derives the distance between the specified points on the xz-plane.
float dtVdist2DSqr (const float *v1, const float *v2)
 Derives the square of the distance between the specified points on the xz-plane.
void dtVnormalize (float *v)
 Normalizes the vector.
bool dtVequal (const float *p0, const float *p1)
 Performs a 'sloppy' colocation check of the specified points.
float dtVdot2D (const float *u, const float *v)
 Derives the dot product of two vectors on the xz-plane. (u . v)
float dtVperp2D (const float *u, const float *v)
 Derives the xz-plane 2D perp product of the two vectors. (uz*vx - ux*vz)
Computational geometry helper functions.
float dtTriArea2D (const float *a, const float *b, const float *c)
 Derives the signed xz-plane area of the triangle ABC, or the relationship of line AB to point C.
bool dtOverlapQuantBounds (const unsigned short amin[3], const unsigned short amax[3], const unsigned short bmin[3], const unsigned short bmax[3])
 Determines if two axis-aligned bounding boxes overlap.
bool dtOverlapBounds (const float *amin, const float *amax, const float *bmin, const float *bmax)
 Determines if two axis-aligned bounding boxes overlap.
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.
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.
bool dtIntersectSegmentPoly2D (const float *p0, const float *p1, const float *verts, int nverts, float &tmin, float &tmax, int &segMin, int &segMax)
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.
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)
 Derives the centroid of a convex polygon.
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.
Miscellaneous 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.

Definition at line 55 of file DetourCommon.h.

int dtAlign4 ( int  x) [inline]

Definition at line 435 of file DetourCommon.h.

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]
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.

Definition at line 67 of file DetourCommon.h.

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.
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)]
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 
)
unsigned int dtIlog2 ( unsigned int  v) [inline]

Definition at line 423 of file DetourCommon.h.

bool dtIntersectSegmentPoly2D ( const float p0,
const float p1,
const float verts,
int  nverts,
float tmin,
float tmax,
int segMin,
int segMax 
)
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.

Definition at line 50 of file DetourCommon.h.

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.

Definition at line 44 of file DetourCommon.h.

unsigned int dtNextPow2 ( unsigned int  v) [inline]

Definition at line 411 of file DetourCommon.h.

int dtOppositeTile ( int  side) [inline]

Definition at line 437 of file DetourCommon.h.

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

Definition at line 347 of file DetourCommon.h.

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.
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

Definition at line 330 of file DetourCommon.h.

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.
void dtRandomPointInConvexPoly ( const float pts,
const int  npts,
float areas,
const float  s,
const float  t,
float out 
)
template<class T >
T dtSqr ( a) [inline]

Returns the square of the value.

Parameters:
[in]aThe value.
Returns:
The square of the value.

Definition at line 60 of file DetourCommon.h.

float dtSqrt ( float  x)

Returns the square root of the value.

Parameters:
[in]xThe value.
Returns:
The square root of the vlaue.
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

Definition at line 38 of file DetourCommon.h.

void dtSwapByte ( unsigned char *  a,
unsigned char *  b 
) [inline]

Definition at line 439 of file DetourCommon.h.

void dtSwapEndian ( unsigned int v) [inline]

Definition at line 458 of file DetourCommon.h.

void dtSwapEndian ( unsigned short *  v) [inline]

Definition at line 446 of file DetourCommon.h.

void dtSwapEndian ( short *  v) [inline]

Definition at line 452 of file DetourCommon.h.

void dtSwapEndian ( float v) [inline]

Definition at line 470 of file DetourCommon.h.

void dtSwapEndian ( int v) [inline]

Definition at line 464 of file DetourCommon.h.

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.

Definition at line 314 of file DetourCommon.h.

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)]

Definition at line 126 of file DetourCommon.h.

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)]

Definition at line 188 of file DetourCommon.h.

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)]

Definition at line 82 of file DetourCommon.h.

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.

Definition at line 215 of file DetourCommon.h.

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.

Definition at line 241 of file DetourCommon.h.

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.

Definition at line 252 of file DetourCommon.h.

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.

Definition at line 227 of file DetourCommon.h.

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.

Definition at line 93 of file DetourCommon.h.

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.

Definition at line 289 of file DetourCommon.h.

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.

Definition at line 276 of file DetourCommon.h.

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.

Definition at line 198 of file DetourCommon.h.

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.

Definition at line 206 of file DetourCommon.h.

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]

Definition at line 115 of file DetourCommon.h.

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.

Definition at line 103 of file DetourCommon.h.

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)]

Definition at line 168 of file DetourCommon.h.

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)]

Definition at line 158 of file DetourCommon.h.

void dtVnormalize ( float v) [inline]

Normalizes the vector.

Parameters:
[in,out]vThe vector to normalize. [(x, y, z)]

Definition at line 261 of file DetourCommon.h.

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.

Definition at line 300 of file DetourCommon.h.

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.

Definition at line 148 of file DetourCommon.h.

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.

Definition at line 180 of file DetourCommon.h.

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)]

Definition at line 137 of file DetourCommon.h.