diff options
Diffstat (limited to 'src/crepe/system/CollisionSystem.h')
-rw-r--r-- | src/crepe/system/CollisionSystem.h | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index a31ac48..cfa599e 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -5,6 +5,7 @@ #include "api/Transform.h" #include "api/BoxCollider.h" #include "api/CircleCollider.h" +#include "api/Vector2.h" #include <tuple> #include <vector> #include <variant> @@ -19,29 +20,35 @@ private: struct CollidedInfoStor { //! Store either BoxCollider or CircleCollider collider_stor collider; - Transform transform; - Rigidbody rigidbody; // Rigidbody data + Transform& transform; + Rigidbody& rigidbody; // Rigidbody data }; public: - CollisionSystem(); - void update(); -private: - void call_collision_handler(const CollidedInfoStor& data1,const CollidedInfoStor& data2); - std::vector<std::pair<CollidedInfoStor,CollidedInfoStor>> check_collisions(const std::vector<std::reference_wrapper<BoxCollider>>& boxcolliders, const std::vector<std::reference_wrapper<CircleCollider>>& circlecolliders); - bool check_box_box_collision(const BoxCollider& box1, const BoxCollider& box2, const Transform& transform1, const Transform& transform2, const Rigidbody& rigidbody1, const Rigidbody& rigidbody2); - bool check_box_circle_collision(const BoxCollider& box1, const CircleCollider& circle2, const Transform& transform1, const Transform& transform2, const Rigidbody& rigidbody1, const Rigidbody& rigidbody2); - bool check_circle_circle_collision(const CircleCollider& circle1, const CircleCollider& circle2, const Transform& transform1, const Transform& transform2, const Rigidbody& rigidbody1, const Rigidbody& rigidbody2); - Vector2 current_position(const Collider& collider, const Transform& transform, const Rigidbody& rigidbody); -public: struct ColliderInfo { - Collider collider; - Transform transform; - Rigidbody rigidbody; + const Collider& collider; + Transform& transform; + Rigidbody& rigidbody; }; struct CollisionInfo{ ColliderInfo first; ColliderInfo second; + Vector2 move_back_value; }; +public: + CollisionSystem(); + void update(); +private: //handling + void call_collision_handler(CollidedInfoStor& data1,CollidedInfoStor& data2); + void static_collision_handler(CollisionInfo& info); +private: //detection + + std::vector<std::pair<CollidedInfoStor,CollidedInfoStor>> check_collisions(const std::vector<std::reference_wrapper<BoxCollider>>& boxcolliders, const std::vector<std::reference_wrapper<CircleCollider>>& circlecolliders); + bool check_box_box_collision(const BoxCollider& box1, const BoxCollider& box2, const Transform& transform1, const Transform& transform2, const Rigidbody& rigidbody1, const Rigidbody& rigidbody2); + bool check_box_circle_collision(const BoxCollider& box1, const CircleCollider& circle2, const Transform& transform1, const Transform& transform2, const Rigidbody& rigidbody1, const Rigidbody& rigidbody2); + bool check_circle_circle_collision(const CircleCollider& circle1, const CircleCollider& circle2, const Transform& transform1, const Transform& transform2, const Rigidbody& rigidbody1, const Rigidbody& rigidbody2); + Vector2 current_position(const Collider& collider, const Transform& transform, const Rigidbody& rigidbody); + + }; } // namespace crepe |