Fixed bug. Sound not longer always in origin.

This commit is contained in:
Stiffly
2014-05-27 06:05:47 +02:00
parent 62adbdb2c8
commit 7e995fc8b7
4 changed files with 39 additions and 37 deletions
+21 -18
View File
@@ -89,11 +89,11 @@ void GameWorld::Initialize()
{
auto ground = CreateEntity();
auto transform = AddComponent<Components::Transform>(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<Components::Model>(ground);
model->ModelFile = "Models/TestScene3/testScene.obj";
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
//model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj";
auto physics = AddComponent<Components::Physics>(ground);
@@ -102,9 +102,12 @@ void GameWorld::Initialize()
auto groundshape = CreateEntity(ground);
auto transformshape = AddComponent<Components::Transform>(groundshape);
auto meshShape = AddComponent<Components::MeshShape>(groundshape);
auto box = AddComponent<Components::BoxShape>(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<float>() / 8.f, 0.f, 0.f));
auto cameraComp = AddComponent<Components::Camera>(cameraTower);
cameraComp->FarClip = 2000.f;
{
auto se1 = CreateEntity(camera);
auto transform = AddComponent<Components::Transform>(se1);
transform->Position = glm::vec3(0,10,0);
transform->Scale = glm::vec3(3);
auto emitterComponent = AddComponent<Components::SoundEmitter>(se1);
emitterComponent->Path = "Sounds/WUB.mp3";
emitterComponent->MinDistance = 100.f;
emitterComponent->MaxDistance = 10000.f;
emitterComponent->Gain = 1;
// auto model = AddComponent<Components::Model>(se1);
// model->ModelFile = "Models/PlaceHolders/PhysicsTest/PointLight.obj";
}
//auto freeSteering = AddComponent<Components::FreeSteering>(cameraTower);
AddComponent<Components::Listener>(tank);
}
@@ -1099,6 +1089,19 @@ void GameWorld::Initialize()
CommitEntity(tank);
}
auto se1 = CreateEntity();
std::cout<<se1<<std::endl;
auto transform = AddComponent<Components::Transform>(se1);
transform->Position = glm::vec3(20,2,-15);
transform->Scale = glm::vec3(3);
auto emitterComponent = AddComponent<Components::SoundEmitter>(se1);
emitterComponent->Path = "Sounds/WUB.mp3";
emitterComponent->MinDistance = 0.1f;
emitterComponent->MaxDistance = 100000.f;
emitterComponent->Gain = 1;
auto model = AddComponent<Components::Model>(se1);
model->ModelFile = "Models/PlaceHolders/PhysicsTest/PointLight.obj";
/*
for(int i = 0; i < 10; i++)
{
+1 -1
View File
@@ -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);
}
+15 -16
View File
@@ -8,9 +8,8 @@ void Systems::SoundSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EPlaySound, &SoundSystem::PlayASound);
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
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<Components::SoundEmitter>(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);
}
}
+2 -2
View File
@@ -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<EntityID> m_Listeners;
@@ -46,7 +46,7 @@ private:
std::map<EntityID, FMOD_SOUND*> m_Sounds;
std::map<EntityID, FMOD_SOUND*> m_DeleteSounds;
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
};
}