diff options
author | 2016-03-08 11:44:52 +0100 | |
---|---|---|
committer | 2016-03-08 12:58:10 +0100 | |
commit | 6412c5e0763dc079312cd5c81cb077d0c393b2b4 (patch) | |
tree | ed41c94128216146df63c43cd8a5965897557175 /3rdparty/bgfx/examples/common/bounds.cpp | |
parent | 1f352c6af853e5cb0dc06ea6596be77db953a9fd (diff) |
Update BGFX and BX (nw)
Diffstat (limited to '3rdparty/bgfx/examples/common/bounds.cpp')
-rw-r--r-- | 3rdparty/bgfx/examples/common/bounds.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/3rdparty/bgfx/examples/common/bounds.cpp b/3rdparty/bgfx/examples/common/bounds.cpp index 3937b550567..0b2ae4460c9 100644 --- a/3rdparty/bgfx/examples/common/bounds.cpp +++ b/3rdparty/bgfx/examples/common/bounds.cpp @@ -277,6 +277,36 @@ void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _num _sphere.m_radius = bx::fsqrt(maxDistSq); } +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); +} + void buildFrustumPlanes(Plane* _result, const float* _viewProj) { const float xw = _viewProj[ 3]; |