From 15c4cf103c4da7808b7173581ead22ab7190632d Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Thu, 14 Nov 2024 18:49:17 +0100 Subject: updated test --- src/crepe/system/CollisionSystem.cpp | 3 +- src/test/CMakeLists.txt | 1 + src/test/CollisionTest.cpp | 107 ++++++++++++++--------------------- src/test/PhysicsTest.cpp | 1 + 4 files changed, 46 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index a6cf891..0d056a5 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -23,6 +23,7 @@ void CollisionSystem::update() { std::vector> boxcolliders = mgr.get_components_by_type(); std::vector> circlecolliders = mgr.get_components_by_type(); std::vector> collided = check_collisions(boxcolliders,circlecolliders); + std::cout << "DEBUG INFO" << std::endl; for (const auto& collision : collided) { std::cout << "Object " << collision.first << " collided with Object " << collision.second << std::endl; } @@ -206,4 +207,4 @@ Vector2 CollisionSystem::current_position(const Collider& collider, const Transf // Final positions considering scaling and rotation return(transform.position + Vector2(rotated_total_offset_x1, rotated_total_offset_y1)); -} \ No newline at end of file +} diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 0e4eaed..8618ae6 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -2,5 +2,6 @@ target_sources(test_main PUBLIC dummy.cpp # audio.cpp PhysicsTest.cpp + CollisionTest.cpp ) diff --git a/src/test/CollisionTest.cpp b/src/test/CollisionTest.cpp index 1dfe808..1c4c325 100644 --- a/src/test/CollisionTest.cpp +++ b/src/test/CollisionTest.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include using namespace std; @@ -17,70 +17,42 @@ class CollisionTest : public ::testing::Test { protected: GameObject * game_object1; GameObject * game_object2; - PhysicsSystem physics_system; + CollisionSystem collision_system; void SetUp() override { ComponentManager & mgr = ComponentManager::get_instance(); + mgr.delete_all_components(); std::vector> transforms = mgr.get_components_by_id(0); - if (transforms.empty()) { - double width,height,radius = 10; - // ob 1 - game_object1 = new GameObject(0, "", "", Vector2{0, 0}, 0, 0); - game_object1->add_component(Rigidbody::Data{ - .mass = 1, - .gravity_scale = 1, - .body_type = Rigidbody::BodyType::DYNAMIC, - .max_linear_velocity = Vector2{10, 10}, - .max_angular_velocity = 10, - .constraints = {0, 0}, - .use_gravity = true, - .bounce = false, - }); - - game_object1->add_component(Vector2{0,0},width,height); - game_object1->add_component(Vector2{0,0},radius); - //ob 2 - game_object2 = new GameObject(0, "", "", Vector2{0, 0}, 0, 0); - game_object2->add_component(Rigidbody::Data{ - .mass = 1, - .gravity_scale = 1, - .body_type = Rigidbody::BodyType::DYNAMIC, - .max_linear_velocity = Vector2{10, 10}, - .max_angular_velocity = 10, - .constraints = {0, 0}, - .use_gravity = true, - .bounce = false, - }); - game_object2->add_component(Vector2{0,0},width,height); - game_object2->add_component(Vector2{0,0},radius); - - } - for (int i = 0; i < 2; i ++) { - transforms = mgr.get_components_by_id(i); - Transform & transform = transforms.front().get(); - transform.position.x = 0.0; - transform.position.y = 0.0; - transform.rotation = 0.0; - std::vector> rigidbodies - = mgr.get_components_by_id(i); - Rigidbody & rigidbody = rigidbodies.front().get(); - rigidbody.data.angular_velocity = 0; - rigidbody.data.linear_velocity.x = 0; - rigidbody.data.linear_velocity.y = 0; - std::vector> boxcolliders - = mgr.get_components_by_id(i); - BoxCollider & box_collider = boxcolliders.front().get(); - box_collider.offset = {0,0}; - box_collider.width = 10; - box_collider.height = 10; - std::vector> circlecolliders - = mgr.get_components_by_id(i); - CircleCollider & circle_collider = circlecolliders.front().get(); - circle_collider.offset = {0,0}; - circle_collider.radius = 10; - } + // ob 1 + game_object1 = new GameObject(0, "", "", Vector2{0, 0}, 0, 0); + game_object1->add_component(Rigidbody::Data{ + .mass = 1, + .gravity_scale = 1, + .body_type = Rigidbody::BodyType::DYNAMIC, + .max_linear_velocity = Vector2{10, 10}, + .max_angular_velocity = 10, + .constraints = {0, 0, 0}, + .use_gravity = false, + .bounce = false, + }); + + game_object1->add_component(Vector2{0,0},10,10); + + //ob 2 + game_object2 = new GameObject(1, "", "", Vector2{50, 50}, 0, 0); + game_object2->add_component(Rigidbody::Data{ + .mass = 1, + .gravity_scale = 1, + .body_type = Rigidbody::BodyType::DYNAMIC, + .max_linear_velocity = Vector2{10, 10}, + .max_angular_velocity = 10, + .constraints = {0, 0, 0}, + .use_gravity = false, + .bounce = false, + }); + game_object2->add_component(Vector2{0,0},10,10); } }; @@ -89,12 +61,17 @@ TEST_F(CollisionTest, box_box_collision) { ComponentManager & mgr = ComponentManager::get_instance(); std::vector> transforms = mgr.get_components_by_id(0); - const Transform & transform = transforms.front().get(); + Transform & transform = transforms.front().get(); ASSERT_FALSE(transforms.empty()); - EXPECT_EQ(transform.position.y, 0); - physics_system.update(); - EXPECT_EQ(transform.position.y, 1); - physics_system.update(); - EXPECT_EQ(transform.position.y, 3); + transform.position = {39,50}; + collision_system.update(); + transform.position = {40,50}; + collision_system.update(); + transform.position = {41,50}; + collision_system.update(); + transform.position = {44,50}; + collision_system.update(); + transform.position = {50,50}; + collision_system.update(); } diff --git a/src/test/PhysicsTest.cpp b/src/test/PhysicsTest.cpp index 5385962..3332f74 100644 --- a/src/test/PhysicsTest.cpp +++ b/src/test/PhysicsTest.cpp @@ -16,6 +16,7 @@ protected: PhysicsSystem physics_system; void SetUp() override { ComponentManager & mgr = ComponentManager::get_instance(); + mgr.delete_all_components(); std::vector> transforms = mgr.get_components_by_id(0); if (transforms.empty()) { -- cgit v1.2.3