From: Andreas Eversberg Date: Sun, 26 May 2019 06:49:31 +0000 (+0200) Subject: OVR: Snap rotation to absolute steps of 45 degrees, when walking X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=mercenary-reloaded.git;a=commitdiff_plain;h=9d09795a51c4e55c61d1d1ceb50544e21a82a794 OVR: Snap rotation to absolute steps of 45 degrees, when walking The player is always snapped to 0, 45, 90, 135... degrees. This makes it more comfortable when walking inside buildings. --- diff --git a/src/mercenary/main.c b/src/mercenary/main.c index 1ba1f44..8229642 100644 --- a/src/mercenary/main.c +++ b/src/mercenary/main.c @@ -422,6 +422,7 @@ static int joystick_set_x_last = 0, joystick_set_y_last = 0; static int keyboard_on = 0; static enum keycode vr_key_pressed = 0, vr_key = 0; static int we_walk = 0, we_rotate = 0; +static double degrees45 = 45.0 / 180.0 * M_PI; static void handle_vr_poses(void) { @@ -583,16 +584,18 @@ static void handle_vr_poses(void) mercenary_vr_move(1, move_east, move_north, 256, 256); } - /* if we rotate */ + /* snap orientation to steps of 45 degrees */ if (we_rotate == 1) { - /* change orientation */ mercenary_get_orientation(&roll, &pitch, &yaw); + yaw = round(yaw / degrees45) * degrees45; + /* if we rotate: change orientation */ if (stick_right_x > 0) - mercenary_set_orientation(yaw - 45.0 / 180.0 * M_PI); + yaw -= degrees45; else - mercenary_set_orientation(yaw + 45.0 / 180.0 * M_PI); - /* rotate only once */ + yaw += degrees45; + /* rotate only once per stick movement */ we_rotate = 2; + mercenary_set_orientation(yaw); } } if (joystick_set_x_last && !joystick_set_x)