From fb018cd8511e9cae408f8ea7d2b73e66a452625b Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Tue, 3 Dec 2024 18:18:32 +0100 Subject: added and changed some comments --- src/crepe/system/CollisionSystem.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/crepe/system/CollisionSystem.cpp') diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index de14aed..380cc3d 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -28,10 +28,12 @@ void CollisionSystem::update() { ComponentManager & mgr = this->component_manager; game_object_id_t id = 0; RefVector rigidbodies = mgr.get_components_by_type(); + // Collisions can only happen on object with a rigidbody for(Rigidbody& rigidbody : rigidbodies) { if (!rigidbody.active) continue; id = rigidbody.game_object_id; Transform& transform = this->component_manager.get_components_by_id(id).front().get(); + // Check if the boxcollider is active and has the same id as the rigidbody. RefVector boxcolliders = mgr.get_components_by_type(); for (BoxCollider& boxcollider : boxcolliders) { if(boxcollider.game_object_id != id) continue; @@ -45,6 +47,7 @@ void CollisionSystem::update() { } ); } + // Check if the circlecollider is active and has the same id as the rigidbody. RefVector circlecolliders = mgr.get_components_by_type(); for (CircleCollider& circlecollider : circlecolliders) { if(circlecollider.game_object_id != id) continue; @@ -58,7 +61,6 @@ void CollisionSystem::update() { } ); } - } // Check between all colliders if there is a collision @@ -311,7 +313,6 @@ std::vector final_position2.x - half_width2 && // not left - final_position1.x - half_width1 < final_position2.x + half_width2 && // not right - final_position1.y + half_height1 > final_position2.y - half_height2 && // not above - final_position1.y - half_height1 < final_position2.y + half_height2); // not below + return (final_position1.x + half_width1 > final_position2.x - half_width2 && + final_position1.x - half_width1 < final_position2.x + half_width2 && + final_position1.y + half_height1 > final_position2.y - half_height2 && + final_position1.y - half_height1 < final_position2.y + half_height2); } bool CollisionSystem::get_box_circle_collision(const BoxCollider& box1, const CircleCollider& circle2, const Transform& transform1, const Transform& transform2, const Rigidbody& rigidbody1, const Rigidbody& rigidbody2) const { -- cgit v1.2.3