diff options
author | 2023-09-05 17:10:24 +0200 | |
---|---|---|
committer | 2023-09-06 01:10:24 +1000 | |
commit | 1c61ccfe840cdae7a9f92292946a45f3b47e2412 (patch) | |
tree | b56d4b69b96e314abcf56407da44705a602727f1 /3rdparty/bx/src/math.cpp | |
parent | b2c399c61d65063ae95e8387d34b098e9516b1a9 (diff) |
Updated bgfx, bx and bimg to current upstream versions. (#11493)
* Reverted "macOS, iOS: Removed OpenGL/OpenGLES support. (commit 4693983242a698eaafed87faf4ffef1789adc8f9).
* Reverted "Fix macOS build" (commit ce2c2c13eda7d699051f75f598e740a447343a88).
* Reverted "macOS: Fixed deprecated warnings." (commit 10a8cb61f882ebc9bb376ee2341d003880b7037f).
* Added bgfx/README.mame explaining deviations from upstream.
Diffstat (limited to '3rdparty/bx/src/math.cpp')
-rw-r--r-- | 3rdparty/bx/src/math.cpp | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/3rdparty/bx/src/math.cpp b/3rdparty/bx/src/math.cpp index 8975d5bed25..ae9dc4eab61 100644 --- a/3rdparty/bx/src/math.cpp +++ b/3rdparty/bx/src/math.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * Copyright 2011-2023 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bx/blob/master/LICENSE */ @@ -10,7 +10,8 @@ namespace bx { - const float kInfinity = bitsToFloat(UINT32_C(0x7f800000) ); + const float kFloatInfinity = bitsToFloat(kFloatExponentMask); + const double kDoubleInfinity = bitsToDouble(kDoubleExponentMask); namespace { @@ -135,11 +136,11 @@ namespace bx BX_CONST_FUNC float ldexp(float _a, int32_t _b) { const uint32_t ftob = floatToBits(_a); - const uint32_t masked = uint32_and(ftob, UINT32_C(0xff800000) ); + const uint32_t masked = uint32_and(ftob, kFloatSignMask | kFloatExponentMask); const uint32_t expsign0 = uint32_sra(masked, 23); const uint32_t tmp = uint32_iadd(expsign0, _b); const uint32_t expsign1 = uint32_sll(tmp, 23); - const uint32_t mantissa = uint32_and(ftob, UINT32_C(0x007fffff) ); + const uint32_t mantissa = uint32_and(ftob, kFloatMantissaMask); const uint32_t bits = uint32_or(mantissa, expsign1); const float result = bitsToFloat(bits); @@ -149,9 +150,9 @@ namespace bx float frexp(float _a, int32_t* _outExp) { const uint32_t ftob = floatToBits(_a); - const uint32_t masked0 = uint32_and(ftob, UINT32_C(0x7f800000) ); + const uint32_t masked0 = uint32_and(ftob, kFloatExponentMask); const uint32_t exp0 = uint32_srl(masked0, 23); - const uint32_t masked1 = uint32_and(ftob, UINT32_C(0x807fffff) ); + const uint32_t masked1 = uint32_and(ftob, kFloatSignMask | kFloatMantissaMask); const uint32_t bits = uint32_or(masked1, UINT32_C(0x3f000000) ); const float result = bitsToFloat(bits); @@ -242,31 +243,43 @@ namespace bx void mtxLookAt(float* _result, const Vec3& _eye, const Vec3& _at, const Vec3& _up, Handedness::Enum _handedness) { - const Vec3 view = normalize( - Handedness::Right == _handedness - ? sub(_eye, _at) - : sub(_at, _eye) - ); - const Vec3 uxv = cross(_up, view); - const Vec3 right = normalize(uxv); - const Vec3 up = cross(view, right); + const Vec3 eye = Handedness::Left == _handedness ? _eye : neg(_eye); + const Vec3 view = normalize(sub(_at, eye) ); + + Vec3 right = bx::InitNone; + Vec3 up = bx::InitNone; + + const Vec3 uxv = cross(_up, view); + + if (0.0f == dot(uxv, uxv) ) + { + right = { Handedness::Left == _handedness ? -1.0f : 1.0f, 0.0f, 0.0f }; + } + else + { + right = normalize(uxv); + } + + up = cross(view, right); - memSet(_result, 0, sizeof(float)*16); _result[ 0] = right.x; _result[ 1] = up.x; _result[ 2] = view.x; + _result[ 3] = 0.0f; _result[ 4] = right.y; _result[ 5] = up.y; _result[ 6] = view.y; + _result[ 7] = 0.0f; _result[ 8] = right.z; _result[ 9] = up.z; _result[10] = view.z; + _result[11] = 0.0f; - _result[12] = -dot(right, _eye); - _result[13] = -dot(up, _eye); - _result[14] = -dot(view, _eye); + _result[12] = -dot(right, eye); + _result[13] = -dot(up, eye); + _result[14] = -dot(view, eye); _result[15] = 1.0f; } |