added sounds by clicking on button and changed script to compile

This commit is contained in:
Альберт Гадиев 2025-03-01 18:01:24 +06:00
parent 3fa844ddb9
commit bed5ae7a40
4 changed files with 37 additions and 10 deletions

View File

@ -38,6 +38,10 @@ https://github.com/gametutorials/tutorials/blob/master/OpenGL/MD3%20Animation/Ma
linux:
```
g++ Game.cpp main.cpp Math.cpp OpenGlExtensions.cpp Physics.cpp Renderer.cpp ShaderManager.cpp TextureManager.cpp Utils.cpp BoneAnimatedModel.cpp ObjLoader.cpp -o sdl_app -O2 -std=c++14 $(pkg-config --cflags --libs sdl2 gl)
g++ Game.cpp main.cpp Math.cpp OpenGlExtensions.cpp Physics.cpp Renderer.cpp ShaderManager.cpp TextureManager.cpp Utils.cpp BoneAnimatedModel.cpp ObjLoader.cpp cmakeaudioplayer/src/AudioPlayer.cpp TextModel.cpp Inventory.cpp -o sdl_app -O2 -std=c++17 \
-I cmakeaudioplayer/include \
$(pkg-config --cflags --libs sdl2 gl) \
$(pkg-config --cflags --libs vorbis vorbisfile ogg) \
-lopenal
```

View File

@ -33,3 +33,4 @@ target_link_libraries(audioplayer
# Test executable
add_executable(test_audio examples/test_audio.cpp)
target_link_libraries(test_audio PRIVATE audioplayer stdc++fs)
git add ../../sounds

View File

@ -44,22 +44,29 @@ bool AudioPlayer::isOggFile(const std::string& filename) const {
}
std::string AudioPlayer::findFileInSounds(const std::string& filename) {
// Check relative to executable location first (../../sounds)
std::filesystem::path soundsDir = std::filesystem::current_path() / ".." / ".." / "sounds";
// Primary search path - "sounds" directory next to executable
std::filesystem::path soundsDir = std::filesystem::current_path() / "sounds";
// Fallback to ../sounds if not found
std::filesystem::path altSoundsDir = std::filesystem::current_path() / ".." / "sounds";
// Alternative search paths
std::vector<std::filesystem::path> altPaths = {
std::filesystem::current_path() / ".." / "sounds", // One level up
std::filesystem::current_path() / ".." / ".." / "sounds", // Two levels up
"/home/albert/gay-jam/ZeptoLabTest1/sounds" // Absolute path
};
std::cout << "🔍 Searching for \"" << filename << "\" in:\n";
std::cout << " " << soundsDir << "\n";
std::cout << " " << altSoundsDir << "\n";
if (std::filesystem::exists(soundsDir / filename)) {
return (soundsDir / filename).string();
}
if (std::filesystem::exists(altSoundsDir / filename)) {
return (altSoundsDir / filename).string();
// Try alternative paths
for (const auto& path : altPaths) {
std::cout << " " << path << "\n";
if (std::filesystem::exists(path / filename)) {
return (path / filename).string();
}
}
throw std::runtime_error("❌ File not found: " + filename);

View File

@ -18,6 +18,7 @@
#include "TextModel.h"
#include "Inventory.h"
#include "cmakeaudioplayer/include/AudioPlayer.hpp"
#include <memory>
namespace ZL
@ -32,11 +33,11 @@ namespace ZL
Vector4f clipCoords = MultMatrixVector(projectionModelView, inx);
// Перспективное деление
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
float ndcX = clipCoords.v[0] / clipCoords.v[3];
float ndcY = clipCoords.v[1] / clipCoords.v[3];
// Преобразуем NDC в экранные координаты
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NDC <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
screenX = (int)((ndcX + 1.0f) * 0.5f * screenWidth);
//screenY = (int)((1.0f - ndcY) * 0.5f * screenHeight);
screenY = (int)((1.0f + ndcY) * 0.5f * screenHeight);
@ -108,6 +109,9 @@ namespace ZL
VertexRenderStruct coneMeshMutable;
std::vector<ActiveObject> activeObjects;
// Add AudioPlayer instance
std::unique_ptr<AudioPlayer> audioPlayer;
}
static SDL_Window* window = NULL;
@ -397,6 +401,11 @@ namespace ZL
std::cout << "\nAfter removal:\n";
ZL::PrintInventory();
// Initialize audio player
GameObjects::audioPlayer = std::make_unique<AudioPlayer>();
///
}
void render() {
@ -461,6 +470,12 @@ namespace ZL
case SDLK_s:
Env::downPressed = true;
break;
case SDLK_SPACE:
// Play the symphony when space is pressed
if (GameObjects::audioPlayer) {
GameObjects::audioPlayer->playFromSoundsDir("Symphony No.6 (1st movement).ogg");
}
break;
}
}