|
@@ -92,125 +92,125 @@ namespace bx
|
|
|
return tmp == UINT64_C(0x7ff0000000000000);
|
|
return tmp == UINT64_C(0x7ff0000000000000);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float fround(float _f)
|
|
|
|
|
|
|
+ inline float round(float _f)
|
|
|
{
|
|
{
|
|
|
- return ffloor(_f + 0.5f);
|
|
|
|
|
|
|
+ return floor(_f + 0.5f);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float fceil(float _a)
|
|
|
|
|
|
|
+ inline float ceil(float _a)
|
|
|
{
|
|
{
|
|
|
- return -ffloor(-_a);
|
|
|
|
|
|
|
+ return -floor(-_a);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float flerp(float _a, float _b, float _t)
|
|
|
|
|
|
|
+ inline float lerp(float _a, float _b, float _t)
|
|
|
{
|
|
{
|
|
|
return _a + (_b - _a) * _t;
|
|
return _a + (_b - _a) * _t;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float fabs(float _a)
|
|
|
|
|
|
|
+ inline float abs(float _a)
|
|
|
{
|
|
{
|
|
|
return _a < 0.0f ? -_a : _a;
|
|
return _a < 0.0f ? -_a : _a;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float fsign(float _a)
|
|
|
|
|
|
|
+ inline float sign(float _a)
|
|
|
{
|
|
{
|
|
|
return _a < 0.0f ? -1.0f : 1.0f;
|
|
return _a < 0.0f ? -1.0f : 1.0f;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float fsq(float _a)
|
|
|
|
|
|
|
+ inline float square(float _a)
|
|
|
{
|
|
{
|
|
|
return _a * _a;
|
|
return _a * _a;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float fexp2(float _a)
|
|
|
|
|
|
|
+ inline float exp2(float _a)
|
|
|
{
|
|
{
|
|
|
- return fpow(2.0f, _a);
|
|
|
|
|
|
|
+ return pow(2.0f, _a);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float flog2(float _a)
|
|
|
|
|
|
|
+ inline float log2(float _a)
|
|
|
{
|
|
{
|
|
|
- return flog(_a) * kInvLogNat2;
|
|
|
|
|
|
|
+ return log(_a) * kInvLogNat2;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float frsqrt(float _a)
|
|
|
|
|
|
|
+ inline float rsqrt(float _a)
|
|
|
{
|
|
{
|
|
|
- return 1.0f/fsqrt(_a);
|
|
|
|
|
|
|
+ return 1.0f/sqrt(_a);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float ftrunc(float _a)
|
|
|
|
|
|
|
+ inline float trunc(float _a)
|
|
|
{
|
|
{
|
|
|
return float(int(_a) );
|
|
return float(int(_a) );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float ffract(float _a)
|
|
|
|
|
|
|
+ inline float fract(float _a)
|
|
|
{
|
|
{
|
|
|
- return _a - ftrunc(_a);
|
|
|
|
|
|
|
+ return _a - trunc(_a);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float fmod(float _a, float _b)
|
|
|
|
|
|
|
+ inline float mod(float _a, float _b)
|
|
|
{
|
|
{
|
|
|
- return _a - _b * ffloor(_a / _b);
|
|
|
|
|
|
|
+ return _a - _b * floor(_a / _b);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline bool fequal(float _a, float _b, float _epsilon)
|
|
|
|
|
|
|
+ inline bool equal(float _a, float _b, float _epsilon)
|
|
|
{
|
|
{
|
|
|
// http://realtimecollisiondetection.net/blog/?p=89
|
|
// http://realtimecollisiondetection.net/blog/?p=89
|
|
|
- const float lhs = fabs(_a - _b);
|
|
|
|
|
- const float rhs = _epsilon * max(1.0f, fabs(_a), fabs(_b) );
|
|
|
|
|
|
|
+ const float lhs = abs(_a - _b);
|
|
|
|
|
+ const float rhs = _epsilon * max(1.0f, abs(_a), abs(_b) );
|
|
|
return lhs <= rhs;
|
|
return lhs <= rhs;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline bool fequal(const float* _a, const float* _b, uint32_t _num, float _epsilon)
|
|
|
|
|
|
|
+ inline bool equal(const float* _a, const float* _b, uint32_t _num, float _epsilon)
|
|
|
{
|
|
{
|
|
|
- bool equal = fequal(_a[0], _b[0], _epsilon);
|
|
|
|
|
- for (uint32_t ii = 1; equal && ii < _num; ++ii)
|
|
|
|
|
|
|
+ bool result = equal(_a[0], _b[0], _epsilon);
|
|
|
|
|
+ for (uint32_t ii = 1; result && ii < _num; ++ii)
|
|
|
{
|
|
{
|
|
|
- equal = fequal(_a[ii], _b[ii], _epsilon);
|
|
|
|
|
|
|
+ result = equal(_a[ii], _b[ii], _epsilon);
|
|
|
}
|
|
}
|
|
|
- return equal;
|
|
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float fwrap(float _a, float _wrap)
|
|
|
|
|
|
|
+ inline float wrap(float _a, float _wrap)
|
|
|
{
|
|
{
|
|
|
- const float mod = fmod(_a, _wrap);
|
|
|
|
|
- const float result = mod < 0.0f ? _wrap + mod : mod;
|
|
|
|
|
|
|
+ const float tmp0 = mod(_a, _wrap);
|
|
|
|
|
+ const float result = tmp0 < 0.0f ? _wrap + tmp0 : tmp0;
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float fstep(float _edge, float _a)
|
|
|
|
|
|
|
+ inline float step(float _edge, float _a)
|
|
|
{
|
|
{
|
|
|
return _a < _edge ? 0.0f : 1.0f;
|
|
return _a < _edge ? 0.0f : 1.0f;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float fpulse(float _a, float _start, float _end)
|
|
|
|
|
|
|
+ inline float pulse(float _a, float _start, float _end)
|
|
|
{
|
|
{
|
|
|
- return fstep(_a, _start) - fstep(_a, _end);
|
|
|
|
|
|
|
+ return step(_a, _start) - step(_a, _end);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float fsmoothstep(float _a)
|
|
|
|
|
|
|
+ inline float smoothStep(float _a)
|
|
|
{
|
|
{
|
|
|
- return fsq(_a)*(3.0f - 2.0f*_a);
|
|
|
|
|
|
|
+ return square(_a)*(3.0f - 2.0f*_a);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float fbias(float _time, float _bias)
|
|
|
|
|
|
|
+ inline float bias(float _time, float _bias)
|
|
|
{
|
|
{
|
|
|
return _time / ( ( (1.0f/_bias - 2.0f)*(1.0f - _time) ) + 1.0f);
|
|
return _time / ( ( (1.0f/_bias - 2.0f)*(1.0f - _time) ) + 1.0f);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inline float fgain(float _time, float _gain)
|
|
|
|
|
|
|
+ inline float gain(float _time, float _gain)
|
|
|
{
|
|
{
|
|
|
if (_time < 0.5f)
|
|
if (_time < 0.5f)
|
|
|
{
|
|
{
|
|
|
- return fbias(_time * 2.0f, _gain) * 0.5f;
|
|
|
|
|
|
|
+ return bias(_time * 2.0f, _gain) * 0.5f;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return fbias(_time * 2.0f - 1.0f, 1.0f - _gain) * 0.5f + 0.5f;
|
|
|
|
|
|
|
+ return bias(_time * 2.0f - 1.0f, 1.0f - _gain) * 0.5f + 0.5f;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline float angleDiff(float _a, float _b)
|
|
inline float angleDiff(float _a, float _b)
|
|
|
{
|
|
{
|
|
|
- const float dist = fwrap(_b - _a, kPi2);
|
|
|
|
|
- return fwrap(dist*2.0f, kPi2) - dist;
|
|
|
|
|
|
|
+ const float dist = wrap(_b - _a, kPi2);
|
|
|
|
|
+ return wrap(dist*2.0f, kPi2) - dist;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline float angleLerp(float _a, float _b, float _t)
|
|
inline float angleLerp(float _a, float _b, float _t)
|
|
@@ -227,9 +227,9 @@ namespace bx
|
|
|
|
|
|
|
|
inline void vec3Abs(float* _result, const float* _a)
|
|
inline void vec3Abs(float* _result, const float* _a)
|
|
|
{
|
|
{
|
|
|
- _result[0] = fabs(_a[0]);
|
|
|
|
|
- _result[1] = fabs(_a[1]);
|
|
|
|
|
- _result[2] = fabs(_a[2]);
|
|
|
|
|
|
|
+ _result[0] = abs(_a[0]);
|
|
|
|
|
+ _result[1] = abs(_a[1]);
|
|
|
|
|
+ _result[2] = abs(_a[2]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline void vec3Neg(float* _result, const float* _a)
|
|
inline void vec3Neg(float* _result, const float* _a)
|
|
@@ -295,21 +295,21 @@ namespace bx
|
|
|
|
|
|
|
|
inline float vec3Length(const float* _a)
|
|
inline float vec3Length(const float* _a)
|
|
|
{
|
|
{
|
|
|
- return fsqrt(vec3Dot(_a, _a) );
|
|
|
|
|
|
|
+ return sqrt(vec3Dot(_a, _a) );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline void vec3Lerp(float* _result, const float* _a, const float* _b, float _t)
|
|
inline void vec3Lerp(float* _result, const float* _a, const float* _b, float _t)
|
|
|
{
|
|
{
|
|
|
- _result[0] = flerp(_a[0], _b[0], _t);
|
|
|
|
|
- _result[1] = flerp(_a[1], _b[1], _t);
|
|
|
|
|
- _result[2] = flerp(_a[2], _b[2], _t);
|
|
|
|
|
|
|
+ _result[0] = lerp(_a[0], _b[0], _t);
|
|
|
|
|
+ _result[1] = lerp(_a[1], _b[1], _t);
|
|
|
|
|
+ _result[2] = lerp(_a[2], _b[2], _t);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline void vec3Lerp(float* _result, const float* _a, const float* _b, const float* _c)
|
|
inline void vec3Lerp(float* _result, const float* _a, const float* _b, const float* _c)
|
|
|
{
|
|
{
|
|
|
- _result[0] = flerp(_a[0], _b[0], _c[0]);
|
|
|
|
|
- _result[1] = flerp(_a[1], _b[1], _c[1]);
|
|
|
|
|
- _result[2] = flerp(_a[2], _b[2], _c[2]);
|
|
|
|
|
|
|
+ _result[0] = lerp(_a[0], _b[0], _c[0]);
|
|
|
|
|
+ _result[1] = lerp(_a[1], _b[1], _c[1]);
|
|
|
|
|
+ _result[2] = lerp(_a[2], _b[2], _c[2]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline float vec3Norm(float* _result, const float* _a)
|
|
inline float vec3Norm(float* _result, const float* _a)
|
|
@@ -349,60 +349,60 @@ namespace bx
|
|
|
const float ny = _n[1];
|
|
const float ny = _n[1];
|
|
|
const float nz = _n[2];
|
|
const float nz = _n[2];
|
|
|
|
|
|
|
|
- if (bx::fabs(nx) > bx::fabs(nz) )
|
|
|
|
|
|
|
+ if (abs(nx) > abs(nz) )
|
|
|
{
|
|
{
|
|
|
- float invLen = 1.0f / bx::fsqrt(nx*nx + nz*nz);
|
|
|
|
|
|
|
+ float invLen = 1.0f / sqrt(nx*nx + nz*nz);
|
|
|
_t[0] = -nz * invLen;
|
|
_t[0] = -nz * invLen;
|
|
|
_t[1] = 0.0f;
|
|
_t[1] = 0.0f;
|
|
|
_t[2] = nx * invLen;
|
|
_t[2] = nx * invLen;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- float invLen = 1.0f / bx::fsqrt(ny*ny + nz*nz);
|
|
|
|
|
|
|
+ float invLen = 1.0f / sqrt(ny*ny + nz*nz);
|
|
|
_t[0] = 0.0f;
|
|
_t[0] = 0.0f;
|
|
|
_t[1] = nz * invLen;
|
|
_t[1] = nz * invLen;
|
|
|
_t[2] = -ny * invLen;
|
|
_t[2] = -ny * invLen;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- bx::vec3Cross(_b, _n, _t);
|
|
|
|
|
|
|
+ vec3Cross(_b, _n, _t);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline void vec3TangentFrame(const float* _n, float* _t, float* _b, float _angle)
|
|
inline void vec3TangentFrame(const float* _n, float* _t, float* _b, float _angle)
|
|
|
{
|
|
{
|
|
|
vec3TangentFrame(_n, _t, _b);
|
|
vec3TangentFrame(_n, _t, _b);
|
|
|
|
|
|
|
|
- const float sa = fsin(_angle);
|
|
|
|
|
- const float ca = fcos(_angle);
|
|
|
|
|
|
|
+ const float sa = sin(_angle);
|
|
|
|
|
+ const float ca = cos(_angle);
|
|
|
|
|
|
|
|
_t[0] = -sa * _b[0] + ca * _t[0];
|
|
_t[0] = -sa * _b[0] + ca * _t[0];
|
|
|
_t[1] = -sa * _b[1] + ca * _t[1];
|
|
_t[1] = -sa * _b[1] + ca * _t[1];
|
|
|
_t[2] = -sa * _b[2] + ca * _t[2];
|
|
_t[2] = -sa * _b[2] + ca * _t[2];
|
|
|
|
|
|
|
|
- bx::vec3Cross(_b, _n, _t);
|
|
|
|
|
|
|
+ vec3Cross(_b, _n, _t);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline void vec3FromLatLong(float* _vec, float _u, float _v)
|
|
inline void vec3FromLatLong(float* _vec, float _u, float _v)
|
|
|
{
|
|
{
|
|
|
- const float phi = _u * bx::kPi2;
|
|
|
|
|
- const float theta = _v * bx::kPi;
|
|
|
|
|
|
|
+ const float phi = _u * kPi2;
|
|
|
|
|
+ const float theta = _v * kPi;
|
|
|
|
|
|
|
|
- const float st = bx::fsin(theta);
|
|
|
|
|
- const float sp = bx::fsin(phi);
|
|
|
|
|
- const float ct = bx::fcos(theta);
|
|
|
|
|
- const float cp = bx::fcos(phi);
|
|
|
|
|
|
|
+ const float st = sin(theta);
|
|
|
|
|
+ const float sp = sin(phi);
|
|
|
|
|
+ const float ct = cos(theta);
|
|
|
|
|
+ const float cp = cos(phi);
|
|
|
|
|
|
|
|
_vec[0] = -st*sp;
|
|
_vec[0] = -st*sp;
|
|
|
- _vec[1] = ct;
|
|
|
|
|
|
|
+ _vec[1] = ct;
|
|
|
_vec[2] = -st*cp;
|
|
_vec[2] = -st*cp;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline void vec3ToLatLong(float* _u, float* _v, const float* _vec)
|
|
inline void vec3ToLatLong(float* _u, float* _v, const float* _vec)
|
|
|
{
|
|
{
|
|
|
- const float phi = bx::fatan2(_vec[0], _vec[2]);
|
|
|
|
|
- const float theta = bx::facos(_vec[1]);
|
|
|
|
|
|
|
+ const float phi = atan2(_vec[0], _vec[2]);
|
|
|
|
|
+ const float theta = acos(_vec[1]);
|
|
|
|
|
|
|
|
- *_u = (bx::kPi + phi)*bx::kInvPi*0.5f;
|
|
|
|
|
- *_v = theta*bx::kInvPi;
|
|
|
|
|
|
|
+ *_u = (kPi + phi)*kInvPi*0.5f;
|
|
|
|
|
+ *_v = theta*kInvPi;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline void quatIdentity(float* _result)
|
|
inline void quatIdentity(float* _result)
|
|
@@ -478,7 +478,7 @@ namespace bx
|
|
|
const float norm = quatDot(_quat, _quat);
|
|
const float norm = quatDot(_quat, _quat);
|
|
|
if (0.0f < norm)
|
|
if (0.0f < norm)
|
|
|
{
|
|
{
|
|
|
- const float invNorm = 1.0f / fsqrt(norm);
|
|
|
|
|
|
|
+ const float invNorm = 1.0f / sqrt(norm);
|
|
|
_result[0] = _quat[0] * invNorm;
|
|
_result[0] = _quat[0] * invNorm;
|
|
|
_result[1] = _quat[1] * invNorm;
|
|
_result[1] = _quat[1] * invNorm;
|
|
|
_result[2] = _quat[2] * invNorm;
|
|
_result[2] = _quat[2] * invNorm;
|
|
@@ -501,16 +501,16 @@ namespace bx
|
|
|
const float zz = z * z;
|
|
const float zz = z * z;
|
|
|
|
|
|
|
|
const float xx = x * x;
|
|
const float xx = x * x;
|
|
|
- _result[0] = fatan2(2.0f * (x * w - y * z), 1.0f - 2.0f * (xx + zz) );
|
|
|
|
|
- _result[1] = fatan2(2.0f * (y * w + x * z), 1.0f - 2.0f * (yy + zz) );
|
|
|
|
|
- _result[2] = fasin (2.0f * (x * y + z * w) );
|
|
|
|
|
|
|
+ _result[0] = atan2(2.0f * (x * w - y * z), 1.0f - 2.0f * (xx + zz) );
|
|
|
|
|
+ _result[1] = atan2(2.0f * (y * w + x * z), 1.0f - 2.0f * (yy + zz) );
|
|
|
|
|
+ _result[2] = asin (2.0f * (x * y + z * w) );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline void quatRotateAxis(float* _result, const float* _axis, float _angle)
|
|
inline void quatRotateAxis(float* _result, const float* _axis, float _angle)
|
|
|
{
|
|
{
|
|
|
const float ha = _angle * 0.5f;
|
|
const float ha = _angle * 0.5f;
|
|
|
- const float ca = fcos(ha);
|
|
|
|
|
- const float sa = fsin(ha);
|
|
|
|
|
|
|
+ const float ca = cos(ha);
|
|
|
|
|
+ const float sa = sin(ha);
|
|
|
_result[0] = _axis[0] * sa;
|
|
_result[0] = _axis[0] * sa;
|
|
|
_result[1] = _axis[1] * sa;
|
|
_result[1] = _axis[1] * sa;
|
|
|
_result[2] = _axis[2] * sa;
|
|
_result[2] = _axis[2] * sa;
|
|
@@ -520,8 +520,8 @@ namespace bx
|
|
|
inline void quatRotateX(float* _result, float _ax)
|
|
inline void quatRotateX(float* _result, float _ax)
|
|
|
{
|
|
{
|
|
|
const float hx = _ax * 0.5f;
|
|
const float hx = _ax * 0.5f;
|
|
|
- const float cx = fcos(hx);
|
|
|
|
|
- const float sx = fsin(hx);
|
|
|
|
|
|
|
+ const float cx = cos(hx);
|
|
|
|
|
+ const float sx = sin(hx);
|
|
|
_result[0] = sx;
|
|
_result[0] = sx;
|
|
|
_result[1] = 0.0f;
|
|
_result[1] = 0.0f;
|
|
|
_result[2] = 0.0f;
|
|
_result[2] = 0.0f;
|
|
@@ -531,8 +531,8 @@ namespace bx
|
|
|
inline void quatRotateY(float* _result, float _ay)
|
|
inline void quatRotateY(float* _result, float _ay)
|
|
|
{
|
|
{
|
|
|
const float hy = _ay * 0.5f;
|
|
const float hy = _ay * 0.5f;
|
|
|
- const float cy = fcos(hy);
|
|
|
|
|
- const float sy = fsin(hy);
|
|
|
|
|
|
|
+ const float cy = cos(hy);
|
|
|
|
|
+ const float sy = sin(hy);
|
|
|
_result[0] = 0.0f;
|
|
_result[0] = 0.0f;
|
|
|
_result[1] = sy;
|
|
_result[1] = sy;
|
|
|
_result[2] = 0.0f;
|
|
_result[2] = 0.0f;
|
|
@@ -542,8 +542,8 @@ namespace bx
|
|
|
inline void quatRotateZ(float* _result, float _az)
|
|
inline void quatRotateZ(float* _result, float _az)
|
|
|
{
|
|
{
|
|
|
const float hz = _az * 0.5f;
|
|
const float hz = _az * 0.5f;
|
|
|
- const float cz = fcos(hz);
|
|
|
|
|
- const float sz = fsin(hz);
|
|
|
|
|
|
|
+ const float cz = cos(hz);
|
|
|
|
|
+ const float sz = sin(hz);
|
|
|
_result[0] = 0.0f;
|
|
_result[0] = 0.0f;
|
|
|
_result[1] = 0.0f;
|
|
_result[1] = 0.0f;
|
|
|
_result[2] = sz;
|
|
_result[2] = sz;
|
|
@@ -712,7 +712,7 @@ namespace bx
|
|
|
float yy = _vec[0] * _mat[ 1] + _vec[1] * _mat[5] + _vec[2] * _mat[ 9] + _mat[13];
|
|
float yy = _vec[0] * _mat[ 1] + _vec[1] * _mat[5] + _vec[2] * _mat[ 9] + _mat[13];
|
|
|
float zz = _vec[0] * _mat[ 2] + _vec[1] * _mat[6] + _vec[2] * _mat[10] + _mat[14];
|
|
float zz = _vec[0] * _mat[ 2] + _vec[1] * _mat[6] + _vec[2] * _mat[10] + _mat[14];
|
|
|
float ww = _vec[0] * _mat[ 3] + _vec[1] * _mat[7] + _vec[2] * _mat[11] + _mat[15];
|
|
float ww = _vec[0] * _mat[ 3] + _vec[1] * _mat[7] + _vec[2] * _mat[11] + _mat[15];
|
|
|
- float invW = fsign(ww)/ww;
|
|
|
|
|
|
|
+ float invW = sign(ww)/ww;
|
|
|
_result[0] = xx*invW;
|
|
_result[0] = xx*invW;
|
|
|
_result[1] = yy*invW;
|
|
_result[1] = yy*invW;
|
|
|
_result[2] = zz*invW;
|
|
_result[2] = zz*invW;
|