1
1
Fork 0
Browse Source

Handle case of contained collision boxes

thread-physics
= 5 years ago
parent
commit
253ad6e3eb
  1. 7
      Makefile
  2. 19
      game.c

7
Makefile

@ -1,8 +1,13 @@ @@ -1,8 +1,13 @@
CXX = gcc -g
SDL_INCLUDE = -lSDL2 -lm -lSDL2_image
SDL_INCLUDE = -lSDL2 -lm -lSDL2_image -pthread
CXXFLAGS = -Wall $(SDL_INCLUDE)
EXE = main
install: all
run: all
./main
all: $(EXE)
$(EXE): main.o vect.o logger.o game.o garbo.o draw.o

19
game.c

@ -296,6 +296,22 @@ bool sat_collision_check(Body *one, Body *two, Vect *translation) { @@ -296,6 +296,22 @@ bool sat_collision_check(Body *one, Body *two, Vect *translation) {
double left = proj_one[1] < proj_two[1] ? proj_one[1] : proj_two[1];
double right = proj_one[0] > proj_two[0] ? proj_one[0] : proj_two[0];
overlap = left - right;
// one of the shapes is contained
if ((overlap > (proj_one[1] - proj_one[0])
|| (overlap > (proj_two[1] - proj_two[0])))) {
printf("COntained");
double min = proj_one[0] - proj_two[0];
double max = proj_one[1] - proj_two[1];
min = min < 0 ? -min : min;
max = max < 0 ? -max : max;
overlap += min < max ? min : max;
}
printf("OVERLAP : %e\n", overlap);
if (overlap < min_overlap && overlap > 0) {
min_overlap = overlap;
@ -501,7 +517,7 @@ int process_collisions(Body *thing, Vect *trans) { @@ -501,7 +517,7 @@ int process_collisions(Body *thing, Vect *trans) {
} else if (world[k].kind == FLOOR) {
for (int i = 0; i < world[k].floor->numPolys; i++) {
if ((world[k].floor->polys[i].physics->position.x - viewport_pos.x) > (2 *width)
|| (world[k].floor->polys[i].physics->position.x - viewport_pos.x) < 0) {
|| (world[k].floor->polys[i].physics->position.x - viewport_pos.x) < -width) {
continue;
} else {
num++;
@ -586,7 +602,6 @@ void advance_thing(Body * thing) { @@ -586,7 +602,6 @@ void advance_thing(Body * thing) {
/*rest.y = sin(vect_dir(translation)) * impulse;*/
/*accel_thing(thing, rest.x, rest.y);*/
}
uint32_t now = SDL_GetTicks();

Loading…
Cancel
Save