diff --git a/Detour/Include/DetourCommon.h b/Detour/Include/DetourCommon.h index 0888614..2afba0d 100644 --- a/Detour/Include/DetourCommon.h +++ b/Detour/Include/DetourCommon.h @@ -19,6 +19,8 @@ #ifndef DETOURCOMMON_H #define DETOURCOMMON_H +#include "DetourMath.h" + /** @defgroup detour Detour @@ -71,11 +73,6 @@ template inline T dtSqr(T a) { return a*a; } /// @return The value, clamped to the specified range. template inline T dtClamp(T v, T mn, T mx) { return v < mn ? mn : (v > mx ? mx : v); } -/// Returns the square root of the value. -/// @param[in] x The value. -/// @return The square root of the vlaue. -float dtSqrt(float x); - /// @} /// @name Vector helper functions. /// @{ @@ -202,7 +199,7 @@ inline void dtVcopy(float* dest, const float* a) /// @return The scalar length of the vector. inline float dtVlen(const float* v) { - return dtSqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); + return dtMathSqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); } /// Derives the square of the scalar length of the vector. (len * len) @@ -222,7 +219,7 @@ inline float dtVdist(const float* v1, const float* v2) const float dx = v2[0] - v1[0]; const float dy = v2[1] - v1[1]; const float dz = v2[2] - v1[2]; - return dtSqrt(dx*dx + dy*dy + dz*dz); + return dtMathSqrtf(dx*dx + dy*dy + dz*dz); } /// Returns the square of the distance between two points. @@ -247,7 +244,7 @@ inline float dtVdist2D(const float* v1, const float* v2) { const float dx = v2[0] - v1[0]; const float dz = v2[2] - v1[2]; - return dtSqrt(dx*dx + dz*dz); + return dtMathSqrtf(dx*dx + dz*dz); } /// Derives the square of the distance between the specified points on the xz-plane. @@ -265,7 +262,7 @@ inline float dtVdist2DSqr(const float* v1, const float* v2) /// @param[in,out] v The vector to normalize. [(x, y, z)] inline void dtVnormalize(float* v) { - float d = 1.0f / dtSqrt(dtSqr(v[0]) + dtSqr(v[1]) + dtSqr(v[2])); + float d = 1.0f / dtMathSqrtf(dtSqr(v[0]) + dtSqr(v[1]) + dtSqr(v[2])); v[0] *= d; v[1] *= d; v[2] *= d; diff --git a/Detour/Source/DetourCommon.cpp b/Detour/Source/DetourCommon.cpp index a98d8c8..26fe65c 100644 --- a/Detour/Source/DetourCommon.cpp +++ b/Detour/Source/DetourCommon.cpp @@ -21,11 +21,6 @@ ////////////////////////////////////////////////////////////////////////////////////////// -float dtSqrt(float x) -{ - return dtMathSqrtf(x); -} - void dtClosestPtPointTriangle(float* closest, const float* p, const float* a, const float* b, const float* c) { @@ -360,7 +355,7 @@ void dtRandomPointInConvexPoly(const float* pts, const int npts, float* areas, acc += dacc; } - float v = dtSqrt(t); + float v = dtMathSqrtf(t); const float a = 1 - v; const float b = (1 - u) * v; diff --git a/DetourCrowd/Source/DetourObstacleAvoidance.cpp b/DetourCrowd/Source/DetourObstacleAvoidance.cpp index e28a61a..f098272 100644 --- a/DetourCrowd/Source/DetourObstacleAvoidance.cpp +++ b/DetourCrowd/Source/DetourObstacleAvoidance.cpp @@ -44,7 +44,7 @@ static int sweepCircleCircle(const float* c0, const float r0, const float* v, float d = b*b - a*c; if (d < 0.0f) return 0; // no intersection. a = 1.0f / a; - const float rd = dtSqrt(d); + const float rd = dtMathSqrtf(d); tmin = (b - rd) * a; tmax = (b + rd) * a; return 1; @@ -482,7 +482,7 @@ int dtObstacleAvoidanceQuery::sampleVelocityGrid(const float* pos, const float r // vector normalization that ignores the y-component. inline void dtNormalize2D(float* v) { - float d = dtSqrt(v[0]*v[0]+v[2]*v[2]); + float d = dtMathSqrtf(v[0] * v[0] + v[2] * v[2]); if (d==0) return; d = 1.0f / d; diff --git a/RecastDemo/Source/NavMeshTesterTool.cpp b/RecastDemo/Source/NavMeshTesterTool.cpp index f1cc55f..8547bea 100644 --- a/RecastDemo/Source/NavMeshTesterTool.cpp +++ b/RecastDemo/Source/NavMeshTesterTool.cpp @@ -745,7 +745,7 @@ void NavMeshTesterTool::recalc() // Find movement delta. float delta[3], len; dtVsub(delta, steerPos, iterPos); - len = dtSqrt(dtVdot(delta,delta)); + len = dtMathSqrtf(dtVdot(delta, delta)); // If the steer target is end of path or off-mesh link, do not move past the location. if ((endOfPath || offMeshConnection) && len < STEP_SIZE) len = 1;