From fa3188e569be2bebd6a05ada124b7d9ed71008f1 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 27 Sep 2020 22:07:01 -0700 Subject: [PATCH] Harden Listener against NaN as well --- lib/Emitter.cpp | 6 +----- lib/Listener.cpp | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/Emitter.cpp b/lib/Emitter.cpp index 2abc12c..34292fa 100644 --- a/lib/Emitter.cpp +++ b/lib/Emitter.cpp @@ -67,11 +67,7 @@ void Emitter::_update() { /* Calculate attenuation */ float att = _attenuationCurve(dist); att = (m_maxVol - m_minVol) * att + m_minVol; - //if (!std::isnan(att)) { - att = m_attCache.getVolume(att, false); - //} else { - //att = 0.f; - //} + att = m_attCache.getVolume(att, false); if (att > FLT_EPSILON) { /* Apply pan law */ const std::array thisCoefs = m_vox->_panLaw(frontPan, backPan, span); diff --git a/lib/Listener.cpp b/lib/Listener.cpp index c948837..7ecb8b2 100644 --- a/lib/Listener.cpp +++ b/lib/Listener.cpp @@ -12,10 +12,26 @@ static constexpr Vector3f Cross(const Vector3f& a, const Vector3f& b) { void Listener::setVectors(const float* pos, const float* dir, const float* heading, const float* up) { for (int i = 0; i < 3; ++i) { - m_pos[i] = pos[i]; - m_dir[i] = dir[i]; - m_heading[i] = heading[i]; - m_up[i] = up[i]; + if (!std::isnan(pos[i])) { + m_pos[i] = pos[i]; + } else { + m_pos[i] = 0.f; + } + if (!std::isnan(dir[i])) { + m_dir[i] = dir[i]; + } else { + m_dir[i] = 0.f; + } + if (!std::isnan(heading[i])) { + m_heading[i] = heading[i]; + } else { + m_heading[i] = 0.f; + } + if (std::isnan(up[i])) { + m_up[i] = up[i]; + } else { + m_heading[i] = 0.f; + } } m_heading = Normalize(m_heading);