aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
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
parentfe396c458b38ee209dd4c1f3ba4d053bef20f57a (diff)
improved doxygen
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/api/Rigidbody.h31
-rw-r--r--src/crepe/system/CollisionSystem.cpp17
-rw-r--r--src/crepe/system/CollisionSystem.h41
3 files changed, 51 insertions, 38 deletions
diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h
index df97763..9dbb42b 100644
--- a/src/crepe/api/Rigidbody.h
+++ b/src/crepe/api/Rigidbody.h
@@ -123,26 +123,37 @@ public:
*/
float elastisity_coefficient = 0.0;
- //! Enable static collision handeling for object colliding with kinematic object in collision system
- bool kinematic_collision = true;
-
/**
- * \brief Defines the collision layers of a GameObject.
+ * \brief Enables collision handling for objects colliding with kinematic objects.
*
- * The `collision_layers` specifies the layers that the GameObject will collide with.
- * Each element represents a layer ID, and the GameObject will only detect
- * collisions with other GameObjects that belong to that `collision_layer`.
+ * Enables collision handling for objects colliding with kinematic objects in the collision system.
+ * If `kinematic_collision` is true, dynamic objects cannot pass through this kinematic object.
+ * This ensures that kinematic objects delegate collision handling to the collision system.
*/
+ bool kinematic_collision = true;
+
+ /**
+ * \brief Defines the collision layers a GameObject interacts with.
+ *
+ * The `collision_layers` represent the set of layers the GameObject can detect collisions with.
+ * Each element in this set corresponds to a layer ID. The GameObject will only collide with other
+ * GameObjects that belong to one these layers.
+ */
std::set<int> collision_layers = {0};
- //! the collision layer of the object.
+ /**
+ * \brief Specifies the collision layer of the GameObject.
+ *
+ * The `collision_layer` indicates the single layer that this GameObject belongs to.
+ * This determines which layers other objects must match to detect collisions with this object.
+ */
int collision_layer = 0;
/**
* \brief Defines the collision layers of a GameObject.
*
* The `collision_names` specifies where the GameObject will collide with.
- * Each element represents a name.
+ * Each element represents a name from the Metadata of the gameobject.
*/
std::set<std::string> collision_names;
@@ -150,7 +161,7 @@ public:
* \brief Defines the collision layers of a GameObject.
*
* The `collision_tags` specifies where the GameObject will collide with.
- * Each element represents a tag.
+ * Each element represents a tag from the Metadata of the gameobject.
*/
std::set<std::string> collision_tags;
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);