solve_aabb_aabb now incorporates sprite position in all calculations
parent
7950e45632
commit
5185f5062b
|
@ -146,10 +146,20 @@ float _solve_circle_circle(const object_t* a, const object_t* b, float* out_px,
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
float _solve_aabb_aabb(const object_t* a, const object_t* b, float* out_px, float* out_py) {
|
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 aminx = a->physics.aabb.x + a->sprite.x;
|
||||||
float left = (a->physics.aabb.x + a->sprite.x) - (b->physics.aabb.x + b->physics.aabb.w + b->sprite.x);
|
float amaxx = aminx + a->physics.aabb.w;
|
||||||
float top = (a->physics.aabb.y + a->sprite.y) - (b->physics.aabb.y + b->physics.aabb.w + b->sprite.y);
|
float bminx = b->physics.aabb.x + b->sprite.x;
|
||||||
float bottom = (a->physics.aabb.y + a->physics.aabb.h) - (b->physics.aabb.y + b->sprite.y);
|
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;
|
float ret = right;
|
||||||
*out_px = 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) {
|
void solve_collision_slide(object_t* left, object_t* right) {
|
||||||
float dx, dy;
|
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.x += dx;
|
||||||
left->sprite.y += dy;
|
left->sprite.y += dy;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue