mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Recast: use math functions from Recast & Detour itself
Make the code base more consistent.
This commit is contained in:
parent
54c00591d1
commit
1853b571c5
@ -348,8 +348,8 @@ void duAppendCylinder(struct duDebugDraw* dd, float minx, float miny, float minz
|
||||
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] = rdMathCosf(a);
|
||||
dir[i*2+1] = rdMathSinf(a);
|
||||
}
|
||||
}
|
||||
|
||||
@ -395,50 +395,18 @@ inline void evalArc(const float x0, const float y0, const float z0,
|
||||
res[2] = z0 + dz * u + h * (1-(u*2-1)*(u*2-1));
|
||||
}
|
||||
|
||||
|
||||
inline void vcross(float* dest, const float* v1, const float* v2)
|
||||
{
|
||||
dest[0] = v1[1]*v2[2] - v1[2]*v2[1];
|
||||
dest[1] = v1[2]*v2[0] - v1[0]*v2[2];
|
||||
dest[2] = v1[0]*v2[1] - v1[1]*v2[0];
|
||||
}
|
||||
|
||||
inline void vnormalize(float* v)
|
||||
{
|
||||
float d = 1.0f / sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
|
||||
v[0] *= d;
|
||||
v[1] *= d;
|
||||
v[2] *= d;
|
||||
}
|
||||
|
||||
inline void vsub(float* dest, const float* v1, const float* v2)
|
||||
{
|
||||
dest[0] = v1[0]-v2[0];
|
||||
dest[1] = v1[1]-v2[1];
|
||||
dest[2] = v1[2]-v2[2];
|
||||
}
|
||||
|
||||
inline float vdistSqr(const float* v1, const float* v2)
|
||||
{
|
||||
const float x = v1[0]-v2[0];
|
||||
const float y = v1[1]-v2[1];
|
||||
const float z = v1[2]-v2[2];
|
||||
return x*x + y*y + z*z;
|
||||
}
|
||||
|
||||
|
||||
void appendArrowHead(struct duDebugDraw* dd, const float* p, const float* q,
|
||||
const float s, unsigned int col)
|
||||
{
|
||||
const float eps = 0.001f;
|
||||
if (!dd) return;
|
||||
if (vdistSqr(p,q) < eps*eps) return;
|
||||
if (rdVdistSqr(p,q) < eps*eps) return;
|
||||
float ax[3], ay[3] = {0,1,0}, az[3];
|
||||
vsub(az, q, p);
|
||||
vnormalize(az);
|
||||
vcross(ax, ay, az);
|
||||
vcross(ay, az, ax);
|
||||
vnormalize(ay);
|
||||
rdVsub(az, q, p);
|
||||
rdVnormalize(az);
|
||||
rdVcross(ax, ay, az);
|
||||
rdVcross(ay, az, ax);
|
||||
rdVnormalize(ay);
|
||||
|
||||
dd->vertex(p, col);
|
||||
dd->vertex(p[0]+az[0]*s+ay[0]*s/2, p[1]+az[1]*s+ay[1]*s/2, p[2]+az[2]*s+ay[2]*s/2, col);
|
||||
@ -458,7 +426,7 @@ void duAppendArc(struct duDebugDraw* dd, const float x0, const float y0, const f
|
||||
const float dx = x1 - x0;
|
||||
const float dy = y1 - y0;
|
||||
const float dz = z1 - z0;
|
||||
const float len = sqrtf(dx*dx + dy*dy + dz*dz);
|
||||
const float len = rdMathSqrtf(dx*dx + dy*dy + dz*dz);
|
||||
float prev[3];
|
||||
evalArc(x0,y0,z0, dx,dy,dz, len*h, PAD, prev);
|
||||
for (int i = 1; i <= NUM_ARC_PTS; ++i)
|
||||
@ -519,8 +487,8 @@ void duAppendCircle(struct duDebugDraw* dd, const float x, const float y, const
|
||||
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] = rdMathCosf(a);
|
||||
dir[i*2+1] = rdMathSinf(a);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -904,6 +904,3 @@ void duDebugDrawTileCachePolyMesh(duDebugDraw* dd, const struct dtTileCachePolyM
|
||||
}
|
||||
dd->end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -84,7 +84,7 @@ void duDebugDrawTriMeshSlope(duDebugDraw* dd, const float* verts, int /*nverts*/
|
||||
if (!tris) return;
|
||||
if (!normals) return;
|
||||
|
||||
const float walkableThr = cosf(walkableSlopeAngle/180.0f*DU_PI);
|
||||
const float walkableThr = rdMathCosf(walkableSlopeAngle/180.0f*DU_PI);
|
||||
|
||||
float uva[2];
|
||||
float uvb[2];
|
||||
|
@ -1251,8 +1251,8 @@ const dtMeshTile* dtNavMesh::getTile(int i) const
|
||||
|
||||
void dtNavMesh::calcTileLoc(const float* pos, int* tx, int* ty) const
|
||||
{
|
||||
*tx = (int)floorf((m_orig[0]-pos[0]) / m_tileWidth);
|
||||
*ty = (int)floorf((pos[1]-m_orig[1]) / m_tileHeight);
|
||||
*tx = (int)rdMathFloorf((m_orig[0]-pos[0]) / m_tileWidth);
|
||||
*ty = (int)rdMathFloorf((pos[1]-m_orig[1]) / m_tileHeight);
|
||||
}
|
||||
|
||||
dtStatus dtNavMesh::getTileAndPolyByRef(const dtPolyRef ref, const dtMeshTile** tile, const dtPoly** poly) const
|
||||
|
@ -491,8 +491,8 @@ inline void dtNormalize2D(float* v)
|
||||
// vector normalization that ignores the z-component.
|
||||
inline void dtRorate2D(float* dest, const float* v, float ang)
|
||||
{
|
||||
float c = cosf(ang);
|
||||
float s = sinf(ang);
|
||||
float c = rdMathCosf(ang);
|
||||
float s = rdMathSinf(ang);
|
||||
dest[0] = v[0]*c - v[1]*s;
|
||||
dest[1] = v[0]*s + v[1]*c;
|
||||
dest[2] = v[2];
|
||||
@ -527,8 +527,8 @@ int dtObstacleAvoidanceQuery::sampleVelocityAdaptive(const float* pos, const flo
|
||||
const int nd = rdClamp(ndivs, 1, DT_MAX_PATTERN_DIVS);
|
||||
const int nr = rdClamp(nrings, 1, DT_MAX_PATTERN_RINGS);
|
||||
const float da = (1.0f/nd) * RD_PI*2;
|
||||
const float ca = cosf(da);
|
||||
const float sa = sinf(da);
|
||||
const float ca = rdMathCosf(da);
|
||||
const float sa = rdMathSinf(da);
|
||||
|
||||
// desired direction
|
||||
float ddir[6];
|
||||
|
@ -440,8 +440,8 @@ dtStatus dtTileCache::addBoxObstacle(const float* center, const float* halfExten
|
||||
rdVcopy(ob->orientedBox.center, center);
|
||||
rdVcopy(ob->orientedBox.halfExtents, halfExtents);
|
||||
|
||||
float coshalf= cosf(0.5f*yRadians);
|
||||
float sinhalf = sinf(-0.5f*yRadians);
|
||||
float coshalf= rdMathCosf(0.5f*yRadians);
|
||||
float sinhalf = rdMathSinf(-0.5f*yRadians);
|
||||
ob->orientedBox.rotAux[0] = coshalf*sinhalf;
|
||||
ob->orientedBox.rotAux[1] = coshalf*coshalf - 0.5f;
|
||||
|
||||
|
@ -2063,12 +2063,12 @@ dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const float* orig, const float c
|
||||
const float ics = 1.0f/cs;
|
||||
const float ich = 1.0f/ch;
|
||||
|
||||
int minx = (int)floorf((bmin[0]-orig[0])*ics);
|
||||
int miny = (int)floorf((bmin[1]-orig[1])*ics);
|
||||
int minz = (int)floorf((bmin[2]-orig[2])*ich);
|
||||
int maxx = (int)floorf((bmax[0]-orig[0])*ics);
|
||||
int maxy = (int)floorf((bmax[1]-orig[1])*ics);
|
||||
int maxz = (int)floorf((bmax[2]-orig[2])*ich);
|
||||
int minx = (int)rdMathFloorf((bmin[0]-orig[0])*ics);
|
||||
int miny = (int)rdMathFloorf((bmin[1]-orig[1])*ics);
|
||||
int minz = (int)rdMathFloorf((bmin[2]-orig[2])*ich);
|
||||
int maxx = (int)rdMathFloorf((bmax[0]-orig[0])*ics);
|
||||
int maxy = (int)rdMathFloorf((bmax[1]-orig[1])*ics);
|
||||
int maxz = (int)rdMathFloorf((bmax[2]-orig[2])*ich);
|
||||
|
||||
if (maxx < 0) return DT_SUCCESS;
|
||||
if (minx >= w) return DT_SUCCESS;
|
||||
@ -2106,12 +2106,12 @@ dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const float* orig, const float c
|
||||
float cy = (center[1] - orig[1])*ics;
|
||||
|
||||
float maxr = 1.41f*rdMax(halfExtents[0], halfExtents[1]);
|
||||
int minx = (int)floorf(cx - maxr*ics);
|
||||
int maxx = (int)floorf(cx + maxr*ics);
|
||||
int miny = (int)floorf(cy - maxr*ics);
|
||||
int maxy = (int)floorf(cy + maxr*ics);
|
||||
int minz = (int)floorf((center[2]-halfExtents[2]-orig[2])*ich);
|
||||
int maxz = (int)floorf((center[2]+halfExtents[2]-orig[2])*ich);
|
||||
int minx = (int)rdMathFloorf(cx - maxr*ics);
|
||||
int maxx = (int)rdMathFloorf(cx + maxr*ics);
|
||||
int miny = (int)rdMathFloorf(cy - maxr*ics);
|
||||
int maxy = (int)rdMathFloorf(cy + maxr*ics);
|
||||
int minz = (int)rdMathFloorf((center[2]-halfExtents[2]-orig[2])*ich);
|
||||
int maxz = (int)rdMathFloorf((center[2]+halfExtents[2]-orig[2])*ich);
|
||||
|
||||
if (maxx < 0) return DT_SUCCESS;
|
||||
if (minx >= w) return DT_SUCCESS;
|
||||
|
@ -331,7 +331,7 @@ void rcMarkWalkableTriangles(rcContext* context, const float walkableSlopeAngle,
|
||||
rdIgnoreUnused(context);
|
||||
rdIgnoreUnused(numVerts);
|
||||
|
||||
const float walkableThr = cosf(walkableSlopeAngle / 180.0f * RD_PI);
|
||||
const float walkableThr = rdMathCosf(walkableSlopeAngle / 180.0f * RD_PI);
|
||||
|
||||
float norm[3];
|
||||
|
||||
@ -356,7 +356,7 @@ void rcClearUnwalkableTriangles(rcContext* context, const float walkableSlopeAng
|
||||
rdIgnoreUnused(numVerts);
|
||||
|
||||
// The minimum Z value for a face normal of a triangle with a walkable slope.
|
||||
const float walkableLimitZ = cosf(walkableSlopeAngle / 180.0f * RD_PI);
|
||||
const float walkableLimitZ = rdMathCosf(walkableSlopeAngle / 180.0f * RD_PI);
|
||||
|
||||
float faceNormal[3];
|
||||
for (int i = 0; i < numTris; ++i)
|
||||
|
@ -1474,13 +1474,13 @@ bool rcMergePolyMeshes(rcContext* ctx, rcPolyMesh** meshes, const int nmeshes, r
|
||||
{
|
||||
const rcPolyMesh* pmesh = meshes[i];
|
||||
|
||||
const unsigned short ox = (unsigned short)floorf((pmesh->bmin[0]-mesh.bmin[0])/mesh.cs+0.5f);
|
||||
const unsigned short oy = (unsigned short)floorf((pmesh->bmin[1]-mesh.bmin[1])/mesh.cs+0.5f);
|
||||
const unsigned short ox = (unsigned short)rdMathFloorf((pmesh->bmin[0]-mesh.bmin[0])/mesh.cs+0.5f);
|
||||
const unsigned short oy = (unsigned short)rdMathFloorf((pmesh->bmin[1]-mesh.bmin[1])/mesh.cs+0.5f);
|
||||
|
||||
bool isMinX = (ox == 0);
|
||||
bool isMinY = (oy == 0);
|
||||
bool isMaxX = ((unsigned short)floorf((mesh.bmax[0] - pmesh->bmax[0]) / mesh.cs + 0.5f)) == 0;
|
||||
bool isMaxY = ((unsigned short)floorf((mesh.bmax[1] - pmesh->bmax[1]) / mesh.cs + 0.5f)) == 0;
|
||||
bool isMaxX = ((unsigned short)rdMathFloorf((mesh.bmax[0] - pmesh->bmax[0]) / mesh.cs + 0.5f)) == 0;
|
||||
bool isMaxY = ((unsigned short)rdMathFloorf((mesh.bmax[1] - pmesh->bmax[1]) / mesh.cs + 0.5f)) == 0;
|
||||
bool isOnBorder = (isMinX || isMinY || isMaxX || isMaxY);
|
||||
|
||||
for (int j = 0; j < pmesh->nverts; ++j)
|
||||
|
@ -46,7 +46,7 @@ inline float vdistSq2(const float* p, const float* q)
|
||||
|
||||
inline float vdist2(const float* p, const float* q)
|
||||
{
|
||||
return sqrtf(vdistSq2(p,q));
|
||||
return rdMathSqrtf(vdistSq2(p,q));
|
||||
}
|
||||
|
||||
inline float vcross2(const float* p1, const float* p2, const float* p3)
|
||||
@ -69,7 +69,7 @@ static bool circumCircle(const float* p1, const float* p2, const float* p3,
|
||||
rdVsub(v3, p3,p1);
|
||||
|
||||
const float cp = vcross2(v1, v2, v3);
|
||||
if (fabsf(cp) > EPS)
|
||||
if (rdMathFabsf(cp) > EPS)
|
||||
{
|
||||
const float v1Sq = vdot2(v1,v1);
|
||||
const float v2Sq = vdot2(v2,v2);
|
||||
@ -110,7 +110,7 @@ static float distPtTri(const float* p, const float* a, const float* b, const flo
|
||||
if (u >= -EPS && v >= -EPS && (u+v) <= 1+EPS)
|
||||
{
|
||||
const float z = a[2] + v0[2]*u + v1[2]*v;
|
||||
return fabsf(z-p[2]);
|
||||
return rdMathFabsf(z-p[2]);
|
||||
}
|
||||
return FLT_MAX;
|
||||
}
|
||||
@ -198,8 +198,8 @@ static unsigned short getHeight(const float fx, const float fy, const float fz,
|
||||
const float /*cs*/, const float ics, const float ch,
|
||||
const int radius, const rcHeightPatch& hp)
|
||||
{
|
||||
int ix = (int)floorf(fx*ics + 0.01f);
|
||||
int iy = (int)floorf(fy*ics + 0.01f);
|
||||
int ix = (int)rdMathFloorf(fx*ics + 0.01f);
|
||||
int iy = (int)rdMathFloorf(fy*ics + 0.01f);
|
||||
ix = rdClamp(ix-hp.xmin, 0, hp.width - 1);
|
||||
iy = rdClamp(iy-hp.ymin, 0, hp.height - 1);
|
||||
unsigned short h = hp.data[ix+iy*hp.width];
|
||||
@ -226,7 +226,7 @@ static unsigned short getHeight(const float fx, const float fy, const float fz,
|
||||
const unsigned short nh = hp.data[nx + ny*hp.width];
|
||||
if (nh != RC_UNSET_HEIGHT)
|
||||
{
|
||||
const float d = fabsf(nh*ch - fz);
|
||||
const float d = rdMathFabsf(nh*ch - fz);
|
||||
if (d < dmin)
|
||||
{
|
||||
h = nh;
|
||||
@ -274,7 +274,7 @@ static unsigned short getHeight(const float fx, const float fy, const float fz,
|
||||
|
||||
// No height found, return a reasonable fall back height.
|
||||
if (h == RC_UNSET_HEIGHT)
|
||||
h = (unsigned short)floorf(fz/ch);
|
||||
h = (unsigned short)rdMathFloorf(fz/ch);
|
||||
|
||||
return h;
|
||||
}
|
||||
@ -811,7 +811,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
|
||||
bool swapped = false;
|
||||
// Make sure the segments are always handled in same order
|
||||
// using lexological sort or else there will be seams.
|
||||
if (fabsf(vj[0]-vi[0]) < 1e-6f)
|
||||
if (rdMathFabsf(vj[0]-vi[0]) < 1e-6f)
|
||||
{
|
||||
if (vj[1] > vi[1])
|
||||
{
|
||||
@ -831,8 +831,8 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
|
||||
float dx = vi[0] - vj[0];
|
||||
float dy = vi[1] - vj[1];
|
||||
float dz = vi[2] - vj[2];
|
||||
float d = sqrtf(dx*dx + dy*dy);
|
||||
int nn = 1 + (int)floorf(d/sampleDist);
|
||||
float d = rdMathSqrtf(dx*dx + dy*dy);
|
||||
int nn = 1 + (int)rdMathFloorf(d/sampleDist);
|
||||
if (nn >= MAX_VERTS_PER_EDGE) nn = MAX_VERTS_PER_EDGE-1;
|
||||
if (nverts+nn >= MAX_VERTS)
|
||||
nn = MAX_VERTS-1-nverts;
|
||||
@ -937,10 +937,10 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
|
||||
rdVmin(bmin, &in[i*3]);
|
||||
rdVmax(bmax, &in[i*3]);
|
||||
}
|
||||
int x0 = (int)floorf(bmin[0]/sampleDist);
|
||||
int x1 = (int)ceilf(bmax[0]/sampleDist);
|
||||
int y0 = (int)floorf(bmin[1]/sampleDist);
|
||||
int y1 = (int)ceilf(bmax[1]/sampleDist);
|
||||
int x0 = (int)rdMathFloorf(bmin[0]/sampleDist);
|
||||
int x1 = (int)rdMathCeilf(bmax[0]/sampleDist);
|
||||
int y0 = (int)rdMathFloorf(bmin[1]/sampleDist);
|
||||
int y1 = (int)rdMathCeilf(bmax[1]/sampleDist);
|
||||
samples.clear();
|
||||
for (int y = y0; y < y1; ++y)
|
||||
{
|
||||
@ -1299,7 +1299,7 @@ bool rcBuildPolyMeshDetail(rcContext* ctx, const rcPolyMesh& mesh, const rcCompa
|
||||
const float ch = mesh.ch;
|
||||
const float* orig = mesh.bmin;
|
||||
const int borderSize = mesh.borderSize;
|
||||
const int heightSearchRadius = rdMax(1, (int)ceilf(mesh.maxEdgeError));
|
||||
const int heightSearchRadius = rdMax(1, (int)rdMathCeilf(mesh.maxEdgeError));
|
||||
|
||||
rdIntArray edges(64);
|
||||
rdIntArray tris(512);
|
||||
|
@ -440,8 +440,8 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
|
||||
}
|
||||
|
||||
// Snap the span to the heightfield height grid.
|
||||
unsigned short spanMinCellIndex = (unsigned short)rdClamp((int)floorf(spanMin * inverseCellHeight), 0, RC_SPAN_MAX_HEIGHT);
|
||||
unsigned short spanMaxCellIndex = (unsigned short)rdClamp((int)ceilf(spanMax * inverseCellHeight), (int)spanMinCellIndex + 1, RC_SPAN_MAX_HEIGHT);
|
||||
unsigned short spanMinCellIndex = (unsigned short)rdClamp((int)rdMathFloorf(spanMin * inverseCellHeight), 0, RC_SPAN_MAX_HEIGHT);
|
||||
unsigned short spanMaxCellIndex = (unsigned short)rdClamp((int)rdMathCeilf(spanMax * inverseCellHeight), (int)spanMinCellIndex + 1, RC_SPAN_MAX_HEIGHT);
|
||||
|
||||
if (!addSpan(hf, x, y, spanMinCellIndex, spanMaxCellIndex, areaID, flagMergeThreshold))
|
||||
{
|
||||
|
@ -129,7 +129,7 @@ bool rdIntersectSegmentPoly2D(const float* p0, const float* p1,
|
||||
rdVsub(diff, p0, &verts[j*3]);
|
||||
const float n = rdVperp2D(edge, diff);
|
||||
const float d = rdVperp2D(dir, edge);
|
||||
if (fabsf(d) < EPS)
|
||||
if (rdMathFabsf(d) < EPS)
|
||||
{
|
||||
// S is nearly parallel to this edge
|
||||
if (n < 0)
|
||||
@ -212,7 +212,7 @@ bool rdClosestHeightPointTriangle(const float* p, const float* a, const float* b
|
||||
|
||||
// Compute scaled barycentric coordinates
|
||||
float denom = v0[0] * v1[1] - v0[1] * v1[0];
|
||||
if (fabsf(denom) < EPS)
|
||||
if (rdMathFabsf(denom) < EPS)
|
||||
return false;
|
||||
|
||||
float u = v1[1] * v2[0] - v1[0] * v2[1];
|
||||
@ -379,7 +379,7 @@ bool rdIntersectSegSeg2D(const float* ap, const float* aq,
|
||||
rdVsub(v,bq,bp);
|
||||
rdVsub(w,ap,bp);
|
||||
float d = vperpXY(u,v);
|
||||
if (fabsf(d) < 1e-6f) return false;
|
||||
if (rdMathFabsf(d) < 1e-6f) return false;
|
||||
s = vperpXY(v,w) / d;
|
||||
t = vperpXY(u,w) / d;
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user