aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-12-02 13:18:36 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-12-02 13:18:36 +0100
commitad504dbf5152b663c3b503b04012efe092120b6d (patch)
tree1e0a2f9e1b9815bfa30f7cf24a7858f4c04119c6 /src/crepe
parent09c4c1485ab797dc5f6f850b96262e2f7bbbd1ec (diff)
added some comments and const
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/api/BoxCollider.cpp2
-rw-r--r--src/crepe/api/BoxCollider.h6
-rw-r--r--src/crepe/api/CircleCollider.cpp2
-rw-r--r--src/crepe/api/CircleCollider.h4
-rw-r--r--src/crepe/system/CollisionSystem.cpp12
-rw-r--r--src/crepe/system/CollisionSystem.h2
6 files changed, 18 insertions, 10 deletions
diff --git a/src/crepe/api/BoxCollider.cpp b/src/crepe/api/BoxCollider.cpp
index 4c767c8..6034837 100644
--- a/src/crepe/api/BoxCollider.cpp
+++ b/src/crepe/api/BoxCollider.cpp
@@ -4,4 +4,4 @@
using namespace crepe;
-BoxCollider::BoxCollider(game_object_id_t game_object_id,vec2 offset, double width, double height) : Collider(game_object_id,offset), width(width), height(height) {}
+BoxCollider::BoxCollider(game_object_id_t game_object_id,vec2 offset, float width, float height) : Collider(game_object_id,offset), width(width), height(height) {}
diff --git a/src/crepe/api/BoxCollider.h b/src/crepe/api/BoxCollider.h
index 6135954..2ce1ee8 100644
--- a/src/crepe/api/BoxCollider.h
+++ b/src/crepe/api/BoxCollider.h
@@ -12,13 +12,13 @@ namespace crepe {
*/
class BoxCollider : public Collider {
public:
- BoxCollider(game_object_id_t game_object_id,vec2 offset, double width, double height);
+ BoxCollider(game_object_id_t game_object_id,vec2 offset, float width, float height);
//! Width of box collider
- double width;
+ float width;
//! Height of box collider
- double height;
+ float height;
};
} // namespace crepe
diff --git a/src/crepe/api/CircleCollider.cpp b/src/crepe/api/CircleCollider.cpp
index 43de991..497ebba 100644
--- a/src/crepe/api/CircleCollider.cpp
+++ b/src/crepe/api/CircleCollider.cpp
@@ -3,4 +3,4 @@
using namespace crepe;
-CircleCollider::CircleCollider(game_object_id_t game_object_id,vec2 offset, int radius) : Collider(game_object_id,offset), radius(radius) {}
+CircleCollider::CircleCollider(game_object_id_t game_object_id,vec2 offset, float radius) : Collider(game_object_id,offset), radius(radius) {}
diff --git a/src/crepe/api/CircleCollider.h b/src/crepe/api/CircleCollider.h
index 843547f..c61f027 100644
--- a/src/crepe/api/CircleCollider.h
+++ b/src/crepe/api/CircleCollider.h
@@ -14,10 +14,10 @@ namespace crepe {
class CircleCollider : public Collider {
public:
- CircleCollider(game_object_id_t game_object_id,vec2 offset, int radius);
+ CircleCollider(game_object_id_t game_object_id,vec2 offset, float radius);
//! Radius of the circle collider.
- double radius;
+ float radius;
};
} // namespace crepe
diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp
index 0b83bce..70fe855 100644
--- a/src/crepe/system/CollisionSystem.cpp
+++ b/src/crepe/system/CollisionSystem.cpp
@@ -105,6 +105,7 @@ std::pair<vec2,CollisionSystem::Direction> CollisionSystem::collision_handler(Co
vec2 collider_pos1 = current_position(collider1.offset, data1.transform, data1.rigidbody);
vec2 collider_pos2 = current_position(collider2.offset, data2.transform, data2.rigidbody);
resolution = box_box_resolution(collider1,collider2,collider_pos1,collider_pos2);
+ break;
}
case CollisionInternalType::BOX_CIRCLE: {
const BoxCollider & collider1 = std::get<std::reference_wrapper<BoxCollider>>(data1.collider);
@@ -112,7 +113,7 @@ std::pair<vec2,CollisionSystem::Direction> CollisionSystem::collision_handler(Co
vec2 collider_pos1 = current_position(collider1.offset, data1.transform, data1.rigidbody);
vec2 collider_pos2 = current_position(collider2.offset, data2.transform, data2.rigidbody);
resolution = circle_box_resolution(collider2,collider1,collider_pos2,collider_pos1);
-
+ break;
}
case CollisionInternalType::CIRCLE_CIRCLE: {
const CircleCollider & collider1 = std::get<std::reference_wrapper<CircleCollider>>(data1.collider);
@@ -120,6 +121,7 @@ std::pair<vec2,CollisionSystem::Direction> CollisionSystem::collision_handler(Co
vec2 collider_pos1 = current_position(collider1.offset, data1.transform, data1.rigidbody);
vec2 collider_pos2 = current_position(collider2.offset, data2.transform, data2.rigidbody);
resolution = circle_circle_resolution(collider1,collider2,collider_pos1,collider_pos2);
+ break;
}
case CollisionInternalType::CIRCLE_BOX: {
const CircleCollider & collider1 = std::get<std::reference_wrapper<CircleCollider>>(data1.collider);
@@ -127,6 +129,7 @@ std::pair<vec2,CollisionSystem::Direction> CollisionSystem::collision_handler(Co
vec2 collider_pos1 = current_position(collider1.offset, data1.transform, data1.rigidbody);
vec2 collider_pos2 = current_position(collider2.offset, data2.transform, data2.rigidbody);
resolution = circle_box_resolution(collider1,collider2,collider_pos1,collider_pos2);
+ break;
}
}
@@ -282,18 +285,23 @@ std::vector<std::pair<CollisionSystem::CollisionInternal,CollisionSystem::Collis
// Quadtree code
// Quadtree is placed over the input vector
+ // Return data of collided colliders which are variants
std::vector<std::pair<CollisionInternal,CollisionInternal>> collisions_ret;
+ //using visit to visit the variant to access the active and id.
for (size_t i = 0; i < colliders.size(); ++i) {
std::visit([&](auto& inner_collider_ref) {
+ // Return from visit if collider or components are not active
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;
for (size_t j = i + 1; j < colliders.size(); ++j) {
std::visit([&](auto& outer_collider_ref) {
+ // Return from visit if collider or components are not active and if they have the same id.
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(outer_collider_ref.get().game_object_id);
if (!outer_components) return;
+ // Get collision type form variant colliders
CollisionInternalType type = check_collider_type(colliders[i],colliders[j]);
if(!check_collision({
.collider = colliders[i],
@@ -336,7 +344,7 @@ CollisionSystem::get_active_transform_and_rigidbody(game_object_id_t game_object
return std::make_pair(std::ref(transform), std::ref(rigidbody));
}
-CollisionSystem::CollisionInternalType CollisionSystem::check_collider_type(const collider_variant& collider1,const collider_variant& collider2){
+CollisionSystem::CollisionInternalType CollisionSystem::check_collider_type(const collider_variant& collider1,const collider_variant& collider2) const{
if(std::holds_alternative<std::reference_wrapper<CircleCollider>>(collider1)){
if(std::holds_alternative<std::reference_wrapper<CircleCollider>>(collider2))
{
diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h
index 86b8b7a..fc91603 100644
--- a/src/crepe/system/CollisionSystem.h
+++ b/src/crepe/system/CollisionSystem.h
@@ -92,7 +92,7 @@ private:
* \param collider2 Second collider variant (BoxCollider or CircleCollider).
* \return The combined type of the two colliders.
*/
- CollisionInternalType check_collider_type(const collider_variant& collider1,const collider_variant& collider2);
+ CollisionInternalType check_collider_type(const collider_variant& collider1,const collider_variant& collider2) const;
/**
* \brief Calculates the current position of a collider.