From a556b45abf18f1bd509daaf63b66b7d55e9fd291 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Mon, 22 Apr 2024 21:56:26 -0400 Subject: add engine version --- .../environmentcollisiondetectionsystem.cpp | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 engine-ocean/Game/Systems/CollisionSystems/environmentcollisiondetectionsystem.cpp (limited to 'engine-ocean/Game/Systems/CollisionSystems/environmentcollisiondetectionsystem.cpp') diff --git a/engine-ocean/Game/Systems/CollisionSystems/environmentcollisiondetectionsystem.cpp b/engine-ocean/Game/Systems/CollisionSystems/environmentcollisiondetectionsystem.cpp new file mode 100644 index 0000000..3470dd8 --- /dev/null +++ b/engine-ocean/Game/Systems/CollisionSystems/environmentcollisiondetectionsystem.cpp @@ -0,0 +1,93 @@ +#include "environmentcollisiondetectionsystem.h" +#include "Game/Components/CollisionComponents/BoundingDynamicMesh.h" +#include "Game/Components/CollisionComponents/CollisionComponent.h" +#include "Game/Components/TransformComponent.h" +#include "Game/GameObjects/GameObject.h" +#include "Game/Systems/CollisionSystems/ellipsoidtrianglecollisionsystem.h" +#include + +EnvironmentCollisionDetectionSystem::EnvironmentCollisionDetectionSystem( + std::map>& dynamic_gameobjects, + std::map>& rigid_gameobjects, + std::map>>& lootables, + std::map& global_blackboard) : + m_dynamic_gameobjects(dynamic_gameobjects), + m_ellipsoid_triangle_collision_system(std::make_unique(rigid_gameobjects)), + m_global_blackboard(global_blackboard), + m_lootables(lootables) +{ + +} + +TransformComponent* EnvironmentCollisionDetectionSystem::getTransform(std::shared_ptr &go){ + return go->getComponent(); + +} + +CollisionComponent* EnvironmentCollisionDetectionSystem::getCollisionComp(std::shared_ptr &go){ + return go->getComponent(); +} + +void EnvironmentCollisionDetectionSystem::detectCollisionWithEnvironment(double deltaTime){ + for (auto &go : m_dynamic_gameobjects){ + collideDynamic(go.first, go.second); + + } +} + + +void EnvironmentCollisionDetectionSystem::collideDynamic(std::string go_name, std::shared_ptr go){ + if (!go->hasComponent()){ + return; + } + + std::pair, glm::vec3> pair = + m_ellipsoid_triangle_collision_system->mtvSlide(getTransform(go)->old_pos, + //getTransform(go.second)->estimated_final_pos, + m_global_blackboard[go_name].locationData.setToPos, + getCollisionComp(go)->getCollisionShape()->getEllipsoidDimensions()); + + // assume not on ground first; then determine if we are touching ground + getTransform(go)->onGround = false; + m_global_blackboard[go_name].conditionData["onGround"].conditionTrue = false; + for (const CollisionData &collision : pair.first){ + if (glm::dot(glm::vec3(0,1,0), collision.triangle_n) > 0.f){ + getTransform(go)->onGround = true; + m_global_blackboard[go_name].conditionData["onGround"].conditionTrue = true; + + } + } + + if (getTransform(go)->onGround){ + if (getTransform(go)->yVelocity < 0){ + getTransform(go)->yVelocity = 0.f; + getTransform(go)->gravity = 0.f; + } + } + + if (!getTransform(go)->onGround){ + getTransform(go)->gravity = -25.f; + } + + + if (!getTransform(go)->movingLaterally && + getTransform(go)->onGround){ + getTransform(go)->setPos(getTransform(go)->old_pos); + } else { + getTransform(go)->setPos(pair.second); + } + + getCollisionComp(go)->getCollisionShape()->updateCenterPos(getTransform(go)->getPos()); +} + + +void EnvironmentCollisionDetectionSystem::update(double deltaTime){ + detectCollisionWithEnvironment(deltaTime); +} + +void EnvironmentCollisionDetectionSystem::draw(){} +void EnvironmentCollisionDetectionSystem::scrollEvent(double distance){} +void EnvironmentCollisionDetectionSystem::mousePosEvent(double xpos, double ypos){} + + + -- cgit v1.2.3-70-g09d2