From 24246e115c3b7829d2981a2f60ac77da657f2ed5 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 4 Dec 2024 20:42:53 +0100 Subject: added collision layers --- src/crepe/system/CollisionSystem.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/crepe/system/CollisionSystem.cpp') diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 34cd125..3c103e9 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -359,6 +359,7 @@ CollisionSystem::gather_collisions(std::vector & colliders) { 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; + if(!have_common_layer(colliders[i].rigidbody.data.collision_layers,colliders[j].rigidbody.data.collision_layers)) continue; CollisionInternalType type = get_collider_type(colliders[i].collider, colliders[j].collider); if (!get_collision( @@ -381,6 +382,17 @@ CollisionSystem::gather_collisions(std::vector & colliders) { return collisions_ret; } +bool CollisionSystem::have_common_layer(const std::vector& layers1, const std::vector& layers2) { + // Iterate through each layer in the first vector + for (int layer : layers1) { + // Check if the current layer is present in the second vector + if (std::find(layers2.begin(), layers2.end(), layer) != layers2.end()) { + return true; // Common layer found + } + } + return false; // No common layers found +} + CollisionSystem::CollisionInternalType CollisionSystem::get_collider_type(const collider_variant & collider1, const collider_variant & collider2) const { -- cgit v1.2.3