Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. //==========================================================================
  2. //
  3. // S_GetRolloff
  4. //
  5. //==========================================================================
  6.  
  7. float S_GetRolloff(FRolloffInfo *rolloff, float distance, bool logarithmic)
  8. {
  9.     if (rolloff == NULL)
  10.     {
  11.         return 0;
  12.     }
  13.  
  14.     if (distance <= rolloff->MinDistance)
  15.     {
  16.         return 1;
  17.     }
  18.     if (rolloff->RolloffType == ROLLOFF_Log)
  19.     { // Logarithmic rolloff has no max distance where it goes silent.
  20.         return rolloff->MinDistance / (rolloff->MinDistance + rolloff->RolloffFactor * (distance - rolloff->MinDistance));
  21.     }
  22.     if (distance >= rolloff->MaxDistance)
  23.     {
  24.         return 0;
  25.     }
  26.  
  27.     float volume = (rolloff->MaxDistance - distance) / (rolloff->MaxDistance - rolloff->MinDistance);
  28.     if (rolloff->RolloffType == ROLLOFF_Custom && S_SoundCurve != NULL)
  29.     {
  30.         volume = S_SoundCurve[int(S_SoundCurveSize * (1 - volume))] / 127.f;
  31.     }
  32.     if (logarithmic)
  33.     {
  34.         if (rolloff->RolloffType == ROLLOFF_Linear)
  35.         {
  36.             return volume;
  37.         }
  38.         else
  39.         {
  40.             return float((powf(10.f, volume) - 1.) / 9.);
  41.         }
  42.     }
  43.     else
  44.     {
  45.         if (rolloff->RolloffType == ROLLOFF_Linear)
  46.         {
  47.             return float(log10(9. * volume + 1.));
  48.         }
  49.         else
  50.         {
  51.             return volume;
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement