mirror of
https://github.com/raysan5/raylib.git
synced 2026-01-31 19:29:18 -05:00
EXAMPLES: Format tweaks
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [audio] example - Playing spatialized 3D sound
|
||||
* raylib [audio] example - spatialized 3D sound
|
||||
*
|
||||
* Example complexity rating: [★★☆☆] 2/4
|
||||
*
|
||||
@ -31,9 +31,9 @@ int main(void)
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - Playing spatialized 3D sound");
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - spatialized 3D sound");
|
||||
|
||||
InitAudioDevice();
|
||||
|
||||
Sound sound = LoadSound("resources/coin.wav");
|
||||
@ -45,9 +45,9 @@ int main(void)
|
||||
.fovy = 60,
|
||||
.projection = CAMERA_PERSPECTIVE
|
||||
};
|
||||
|
||||
|
||||
DisableCursor();
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@ -89,7 +89,7 @@ int main(void)
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadSound(sound);
|
||||
CloseAudioDevice(); // Close audio device
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
@ -100,23 +100,23 @@ static void SetSoundPosition(Camera listener, Sound sound, Vector3 position, flo
|
||||
// Calculate direction vector and distance between listener and sound source
|
||||
Vector3 direction = Vector3Subtract(position, listener.position);
|
||||
float distance = Vector3Length(direction);
|
||||
|
||||
|
||||
// Apply logarithmic distance attenuation and clamp between 0-1
|
||||
float attenuation = 1.0f/(1.0f + (distance/maxDist));
|
||||
attenuation = Clamp(attenuation, 0.0f, 1.0f);
|
||||
|
||||
|
||||
// Calculate normalized vectors for spatial positioning
|
||||
Vector3 normalizedDirection = Vector3Normalize(direction);
|
||||
Vector3 forward = Vector3Normalize(Vector3Subtract(listener.target, listener.position));
|
||||
Vector3 right = Vector3Normalize(Vector3CrossProduct(listener.up, forward));
|
||||
|
||||
|
||||
// Reduce volume for sounds behind the listener
|
||||
float dotProduct = Vector3DotProduct(forward, normalizedDirection);
|
||||
if (dotProduct < 0.0f) attenuation *= (1.0f + dotProduct*0.5f);
|
||||
|
||||
|
||||
// Set stereo panning based on sound position relative to listener
|
||||
float pan = 0.5f + 0.5f*Vector3DotProduct(normalizedDirection, right);
|
||||
|
||||
|
||||
// Apply final sound properties
|
||||
SetSoundVolume(sound, attenuation);
|
||||
SetSoundPan(sound, pan);
|
||||
|
||||
Reference in New Issue
Block a user