diff options
author | Joerg Mueller <nexyon@gmail.com> | 2011-08-22 22:59:56 +0400 |
---|---|---|
committer | Joerg Mueller <nexyon@gmail.com> | 2011-08-22 22:59:56 +0400 |
commit | a71c215f228173070d41faef1321db25b40d723e (patch) | |
tree | f5b81a18f01c7dd8e7450e3c6fc823038b3c11da /source/gameengine | |
parent | ee40894c05b1d5f07eda671bad74f18605cde0b6 (diff) |
3D Audio GSoC:
Final GSoC commit.
* Bugfix: Negative frames crashed
* Bugfix: JOS sample buffer size prediction error (wasted memory)
* Optimisation: for JOS upsampling (around 12 % difference measured here)
* Optimisation: Better filter for JOS resampling
* Bugfix: Error in relative 3D audio code.
* Removed Attenuation
* Bugfix: Multiple scenes in BGE lead to errors, BGE audio now all relative, to support multiple scenes.
Diffstat (limited to 'source/gameengine')
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 16 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_SoundActuator.cpp | 35 |
2 files changed, 33 insertions, 18 deletions
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index a51105e0c16..dd1cc09cdc6 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -1008,7 +1008,8 @@ void KX_KetsjiEngine::DoSound(KX_Scene* scene) { m_logger->StartLog(tc_sound, m_kxsystem->GetTimeInSeconds(), true); - KX_Camera* cam = scene->GetActiveCamera(); + // nothing to do here, everything relative now... + /*KX_Camera* cam = scene->GetActiveCamera(); if (!cam) return; @@ -1016,16 +1017,17 @@ void KX_KetsjiEngine::DoSound(KX_Scene* scene) if(dev) { AUD_Vector3 v; - float q[4]; - cam->NodeGetWorldPosition().getValue(v.get()); + //float q[4]; + //cam->NodeGetWorldPosition().getValue(v.get()); dev->setListenerLocation(v); - cam->GetLinearVelocity().getValue(v.get()); + //cam->GetLinearVelocity().getValue(v.get()); dev->setListenerVelocity(v); - cam->NodeGetWorldOrientation().getRotation().getValue(q); - dev->setListenerOrientation(AUD_Quaternion(q[3], q[0], q[1], q[2])); - } + //cam->NodeGetWorldOrientation().getRotation().getValue(q); + //dev->setListenerOrientation(AUD_Quaternion(q[3], q[0], q[1], q[2])); + dev->setListenerOrientation(AUD_Quaternion()); + }*/ } diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index eb75e4944a7..6c7b515c095 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -46,6 +46,8 @@ #include "KX_GameObject.h" #include "KX_PyMath.h" // needed for PyObjectFrom() +#include "KX_PythonInit.h" +#include "KX_Camera.h" #include <iostream> /* ------------------------------------------------------------------------- */ @@ -112,7 +114,7 @@ void KX_SoundActuator::play() if(m_is3d && !handle3d.isNull()) { - handle3d->setRelative(false); + handle3d->setRelative(true); handle3d->setVolumeMaximum(m_3d.max_gain); handle3d->setVolumeMinimum(m_3d.min_gain); handle3d->setDistanceReference(m_3d.reference_distance); @@ -222,16 +224,27 @@ bool KX_SoundActuator::Update(double curtime, bool frame) if(m_is3d && !handle3d.isNull()) { - KX_GameObject* obj = (KX_GameObject*)this->GetParent(); - AUD_Vector3 v; - float q[4]; - - obj->NodeGetWorldPosition().getValue(v.get()); - handle3d->setSourceLocation(v); - obj->GetLinearVelocity().getValue(v.get()); - handle3d->setSourceVelocity(v); - obj->NodeGetWorldOrientation().getRotation().getValue(q); - handle3d->setSourceOrientation(AUD_Quaternion(q[3], q[0], q[1], q[2])); + KX_Camera* cam = KX_GetActiveScene()->GetActiveCamera(); + if (cam) + { + KX_GameObject* obj = (KX_GameObject*)this->GetParent(); + MT_Point3 p; + MT_Matrix3x3 Mo; + AUD_Vector3 v; + float q[4]; + + Mo = cam->NodeGetWorldOrientation().inverse(); + p = (obj->NodeGetWorldPosition() - cam->NodeGetWorldPosition()); + p = Mo * p; + p.getValue(v.get()); + handle3d->setSourceLocation(v); + p = (obj->GetLinearVelocity() - cam->GetLinearVelocity()); + p = Mo * p; + p.getValue(v.get()); + handle3d->setSourceVelocity(v); + (Mo * obj->NodeGetWorldOrientation()).getRotation().getValue(q); + handle3d->setSourceOrientation(AUD_Quaternion(q[3], q[0], q[1], q[2])); + } } result = true; } |