Created
April 24, 2026 02:44
-
-
Save Woynert/6c84c9f7831a8dc430252ac6c0297088 to your computer and use it in GitHub Desktop.
module_aabb.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| I was testing for the obvious thing: check if 100% there is collision. | |
| But it's better to check for the opposite: check when there is NO collision. | |
| (Learned that from tsoding) | |
| */ | |
| #ifndef AABB_H | |
| #define AABB_H | |
| #include "raylib.h" | |
| #include "typedef.h" | |
| bool AABB_has_point(AABB box, Vector2 point) { | |
| //return | |
| //(fabsf(point.x - box.pos.x) < (box.size.x / 2.0f)) && | |
| //(fabsf(point.y - box.pos.y) < (box.size.y / 2.0f)) | |
| //; | |
| float left = box.pos.x; | |
| float right = box.pos.x + box.size.x; | |
| float top = box.pos.y; | |
| float bottom = box.pos.y + box.size.y; | |
| return ! ( | |
| point.x > right || | |
| point.x < left || | |
| point.y > bottom || | |
| point.y < top | |
| ); | |
| } | |
| bool AABB_simple_collide (AABB lhs, AABB rhs) | |
| { | |
| //return ( | |
| //(fabs(lhs.pos.x - rhs.pos.x) <= (lhs.size.x + rhs.size.x)/2.f) && | |
| //(fabs(lhs.pos.y - rhs.pos.y) <= (lhs.size.y + rhs.size.y)/2.f) | |
| //); | |
| float left1 = lhs.pos.x; | |
| float right1 = lhs.pos.x + lhs.size.x; | |
| float top1 = lhs.pos.y; | |
| float bottom1 = lhs.pos.y + lhs.size.y; | |
| float left2 = rhs.pos.x; | |
| float right2 = rhs.pos.x + rhs.size.x; | |
| float top2 = rhs.pos.y; | |
| float bottom2 = rhs.pos.y + rhs.size.y; | |
| return ! ( | |
| left1 > right2 || left2 > right1 || | |
| top1 > bottom2 || top2 > bottom1 | |
| ); | |
| } | |
| #endif // !AABB_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment