a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit ae19785db0f7a44b4deb4aedae6dd74c620fa5c4
parent c1fc73a188a95355ee47a30feccbe5bcfd8c92c4
Author: amin <dev@aminmesbah.com>
Date:   Sat, 20 Apr 2019 00:02:13 +0000

Do proper AABB hit detection

FossilOrigin-Name: 0e1110aad42fe03622e28a2c845d01425789aa44ad519cf8a5eb6643eaea5bc6
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; }