aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-12-19 18:30:33 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-12-19 18:30:33 +0100
commit3a5d4c67dba2edd54a5c888432a8d794d152255e (patch)
tree43fec0bd1b40b4ca297639c150e19f67bf11061d /src/crepe/system
parent2c4627673f48196e845fc1bcb7b62b3de72c7ab6 (diff)
improved doxygen comments
Diffstat (limited to 'src/crepe/system')
-rw-r--r--src/crepe/system/CollisionSystem.cpp15
-rw-r--r--src/crepe/system/CollisionSystem.h51
2 files changed, 45 insertions, 21 deletions
diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp
index 3da8a50..a8e6181 100644
--- a/src/crepe/system/CollisionSystem.cpp
+++ b/src/crepe/system/CollisionSystem.cpp
@@ -250,6 +250,7 @@ vec2 CollisionSystem::get_box_box_detection(const BoxColliderInternal & box1, co
&& pos1.y + half_height1 > pos2.y - half_height2
&& pos1.y - half_height1 < pos2.y + half_height2)
{
+ resolution = {0,0};
float overlap_x = (half_width1 + half_width2) - std::abs(delta.x);
float overlap_y = (half_height1 + half_height2) - std::abs(delta.y);
if (overlap_x > 0 && overlap_y > 0) {
@@ -404,7 +405,6 @@ CollisionSystem::CollisionInfo CollisionSystem::get_collision_info(const Collisi
return collision_info;
}
-// 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.other.rigidbody.data.body_type;
@@ -425,7 +425,7 @@ void CollisionSystem::determine_collision_handler(const CollisionInfo & info) {
// Handle collision
if (static_collision || kinematic_collision) this->static_collision_handler(inverted);
// Call scripts
- this->call_collision_events(inverted, info);
+ this->call_collision_events(inverted);
return;
}
@@ -436,7 +436,7 @@ void CollisionSystem::determine_collision_handler(const CollisionInfo & info) {
// Handle collision
if (static_collision || kinematic_collision) this->static_collision_handler(info);
// Call scripts
- this->call_collision_events(info, inverted);
+ this->call_collision_events(info);
return;
}
@@ -444,7 +444,7 @@ void CollisionSystem::determine_collision_handler(const CollisionInfo & info) {
// Handle collision
this->dynamic_collision_handler(info);
// Call scripts
- this->call_collision_events(info, inverted);
+ this->call_collision_events(info);
}
void CollisionSystem::static_collision_handler(const CollisionInfo & info) {
@@ -565,14 +565,13 @@ void CollisionSystem::dynamic_collision_handler(const CollisionInfo & info) {
}
}
-void CollisionSystem::call_collision_events(const CollisionInfo & info,
- const CollisionInfo & info_inverted) {
+void CollisionSystem::call_collision_events(const CollisionInfo & info) {
CollisionEvent data(info);
- CollisionEvent data_inverted(info_inverted);
+ CollisionEvent data_inverted(-info);
EventManager & emgr = this->mediator.event_manager;
emgr.trigger_event<CollisionEvent>(data, info.self.transform.game_object_id);
emgr.trigger_event<CollisionEvent>(data_inverted,
- info_inverted.self.transform.game_object_id);
+ -info.self.transform.game_object_id);
}
diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h
index 2e9901c..30340b5 100644
--- a/src/crepe/system/CollisionSystem.h
+++ b/src/crepe/system/CollisionSystem.h
@@ -146,9 +146,12 @@ private:
/**
- * \brief Determines the appropriate collision handler for a collision.
+ * \brief Determines the appropriate collision handler for a given collision event.
*
- * Decides the correct resolution process based on the dynamic or static nature of the colliders involved.
+ * This function identifies the correct collision resolution process based on the body types
+ * of the colliders involved in the collision. It delegates
+ * collision handling to specific handlers and calls collision event scripts
+ * as needed.
*
* \param info Collision information containing data about both colliders.
*/
@@ -160,14 +163,20 @@ 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);
+ void call_collision_events(const CollisionInfo & info);
/**
* \brief Handles collisions involving static objects.
*
- * Resolves collisions by adjusting positions and modifying velocities if bounce is enabled.
+ * This function resolves collisions between static and dynamic objects by adjusting
+ * the position of the static object and modifying the velocity of the dynamic object
+ * if elasticity is enabled. The position of the static object is corrected
+ * based on the collision resolution, and the dynamic object's velocity is adjusted
+ * accordingly to reflect the collision response.
+ *
+ * The handling includes stopping movement, applying bouncing based on the elasticity
+ * coefficient, and adjusting the position of the dynamic object if needed.
*
* \param info Collision information containing data about both colliders.
*/
@@ -176,7 +185,10 @@ private:
/**
* \brief Handles collisions involving dynamic objects.
*
- * Resolves collisions by adjusting positions and modifying velocities if bounce is enabled.
+ * Resolves collisions between two dynamic objects by adjusting their positions and modifying
+ * their velocities based on the collision resolution. If elasticity is enabled,
+ * the velocity of both objects is reversed and scaled by the respective elasticity coefficient.
+ * The positions of the objects are adjusted based on the collision resolution.
*
* \param info Collision information containing data about both colliders.
*/
@@ -186,7 +198,8 @@ private:
/**
* \brief Checks for collisions between colliders.
*
- * Identifies collisions and generates pairs of colliding objects for further processing.
+ * This function checks all active colliders and identifies pairs of colliding objects.
+ * For each identified collision, the appropriate collision data is returned as pairs for further processing.
*
* \param colliders A collection of all active colliders.
* \return A list of collision pairs with their associated data.
@@ -212,7 +225,9 @@ private:
/**
* \brief Checks for collision between two colliders.
*
- * Calls the appropriate collision detection function based on the collider types.
+ * This function determines whether two colliders are colliding based on their types.
+ * It calls the appropriate collision detection function based on the collider pair type and stores the collision resolution data.
+ * If a collision is detected, it returns true, otherwise false.
*
* \param first_info Collision data for the first collider.
* \param second_info Collision data for the second collider.
@@ -224,29 +239,39 @@ private:
/**
* \brief Detects collisions between two BoxColliders.
*
+ * This function checks whether two `BoxCollider` are colliding based on their positions and scaled dimensions.
+ * If a collision is detected, it calculates the overlap along the X and Y axes and returns the resolution vector.
+ * If no collision is detected, it returns a vector with NaN values.
+
* \param box1 Information about the first BoxCollider.
* \param box2 Information about the second BoxCollider.
- * \return returns resolution vector if collide otherwise returns {-1,-1}
+ * \return If colliding, returns the resolution vector; otherwise, returns {NaN, NaN}.
*/
vec2 get_box_box_detection(const BoxColliderInternal & box1, const BoxColliderInternal & box2) const;
/**
* \brief Check collision for box on circle collider
*
+ * This function detects if a collision occurs between a rectangular box and a circular collider.
+ * If a collision is detected, the function calculates the resolution vector to resolve the collision.
+ * If no collision is detected, it returns a vector with NaN values
+ *
* \param box1 Information about the BoxCollider.
* \param circle2 Information about the circleCollider.
- * \return returns resolution vector if collide otherwise returns {-1,-1}
+ * \return If colliding, returns the resolution vector; otherwise, returns {NaN, NaN}.
*/
vec2 get_box_circle_detection(const BoxColliderInternal & box1, const CircleColliderInternal & circle2) const;
/**
* \brief Check collision for circle on circle collider
*
+ * This function detects if a collision occurs between two circular colliders.
+ * If a collision is detected, it calculates the resolution vector to resolve the collision.
+ * If no collision is detected, it returns a vector with NaN values.
+ *
* \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
+ * \return If colliding, returns the resolution vector; otherwise, returns {NaN, NaN}.
*/
vec2 get_circle_circle_detection(const CircleColliderInternal & circle1, const CircleColliderInternal & circle2) const;
};