diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2024-12-03 18:18:32 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2024-12-03 18:18:32 +0100 |
commit | fb018cd8511e9cae408f8ea7d2b73e66a452625b (patch) | |
tree | f1eb5606e78142231089962c0d33bb6196302b5e /src | |
parent | 3622b63a0d2ce3f1168d2b43d91987076c7c94cd (diff) |
added and changed some comments
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/system/CollisionSystem.cpp | 13 | ||||
-rw-r--r-- | 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<Rigidbody> rigidbodies = mgr.get_components_by_type<Rigidbody>(); + // 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<Transform>(id).front().get(); + // Check if the boxcollider is active and has the same id as the rigidbody. RefVector<BoxCollider> boxcolliders = mgr.get_components_by_type<BoxCollider>(); 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<CircleCollider> circlecolliders = mgr.get_components_by_type<CircleCollider>(); 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<std::pair<CollisionSystem::CollisionInternal,CollisionSystem::Collis for (size_t i = 0; i < colliders.size(); ++i) { for (size_t j = i + 1; j < colliders.size(); ++j) { if(colliders[i].id == colliders[j].id) continue; - // Get collision type form variant colliders CollisionInternalType type = get_collider_type(colliders[i].collider,colliders[j].collider); if(!get_collision({ .collider = colliders[i].collider, @@ -410,10 +411,10 @@ bool CollisionSystem::get_box_box_collision(const BoxCollider& box1, const BoxCo float half_height2 = box2.height / 2.0; // Check if the boxes overlap along the X and Y axes - return (final_position1.x + half_width1 > 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; |