From 66f0ea3eebeaa16e53afa907cb1547542b6f1fe8 Mon Sep 17 00:00:00 2001 From: CobaltXII Date: Thu, 3 Jan 2019 11:21:23 -0500 Subject: [PATCH] void do_collision_detection_and_response is now of type bool --- src/inc/hitbox.hpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/inc/hitbox.hpp b/src/inc/hitbox.hpp index c2d5eee..ce95b23 100644 --- a/src/inc/hitbox.hpp +++ b/src/inc/hitbox.hpp @@ -99,10 +99,13 @@ inline float hitbox_z_depth(hitbox a, hitbox b, float eps = 0.00128f) } // Do collision detection and response on one dynamic hitbox with an array of -// several static hitboxes while applying velocity to the dynamic hitbox. +// several static hitboxes while applying velocity to the dynamic hitbox. +// Returns true if the object hits anything. -void do_collision_detection_and_response(hitbox& object, std::vector obstacles, float& vx, float& vy, float& vz, int precision = 64) +bool do_collision_detection_and_response(hitbox& object, std::vector obstacles, float& vx, float& vy, float& vz, int precision = 64) { + bool collisions = false; + for (int p = 0; p < precision; p++) { object.x += vx / precision; @@ -113,6 +116,8 @@ void do_collision_detection_and_response(hitbox& object, std::vector obs if (hitbox_intersect(object, obstacle)) { + collisions = true; + object.x += hitbox_x_depth(object, obstacle); vx = 0.0f; @@ -127,6 +132,8 @@ void do_collision_detection_and_response(hitbox& object, std::vector obs if (hitbox_intersect(object, obstacle)) { + collisions = true; + object.y += hitbox_y_depth(object, obstacle); vy = 0.0f; @@ -141,10 +148,14 @@ void do_collision_detection_and_response(hitbox& object, std::vector obs if (hitbox_intersect(object, obstacle)) { + collisions = true; + object.z += hitbox_z_depth(object, obstacle); vz = 0.0f; } } } + + return collisions; } \ No newline at end of file