diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2024-11-14 18:49:17 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2024-11-14 18:49:17 +0100 |
commit | 15c4cf103c4da7808b7173581ead22ab7190632d (patch) | |
tree | 85d1a3a78325661e41b2e50607e735982756fbb4 | |
parent | 5ee56897e28dea05853e463e061d7f21cb9771a3 (diff) |
updated test
-rw-r--r-- | src/crepe/system/CollisionSystem.cpp | 3 | ||||
-rw-r--r-- | src/test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/test/CollisionTest.cpp | 107 | ||||
-rw-r--r-- | src/test/PhysicsTest.cpp | 1 |
4 files changed, 46 insertions, 66 deletions
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<std::reference_wrapper<BoxCollider>> boxcolliders = mgr.get_components_by_type<BoxCollider>(); std::vector<std::reference_wrapper<CircleCollider>> circlecolliders = mgr.get_components_by_type<CircleCollider>(); std::vector<std::pair<int, int>> 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 <crepe/api/GameObject.h> #include <crepe/api/Rigidbody.h> #include <crepe/api/Transform.h> -#include <crepe/system/PhysicsSystem.h> +#include <crepe/system/CollisionSystem.h> #include <gtest/gtest.h> 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<std::reference_wrapper<Transform>> transforms = mgr.get_components_by_id<Transform>(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>(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<BoxCollider>(Vector2{0,0},width,height); - game_object1->add_component<CircleCollider>(Vector2{0,0},radius); - //ob 2 - game_object2 = new GameObject(0, "", "", Vector2{0, 0}, 0, 0); - game_object2->add_component<Rigidbody>(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<BoxCollider>(Vector2{0,0},width,height); - game_object2->add_component<CircleCollider>(Vector2{0,0},radius); - - } - for (int i = 0; i < 2; i ++) { - transforms = mgr.get_components_by_id<Transform>(i); - Transform & transform = transforms.front().get(); - transform.position.x = 0.0; - transform.position.y = 0.0; - transform.rotation = 0.0; - std::vector<std::reference_wrapper<Rigidbody>> rigidbodies - = mgr.get_components_by_id<Rigidbody>(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<std::reference_wrapper<BoxCollider>> boxcolliders - = mgr.get_components_by_id<BoxCollider>(i); - BoxCollider & box_collider = boxcolliders.front().get(); - box_collider.offset = {0,0}; - box_collider.width = 10; - box_collider.height = 10; - std::vector<std::reference_wrapper<CircleCollider>> circlecolliders - = mgr.get_components_by_id<CircleCollider>(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>(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<BoxCollider>(Vector2{0,0},10,10); + + //ob 2 + game_object2 = new GameObject(1, "", "", Vector2{50, 50}, 0, 0); + game_object2->add_component<Rigidbody>(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<BoxCollider>(Vector2{0,0},10,10); } }; @@ -89,12 +61,17 @@ TEST_F(CollisionTest, box_box_collision) { ComponentManager & mgr = ComponentManager::get_instance(); std::vector<std::reference_wrapper<Transform>> transforms = mgr.get_components_by_id<Transform>(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<std::reference_wrapper<Transform>> transforms = mgr.get_components_by_id<Transform>(0); if (transforms.empty()) { |