Billboarding working again

This commit is contained in:
Stiffly
2014-06-03 23:48:13 +02:00
parent df32a3b07d
commit 909ee94e26
6 changed files with 48 additions and 24 deletions
+1 -1
Submodule assets updated: c61526f5fc...588da9ca0d
+2 -2
View File
@@ -590,7 +590,7 @@ void GameWorld::Initialize()
{ {
EntityID Wall = CreateWall(glm::vec3(i*10.f, -15.f, 0.f), glm::quat()); EntityID Wall = CreateWall(glm::vec3(i*10.f, -15.f, 0.f), glm::quat());
} }
#pragma endregion Region for all wall creations #pragma endregion Region for all wall creations
/*EntityID tank1 = CreateTank(1); /*EntityID tank1 = CreateTank(1);
@@ -616,7 +616,7 @@ void GameWorld::Initialize()
EventBroker->Publish(e); EventBroker->Publish(e);
}*/ }*/
CreateGarage(glm::vec3(-3.93076, -49, 0), 1); CreateGarage(glm::vec3(-3.93076, 0, 0), 1);
{ {
auto flag = CreateEntity(); auto flag = CreateEntity();
+14 -1
View File
@@ -531,7 +531,20 @@ void Renderer::ForwardRendering(RenderQueue &rq)
if (spriteJob) if (spriteJob)
{ {
glm::mat4 modelMatrix = spriteJob->ModelMatrix; glm::mat4 modelMatrix = spriteJob->ModelMatrix;
MVP = cameraMatrix * modelMatrix; MVP = cameraMatrix * modelMatrix * glm::inverse(glm::toMat4(glm::inverse(m_Camera->Orientation())));
//auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
//if (transformComponent && spriteComponent)
//{
// //TEMP
// Texture* texture = m_World->ResourceManager->Load<Texture>("Texture", spriteComponent->SpriteFile);
// //glBindTexture(GL_TEXTURE_2D, texture);
// auto transform = m_World->GetComponent<Components::Transform>(spriteComponent->Entity);
// glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(transform->Orientation).z, glm::vec3(0, 0, -1));
// m_Renderer->AddTextureToDraw(texture, transform->Position, orientation2D, transform->Scale);
//}
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4(MVP))); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4(MVP)));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4(modelMatrix))); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4(modelMatrix)));
+22 -18
View File
@@ -44,20 +44,31 @@ void Systems::SoundSystem::Update(double dt)
std::map<EntityID, FMOD_CHANNEL*>::iterator it; std::map<EntityID, FMOD_CHANNEL*>::iterator it;
for(it = m_DeleteChannels.begin(); it != m_DeleteChannels.end();) for(it = m_DeleteChannels.begin(); it != m_DeleteChannels.end();)
{ {
FMOD_BOOL *isPlaying = false; FMOD_BOOL isPlaying = false;
FMOD_Channel_IsPlaying(it->second, isPlaying); FMOD_Channel_IsPlaying(it->second, &isPlaying);
if(isPlaying) if(isPlaying)
{ {
it++; it++;
} }
else else
{ {
FMOD_Sound_Release(m_DeleteSounds[it->first]); // FMOD_Sound_Release(m_DeleteSounds[it->first]);
m_DeleteSounds.erase(it->first); // m_DeleteSounds.erase(it->first);
it = m_DeleteChannels.erase(it); it = m_DeleteChannels.erase(it);
} }
} }
//LOG_INFO("Antal emitters i listan: %i", m_Channels.size());
for (auto channel : m_Channels)
{
FMOD_BOOL isPlaying = false;
FMOD_Channel_IsPlaying(channel.second, &isPlaying);
if(!isPlaying)
{
m_Channels.erase(channel.first);
}
}
} }
void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
@@ -86,7 +97,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
if(emitter) if(emitter)
{ {
FMOD_CHANNEL* channel = m_Channels[entity]; FMOD_CHANNEL* channel = m_Channels[entity];
FMOD_SOUND* sound = m_Sounds[entity]; //FMOD_SOUND* sound = m_Sounds[entity];
auto eTransform = m_World->GetComponent<Components::Transform>(entity); auto eTransform = m_World->GetComponent<Components::Transform>(entity);
glm::vec3 tPos = m_TransformSystem->AbsolutePosition(entity); glm::vec3 tPos = m_TransformSystem->AbsolutePosition(entity);
@@ -121,20 +132,13 @@ bool Systems::SoundSystem::OnComponentCreated(const Events::ComponentCreated &ev
float pitch = emitter->Pitch; float pitch = emitter->Pitch;
//LoadSound(sound, path, maxDist, minDist); //LoadSound(sound, path, maxDist, minDist);
m_Channels.insert(std::make_pair(emitter->Entity, channel)); m_Channels.insert(std::make_pair(emitter->Entity, channel));
m_Sounds.insert(std::make_pair(emitter->Entity, sound)); // m_Sounds.insert(std::make_pair(emitter->Entity, sound));
} }
return true; return true;
} }
bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event) bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event)
{ {
// auto emitter = m_World->GetComponent<Components::SoundEmitter>(event.Emitter);
// if(!emitter)
// {
// LOG_ERROR("FMOD: The Entity %i does not have a SoundEmitter-component, but is trying to play a sound", event.Emitter);FMOD_CHANNEL* channel = m_Channels[event.Emitter];
// return false;
// }
auto eEntity = m_World->CreateEntity(); auto eEntity = m_World->CreateEntity();
auto eTransform = m_World->AddComponent<Components::Transform>(eEntity); auto eTransform = m_World->AddComponent<Components::Transform>(eEntity);
eTransform->Position = event.Position; eTransform->Position = event.Position;
@@ -146,10 +150,10 @@ bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event)
eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D; eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D;
Sound* sound = ResourceManager->Load<Sound>("Sound3D", event.Resource); Sound* sound = ResourceManager->Load<Sound>("Sound3D", event.Resource);
m_Sounds[eEntity] = *sound; //m_Sounds[eEntity] = *sound;
FMOD_Sound_Set3DMinMaxDistance(*sound, eComponent->MinDistance, eComponent->MaxDistance); FMOD_Sound_Set3DMinMaxDistance(*sound, eComponent->MinDistance, eComponent->MaxDistance);
PlaySound(&m_Channels[eEntity], m_Sounds[eEntity], 1.0, eComponent->Loop); PlaySound(&m_Channels[eEntity], *sound, 1.0, eComponent->Loop);
return true; return true;
} }
@@ -161,7 +165,7 @@ bool Systems::SoundSystem::PlayBGM(const Events::PlayBGM &event)
m_Channels[emitter] = m_BGMChannel; m_Channels[emitter] = m_BGMChannel;
eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D; eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D;
Sound* sound = ResourceManager->Load<Sound>("Sound2D", event.Resource); Sound* sound = ResourceManager->Load<Sound>("Sound2D", event.Resource);
m_Sounds[emitter] = *sound; //m_Sounds[emitter] = *sound;
FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_Channels[emitter]); FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_Channels[emitter]);
return true; return true;
@@ -200,8 +204,8 @@ void Systems::SoundSystem::OnComponentRemoved(EntityID entity, std::string type,
if(emitter) if(emitter)
{ {
m_DeleteChannels.insert(std::make_pair(entity, m_Channels[entity])); m_DeleteChannels.insert(std::make_pair(entity, m_Channels[entity]));
m_DeleteSounds.insert(std::make_pair(entity, m_Sounds[entity])); //m_DeleteSounds.insert(std::make_pair(entity, m_Sounds[entity]));
m_Channels.erase(entity); m_Channels.erase(entity);
m_Sounds.erase(entity); //m_Sounds.erase(entity);
} }
} }
+1 -1
View File
@@ -52,7 +52,7 @@ private:
std::vector<EntityID> m_Listeners; std::vector<EntityID> m_Listeners;
std::map<EntityID, FMOD_CHANNEL*> m_Channels; std::map<EntityID, FMOD_CHANNEL*> m_Channels;
std::map<EntityID, FMOD_CHANNEL*> m_DeleteChannels; std::map<EntityID, FMOD_CHANNEL*> m_DeleteChannels;
std::map<EntityID, FMOD_SOUND*> m_Sounds; //std::map<EntityID, FMOD_SOUND*> m_Sounds;
std::map<EntityID, FMOD_SOUND*> m_DeleteSounds; std::map<EntityID, FMOD_SOUND*> m_DeleteSounds;
std::shared_ptr<Systems::TransformSystem> m_TransformSystem; std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
+8 -1
View File
@@ -97,7 +97,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
m_TimeSinceLastShot[tankSteeringComponent->Barrel] = 0; m_TimeSinceLastShot[tankSteeringComponent->Barrel] = 0;
Events::PlaySFX e; Events::PlaySFX e;
e.Resource = "Sounds/SFX/LongBoom.wav"; e.Resource = "Sounds/SFX/TankShot.mp3";
e.Position = absoluteTransform.Position; e.Position = absoluteTransform.Position;
e.Loop = false; e.Loop = false;
EventBroker->Publish(e); EventBroker->Publish(e);
@@ -193,6 +193,13 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e)
e.Color = glm::vec4(2, 2, 2, 0.2); e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e); EventBroker->Publish(e);
} }
{
Events::PlaySFX e;
e.MinDistance = 150.f;
e.Position = shellTransform->Position;
e.Resource = "Sounds/SFX/Explosion.wav";
EventBroker->Publish(e);
}
for (auto &physComponent : *physicsComponents) for (auto &physComponent : *physicsComponents)
{ {