Now calculating the velocity for the listener correctly.
This commit is contained in:
@@ -41,7 +41,7 @@ public:
|
||||
SoundSystem(World* world, EventBroker* eventBroker, bool editorMode);
|
||||
~SoundSystem();
|
||||
// Update emitters / listener
|
||||
void Update();
|
||||
void Update(double dt);
|
||||
private:
|
||||
// Help functions for working with OpenaAL
|
||||
void setListenerPos(glm::vec3 pos) { alListener3f(AL_POSITION, pos.x, pos.y, pos.z); };
|
||||
@@ -55,10 +55,10 @@ private:
|
||||
|
||||
// Logic
|
||||
void initOpenAL();
|
||||
void updateEmitters();
|
||||
void updateListener();
|
||||
void updateEmitters(double dt);
|
||||
void updateListener(double dt);
|
||||
void deleteInactiveEmitters();
|
||||
void addNewEmitters();
|
||||
void addNewEmitters(double dt);
|
||||
Source* createSource(std::string filePath);
|
||||
void playSound(Source* source);
|
||||
void stopSound(Source* source);
|
||||
|
||||
@@ -47,13 +47,13 @@ void SoundSystem::stopEmitters()
|
||||
}
|
||||
}
|
||||
|
||||
void SoundSystem::Update()
|
||||
void SoundSystem::Update(double dt)
|
||||
{
|
||||
m_EventBroker->Process<SoundSystem>();
|
||||
addNewEmitters(); // can be optimized with "EEntityCreated"
|
||||
addNewEmitters(dt); // can be optimized with "EEntityCreated"
|
||||
deleteInactiveEmitters(); // can be optimized with "EEntityDeleted"
|
||||
updateEmitters();
|
||||
updateListener();
|
||||
updateEmitters( dt);
|
||||
updateListener( dt);
|
||||
}
|
||||
|
||||
void SoundSystem::deleteInactiveEmitters()
|
||||
@@ -85,7 +85,7 @@ void SoundSystem::deleteInactiveEmitters()
|
||||
}
|
||||
}
|
||||
|
||||
void SoundSystem::addNewEmitters()
|
||||
void SoundSystem::addNewEmitters(double dt)
|
||||
{
|
||||
auto emitterComponents = m_World->GetComponents("SoundEmitter");
|
||||
if (emitterComponents == nullptr) {
|
||||
@@ -102,7 +102,7 @@ void SoundSystem::addNewEmitters()
|
||||
}
|
||||
}
|
||||
|
||||
void SoundSystem::updateEmitters()
|
||||
void SoundSystem::updateEmitters(double dt)
|
||||
{
|
||||
std::unordered_map<EntityID, Source*>::iterator it;
|
||||
for (it = m_Sources.begin(); it != m_Sources.end(); it++) {
|
||||
@@ -133,9 +133,8 @@ void SoundSystem::updateEmitters()
|
||||
}
|
||||
}
|
||||
|
||||
void SoundSystem::updateListener()
|
||||
void SoundSystem::updateListener(double dt)
|
||||
{
|
||||
int testremove = 0;
|
||||
// Should only be one listener.
|
||||
auto listenerComponents = m_World->GetComponents("Listener");
|
||||
if (listenerComponents == nullptr) {
|
||||
@@ -146,14 +145,10 @@ void SoundSystem::updateListener()
|
||||
glm::vec3 previousPos;
|
||||
alGetListener3f(AL_POSITION, &previousPos.x, &previousPos.y, &previousPos.z); // Get previous pos
|
||||
glm::vec3 nextPos = Transform::AbsolutePosition(m_World, listener); // Get next (current) pos
|
||||
glm::vec3 velocity = nextPos - previousPos; // Calculate velocity
|
||||
glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt; // Calculate velocity
|
||||
setListenerPos(nextPos);
|
||||
//setListenerVel(velocity);
|
||||
setListenerVel(velocity);
|
||||
setListenerOri(glm::eulerAngles(Transform::AbsoluteOrientation(m_World, listener)));
|
||||
testremove++;
|
||||
}
|
||||
if (testremove > 1) {
|
||||
testremove = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ void Game::Tick()
|
||||
debugTick(dt);
|
||||
m_Renderer->Update(dt);
|
||||
m_EventBroker->Process<Client>();
|
||||
m_SoundSystem->Update();
|
||||
m_SoundSystem->Update(dt);
|
||||
GLERROR("Game::Tick m_RenderQueueFactory->Update");
|
||||
m_Renderer->Draw(*m_RenderFrame);
|
||||
GLERROR("Game::Tick m_Renderer->Draw");
|
||||
|
||||
Reference in New Issue
Block a user