diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2024-12-19 08:36:17 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2024-12-19 08:36:17 +0100 |
commit | 714edd69d53a6243e9a2b81f62d309c96b71dd8d (patch) | |
tree | 12492c1f89ac4f5d38292e671c48f78eab95879e | |
parent | 5a087d8a01d00a737ae602370c2c3514294da88d (diff) |
bug fix and doxygen fix
-rw-r--r-- | src/crepe/system/CollisionSystem.cpp | 4 | ||||
-rw-r--r-- | src/crepe/system/CollisionSystem.h | 66 | ||||
-rw-r--r-- | src/example/game.cpp | 4 |
3 files changed, 38 insertions, 36 deletions
diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 75e914d..719713c 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -407,9 +407,9 @@ CollisionSystem::CollisionInfo CollisionSystem::get_collision_info(const Collisi // Below is for collision handling void CollisionSystem::determine_collision_handler(const CollisionInfo & info) { Rigidbody::BodyType self_type = info.self.rigidbody.data.body_type; - Rigidbody::BodyType other_type = info.self.rigidbody.data.body_type; + Rigidbody::BodyType other_type = info.other.rigidbody.data.body_type; bool self_kinematic = info.self.rigidbody.data.kinematic_collision; - bool other_kinematic = info.self.rigidbody.data.kinematic_collision; + bool other_kinematic = info.other.rigidbody.data.kinematic_collision; // Inverted collision info CollisionInfo inverted = -info; // If both objects are static skip handle call collision script diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index 7792e50..13ce8f0 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -34,18 +34,19 @@ private: BOTH }; public: - /** - * \brief Structure representing detailed collision information between two colliders. - * - * Includes information about the colliding objects and the resolution data for handling the collision. - */ - + + //! Structure representing components of the collider struct ColliderInfo { Transform & transform; Rigidbody & rigidbody; Metadata & metadata; }; + /** + * \brief Structure representing detailed collision information between two colliders. + * + * Includes information about the colliding objects and the resolution data for handling the collision. + */ struct CollisionInfo { ColliderInfo self; ColliderInfo other; @@ -86,12 +87,14 @@ private: Direction resolution_direction = Direction::NONE; }; + //! Structure of collider with addtitional components struct BoxColliderInternal { BoxCollider & collider; Transform & transform; Rigidbody & rigidbody; }; + //! Structure of collider with addtitional components struct CircleColliderInternal { CircleCollider & collider; Transform & transform; @@ -123,9 +126,19 @@ private: * \param data1 Collision data for the first collider. * \param data2 Collision data for the second collider. */ - CollisionInfo get_collision_info(const CollisionInternal & this_data, const CollisionInternal & other_data) const; //done + CollisionInfo get_collision_info(const CollisionInternal & data1, const CollisionInternal & data2) const; + /** + * \brief Corrects the resolution of the collision + * + * This function corrects the resolution by fixing the x or y if it is empty. + * Besides this with the input of the resolution the direction is saved before correction. + * + * \param resolution resolution vector that needs to be corrected + * \param rigidbody rigidbody data used to correct resolution + * \return Direction of resolution + */ Direction resolution_correction(vec2 & resolution,const Rigidbody::Data & rigidbody); @@ -136,7 +149,7 @@ private: * * \param info Collision information containing data about both colliders. */ - void determine_collision_handler(const CollisionInfo & info); //done + void determine_collision_handler(const CollisionInfo & info); /** * \brief Calls both collision script @@ -144,6 +157,7 @@ private: * Calls both collision script to let user add additonal handeling or handle full collision. * * \param info Collision information containing data about both colliders. + * \param info_inverted Collision information containing data about both colliders in opposite order. */ void call_collision_events(const CollisionInfo & info, const CollisionInfo & info_inverted); @@ -154,7 +168,7 @@ private: * * \param info Collision information containing data about both colliders. */ - void static_collision_handler(const CollisionInfo & info); //done + void static_collision_handler(const CollisionInfo & info); /** * \brief Handles collisions involving dynamic objects. @@ -163,7 +177,7 @@ private: * * \param info Collision information containing data about both colliders. */ - void dynamic_collision_handler(const CollisionInfo & info); //done + void dynamic_collision_handler(const CollisionInfo & info); private: /** @@ -175,7 +189,7 @@ private: * \return A list of collision pairs with their associated data. */ std::vector<std::pair<CollisionInternal, CollisionInternal>> - gather_collisions(std::vector<CollisionInternal> & colliders); //done + gather_collisions(std::vector<CollisionInternal> & colliders); /** * \brief Checks if the settings allow collision @@ -207,39 +221,27 @@ private: /** * \brief Detects collisions between two BoxColliders. * - * \param box1 The first BoxCollider. - * \param box2 The second BoxCollider. - * \param transform1 Transform of the first object. - * \param transform2 Transform of the second object. - * \param rigidbody1 Rigidbody of the first object. - * \param rigidbody2 Rigidbody of the second object. - * \return True if a collision is detected, otherwise false. + * \param box1 Information about the first BoxCollider. + * \param box2 Information about the second BoxCollider. + * \return returns resolution vector if collide otherwise returns {-1,-1} */ vec2 get_box_box_detection(const BoxColliderInternal & box1, const BoxColliderInternal & box2) const; /** * \brief Check collision for box on circle collider * - * \param box1 The BoxCollider - * \param circle2 The CircleCollider - * \param transform1 Transform of the first object. - * \param transform2 Transform of the second object. - * \param rigidbody1 Rigidbody of the first object. - * \param rigidbody2 Rigidbody of the second object. - * \return True if a collision is detected, otherwise false. + * \param box1 Information about the BoxCollider. + * \param circle2 Information about the circleCollider. + * \return returns resolution vector if collide otherwise returns {-1,-1} */ vec2 get_box_circle_detection(const BoxColliderInternal & box1, const CircleColliderInternal & circle2) const; /** * \brief Check collision for circle on circle collider * - * \param circle1 First CircleCollider - * \param circle2 Second CircleCollider - * \param transform1 Transform of the first object. - * \param transform2 Transform of the second object. - * \param rigidbody1 Rigidbody of the first object. - * \param rigidbody2 Rigidbody of the second object. - * \return True if a collision is detected, otherwise false. + * \param circle1 Information about the first circleCollider. + * \param circle2 Information about the second circleCollider. + * \return returns resolution vector if collide otherwise returns {-1,-1} * * \return status of collision */ diff --git a/src/example/game.cpp b/src/example/game.cpp index 01e55d5..f931878 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -206,7 +206,7 @@ public: vec2{world_collider, world_collider}, vec2{0, screen_size_height / 2 + world_collider / 2}); // Bottom world.add_component<BoxCollider>( - vec2{world_collider, world_collider},git stauts + vec2{world_collider, world_collider}, vec2{0 - (screen_size_width / 2 + world_collider / 2), 0}); // Left world.add_component<BoxCollider>( vec2{world_collider, world_collider}, @@ -256,7 +256,7 @@ public: "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1); game_object2.add_component<Rigidbody>(Rigidbody::Data{ .mass = 1, - .gravity_scale = 1, + .gravity_scale = 0, .body_type = Rigidbody::BodyType::DYNAMIC, .linear_velocity = {0, 0}, .constraints = {0, 0, 0}, |