aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-12-19 17:50:12 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-12-19 17:50:12 +0100
commit2c4627673f48196e845fc1bcb7b62b3de72c7ab6 (patch)
treebf757a900c649f2a4ef4b56a63d9b6d9474f3e50 /src/crepe/system
parentfe396c458b38ee209dd4c1f3ba4d053bef20f57a (diff)
improved doxygen
Diffstat (limited to 'src/crepe/system')
-rw-r--r--src/crepe/system/CollisionSystem.cpp17
-rw-r--r--src/crepe/system/CollisionSystem.h41
2 files changed, 30 insertions, 28 deletions
diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp
index 6ed640a..3da8a50 100644
--- a/src/crepe/system/CollisionSystem.cpp
+++ b/src/crepe/system/CollisionSystem.cpp
@@ -167,7 +167,7 @@ bool CollisionSystem::detect_collision(CollisionInternal & self,CollisionInterna
.rigidbody = other.info.rigidbody
};
resolution = this->get_box_box_detection(BOX1, BOX2);
- if(resolution == vec2{-1,-1}) return false;
+ if(std::isnan(resolution.x) && std::isnan(resolution.y)) return false;
break;
}
@@ -183,7 +183,7 @@ bool CollisionSystem::detect_collision(CollisionInternal & self,CollisionInterna
.rigidbody = other.info.rigidbody
};
resolution = this->get_box_circle_detection(BOX1, CIRCLE2);
- if(resolution == vec2{-1,-1}) return false;
+ if(std::isnan(resolution.x) && std::isnan(resolution.y)) return false;
resolution = -resolution;
break;
}
@@ -199,7 +199,7 @@ bool CollisionSystem::detect_collision(CollisionInternal & self,CollisionInterna
.rigidbody = other.info.rigidbody
};
resolution = this->get_circle_circle_detection(CIRCLE1,CIRCLE2);
- if(resolution == vec2{-1,-1}) return false;
+ if(std::isnan(resolution.x) && std::isnan(resolution.y)) return false;
break;
}
case CollisionInternalType::CIRCLE_BOX: {
@@ -214,7 +214,7 @@ bool CollisionSystem::detect_collision(CollisionInternal & self,CollisionInterna
.rigidbody = other.info.rigidbody
};
resolution = this->get_box_circle_detection(BOX2, CIRCLE1);
- if(resolution == vec2{-1,-1}) return false;
+ if(std::isnan(resolution.x) && std::isnan(resolution.y)) return false;
break;
}
case CollisionInternalType::NONE:
@@ -228,7 +228,7 @@ bool CollisionSystem::detect_collision(CollisionInternal & self,CollisionInterna
}
vec2 CollisionSystem::get_box_box_detection(const BoxColliderInternal & box1, const BoxColliderInternal & box2) const {
- vec2 resolution;
+ vec2 resolution{std::nanf(""), std::nanf("")};
// Get current positions of colliders
vec2 pos1 = AbsolutePosition::get_position(box1.transform, box1.collider.offset);
vec2 pos2 = AbsolutePosition::get_position(box2.transform, box2.collider.offset);
@@ -266,9 +266,8 @@ vec2 CollisionSystem::get_box_box_detection(const BoxColliderInternal & box1, co
resolution.y = (delta.y > 0) ? -overlap_y : overlap_y;
}
}
- return resolution;
}
- return vec2{-1,-1};
+ return resolution;
}
vec2 CollisionSystem::get_box_circle_detection(const BoxColliderInternal & box, const CircleColliderInternal & circle) const {
@@ -312,7 +311,7 @@ vec2 CollisionSystem::get_box_circle_detection(const BoxColliderInternal & box,
return vec2{collision_normal * penetration_depth};
}
// No collision
- return vec2{-1,-1};
+ return vec2{std::nanf(""), std::nanf("")};
}
vec2 CollisionSystem::get_circle_circle_detection(const CircleColliderInternal & circle1, const CircleColliderInternal & circle2) const {
@@ -353,7 +352,7 @@ vec2 CollisionSystem::get_circle_circle_detection(const CircleColliderInternal &
return resolution;
}
// No collision
- return vec2{-1,-1};
+ return vec2{std::nanf(""), std::nanf("")};
}
CollisionSystem::Direction CollisionSystem::resolution_correction(vec2 & resolution,const Rigidbody::Data & rigidbody) {
diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h
index 13ce8f0..2e9901c 100644
--- a/src/crepe/system/CollisionSystem.h
+++ b/src/crepe/system/CollisionSystem.h
@@ -31,7 +31,7 @@ private:
//! Movement in the Y direction.
Y_DIRECTION,
//! Movement in both X and Y directions.
- BOTH
+ BOTH,
};
public:
@@ -87,19 +87,17 @@ 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;
- Rigidbody & rigidbody;
+ //! Structure of a collider with additional components
+ template <typename ColliderType>
+ struct ColliderInternal {
+ ColliderType& collider;
+ Transform& transform;
+ Rigidbody& rigidbody;
};
+ //! Predefined BoxColliderInternal. (System is only made for this type)
+ using BoxColliderInternal = ColliderInternal<BoxCollider>;
+ //! Predefined CircleColliderInternal. (System is only made for this type)
+ using CircleColliderInternal = ColliderInternal<CircleCollider>;
public:
//! Updates the collision system by checking for collisions between colliders and handling them.
@@ -119,9 +117,11 @@ private:
private:
/**
- * \brief Handles collision resolution between two colliders.
+ * \brief Converts internal collision data into user-accessible collision information.
*
- * Processes collision data and adjusts objects to resolve collisions and/or calls the user oncollision script function.
+ * This function processes collision data from two colliding entities and packages it
+ * into a structured format that is accessible for further use,
+ * such as resolving collisions and triggering user-defined collision scripts.
*
* \param data1 Collision data for the first collider.
* \param data2 Collision data for the second collider.
@@ -130,14 +130,17 @@ private:
/**
- * \brief Corrects the resolution of the collision
+ * \brief Corrects the collision resolution vector and determines its direction.
*
- * 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.
+ * This function adjusts the provided resolution vector based on the
+ * rigidbody's linear velocity to ensure consistent collision correction. If the resolution
+ * vector has only one non-zero component (either x or y), the missing component is computed
+ * based on the rigidbody's velocity. If both components are non-zero, it indicates a corner
+ * collision. The function also identifies the direction of the resolution and returns it.
*
* \param resolution resolution vector that needs to be corrected
* \param rigidbody rigidbody data used to correct resolution
- * \return Direction of resolution
+ * \return A Direction indicating the resolution direction
*/
Direction resolution_correction(vec2 & resolution,const Rigidbody::Data & rigidbody);