From da6e50dc7eb17671664033b871e58fc57c657ba6 Mon Sep 17 00:00:00 2001 From: stiffly Date: Thu, 7 Jan 2016 17:04:43 +0100 Subject: [PATCH] Correct orientation. Need to clean this up. --- include/Engine/Sound/SoundSystem.h | 17 ++++++++++++++++- src/Engine/Sound/SoundSystem.cpp | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/Engine/Sound/SoundSystem.h b/include/Engine/Sound/SoundSystem.h index 0555feb4..de31e216 100644 --- a/include/Engine/Sound/SoundSystem.h +++ b/include/Engine/Sound/SoundSystem.h @@ -4,6 +4,7 @@ #include #include "glm/common.hpp" +#include "glm/gtx/rotate_vector.hpp" #include "OpenAL/al.h" #include "OpenAL/alc.h" @@ -31,7 +32,21 @@ private: glm::vec3 listnerPos() { glm::vec3 pos; alGetListener3f(AL_POSITION, &pos.x, &pos.y, &pos.z); return pos; }; void setListenerVel(glm::vec3 vel) { alListener3f(AL_VELOCITY, vel.x, vel.y, vel.z); }; glm::vec3 listenerVel() { glm::vec3 vel; alGetListener3f(AL_VELOCITY, &vel.x, &vel.y, &vel.z); return vel; }; - void setListenerOri(glm::vec3 ori) { alListener3f(AL_ORIENTATION, ori.x, ori.y, ori.z); }; + void setListenerOri(glm::vec3 ori) + { + glm::vec3 forward = glm::vec3(0.0, 0.0, -1.0); + forward = glm::rotateX(forward, ori.x); + forward = glm::rotateY(forward, ori.y); + forward = glm::rotateZ(forward, ori.z); + glm::normalize(forward); + glm::vec3 up = glm::vec3(0.0, 1.0, 0.0); + up = glm::rotateX(up, ori.x); + up = glm::rotateY(up, ori.y); + up = glm::rotateZ(up, ori.z); + glm::normalize(up); + ALfloat lori[6] = { forward.x, forward.y, forward.z , up.x, up.y, up.z }; + alListenerfv(AL_ORIENTATION, lori); + }; glm::vec3 listenerOri() { glm::vec3 ori; alGetListener3f(AL_ORIENTATION, &ori.x, &ori.y, &ori.z); return ori; }; void setSourcePos(ALuint source, glm::vec3 pos) { ALfloat spos[3] = { pos.x, pos.y, pos.z }; alSourcefv(source, AL_POSITION, spos); }; void setSourceVel(ALuint source, glm::vec3 vel) { ALfloat svel[3] = { vel.x, vel.y, vel.z }; alSourcefv(source, AL_VELOCITY, svel); }; diff --git a/src/Engine/Sound/SoundSystem.cpp b/src/Engine/Sound/SoundSystem.cpp index b9736096..64312fa8 100644 --- a/src/Engine/Sound/SoundSystem.cpp +++ b/src/Engine/Sound/SoundSystem.cpp @@ -35,6 +35,7 @@ void SoundSystem::Update() EntityID listener = (*it).EntityID; auto transform = m_World->GetComponent(listener, "Transform"); setListenerPos(transform["Position"]); + setListenerOri(transform["Orientation"]); } }