Implemented KRAudioManager::setListenerOrientation
Implemented KRAudioManager::setListenerOrientationFromModelMatrix Implemented KRAudioManager::getListenerForward Implemented KRAudioManager::getListenerUp Implemented KRAudioManager::getListenerPosition Listener position and orientation are no longer automatically coupled to the camera's model matrix, and must be set manually using these new functions.
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
#include "KRAudioBuffer.h"
|
#include "KRAudioBuffer.h"
|
||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
#include "KRVector2.h"
|
#include "KRVector2.h"
|
||||||
|
#include "KRCollider.h"
|
||||||
#include <Accelerate/Accelerate.h>
|
#include <Accelerate/Accelerate.h>
|
||||||
|
|
||||||
OSStatus alcASASetListenerProc(const ALuint property, ALvoid *data, ALuint dataSize);
|
OSStatus alcASASetListenerProc(const ALuint property, ALvoid *data, ALuint dataSize);
|
||||||
@@ -1071,17 +1072,35 @@ void KRAudioManager::makeCurrentContext()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRAudioManager::setViewMatrix(const KRMat4 &viewMatrix)
|
void KRAudioManager::setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix)
|
||||||
{
|
{
|
||||||
KRMat4 invView = viewMatrix;
|
setListenerOrientation(
|
||||||
invView.invert();
|
KRMat4::Dot(modelMatrix, KRVector3(0.0, 0.0, 0.0)),
|
||||||
|
KRVector3::Normalize(KRMat4::Dot(modelMatrix, KRVector3(0.0, 0.0, -1.0)) - m_listener_position),
|
||||||
|
KRVector3::Normalize(KRMat4::Dot(modelMatrix, KRVector3(0.0, 1.0, 0.0)) - m_listener_position)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
m_listener_position = KRMat4::Dot(invView, KRVector3(0.0, 0.0, 0.0));
|
KRVector3 &KRAudioManager::getListenerForward()
|
||||||
m_listener_forward = KRMat4::Dot(invView, KRVector3(0.0, 0.0, -1.0)) - m_listener_position;
|
{
|
||||||
m_listener_up = KRMat4::Dot(invView, KRVector3(0.0, 1.0, 0.0)) - m_listener_position;
|
return m_listener_forward;
|
||||||
|
}
|
||||||
|
|
||||||
m_listener_up.normalize();
|
KRVector3 &KRAudioManager::getListenerPosition()
|
||||||
m_listener_forward.normalize();
|
{
|
||||||
|
return m_listener_position;
|
||||||
|
}
|
||||||
|
|
||||||
|
KRVector3 &KRAudioManager::getListenerUp()
|
||||||
|
{
|
||||||
|
return m_listener_up;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRAudioManager::setListenerOrientation(const KRVector3 &position, const KRVector3 &forward, const KRVector3 &up)
|
||||||
|
{
|
||||||
|
m_listener_position = position;
|
||||||
|
m_listener_forward = forward;
|
||||||
|
m_listener_up = up;
|
||||||
|
|
||||||
makeCurrentContext();
|
makeCurrentContext();
|
||||||
if(m_audio_engine == KRAKEN_AUDIO_OPENAL) {
|
if(m_audio_engine == KRAKEN_AUDIO_OPENAL) {
|
||||||
@@ -1253,12 +1272,20 @@ void KRAudioManager::renderHRTF()
|
|||||||
KRAudioSource *source = *itr;
|
KRAudioSource *source = *itr;
|
||||||
KRAudioSample *source_sample = source->getAudioSample();
|
KRAudioSample *source_sample = source->getAudioSample();
|
||||||
if(source_sample) {
|
if(source_sample) {
|
||||||
|
KRVector3 source_world_position = source->getWorldTranslation();
|
||||||
KRVector3 source_listener_space = KRMat4::Dot(inv_listener_mat, source->getWorldTranslation());
|
KRVector3 source_listener_space = KRMat4::Dot(inv_listener_mat, source_world_position);
|
||||||
KRVector3 source_dir = KRVector3::Normalize(source_listener_space);
|
KRVector3 source_dir = KRVector3::Normalize(source_listener_space);
|
||||||
float distance = source_listener_space.magnitude();
|
float distance = source_listener_space.magnitude();
|
||||||
float gain = source->getGain() * m_global_gain / pow(KRMAX(distance / source->getReferenceDistance(), 1.0f), source->getRolloffFactor());
|
float gain = source->getGain() * m_global_gain / pow(KRMAX(distance / source->getReferenceDistance(), 1.0f), source->getRolloffFactor());
|
||||||
|
|
||||||
|
if(source->getEnableOcclusion() && false) {
|
||||||
|
KRHitInfo hitinfo;
|
||||||
|
if(source->getScene().lineCast(m_listener_position, source_world_position, hitinfo, KRAKEN_COLLIDER_AUDIO)) {
|
||||||
|
gain = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
float azimuth = atan2(source_dir.x, source_dir.z);
|
float azimuth = atan2(source_dir.x, source_dir.z);
|
||||||
float elevation = atan( source_dir.y / sqrt(source_dir.x * source_dir.x + source_dir.z * source_dir.z));
|
float elevation = atan( source_dir.y / sqrt(source_dir.x * source_dir.x + source_dir.z * source_dir.z));
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,11 @@ public:
|
|||||||
KRAudioSample *load(const std::string &name, const std::string &extension, KRDataBlock *data);
|
KRAudioSample *load(const std::string &name, const std::string &extension, KRDataBlock *data);
|
||||||
KRAudioSample *get(const std::string &name);
|
KRAudioSample *get(const std::string &name);
|
||||||
|
|
||||||
void setViewMatrix(const KRMat4 &viewMatrix);
|
void setListenerOrientation(const KRVector3 &position, const KRVector3 &forward, const KRVector3 &up);
|
||||||
|
void setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix);
|
||||||
|
KRVector3 &getListenerForward();
|
||||||
|
KRVector3 &getListenerPosition();
|
||||||
|
KRVector3 &getListenerUp();
|
||||||
|
|
||||||
void makeCurrentContext();
|
void makeCurrentContext();
|
||||||
|
|
||||||
|
|||||||
@@ -69,9 +69,6 @@ void KRCamera::renderFrame(float deltaTime, GLint renderBufferWidth, GLint rende
|
|||||||
|
|
||||||
|
|
||||||
KRMat4 viewMatrix = KRMat4::Invert(getModelMatrix());
|
KRMat4 viewMatrix = KRMat4::Invert(getModelMatrix());
|
||||||
getContext().getAudioManager()->setViewMatrix(viewMatrix); // FINDME, TODO - Should we support de-coupling the audio listener location from the camera?
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
settings.setViewportSize(KRVector2(backingWidth, backingHeight));
|
settings.setViewportSize(KRVector2(backingWidth, backingHeight));
|
||||||
KRMat4 projectionMatrix;
|
KRMat4 projectionMatrix;
|
||||||
|
|||||||
Reference in New Issue
Block a user