From 7e995fc8b77dfd4960a325cb1bc0280976f493d3 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Tue, 27 May 2014 06:05:47 +0200 Subject: [PATCH] Fixed bug. Sound not longer always in origin. --- src/GameWorld.cpp | 39 ++++++++++++++++++++----------------- src/InputManager.cpp | 2 +- src/Systems/SoundSystem.cpp | 31 ++++++++++++++--------------- src/Systems/SoundSystem.h | 4 ++-- 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index c4e4c68..0a774e8 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -89,11 +89,11 @@ void GameWorld::Initialize() { auto ground = CreateEntity(); auto transform = AddComponent(ground); - transform->Position = glm::vec3(0, -50, 0); - //transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f); + transform->Position = glm::vec3(0, 0, 0); + transform->Scale = glm::vec3(500.0f, 0.5f, 500.0f); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); auto model = AddComponent(ground); - model->ModelFile = "Models/TestScene3/testScene.obj"; + model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; //model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj"; auto physics = AddComponent(ground); @@ -102,9 +102,12 @@ void GameWorld::Initialize() auto groundshape = CreateEntity(ground); auto transformshape = AddComponent(groundshape); - auto meshShape = AddComponent(groundshape); + auto box = AddComponent(groundshape); + box->Width = 1000.f; + box->Height = 1.f; + box->Depth = 1000.f; //meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain2.obj"; - meshShape->ResourceName = "Models/TestScene3/testScene.obj"; + //meshShape->ResourceName = "Models/TestScene3/testScene.obj"; CommitEntity(groundshape); @@ -342,19 +345,6 @@ void GameWorld::Initialize() //transform->Orientation = glm::quat(glm::vec3(glm::pi() / 8.f, 0.f, 0.f)); auto cameraComp = AddComponent(cameraTower); cameraComp->FarClip = 2000.f; - { - auto se1 = CreateEntity(camera); - auto transform = AddComponent(se1); - transform->Position = glm::vec3(0,10,0); - transform->Scale = glm::vec3(3); - auto emitterComponent = AddComponent(se1); - emitterComponent->Path = "Sounds/WUB.mp3"; - emitterComponent->MinDistance = 100.f; - emitterComponent->MaxDistance = 10000.f; - emitterComponent->Gain = 1; - // auto model = AddComponent(se1); - // model->ModelFile = "Models/PlaceHolders/PhysicsTest/PointLight.obj"; - } //auto freeSteering = AddComponent(cameraTower); AddComponent(tank); } @@ -1099,6 +1089,19 @@ void GameWorld::Initialize() CommitEntity(tank); } + auto se1 = CreateEntity(); + std::cout<(se1); + transform->Position = glm::vec3(20,2,-15); + transform->Scale = glm::vec3(3); + auto emitterComponent = AddComponent(se1); + emitterComponent->Path = "Sounds/WUB.mp3"; + emitterComponent->MinDistance = 0.1f; + emitterComponent->MaxDistance = 100000.f; + emitterComponent->Gain = 1; + auto model = AddComponent(se1); + model->ModelFile = "Models/PlaceHolders/PhysicsTest/PointLight.obj"; + /* for(int i = 0; i < 10; i++) { diff --git a/src/InputManager.cpp b/src/InputManager.cpp index da76a1d..ec220ff 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -46,7 +46,7 @@ void InputManager::Update(double dt) { Events::PlaySound e; e.Resource = "Sounds/WUB.mp3"; - e.Emitter = 16; + e.Emitter = 66; e.Loop = true; EventBroker->Publish(e); } diff --git a/src/Systems/SoundSystem.cpp b/src/Systems/SoundSystem.cpp index 6c44506..3339546 100755 --- a/src/Systems/SoundSystem.cpp +++ b/src/Systems/SoundSystem.cpp @@ -8,9 +8,8 @@ void Systems::SoundSystem::Initialize() EVENT_SUBSCRIBE_MEMBER(m_EPlaySound, &SoundSystem::PlayASound); m_TransformSystem = m_World->GetSystem(); - FMOD_System_Create(&m_System); - FMOD_RESULT result = FMOD_System_Init(m_System, 32, FMOD_INIT_NORMAL, 0); + FMOD_RESULT result = FMOD_System_Init(m_System, 32, FMOD_INIT_3D_RIGHTHANDED, 0); if(result != FMOD_OK) { LOG_ERROR("Did initialized load FMOD correctly"); @@ -19,7 +18,7 @@ void Systems::SoundSystem::Initialize() { LOG_INFO("FMOD initialized successfully"); } - FMOD_System_Set3DSettings(m_System, 10.f, 1.f, 100.f); //dopplerScale, distancefactor, rolloffscale + FMOD_System_Set3DSettings(m_System, 10.f, 1.f, 1.f); //dopplerScale, distancefactor, rolloffscale } @@ -72,10 +71,9 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par glm::vec3 tVel = (lTransform->Velocity * 1000.f) / (float)dt; FMOD_VECTOR lVel = {tVel.x, tVel.y, tVel.z}; - glm::mat3 tOri = glm::toMat3(lTransform->Orientation); - glm::vec3 tUp = glm::normalize(tOri[1]); + glm::vec3 tUp = glm::normalize(lTransform->Orientation * glm::vec3(0,1,0)); FMOD_VECTOR lUp = {tUp.x, tUp.y, tUp.z}; - glm::vec3 tForward = glm::normalize(tOri[2]); + glm::vec3 tForward = glm::normalize(lTransform->Orientation * glm::vec3(0,0,-1)); FMOD_VECTOR lForward = {tForward.x, tForward.y, tForward.z}; FMOD_System_Set3DListenerAttributes(m_System, lID, (const FMOD_VECTOR*)&lPos, (const FMOD_VECTOR*)&lVel, (const FMOD_VECTOR*)&lForward, (const FMOD_VECTOR*)&lUp); @@ -94,7 +92,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par glm::vec3 tVel = (eTransform->Velocity * 1000.f) / float(dt); FMOD_VECTOR eVel = {tVel.x, tVel.y, tVel.z}; - FMOD_Channel_Set3DAttributes(channel, (const FMOD_VECTOR*)&ePos, (const FMOD_VECTOR*)&eVel); + FMOD_Channel_Set3DAttributes(channel, &ePos, &eVel); } } @@ -127,6 +125,7 @@ bool Systems::SoundSystem::OnComponentCreated(const Events::ComponentCreated &ev bool Systems::SoundSystem::PlayASound(const Events::PlaySound &event) { + auto emitter = m_World->GetComponent(event.Emitter); if(!emitter) { @@ -134,13 +133,13 @@ bool Systems::SoundSystem::PlayASound(const Events::PlaySound &event) return false; } - if(emitter->Path != event.Resource) //Caching sound file - { +// if(emitter->Path != event.Resource) //Caching sound file +// { LoadSound(m_Sounds[event.Emitter], event.Resource, 1000.f, 1.f); - emitter->Path = event.Resource; - } +// emitter->Path = event.Resource; +// } - PlaySound(m_Channels[event.Emitter], m_Sounds[event.Emitter], 1.0, event.Loop); + PlaySound(&m_Channels[event.Emitter], m_Sounds[event.Emitter], 1.0, event.Loop); FMOD_System_Update(m_System); FMOD_BOOL* isPlaying = false; if(!FMOD_Channel_IsPlaying(m_Channels[event.Emitter], isPlaying)) @@ -162,13 +161,13 @@ void Systems::SoundSystem::LoadSound(FMOD_SOUND* &sound, std::string filePath, f FMOD_Sound_Set3DMinMaxDistance(sound, minDist, maxDist); } -void Systems::SoundSystem::PlaySound(FMOD_CHANNEL* channel, FMOD_SOUND* sound, float volume, bool loop) +void Systems::SoundSystem::PlaySound(FMOD_CHANNEL** channel, FMOD_SOUND* sound, float volume, bool loop) { - FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, sound, false, &channel); - FMOD_Channel_SetVolume(channel, volume); + FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, sound, false, channel); + FMOD_Channel_SetVolume(*channel, volume); if(loop) { - FMOD_Channel_SetMode(channel, FMOD_LOOP_NORMAL); + FMOD_Channel_SetMode(*channel, FMOD_LOOP_NORMAL); FMOD_Sound_SetLoopCount(sound, -1); } } diff --git a/src/Systems/SoundSystem.h b/src/Systems/SoundSystem.h index 2cf36a3..edd322e 100755 --- a/src/Systems/SoundSystem.h +++ b/src/Systems/SoundSystem.h @@ -37,7 +37,7 @@ private: bool PlayASound(const Events::PlaySound &event); void LoadSound(FMOD_SOUND*&, std::string, float, float); - void PlaySound(FMOD_CHANNEL*, FMOD_SOUND*, float volume, bool loop); + void PlaySound(FMOD_CHANNEL**, FMOD_SOUND*, float volume, bool loop); FMOD_SYSTEM* m_System; std::vector m_Listeners; @@ -46,7 +46,7 @@ private: std::map m_Sounds; std::map m_DeleteSounds; std::shared_ptr m_TransformSystem; - + }; }