|
|
|
@ -394,6 +394,51 @@ void update_viewport(Body *pl) {
@@ -394,6 +394,51 @@ void update_viewport(Body *pl) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void accel_update_viewport(Body *pl) { |
|
|
|
|
const double accel = 0.0001; |
|
|
|
|
const float xmargin = 0.5; |
|
|
|
|
const float ymargin = 0.2; |
|
|
|
|
|
|
|
|
|
static Vect target_pos = (Vect) {.x=0, .y=0}; |
|
|
|
|
static Vect vel = (Vect) {.x=0.0, .y=0.0}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pl->position.x - viewport_pos.x > (1-xmargin) * width) { |
|
|
|
|
target_pos.x = - ((1-xmargin) * width - pl->position.x); |
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pl->position.x - target_pos.x < xmargin * width) { |
|
|
|
|
target_pos.x = -(xmargin * width - pl->position.x); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (pl->position.y - target_pos.y > (1-ymargin) * height) { |
|
|
|
|
target_pos.y = -((1-ymargin) * height - pl->position.y); |
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pl->position.y - target_pos.y < ymargin * height) { |
|
|
|
|
target_pos.y = -(ymargin * height - pl->position.y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
viewport_pos = target_pos; |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
Vect delta = vect_add(target_pos, vect_scalar(viewport_pos, -1)); |
|
|
|
|
printf("d %f %f\n", delta.x, delta.y); |
|
|
|
|
printf("d %f\n", vect_mag(delta)); |
|
|
|
|
|
|
|
|
|
if ((vect_mag(delta) < 0.001 )) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Vect dir = vect_scalar(delta, 1/vect_mag(delta)); |
|
|
|
|
Vect vel_delta = vect_scalar(dir, accel * time_delta); |
|
|
|
|
vel = vect_add(vel, vel_delta); |
|
|
|
|
|
|
|
|
|
Vect pos_delta = vect_scalar(vel, time_delta/2); |
|
|
|
|
|
|
|
|
|
viewport_pos = vect_add(viewport_pos, pos_delta); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double interpolate_h(Vect left, Vect right, double x) { |
|
|
|
|
static Vect v; |
|
|
|
|
|
|
|
|
@ -719,7 +764,7 @@ void redraw_buffer(SDL_Renderer * ren) {
@@ -719,7 +764,7 @@ void redraw_buffer(SDL_Renderer * ren) {
|
|
|
|
|
|
|
|
|
|
if (SDL_LockMutex(player.physics->lock) == 0){ |
|
|
|
|
lplayer = *player.physics; |
|
|
|
|
update_viewport(&lplayer); |
|
|
|
|
accel_update_viewport(&lplayer); |
|
|
|
|
} else { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|