audio_sound_positioning - fix SetSoundPosition and panning
This commit is contained in:
parent
8329b93aab
commit
c6b34d2322
1 changed files with 9 additions and 2 deletions
|
|
@ -116,14 +116,21 @@ static void SetSoundPosition(Camera listener, Sound sound, Vector3 position, flo
|
||||||
// Calculate normalized vectors for spatial positioning
|
// Calculate normalized vectors for spatial positioning
|
||||||
Vector3 normalizedDirection = Vector3Normalize(direction);
|
Vector3 normalizedDirection = Vector3Normalize(direction);
|
||||||
Vector3 forward = Vector3Normalize(Vector3Subtract(listener.target, listener.position));
|
Vector3 forward = Vector3Normalize(Vector3Subtract(listener.target, listener.position));
|
||||||
Vector3 right = Vector3Normalize(Vector3CrossProduct(listener.up, forward));
|
Vector3 right = Vector3Normalize(Vector3CrossProduct(forward, listener.up));
|
||||||
|
|
||||||
// Reduce volume for sounds behind the listener
|
// Reduce volume for sounds behind the listener
|
||||||
float dotProduct = Vector3DotProduct(forward, normalizedDirection);
|
float dotProduct = Vector3DotProduct(forward, normalizedDirection);
|
||||||
if (dotProduct < 0.0f) attenuation *= (1.0f + dotProduct*0.5f);
|
if (dotProduct < 0.0f) attenuation *= (1.0f + dotProduct*0.5f);
|
||||||
|
|
||||||
// Set stereo panning based on sound position relative to listener
|
// Set stereo panning based on sound position relative to listener
|
||||||
float pan = 0.5f + 0.5f*Vector3DotProduct(normalizedDirection, right);
|
float pan = 0;
|
||||||
|
if (RAYLIB_VERSION_MAJOR >= 6) {
|
||||||
|
// -1.0 - 1.0
|
||||||
|
pan = Clamp(Vector3DotProduct(normalizedDirection, right), -1.0f, 1.0f);
|
||||||
|
} else {
|
||||||
|
// 0.0 - 1.0
|
||||||
|
pan = 0.5f + 0.5f*Vector3DotProduct(normalizedDirection, right);
|
||||||
|
}
|
||||||
|
|
||||||
// Apply final sound properties
|
// Apply final sound properties
|
||||||
SetSoundVolume(sound, attenuation);
|
SetSoundVolume(sound, attenuation);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue