|
22 | 22 | #endif |
23 | 23 |
|
24 | 24 | #include "renderer.h" |
| 25 | +#include "engine.h" |
25 | 26 |
|
26 | 27 | // OpenAL error checking utility |
27 | 28 | static void CheckOpenALError(const std::string& operation) { |
@@ -537,7 +538,10 @@ void AudioSystem::GenerateSineWavePing(float* buffer, uint32_t sampleCount, uint |
537 | 538 |
|
538 | 539 | } |
539 | 540 |
|
540 | | -bool AudioSystem::Initialize(Renderer* renderer) { |
| 541 | +bool AudioSystem::Initialize(Engine* engine, Renderer* renderer) { |
| 542 | + // Store the engine reference for accessing active camera |
| 543 | + this->engine = engine; |
| 544 | + |
541 | 545 | if (renderer) { |
542 | 546 | // Validate renderer if provided |
543 | 547 | if (!renderer->IsInitialized()) { |
@@ -588,6 +592,24 @@ void AudioSystem::Update(float deltaTime) { |
588 | 592 | return; |
589 | 593 | } |
590 | 594 |
|
| 595 | + // Synchronize HRTF listener position and orientation with active camera |
| 596 | + if (engine) { |
| 597 | + CameraComponent* activeCamera = engine->GetActiveCamera(); |
| 598 | + if (activeCamera) { |
| 599 | + // Get camera position |
| 600 | + glm::vec3 cameraPos = activeCamera->GetPosition(); |
| 601 | + SetListenerPosition(cameraPos.x, cameraPos.y, cameraPos.z); |
| 602 | + |
| 603 | + // Calculate camera forward and up vectors for orientation |
| 604 | + // The camera looks at its target, so forward = normalize(target - position) |
| 605 | + glm::vec3 target = activeCamera->GetTarget(); |
| 606 | + glm::vec3 up = activeCamera->GetUp(); |
| 607 | + glm::vec3 forward = glm::normalize(target - cameraPos); |
| 608 | + |
| 609 | + SetListenerOrientation(forward.x, forward.y, forward.z, up.x, up.y, up.z); |
| 610 | + } |
| 611 | + } |
| 612 | + |
591 | 613 | // Update audio sources and process spatial audio |
592 | 614 | for (auto& source : sources) { |
593 | 615 | if (!source->IsPlaying()) { |
|
0 commit comments