diff options
author | 2016-05-27 20:57:02 +0200 | |
---|---|---|
committer | 2016-05-27 20:57:02 +0200 | |
commit | 913861105b76ed923e1b341cc5235792542c5d6b (patch) | |
tree | d8d7d2fe370d4aa3ad1426213fbb381165e9a5e7 /3rdparty/bgfx/examples/common/bounds.cpp | |
parent | 5469ca37600b3d4d241a0af2617f53f65d4adbff (diff) |
Update BGFX and BX (nw)
Diffstat (limited to '3rdparty/bgfx/examples/common/bounds.cpp')
-rw-r--r-- | 3rdparty/bgfx/examples/common/bounds.cpp | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/3rdparty/bgfx/examples/common/bounds.cpp b/3rdparty/bgfx/examples/common/bounds.cpp index 0b2ae4460c9..f8f7113e08b 100644 --- a/3rdparty/bgfx/examples/common/bounds.cpp +++ b/3rdparty/bgfx/examples/common/bounds.cpp @@ -279,32 +279,26 @@ void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _num void calcPlaneUv(const Plane& _plane, float* _udir, float* _vdir) { - const uint8_t axis = - bx::fabsolute(_plane.m_normal[0]) > 0.6f ? 0 - : (bx::fabsolute(_plane.m_normal[1]) > 0.6f ? 1 - : 2 - ); - const uint8_t* index = (uint8_t*)&"\x1\x2\x0\x2\x0\x1"[axis*2]; - const uint8_t idx0 = *(index ); - const uint8_t idx1 = *(index+1); - - _udir[0] = 0.0f; - _udir[1] = 0.0f; - _udir[2] = 0.0f; - _udir[idx0] = 1.0f; - - _vdir[0] = 0.0f; - _vdir[1] = 0.0f; - _vdir[2] = 0.0f; - _vdir[idx1] = 1.0f; - - const float invPlaneAxis = 1.0f / _plane.m_normal[axis]; - - _udir[axis] -= bx::vec3Dot(_udir, _plane.m_normal) * invPlaneAxis; - bx::vec3Norm(_udir, _udir); - - _vdir[axis] -= bx::vec3Dot(_vdir, _plane.m_normal) * invPlaneAxis; - bx::vec3Norm(_vdir, _vdir); + const float nx = _plane.m_normal[0]; + const float ny = _plane.m_normal[1]; + const float nz = _plane.m_normal[2]; + + if (bx::fabsolute(nx) > bx::fabsolute(nz) ) + { + float invLen = 1.0f / bx::fsqrt(nx*nx + nz*nz); + _udir[0] = -nz * invLen; + _udir[1] = 0.0f; + _udir[2] = nx * invLen; + } + else + { + float invLen = 1.0f / bx::fsqrt(ny*ny + nz*nz); + _udir[0] = 0.0f; + _udir[1] = nz * invLen; + _udir[2] = -ny * invLen; + } + + bx::vec3Cross(_vdir, _plane.m_normal, _udir); } void buildFrustumPlanes(Plane* _result, const float* _viewProj) |