mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-29 16:05:59 +01:00
improve collision detection algorithm
This commit is contained in:
parent
59a71f59b9
commit
854a9381ca
1 changed files with 27 additions and 15 deletions
|
@ -91,22 +91,34 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
|
||||||
sample->x_offs, sample->y_offs + 128);
|
sample->x_offs, sample->y_offs + 128);
|
||||||
bool lr_collision = !wlr_output_layout_output_at(sample->layout,
|
bool lr_collision = !wlr_output_layout_output_at(sample->layout,
|
||||||
sample->x_offs + 128, sample->y_offs + 128);
|
sample->x_offs + 128, sample->y_offs + 128);
|
||||||
bool has_double_collision = false;
|
|
||||||
|
|
||||||
if ((ur_collision && ul_collision) || (lr_collision && ll_collision)) {
|
if (ur_collision && ul_collision && ll_collision && lr_collision) {
|
||||||
sample->y_vel *= -1;
|
// oops we went off the screen somehow
|
||||||
has_double_collision = true;
|
struct wlr_output_layout_output *main_l_output;
|
||||||
|
main_l_output = wlr_output_layout_get(sample->layout, sample->main_output);
|
||||||
|
sample->x_offs = main_l_output->x + 20;
|
||||||
|
sample->y_offs = main_l_output->y + 20;
|
||||||
|
} else if (ur_collision && ul_collision) {
|
||||||
|
sample->y_vel = fabs(sample->y_vel);
|
||||||
|
} else if (lr_collision && ll_collision) {
|
||||||
|
sample->y_vel = -fabs(sample->y_vel);
|
||||||
|
} else if (ll_collision && ul_collision) {
|
||||||
|
sample->x_vel = fabs(sample->x_vel);
|
||||||
|
} else if (ur_collision && lr_collision) {
|
||||||
|
sample->x_vel = -fabs(sample->x_vel);
|
||||||
|
} else {
|
||||||
|
if (ur_collision || lr_collision) {
|
||||||
|
sample->x_vel = -fabs(sample->x_vel);
|
||||||
}
|
}
|
||||||
|
if (ul_collision || ll_collision) {
|
||||||
if ((ll_collision && ul_collision) || (ur_collision && lr_collision)) {
|
sample->x_vel = fabs(sample->x_vel);
|
||||||
sample->x_vel *= -1;
|
}
|
||||||
has_double_collision = true;
|
if (ul_collision || ur_collision) {
|
||||||
|
sample->y_vel = fabs(sample->y_vel);
|
||||||
|
}
|
||||||
|
if (ll_collision || lr_collision) {
|
||||||
|
sample->y_vel = -fabs(sample->y_vel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!has_double_collision &&
|
|
||||||
(ur_collision || ul_collision || lr_collision || ll_collision)) {
|
|
||||||
sample->x_vel *= -1;
|
|
||||||
sample->y_vel *= -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sample->x_offs += sample->x_vel * seconds;
|
sample->x_offs += sample->x_vel * seconds;
|
||||||
|
|
Loading…
Reference in a new issue