diff options
-rw-r--r-- | alc/alu.cpp | 2 | ||||
-rw-r--r-- | common/vecmat.h | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/alc/alu.cpp b/alc/alu.cpp index 0cbfefec..a29c2833 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -1323,7 +1323,7 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex const bool directional{Direction.normalize() > 0.0f}; alu::Vector ToSource{Position[0], Position[1], Position[2], 0.0f}; - const float Distance{ToSource.normalize()}; + const float Distance{ToSource.normalize(props->RefDistance / 1024.0f)}; /* Initial source gain */ GainTriplet DryGain{props->Gain, 1.0f, 1.0f}; diff --git a/common/vecmat.h b/common/vecmat.h index d301cc30..997b535b 100644 --- a/common/vecmat.h +++ b/common/vecmat.h @@ -35,10 +35,11 @@ public: return *this; } - T normalize() + T normalize(T lim = std::numeric_limits<T>::epsilon()) { + lim = std::max(lim, std::numeric_limits<T>::epsilon()); const T length{std::sqrt(mVals[0]*mVals[0] + mVals[1]*mVals[1] + mVals[2]*mVals[2])}; - if(length > std::numeric_limits<T>::epsilon()) + if(length > lim) { T inv_length{T{1}/length}; mVals[0] *= inv_length; |