a-game

2D platformer written from scratch.
Log | Files | Refs | README | LICENSE

commit 58903f12bd2027cf38c6fbcd3522751619bbddf0
parent 124e4a953fcda1ed6ca0dcb0685f55da122be2d4
Author: Amin Mesbah <dev@aminmesbah.com>
Date:   Fri, 19 Apr 2019 17:02:13 -0700

Do proper AABB hit detection

Diffstat:
Msrc/glmth.h | 8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/glmth.h b/src/glmth.h @@ -7,9 +7,13 @@ internal inline bool glmth_aabb_intersect(rect r1, rect r2) { + f32 total_w = (r1.max.x - r1.min.x) + (r2.max.x - r2.min.x); + f32 total_h = (r1.max.y - r1.min.y) + (r2.max.y - r2.min.y); bool aabbs_do_indeed_intersect = ( - (r1.min.x >= r2.max.x && r1.min.y >= r2.max.y) - || (r2.min.x >= r1.max.x && r2.min.y >= r1.max.y) + fabsf(r1.max.x - r2.min.x) <= total_w + && fabsf(r1.max.y - r2.min.y) <= total_h + && fabsf(r2.max.x - r1.min.x) <= total_w + && fabsf(r2.max.y - r1.min.y) <= total_h ); return aabbs_do_indeed_intersect; }