diff --git a/src/input/input_handler.cpp b/src/input/input_handler.cpp index dc969fda9..cc6cf29d4 100644 --- a/src/input/input_handler.cpp +++ b/src/input/input_handler.cpp @@ -66,6 +66,7 @@ auto output_array = std::array{ ControllerOutput(LEFTJOYSTICK_HALFMODE), ControllerOutput(RIGHTJOYSTICK_HALFMODE), ControllerOutput(KEY_TOGGLE), + ControllerOutput(MOUSE_GYRO_ROLL_MODE), // Button mappings ControllerOutput(SDL_GAMEPAD_BUTTON_NORTH), // Triangle @@ -534,6 +535,9 @@ void ControllerOutput::FinalizeUpdate() { // to do it, and it would be inconvenient to force it here, when AddUpdate does the job just // fine, and a toggle doesn't have to checked against every input that's bound to it, it's // enough that one is pressed + case MOUSE_GYRO_ROLL_MODE: + SetMouseGyroRollMode(new_button_state); + break; default: // is a normal key (hopefully) controller->CheckButton(0, SDLGamepadToOrbisButton(button), new_button_state); break; diff --git a/src/input/input_handler.h b/src/input/input_handler.h index 797a8eff8..189970c12 100644 --- a/src/input/input_handler.h +++ b/src/input/input_handler.h @@ -35,6 +35,7 @@ #define BACK_BUTTON 0x00040000 #define KEY_TOGGLE 0x00200000 +#define MOUSE_GYRO_ROLL_MODE 0x00400000 #define SDL_UNMAPPED UINT32_MAX - 1 @@ -114,6 +115,7 @@ const std::map string_to_cbutton_map = { {"lpaddle_low", SDL_GAMEPAD_BUTTON_LEFT_PADDLE2}, {"rpaddle_high", SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1}, {"rpaddle_low", SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2}, + {"mouse_gyro_roll_mode", MOUSE_GYRO_ROLL_MODE}, }; const std::map string_to_axis_map = { diff --git a/src/input/input_mouse.cpp b/src/input/input_mouse.cpp index 82774924c..3c718dbd5 100644 --- a/src/input/input_mouse.cpp +++ b/src/input/input_mouse.cpp @@ -14,6 +14,7 @@ namespace Input { int mouse_joystick_binding = 0; float mouse_deadzone_offset = 0.5, mouse_speed = 1, mouse_speed_offset = 0.1250; +bool mouse_gyro_roll_mode = false; Uint32 mouse_polling_id = 0; MouseMode mouse_mode = MouseMode::Off; @@ -38,6 +39,10 @@ void SetMouseParams(float mdo, float ms, float mso) { mouse_speed_offset = mso; } +void SetMouseGyroRollMode(bool mode) { + mouse_gyro_roll_mode = mode; +} + void EmulateJoystick(GameController* controller, u32 interval) { Axis axis_x, axis_y; @@ -80,6 +85,10 @@ void EmulateGyro(GameController* controller, u32 interval) { SDL_GetRelativeMouseState(&d_x, &d_y); controller->Acceleration(1, constant_down_accel); float gyro_from_mouse[3] = {-d_y / 100, -d_x / 100, 0.0f}; + if (mouse_gyro_roll_mode) { + gyro_from_mouse[1] = 0.0f; + gyro_from_mouse[2] = -d_x / 100; + } controller->Gyro(1, gyro_from_mouse); } diff --git a/src/input/input_mouse.h b/src/input/input_mouse.h index 2472f48d3..a56ef2d8f 100644 --- a/src/input/input_mouse.h +++ b/src/input/input_mouse.h @@ -17,6 +17,7 @@ enum MouseMode { bool ToggleMouseModeTo(MouseMode m); void SetMouseToJoystick(int joystick); void SetMouseParams(float mouse_deadzone_offset, float mouse_speed, float mouse_speed_offset); +void SetMouseGyroRollMode(bool mode); void EmulateJoystick(GameController* controller, u32 interval); void EmulateGyro(GameController* controller, u32 interval);