Merge pull request #4 from mendsley/math
Add wrappers for the standard math library
This commit is contained in:
commit
200dd00cb9
@ -17,9 +17,9 @@
|
||||
//
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include "DebugDraw.h"
|
||||
#include "DetourMath.h"
|
||||
|
||||
|
||||
duDebugDraw::~duDebugDraw()
|
||||
@ -180,8 +180,8 @@ void duAppendCylinderWire(struct duDebugDraw* dd, float minx, float miny, float
|
||||
for (int i = 0; i < NUM_SEG; ++i)
|
||||
{
|
||||
const float a = (float)i/(float)NUM_SEG*DU_PI*2;
|
||||
dir[i*2] = cosf(a);
|
||||
dir[i*2+1] = sinf(a);
|
||||
dir[i*2] = dtMathCosf(a);
|
||||
dir[i*2+1] = dtMathSinf(a);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
#include "DebugDraw.h"
|
||||
#include "DetourDebugDraw.h"
|
||||
#include "DetourNavMesh.h"
|
||||
|
21
Detour/Include/DetourMath.h
Normal file
21
Detour/Include/DetourMath.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef DETOURMATH_H
|
||||
#define DETOURMATH_H
|
||||
|
||||
/**
|
||||
@defgroup detour Detour
|
||||
|
||||
Members in this module are wrappers around the standard math library
|
||||
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define dtMathFabs(x) fabs(x)
|
||||
#define dtMathSqrtf(x) sqrtf(x)
|
||||
#define dtMathFloorf(x) floorf(x)
|
||||
#define dtMathCeilf(x) ceilf(x)
|
||||
#define dtMathCosf(x) cosf(x)
|
||||
#define dtMathSinf(x) sinf(x)
|
||||
#define dtMathAtan2f(y, x) atan2f(y, x)
|
||||
|
||||
#endif
|
@ -16,14 +16,14 @@
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
#include "DetourCommon.h"
|
||||
#include "DetourMath.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
float dtSqrt(float x)
|
||||
{
|
||||
return sqrtf(x);
|
||||
return dtMathSqrtf(x);
|
||||
}
|
||||
|
||||
void dtClosestPtPointTriangle(float* closest, const float* p,
|
||||
|
@ -16,13 +16,13 @@
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "DetourNavMesh.h"
|
||||
#include "DetourNode.h"
|
||||
#include "DetourCommon.h"
|
||||
#include "DetourMath.h"
|
||||
#include "DetourAlloc.h"
|
||||
#include "DetourAssert.h"
|
||||
#include <new>
|
||||
|
@ -16,13 +16,13 @@
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <float.h>
|
||||
#include "DetourNavMesh.h"
|
||||
#include "DetourCommon.h"
|
||||
#include "DetourMath.h"
|
||||
#include "DetourNavMeshBuilder.h"
|
||||
#include "DetourAlloc.h"
|
||||
#include "DetourAssert.h"
|
||||
@ -202,8 +202,8 @@ static int createBVTree(const unsigned short* verts, const int /*nverts*/,
|
||||
if (z > it.bmax[2]) it.bmax[2] = z;
|
||||
}
|
||||
// Remap y
|
||||
it.bmin[1] = (unsigned short)floorf((float)it.bmin[1]*ch/cs);
|
||||
it.bmax[1] = (unsigned short)ceilf((float)it.bmax[1]*ch/cs);
|
||||
it.bmin[1] = (unsigned short)dtMathFloorf((float)it.bmin[1]*ch/cs);
|
||||
it.bmax[1] = (unsigned short)dtMathCeilf((float)it.bmax[1]*ch/cs);
|
||||
}
|
||||
|
||||
int curNode = 0;
|
||||
|
@ -16,13 +16,13 @@
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
#include "DetourNavMeshQuery.h"
|
||||
#include "DetourNavMesh.h"
|
||||
#include "DetourNode.h"
|
||||
#include "DetourCommon.h"
|
||||
#include "DetourMath.h"
|
||||
#include "DetourAlloc.h"
|
||||
#include "DetourAssert.h"
|
||||
#include <new>
|
||||
@ -3342,7 +3342,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
|
||||
dtVsub(hitNormal, centerPos, hitPos);
|
||||
dtVnormalize(hitNormal);
|
||||
|
||||
*hitDist = sqrtf(radiusSqr);
|
||||
*hitDist = dtMathSqrtf(radiusSqr);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
//
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <float.h>
|
||||
#include <stdlib.h>
|
||||
@ -27,6 +26,7 @@
|
||||
#include "DetourNavMeshQuery.h"
|
||||
#include "DetourObstacleAvoidance.h"
|
||||
#include "DetourCommon.h"
|
||||
#include "DetourMath.h"
|
||||
#include "DetourAssert.h"
|
||||
#include "DetourAlloc.h"
|
||||
|
||||
@ -206,7 +206,7 @@ static int getNeighbours(const float* pos, const float height, const float range
|
||||
// Check for overlap.
|
||||
float diff[3];
|
||||
dtVsub(diff, pos, ag->npos);
|
||||
if (fabsf(diff[1]) >= (height+ag->params.height)/2.0f)
|
||||
if (dtMathFabs(diff[1]) >= (height+ag->params.height)/2.0f)
|
||||
continue;
|
||||
diff[1] = 0;
|
||||
const float distSqr = dtVlenSqr(diff);
|
||||
@ -1200,7 +1200,7 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
continue;
|
||||
if (distSqr > dtSqr(separationDist))
|
||||
continue;
|
||||
const float dist = sqrtf(distSqr);
|
||||
const float dist = dtMathSqrtf(distSqr);
|
||||
const float weight = separationWeight * (1.0f - dtSqr(dist*invSeparationDist));
|
||||
|
||||
dtVmad(disp, disp, diff, weight/dist);
|
||||
@ -1318,7 +1318,7 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
float dist = dtVlenSqr(diff);
|
||||
if (dist > dtSqr(ag->params.radius + nei->params.radius))
|
||||
continue;
|
||||
dist = sqrtf(dist);
|
||||
dist = dtMathSqrtf(dist);
|
||||
float pen = (ag->params.radius + nei->params.radius) - dist;
|
||||
if (dist < 0.0001f)
|
||||
{
|
||||
|
@ -18,10 +18,10 @@
|
||||
|
||||
#include "DetourObstacleAvoidance.h"
|
||||
#include "DetourCommon.h"
|
||||
#include "DetourMath.h"
|
||||
#include "DetourAlloc.h"
|
||||
#include "DetourAssert.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <new>
|
||||
|
||||
@ -58,7 +58,7 @@ static int isectRaySeg(const float* ap, const float* u,
|
||||
dtVsub(v,bq,bp);
|
||||
dtVsub(w,ap,bp);
|
||||
float d = dtVperp2D(u,v);
|
||||
if (fabsf(d) < 1e-6f) return 0;
|
||||
if (dtMathFabs(d) < 1e-6f) return 0;
|
||||
d = 1.0f/d;
|
||||
t = dtVperp2D(v,w) * d;
|
||||
if (t < 0 || t > 1) return 0;
|
||||
@ -482,7 +482,7 @@ int dtObstacleAvoidanceQuery::sampleVelocityAdaptive(const float* pos, const flo
|
||||
const int nd = dtClamp(ndivs, 1, DT_MAX_PATTERN_DIVS);
|
||||
const int nr = dtClamp(nrings, 1, DT_MAX_PATTERN_RINGS);
|
||||
const float da = (1.0f/nd) * DT_PI*2;
|
||||
const float dang = atan2f(dvel[2], dvel[0]);
|
||||
const float dang = dtMathAtan2f(dvel[2], dvel[0]);
|
||||
|
||||
// Always add sample at zero
|
||||
pat[npat*2+0] = 0;
|
||||
|
@ -16,11 +16,11 @@
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <new>
|
||||
#include "DetourProximityGrid.h"
|
||||
#include "DetourCommon.h"
|
||||
#include "DetourMath.h"
|
||||
#include "DetourAlloc.h"
|
||||
#include "DetourAssert.h"
|
||||
|
||||
@ -103,10 +103,10 @@ void dtProximityGrid::addItem(const unsigned short id,
|
||||
const float minx, const float miny,
|
||||
const float maxx, const float maxy)
|
||||
{
|
||||
const int iminx = (int)floorf(minx * m_invCellSize);
|
||||
const int iminy = (int)floorf(miny * m_invCellSize);
|
||||
const int imaxx = (int)floorf(maxx * m_invCellSize);
|
||||
const int imaxy = (int)floorf(maxy * m_invCellSize);
|
||||
const int iminx = (int)dtMathFloorf(minx * m_invCellSize);
|
||||
const int iminy = (int)dtMathFloorf(miny * m_invCellSize);
|
||||
const int imaxx = (int)dtMathFloorf(maxx * m_invCellSize);
|
||||
const int imaxy = (int)dtMathFloorf(maxy * m_invCellSize);
|
||||
|
||||
m_bounds[0] = dtMin(m_bounds[0], iminx);
|
||||
m_bounds[1] = dtMin(m_bounds[1], iminy);
|
||||
@ -137,10 +137,10 @@ int dtProximityGrid::queryItems(const float minx, const float miny,
|
||||
const float maxx, const float maxy,
|
||||
unsigned short* ids, const int maxIds) const
|
||||
{
|
||||
const int iminx = (int)floorf(minx * m_invCellSize);
|
||||
const int iminy = (int)floorf(miny * m_invCellSize);
|
||||
const int imaxx = (int)floorf(maxx * m_invCellSize);
|
||||
const int imaxy = (int)floorf(maxy * m_invCellSize);
|
||||
const int iminx = (int)dtMathFloorf(minx * m_invCellSize);
|
||||
const int iminy = (int)dtMathFloorf(miny * m_invCellSize);
|
||||
const int imaxx = (int)dtMathFloorf(maxx * m_invCellSize);
|
||||
const int imaxy = (int)dtMathFloorf(maxy * m_invCellSize);
|
||||
|
||||
int n = 0;
|
||||
|
||||
|
@ -3,9 +3,9 @@
|
||||
#include "DetourNavMeshBuilder.h"
|
||||
#include "DetourNavMesh.h"
|
||||
#include "DetourCommon.h"
|
||||
#include "DetourMath.h"
|
||||
#include "DetourAlloc.h"
|
||||
#include "DetourAssert.h"
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <new>
|
||||
|
||||
@ -409,10 +409,10 @@ dtStatus dtTileCache::queryTiles(const float* bmin, const float* bmax,
|
||||
|
||||
const float tw = m_params.width * m_params.cs;
|
||||
const float th = m_params.height * m_params.cs;
|
||||
const int tx0 = (int)floorf((bmin[0]-m_params.orig[0]) / tw);
|
||||
const int tx1 = (int)floorf((bmax[0]-m_params.orig[0]) / tw);
|
||||
const int ty0 = (int)floorf((bmin[2]-m_params.orig[2]) / th);
|
||||
const int ty1 = (int)floorf((bmax[2]-m_params.orig[2]) / th);
|
||||
const int tx0 = (int)dtMathFloorf((bmin[0]-m_params.orig[0]) / tw);
|
||||
const int tx1 = (int)dtMathFloorf((bmax[0]-m_params.orig[0]) / tw);
|
||||
const int ty0 = (int)dtMathFloorf((bmin[2]-m_params.orig[2]) / th);
|
||||
const int ty1 = (int)dtMathFloorf((bmax[2]-m_params.orig[2]) / th);
|
||||
|
||||
for (int ty = ty0; ty <= ty1; ++ty)
|
||||
{
|
||||
|
@ -17,11 +17,11 @@
|
||||
//
|
||||
|
||||
#include "DetourCommon.h"
|
||||
#include "DetourMath.h"
|
||||
#include "DetourStatus.h"
|
||||
#include "DetourAssert.h"
|
||||
#include "DetourTileCacheBuilder.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
template<class T> class dtFixedArray
|
||||
@ -1968,12 +1968,12 @@ dtStatus dtMarkCylinderArea(dtTileCacheLayer& layer, const float* orig, const fl
|
||||
const float px = (pos[0]-orig[0])*ics;
|
||||
const float pz = (pos[2]-orig[2])*ics;
|
||||
|
||||
int minx = (int)floorf((bmin[0]-orig[0])*ics);
|
||||
int miny = (int)floorf((bmin[1]-orig[1])*ich);
|
||||
int minz = (int)floorf((bmin[2]-orig[2])*ics);
|
||||
int maxx = (int)floorf((bmax[0]-orig[0])*ics);
|
||||
int maxy = (int)floorf((bmax[1]-orig[1])*ich);
|
||||
int maxz = (int)floorf((bmax[2]-orig[2])*ics);
|
||||
int minx = (int)dtMathFloorf((bmin[0]-orig[0])*ics);
|
||||
int miny = (int)dtMathFloorf((bmin[1]-orig[1])*ich);
|
||||
int minz = (int)dtMathFloorf((bmin[2]-orig[2])*ics);
|
||||
int maxx = (int)dtMathFloorf((bmax[0]-orig[0])*ics);
|
||||
int maxy = (int)dtMathFloorf((bmax[1]-orig[1])*ich);
|
||||
int maxz = (int)dtMathFloorf((bmax[2]-orig[2])*ics);
|
||||
|
||||
if (maxx < 0) return DT_SUCCESS;
|
||||
if (minx >= w) return DT_SUCCESS;
|
||||
|
@ -260,6 +260,10 @@
|
||||
RelativePath="..\..\..\Detour\Include\DetourCommon.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\Detour\Include\DetourMath.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\Detour\Include\DetourNavMesh.h"
|
||||
>
|
||||
|
Loading…
x
Reference in New Issue
Block a user