diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/system/CollisionSystem.cpp | 30 | ||||
-rw-r--r-- | src/test/CollisionTest.cpp | 358 |
2 files changed, 204 insertions, 184 deletions
diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index f61a1dd..6f2c39d 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -5,7 +5,6 @@ #include <utility> #include <variant> #include <optional> -#include <tuple> #include "api/Event.h" #include "api/EventManager.h" @@ -61,18 +60,22 @@ void CollisionSystem::collision_handler_request(CollidedInfoStor& data1,Collided case ColliderStorType::BOX_BOX:{ collider1 = std::get<std::reference_wrapper<BoxCollider>>(data1.collider); collider2 = std::get<std::reference_wrapper<BoxCollider>>(data2.collider); + break; } case ColliderStorType::BOX_CIRCLE:{ collider1 = std::get<std::reference_wrapper<BoxCollider>>(data1.collider); collider2 = std::get<std::reference_wrapper<CircleCollider>>(data2.collider); + break; } case ColliderStorType::CIRCLE_BOX:{ collider1 = std::get<std::reference_wrapper<CircleCollider>>(data1.collider); collider2 = std::get<std::reference_wrapper<BoxCollider>>(data2.collider); + break; } case ColliderStorType::CIRCLE_CIRCLE:{ collider1 = std::get<std::reference_wrapper<CircleCollider>>(data1.collider); collider2 = std::get<std::reference_wrapper<CircleCollider>>(data2.collider); + break; } } @@ -233,17 +236,17 @@ std::vector<std::pair<CollisionSystem::CollidedInfoStor,CollisionSystem::Collide std::vector<std::pair<CollidedInfoStor,CollidedInfoStor>> collisions_ret; for (size_t i = 0; i < colliders.size(); ++i) { std::visit([&](auto& inner_collider_ref) { - if (inner_collider_ref.get().active) return; + if (!inner_collider_ref.get().active) return; auto inner_components = get_active_transform_and_rigidbody(inner_collider_ref.get().game_object_id); - if (inner_components) return; + if (!inner_components) return; for (size_t j = i + 1; j < colliders.size(); ++j) { std::visit([&](auto& outer_collider_ref) { - if (outer_collider_ref.get().active) return; + if (!outer_collider_ref.get().active) return; if (inner_collider_ref.get().game_object_id == outer_collider_ref.get().game_object_id) return; - auto outer_components = get_active_transform_and_rigidbody(inner_collider_ref.get().game_object_id); - if (outer_components) return; + auto outer_components = get_active_transform_and_rigidbody(outer_collider_ref.get().game_object_id); + if (!outer_components) return; ColliderStorType type = check_collider_type(colliders[i],colliders[j]); - check_collision(colliders[i],*inner_components,colliders[j],*outer_components,type); + if(!check_collision(colliders[i],*inner_components,colliders[j],*outer_components,type)) return; collisions_ret.emplace_back( CollidedInfoStor{colliders[i], inner_components->first.get(), inner_components->second.get()}, CollidedInfoStor{colliders[j], outer_components->first.get(), outer_components->second.get()} @@ -295,11 +298,12 @@ bool CollisionSystem::check_collision(const collider_stor& collider1,std::pair<s return check_circle_circle_collision(circle_collider1,circle_collider2,components1.first.get(),components2.first.get(),components1.second.get(),components2.second.get()); } case ColliderStorType::CIRCLE_BOX: { - const BoxCollider & box_collider = std::get<std::reference_wrapper<BoxCollider>>(collider1); - const CircleCollider & circle_collider = std::get<std::reference_wrapper<CircleCollider>>(collider2); + const CircleCollider & circle_collider = std::get<std::reference_wrapper<CircleCollider>>(collider1); + const BoxCollider & box_collider = std::get<std::reference_wrapper<BoxCollider>>(collider2); return check_box_circle_collision(box_collider,circle_collider,components1.first.get(),components2.first.get(),components1.second.get(),components2.second.get()); } } + return false; } @@ -316,10 +320,10 @@ bool CollisionSystem::check_box_box_collision(const BoxCollider& box1, const Box 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 || // box1 is left of box2 - final_position1.x - half_width1 >= final_position2.x + half_width2 || // box1 is right of box2 - final_position1.y + half_height1 <= final_position2.y - half_height2 || // box1 is above box2 - final_position1.y - half_height1 >= final_position2.y + half_height2); // box1 is below box2 + 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 } bool CollisionSystem::check_box_circle_collision(const BoxCollider& box1, const CircleCollider& circle2, const Transform& transform1, const Transform& transform2, const Rigidbody& rigidbody1, const Rigidbody& rigidbody2) { diff --git a/src/test/CollisionTest.cpp b/src/test/CollisionTest.cpp index bbf6348..e158d5c 100644 --- a/src/test/CollisionTest.cpp +++ b/src/test/CollisionTest.cpp @@ -22,6 +22,22 @@ using namespace std::chrono_literals; using namespace crepe; using namespace testing; +// class MyScript : public Script { +// bool oncollision(const CollisionEvent& test) { +// Log::logf("Box {} script on_collision()", test.info.first.collider.game_object_id); +// return true; +// } +// void init() { +// subscribe<CollisionEvent>([this](const CollisionEvent& ev) -> bool { +// return this->oncollision(ev); +// }); +// } +// void update() { +// // Retrieve component from the same GameObject this script is on +// } +// }; + + class CollisionHandler : public Script { public: int box_id; @@ -32,18 +48,18 @@ public: } bool on_collision(const CollisionEvent& ev) { - Log::logf("Box {} script on_collision()", box_id); + //Log::logf("Box {} script on_collision()", box_id); test_fn(ev); return true; } void init() { - //Log::logf("Box {} script init()", box_id); - - // TODO: this should be built into script - subscribe<CollisionEvent>([](const CollisionEvent&) -> bool { - return true; - }); + subscribe<CollisionEvent>([this](const CollisionEvent& ev) -> bool { + return this->on_collision(ev); + }); + } + void update() { + // Retrieve component from the same GameObject this script is on } }; @@ -68,10 +84,10 @@ public: .offset = {0,0}, }); // Create a box with an inner size of 10x10 units - world.add_component<BoxCollider>(Vector2{0, -100}, 100, 100); // Top - world.add_component<BoxCollider>(Vector2{0, 100}, 100, 100); // Bottom - world.add_component<BoxCollider>(Vector2{-100, 0}, 100, 100); // Left - world.add_component<BoxCollider>(Vector2{100, 0}, 100, 100); // right + world.add_component<BoxCollider>(vec2{0, -100}, 100, 100); // Top + world.add_component<BoxCollider>(vec2{0, 100}, 100, 100); // Bottom + world.add_component<BoxCollider>(vec2{-100, 0}, 100, 100); // Left + world.add_component<BoxCollider>(vec2{100, 0}, 100, 100); // right game_object1.add_component<Rigidbody>(Rigidbody::Data{ .mass = 1, @@ -84,7 +100,7 @@ public: .elastisity = 1, .offset = {0,0}, }); - game_object1.add_component<BoxCollider>(Vector2{0, 0}, 10, 10); + game_object1.add_component<BoxCollider>(vec2{0, 0}, 10, 10); BehaviorScript & script_object1 = game_object1.add_component<BehaviorScript>().set_script<CollisionHandler>(1); script_object1_ref = static_cast<CollisionHandler*>(script_object1.script.get()); ASSERT_NE(script_object1_ref, nullptr); @@ -100,7 +116,7 @@ public: .elastisity = 1, .offset = {0,0}, }); - game_object2.add_component<BoxCollider>(Vector2{0, 0}, 10, 10); + game_object2.add_component<BoxCollider>(vec2{0, 0}, 10, 10); BehaviorScript & script_object2 = game_object2.add_component<BehaviorScript>().set_script<CollisionHandler>(2); script_object2_ref = static_cast<CollisionHandler*>(script_object2.script.get()); ASSERT_NE(script_object2_ref, nullptr); @@ -110,170 +126,170 @@ public: } }; -// TEST_F(CollisionTest, collision_example) { -// bool collision_happend = false; -// script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 1); -// }; -// script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 2); -// }; -// EXPECT_FALSE(collision_happend); -// collision_sys.update(); -// EXPECT_FALSE(collision_happend); -// } +TEST_F(CollisionTest, collision_example) { + bool collision_happend = false; + script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 1); + }; + script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 2); + }; + EXPECT_FALSE(collision_happend); + collision_sys.update(); + EXPECT_FALSE(collision_happend); +} -// TEST_F(CollisionTest, collision_box_box_dynamic_both_no_velocity) { -// bool collision_happend = false; -// script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 1); -// EXPECT_EQ(ev.info.move_back_value.x, 10); -// EXPECT_EQ(ev.info.move_back_value.y, 10); -// EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::BOTH); -// }; -// script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 2); -// EXPECT_EQ(ev.info.move_back_value.x, 10); -// EXPECT_EQ(ev.info.move_back_value.y, 10); -// EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::BOTH); -// }; -// EXPECT_FALSE(collision_happend); -// Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); -// tf.position = {50,30}; -// collision_sys.update(); -// EXPECT_TRUE(collision_happend); -// } +TEST_F(CollisionTest, collision_box_box_dynamic_both_no_velocity) { + bool collision_happend = false; + script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 1); + EXPECT_EQ(ev.info.move_back_value.x, 10); + EXPECT_EQ(ev.info.move_back_value.y, 10); + EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::BOTH); + }; + script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 2); + EXPECT_EQ(ev.info.move_back_value.x, 10); + EXPECT_EQ(ev.info.move_back_value.y, 10); + EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::BOTH); + }; + EXPECT_FALSE(collision_happend); + Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); + tf.position = {50,30}; + collision_sys.update(); + EXPECT_TRUE(collision_happend); +} -// TEST_F(CollisionTest, collision_box_box_dynamic_x_direction_no_velocity) { -// bool collision_happend = false; -// script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 1); -// EXPECT_EQ(ev.info.move_back_value.x, -5); -// EXPECT_EQ(ev.info.move_back_value.y, 0); -// EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::X_DIRECTION); -// }; -// script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 2); -// EXPECT_EQ(ev.info.move_back_value.x, 5); -// EXPECT_EQ(ev.info.move_back_value.y, 0); -// EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::X_DIRECTION); -// }; -// EXPECT_FALSE(collision_happend); -// Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); -// tf.position = {45,30}; -// collision_sys.update(); -// EXPECT_TRUE(collision_happend); -// } +TEST_F(CollisionTest, collision_box_box_dynamic_x_direction_no_velocity) { + bool collision_happend = false; + script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 1); + EXPECT_EQ(ev.info.move_back_value.x, -5); + EXPECT_EQ(ev.info.move_back_value.y, 0); + EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::X_DIRECTION); + }; + script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 2); + EXPECT_EQ(ev.info.move_back_value.x, 5); + EXPECT_EQ(ev.info.move_back_value.y, 0); + EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::X_DIRECTION); + }; + EXPECT_FALSE(collision_happend); + Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); + tf.position = {45,30}; + collision_sys.update(); + EXPECT_TRUE(collision_happend); +} -// TEST_F(CollisionTest, collision_box_box_dynamic_y_direction_no_velocity) { -// bool collision_happend = false; -// script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 1); -// EXPECT_EQ(ev.info.move_back_value.x, 0); -// EXPECT_EQ(ev.info.move_back_value.y, -5); -// EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::Y_DIRECTION); -// }; -// script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 2); -// EXPECT_EQ(ev.info.move_back_value.x, 0); -// EXPECT_EQ(ev.info.move_back_value.y, 5); -// EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::Y_DIRECTION); -// }; -// EXPECT_FALSE(collision_happend); -// Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); -// tf.position = {50,25}; -// collision_sys.update(); -// EXPECT_TRUE(collision_happend); -// } +TEST_F(CollisionTest, collision_box_box_dynamic_y_direction_no_velocity) { + bool collision_happend = false; + script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 1); + EXPECT_EQ(ev.info.move_back_value.x, 0); + EXPECT_EQ(ev.info.move_back_value.y, -5); + EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::Y_DIRECTION); + }; + script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 2); + EXPECT_EQ(ev.info.move_back_value.x, 0); + EXPECT_EQ(ev.info.move_back_value.y, 5); + EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::Y_DIRECTION); + }; + EXPECT_FALSE(collision_happend); + Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); + tf.position = {50,25}; + collision_sys.update(); + EXPECT_TRUE(collision_happend); +} -// TEST_F(CollisionTest, collision_box_box_dynamic_both) { -// bool collision_happend = false; -// script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 1); -// EXPECT_EQ(ev.info.move_back_value.x, 10); -// EXPECT_EQ(ev.info.move_back_value.y, 10); -// EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::BOTH); -// }; -// script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 2); -// EXPECT_EQ(ev.info.move_back_value.x, 10); -// EXPECT_EQ(ev.info.move_back_value.y, 10); -// EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::BOTH); -// }; -// EXPECT_FALSE(collision_happend); -// Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); -// tf.position = {50,30}; -// Rigidbody & rg1 = this->mgr.get_components_by_id<Rigidbody>(1).front().get(); -// rg1.data.linear_velocity = {10,10}; -// Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get(); -// rg2.data.linear_velocity = {10,10}; -// collision_sys.update(); -// EXPECT_TRUE(collision_happend); -// } +TEST_F(CollisionTest, collision_box_box_dynamic_both) { + bool collision_happend = false; + script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 1); + EXPECT_EQ(ev.info.move_back_value.x, 10); + EXPECT_EQ(ev.info.move_back_value.y, 10); + EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::BOTH); + }; + script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 2); + EXPECT_EQ(ev.info.move_back_value.x, 10); + EXPECT_EQ(ev.info.move_back_value.y, 10); + EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::BOTH); + }; + EXPECT_FALSE(collision_happend); + Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); + tf.position = {50,30}; + Rigidbody & rg1 = this->mgr.get_components_by_id<Rigidbody>(1).front().get(); + rg1.data.linear_velocity = {10,10}; + Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get(); + rg2.data.linear_velocity = {10,10}; + collision_sys.update(); + EXPECT_TRUE(collision_happend); +} -// TEST_F(CollisionTest, collision_box_box_dynamic_x_direction) { -// bool collision_happend = false; -// script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 1); -// EXPECT_EQ(ev.info.move_back_value.x, -5); -// EXPECT_EQ(ev.info.move_back_value.y, -5); -// EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::X_DIRECTION); -// }; -// script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 2); -// EXPECT_EQ(ev.info.move_back_value.x, 5); -// EXPECT_EQ(ev.info.move_back_value.y, 5); -// EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::X_DIRECTION); -// }; -// EXPECT_FALSE(collision_happend); -// Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); -// tf.position = {45,30}; -// Rigidbody & rg1 = this->mgr.get_components_by_id<Rigidbody>(1).front().get(); -// rg1.data.linear_velocity = {10,10}; -// Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get(); -// rg2.data.linear_velocity = {10,10}; -// collision_sys.update(); -// EXPECT_TRUE(collision_happend); -// } +TEST_F(CollisionTest, collision_box_box_dynamic_x_direction) { + bool collision_happend = false; + script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 1); + EXPECT_EQ(ev.info.move_back_value.x, -5); + EXPECT_EQ(ev.info.move_back_value.y, -5); + EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::X_DIRECTION); + }; + script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 2); + EXPECT_EQ(ev.info.move_back_value.x, 5); + EXPECT_EQ(ev.info.move_back_value.y, 5); + EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::X_DIRECTION); + }; + EXPECT_FALSE(collision_happend); + Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); + tf.position = {45,30}; + Rigidbody & rg1 = this->mgr.get_components_by_id<Rigidbody>(1).front().get(); + rg1.data.linear_velocity = {10,10}; + Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get(); + rg2.data.linear_velocity = {10,10}; + collision_sys.update(); + EXPECT_TRUE(collision_happend); +} -// TEST_F(CollisionTest, collision_box_box_dynamic_y_direction) { -// bool collision_happend = false; -// script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 1); -// EXPECT_EQ(ev.info.move_back_value.x, -5); -// EXPECT_EQ(ev.info.move_back_value.y, -5); -// EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::Y_DIRECTION); -// }; -// script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { -// collision_happend = true; -// EXPECT_EQ(ev.info.first.collider.game_object_id, 2); -// EXPECT_EQ(ev.info.move_back_value.x, 5); -// EXPECT_EQ(ev.info.move_back_value.y, 5); -// EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::Y_DIRECTION); -// }; -// EXPECT_FALSE(collision_happend); -// Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); -// tf.position = {50,25}; -// Rigidbody & rg1 = this->mgr.get_components_by_id<Rigidbody>(1).front().get(); -// rg1.data.linear_velocity = {10,10}; -// Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get(); -// rg2.data.linear_velocity = {10,10}; -// collision_sys.update(); -// EXPECT_TRUE(collision_happend); -// } +TEST_F(CollisionTest, collision_box_box_dynamic_y_direction) { + bool collision_happend = false; + script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 1); + EXPECT_EQ(ev.info.move_back_value.x, -5); + EXPECT_EQ(ev.info.move_back_value.y, -5); + EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::Y_DIRECTION); + }; + script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { + collision_happend = true; + EXPECT_EQ(ev.info.first.collider.game_object_id, 2); + EXPECT_EQ(ev.info.move_back_value.x, 5); + EXPECT_EQ(ev.info.move_back_value.y, 5); + EXPECT_EQ(ev.info.move_back_direction, crepe::CollisionSystem::Direction::Y_DIRECTION); + }; + EXPECT_FALSE(collision_happend); + Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); + tf.position = {50,25}; + Rigidbody & rg1 = this->mgr.get_components_by_id<Rigidbody>(1).front().get(); + rg1.data.linear_velocity = {10,10}; + Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get(); + rg2.data.linear_velocity = {10,10}; + collision_sys.update(); + EXPECT_TRUE(collision_happend); +} TEST_F(CollisionTest, collision_box_box_static_both) { |