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 +++++++------ src/crepe/system/CollisionSystem.h | 5 ++++- 2 files changed, 11 insertions(+), 7 deletions(-) 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 { diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index 9e9096c..7fb8b45 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -37,7 +37,10 @@ private: /** * \brief A structure to store the collision data of a single collider. * - * This structure stores the collider type, its associated transform, and its rigidbody. + * This structure all components and id that are for needed within this system when calculating or handeling collisions. + * The transform and rigidbody are mostly needed for location and rotation. + * In rigidbody additional info is written about what the body of the object is, + * and how it should respond on a collision. */ struct CollisionInternal { game_object_id_t id = 0; -- cgit v1.2.3