diff --git a/include/Engine/Collision/Collision.h b/include/Engine/Collision/Collision.h index c4292907..c3759393 100644 --- a/include/Engine/Collision/Collision.h +++ b/include/Engine/Collision/Collision.h @@ -79,7 +79,8 @@ bool AABBVsAABB(const AABB& a, const AABB& b); bool AABBVsAABB(const AABB& a, const AABB& b, glm::vec3& minimumTranslation); // Calculates an absolute AABB from an entity AABB component -boost::optional EntityAbsoluteAABB(EntityWrapper& entity); +boost::optional EntityAbsoluteAABB(EntityWrapper& entity, bool takeModelBox = false); +boost::optional AbsoluteAABBExplosionEffect(EntityWrapper& entity); } diff --git a/resources/Schema/Components/Collidable.xsd b/resources/Schema/Components/Collidable.xsd index 84c66f11..93f7ac24 100644 --- a/resources/Schema/Components/Collidable.xsd +++ b/resources/Schema/Components/Collidable.xsd @@ -4,5 +4,8 @@ + + Needs a Model or AABB component to work, uses AABB if both are attached. + \ No newline at end of file diff --git a/resources/Schema/Components/Trigger.xsd b/resources/Schema/Components/Trigger.xsd index a8bc8865..8119b966 100644 --- a/resources/Schema/Components/Trigger.xsd +++ b/resources/Schema/Components/Trigger.xsd @@ -4,5 +4,8 @@ + + Needs a Model or AABB component to work, uses AABB if both are attached. + \ No newline at end of file diff --git a/src/Engine/Collision/Collision.cpp b/src/Engine/Collision/Collision.cpp index 249669b9..b7b21969 100644 --- a/src/Engine/Collision/Collision.cpp +++ b/src/Engine/Collision/Collision.cpp @@ -565,10 +565,10 @@ bool AABBvsTriangles(const AABB& box, return hit; } -boost::optional EntityAbsoluteAABB(EntityWrapper& entity) +boost::optional EntityAbsoluteAABB(EntityWrapper& entity, bool takeModelBox) { AABB modelSpaceBox; - if (entity.HasComponent("AABB")) { + if (entity.HasComponent("AABB") && !takeModelBox) { ComponentWrapper& cAABB = entity["AABB"]; modelSpaceBox = EntityAABB::FromOriginSize((glm::vec3)cAABB["Origin"], (glm::vec3)cAABB["Size"]); } else if (entity.HasComponent("Model")) { @@ -612,4 +612,30 @@ boost::optional EntityAbsoluteAABB(EntityWrapper& entity) return aabb; } +boost::optional AbsoluteAABBExplosionEffect(EntityWrapper& entity) +{ + boost::optional modelBox = EntityAbsoluteAABB(entity, true); + if (!modelBox) { + return boost::none; + } + bool isRandom = (bool)entity["ExplosionEffect"]["Randomness"]; + float random = isRandom ? (float)(double)entity["ExplosionEffect"]["RandomnessScalar"] : 0; + glm::vec3 origin = (glm::vec3)entity["ExplosionEffect"]["ExplosionOrigin"]; + glm::vec3 randomVel = (glm::vec3)entity["ExplosionEffect"]["Velocity"]; + randomVel *= (random + 1); + float endVelocity = randomVel.y; + if ((bool)entity["ExplosionEffect"]["ExponentialAccelaration"]) { + endVelocity *= endVelocity / 2.f; + } + float maxRadius = (float)(double)entity["ExplosionEffect"]["ExplosionDuration"] * endVelocity; + glm::vec3 size; + AABB explosionBox(origin - (size / 2.f), origin + (size / 2.f)); + + glm::vec3 mini = glm::min(explosionBox.MinCorner(), (*modelBox).MinCorner()); + glm::vec3 maxi = glm::max(explosionBox.MaxCorner(), (*modelBox).MaxCorner()); + EntityAABB aabb = AABB(mini, maxi); + aabb.Entity = entity; + return aabb; +} + } \ No newline at end of file diff --git a/src/Engine/Collision/FillFrustumOctreeSystem.cpp b/src/Engine/Collision/FillFrustumOctreeSystem.cpp index f02a30f1..2be8bee0 100644 --- a/src/Engine/Collision/FillFrustumOctreeSystem.cpp +++ b/src/Engine/Collision/FillFrustumOctreeSystem.cpp @@ -7,15 +7,13 @@ void FillFrustumOctreeSystem::Update(double dt) void FillFrustumOctreeSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) { + boost::optional absoluteAABB; if (entity.HasComponent("ExplosionEffect")) { - //TODO: Fix hack, get real box by using shader equation. - EntityAABB aabb = AABB(glm::vec3(-300), glm::vec3(300)); - aabb.Entity = entity; - m_Octree->AddDynamicObject(aabb); + absoluteAABB = Collision::AbsoluteAABBExplosionEffect(entity); } else { - boost::optional absoluteAABB = Collision::EntityAbsoluteAABB(entity); - if (absoluteAABB) { - m_Octree->AddDynamicObject(*absoluteAABB); - } + absoluteAABB = Collision::EntityAbsoluteAABB(entity, true); } -} \ No newline at end of file + if (absoluteAABB) { + m_Octree->AddDynamicObject(*absoluteAABB); + } +} diff --git a/src/Engine/Rendering/Model.cpp b/src/Engine/Rendering/Model.cpp index 6457c980..0c3d7877 100644 --- a/src/Engine/Rendering/Model.cpp +++ b/src/Engine/Rendering/Model.cpp @@ -135,7 +135,7 @@ Model::Model(std::string fileName) maxi = glm::max(maxi, v.Position); } - m_Box = AABB(maxi, mini); + m_Box = AABB(mini, maxi); } Model::~Model() diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index cf6f0cda..a16e39a0 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -23,7 +23,7 @@ void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComp void SoundSystem::Update(double dt) { // Temp for play test. - if(m_DrumsIsPlaying) { + if (m_DrumsIsPlaying) { m_DrumsIsPlaying = !drumTimer(dt); } } @@ -66,6 +66,10 @@ bool SoundSystem::OnInputCommand(const Events::InputCommand & e) void SoundSystem::playerJumps() { + if (!LocalPlayer.Valid()) { + return; + } + bool grounded = (bool)m_World->GetComponent(LocalPlayer.ID, "Physics")["IsOnGround"]; if (grounded) { Events::PlaySoundOnEntity e; @@ -121,11 +125,11 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) std::vector paths; paths.push_back("Audio/hurt/hurt" + std::to_string(rand) + ".wav"); -// // Breathe -// int ammountOfbreaths = (static_cast(e.Damage) / 10) + 2; // TEMP: Idk something stupid like this shit -// for (int i = 0; i < ammountOfbreaths; i++) { -// paths.push_back("Audio/exhausted/breath.wav"); -// } + // // Breathe + // int ammountOfbreaths = (static_cast(e.Damage) / 10) + 2; // TEMP: Idk something stupid like this shit + // for (int i = 0; i < ammountOfbreaths; i++) { + // paths.push_back("Audio/exhausted/breath.wav"); + // } Events::PlayQueueOnEntity ev; ev.Emitter = LocalPlayer; ev.FilePaths = paths; @@ -137,7 +141,7 @@ bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e) { Events::PlaySoundOnEntity ev; ev.EmitterID = LocalPlayer.ID; - ev.FilePath = "Audio/die/die2.wav"; + ev.FilePath = "Audio/die/die2.wav"; m_EventBroker->Publish(ev); return false; }