From 5185f5062bd965a22f7880e3eb5381eb23177b94 Mon Sep 17 00:00:00 2001 From: Sara Date: Sun, 16 Jul 2023 21:23:59 +0200 Subject: [PATCH] solve_aabb_aabb now incorporates sprite position in all calculations --- src/corelib/physics.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/corelib/physics.c b/src/corelib/physics.c index dab0b33..8940cf9 100644 --- a/src/corelib/physics.c +++ b/src/corelib/physics.c @@ -146,10 +146,20 @@ float _solve_circle_circle(const object_t* a, const object_t* b, float* out_px, static inline float _solve_aabb_aabb(const object_t* a, const object_t* b, float* out_px, float* out_py) { - float right = (a->physics.aabb.x + a->physics.aabb.w + a->sprite.x) - (b->physics.aabb.x + b->sprite.x); - float left = (a->physics.aabb.x + a->sprite.x) - (b->physics.aabb.x + b->physics.aabb.w + b->sprite.x); - float top = (a->physics.aabb.y + a->sprite.y) - (b->physics.aabb.y + b->physics.aabb.w + b->sprite.y); - float bottom = (a->physics.aabb.y + a->physics.aabb.h) - (b->physics.aabb.y + b->sprite.y); + float aminx = a->physics.aabb.x + a->sprite.x; + float amaxx = aminx + a->physics.aabb.w; + float bminx = b->physics.aabb.x + b->sprite.x; + float bmaxx = bminx + b->physics.aabb.w; + + float aminy = a->physics.aabb.y + a->sprite.y; + float amaxy = aminy + a->physics.aabb.h; + float bminy = b->physics.aabb.y + b->sprite.y; + float bmaxy = bminy + b->physics.aabb.h; + + float right = amaxx - bminx; + float left = aminx - bmaxx; + float top = aminy - bmaxy; + float bottom = amaxy - bminy; float ret = right; *out_px = right; @@ -190,7 +200,7 @@ float get_solve_force(const object_t* a, const object_t* b, float* out_px, float void solve_collision_slide(object_t* left, object_t* right) { float dx, dy; - const float d = get_solve_force(left, right, &dx, &dy); + get_solve_force(left, right, &dx, &dy); left->sprite.x += dx; left->sprite.y += dy; }