mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-25 10:22:33 -05:00
EXAMPLES: Format tweaks
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [audio] example - Mixed audio processing
|
||||
* raylib [audio] example - mixed audio processing
|
||||
*
|
||||
* Example complexity rating: [★★★★] 4/4
|
||||
*
|
||||
|
||||
@ -45,7 +45,7 @@ int main(void)
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateMusicStream(music); // Update music buffer with new stream data
|
||||
|
||||
|
||||
// Restart music playing (stop and play)
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -53,7 +53,7 @@ int main(void)
|
||||
|
||||
float timePlayed = 0.0f; // Time played normalized [0.0f..1.0f]
|
||||
bool pause = false; // Music playing paused
|
||||
|
||||
|
||||
bool enableEffectLPF = false; // Enable effect low-pass-filter
|
||||
bool enableEffectDelay = false; // Enable effect delay (1 second)
|
||||
|
||||
@ -98,7 +98,7 @@ int main(void)
|
||||
if (enableEffectDelay) AttachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
||||
else DetachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
||||
}
|
||||
|
||||
|
||||
// Get normalized time played for current music stream
|
||||
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music);
|
||||
|
||||
@ -119,7 +119,7 @@ int main(void)
|
||||
|
||||
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 230, 20, LIGHTGRAY);
|
||||
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 260, 20, LIGHTGRAY);
|
||||
|
||||
|
||||
DrawText(TextFormat("PRESS F TO TOGGLE LPF EFFECT: %s", enableEffectLPF? "ON" : "OFF"), 200, 320, 20, GRAY);
|
||||
DrawText(TextFormat("PRESS D TO TOGGLE DELAY EFFECT: %s", enableEffectDelay? "ON" : "OFF"), 180, 350, 20, GRAY);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user