diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2024-12-05 22:15:38 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2024-12-05 22:15:38 +0100 |
commit | 453aeafda1503aeafa54b8f6e293936c1a3db5ea (patch) | |
tree | d97f86686f8847f40e6f9e3a51c6878d17896a44 /src/crepe/system | |
parent | 9604616001ac273f2c966c3c829638e905def7bf (diff) |
dynamic and static bug fixes
Diffstat (limited to 'src/crepe/system')
-rw-r--r-- | src/crepe/system/CollisionSystem.cpp | 15 | ||||
-rw-r--r-- | src/crepe/system/CollisionSystem.h | 5 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 86eafc0..f75d0ad 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -159,7 +159,7 @@ CollisionSystem::collision_handler(CollisionInternal & data1, CollisionInternal vec2 collider_pos2 = this->get_current_position(collider2.offset, data2.transform, data2.rigidbody); resolution = this->get_circle_box_resolution(collider2, collider1, collider_pos2, - collider_pos1); + collider_pos1,true); break; } case CollisionInternalType::CIRCLE_CIRCLE: { @@ -185,7 +185,7 @@ CollisionSystem::collision_handler(CollisionInternal & data1, CollisionInternal vec2 collider_pos2 = this->get_current_position(collider2.offset, data2.transform, data2.rigidbody); resolution = this->get_circle_box_resolution(collider1, collider2, collider_pos1, - collider_pos2); + collider_pos2,false); break; } } @@ -261,9 +261,10 @@ vec2 CollisionSystem::get_circle_circle_resolution(const CircleCollider & circle // Normalize the delta vector to get the collision direction vec2 collision_normal = delta / distance; + // Compute the resolution vector - vec2 resolution = collision_normal * penetration_depth; + vec2 resolution = -collision_normal * penetration_depth; return resolution; } @@ -271,7 +272,7 @@ vec2 CollisionSystem::get_circle_circle_resolution(const CircleCollider & circle vec2 CollisionSystem::get_circle_box_resolution(const CircleCollider & circle_collider, const BoxCollider & box_collider, const vec2 & circle_position, - const vec2 & box_position) const { + const vec2 & box_position,bool inverse) const { vec2 delta = circle_position - box_position; // Compute half-dimensions of the box @@ -293,7 +294,7 @@ vec2 CollisionSystem::get_circle_box_resolution(const CircleCollider & circle_co // Compute penetration depth float penetration_depth = circle_collider.radius - distance; - + if(inverse) collision_normal = -collision_normal; // Compute the resolution vector vec2 resolution = collision_normal * penetration_depth; @@ -511,7 +512,7 @@ bool CollisionSystem::get_box_circle_collision(const BoxCollider & box1, float distance_squared = distance_x * distance_x + distance_y * distance_y; // Compare distance squared with the square of the circle's radius - return distance_squared <= circle2.radius * circle2.radius; + return distance_squared <= circle2.radius * circle2.radius-1; } bool CollisionSystem::get_circle_circle_collision(const CircleCollider & circle1, @@ -532,7 +533,7 @@ bool CollisionSystem::get_circle_circle_collision(const CircleCollider & circle1 float radius_sum = circle1.radius + circle2.radius; // Check if the distance between the centers is less than or equal to the sum of the radii - return distance_squared <= radius_sum * radius_sum; + return distance_squared <= radius_sum * radius_sum - 1; } vec2 CollisionSystem::get_current_position(const vec2 & collider_offset, diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index 6995bb5..b978dbb 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -177,13 +177,14 @@ private: * \param circle_collider The first CircleCollider. * \param box_collider The second CircleCollider. * \param circle_position The position of the CircleCollider. - * \param box_position The position of the BocCollider. + * \param box_position The position of the BoxCollider. + * \param inverse Inverted true if box circle collision, false if circle box collision (inverts the direction). * \return The resolution vector for the collision. */ vec2 get_circle_box_resolution(const CircleCollider & circle_collider, const BoxCollider & box_collider, const vec2 & circle_position, - const vec2 & box_position) const; + const vec2 & box_position,bool inverse) const; /** * \brief Determines the appropriate collision handler for a collision. |