Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //==========================================================================
- //
- // S_GetRolloff
- //
- //==========================================================================
- float S_GetRolloff(FRolloffInfo *rolloff, float distance, bool logarithmic)
- {
- if (rolloff == NULL)
- {
- return 0;
- }
- if (distance <= rolloff->MinDistance)
- {
- return 1;
- }
- if (rolloff->RolloffType == ROLLOFF_Log)
- { // Logarithmic rolloff has no max distance where it goes silent.
- return rolloff->MinDistance / (rolloff->MinDistance + rolloff->RolloffFactor * (distance - rolloff->MinDistance));
- }
- if (distance >= rolloff->MaxDistance)
- {
- return 0;
- }
- float volume = (rolloff->MaxDistance - distance) / (rolloff->MaxDistance - rolloff->MinDistance);
- if (rolloff->RolloffType == ROLLOFF_Custom && S_SoundCurve != NULL)
- {
- volume = S_SoundCurve[int(S_SoundCurveSize * (1 - volume))] / 127.f;
- }
- if (logarithmic)
- {
- if (rolloff->RolloffType == ROLLOFF_Linear)
- {
- return volume;
- }
- else
- {
- return float((powf(10.f, volume) - 1.) / 9.);
- }
- }
- else
- {
- if (rolloff->RolloffType == ROLLOFF_Linear)
- {
- return float(log10(9. * volume + 1.));
- }
- else
- {
- return volume;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement