summaryrefslogtreecommitdiff
path: root/src/input_common/drivers/mouse.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/drivers/mouse.cpp')
-rw-r--r--src/input_common/drivers/mouse.cpp86
1 files changed, 45 insertions, 41 deletions
diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp
index f07cf8a0e..dac29c78f 100644
--- a/src/input_common/drivers/mouse.cpp
+++ b/src/input_common/drivers/mouse.cpp
@@ -12,9 +12,13 @@
12 12
13namespace InputCommon { 13namespace InputCommon {
14constexpr int update_time = 10; 14constexpr int update_time = 10;
15constexpr float default_stick_sensitivity = 0.0044f; 15constexpr float default_panning_sensitivity = 0.0010f;
16constexpr float default_motion_sensitivity = 0.0003f; 16constexpr float default_stick_sensitivity = 0.0006f;
17constexpr float default_deadzone_counterweight = 0.01f;
18constexpr float default_motion_panning_sensitivity = 2.5f;
19constexpr float default_motion_sensitivity = 0.416f;
17constexpr float maximum_rotation_speed = 2.0f; 20constexpr float maximum_rotation_speed = 2.0f;
21constexpr float maximum_stick_range = 1.5f;
18constexpr int mouse_axis_x = 0; 22constexpr int mouse_axis_x = 0;
19constexpr int mouse_axis_y = 1; 23constexpr int mouse_axis_y = 1;
20constexpr int wheel_axis_x = 2; 24constexpr int wheel_axis_x = 2;
@@ -81,7 +85,7 @@ void Mouse::UpdateThread(std::stop_token stop_token) {
81} 85}
82 86
83void Mouse::UpdateStickInput() { 87void Mouse::UpdateStickInput() {
84 if (!Settings::values.mouse_panning) { 88 if (!IsMousePanningEnabled()) {
85 return; 89 return;
86 } 90 }
87 91
@@ -89,26 +93,13 @@ void Mouse::UpdateStickInput() {
89 93
90 // Prevent input from exceeding the max range (1.0f) too much, 94 // Prevent input from exceeding the max range (1.0f) too much,
91 // but allow some room to make it easier to sustain 95 // but allow some room to make it easier to sustain
92 if (length > 1.2f) { 96 if (length > maximum_stick_range) {
93 last_mouse_change /= length; 97 last_mouse_change /= length;
94 last_mouse_change *= 1.2f; 98 last_mouse_change *= maximum_stick_range;
95 } 99 }
96 100
97 auto mouse_change = last_mouse_change; 101 SetAxis(identifier, mouse_axis_x, last_mouse_change.x);
98 102 SetAxis(identifier, mouse_axis_y, -last_mouse_change.y);
99 // Bind the mouse change to [0 <= deadzone_counterweight <= 1,1]
100 if (length < 1.0f) {
101 const float deadzone_h_counterweight =
102 Settings::values.mouse_panning_deadzone_x_counterweight.GetValue();
103 const float deadzone_v_counterweight =
104 Settings::values.mouse_panning_deadzone_y_counterweight.GetValue();
105 mouse_change /= length;
106 mouse_change.x *= length + (1 - length) * deadzone_h_counterweight * 0.01f;
107 mouse_change.y *= length + (1 - length) * deadzone_v_counterweight * 0.01f;
108 }
109
110 SetAxis(identifier, mouse_axis_x, mouse_change.x);
111 SetAxis(identifier, mouse_axis_y, -mouse_change.y);
112 103
113 // Decay input over time 104 // Decay input over time
114 const float clamped_length = std::min(1.0f, length); 105 const float clamped_length = std::min(1.0f, length);
@@ -120,14 +111,13 @@ void Mouse::UpdateStickInput() {
120} 111}
121 112
122void Mouse::UpdateMotionInput() { 113void Mouse::UpdateMotionInput() {
123 // This may need its own sensitivity instead of using the average 114 const float sensitivity =
124 const float sensitivity = (Settings::values.mouse_panning_x_sensitivity.GetValue() + 115 IsMousePanningEnabled() ? default_motion_panning_sensitivity : default_motion_sensitivity;
125 Settings::values.mouse_panning_y_sensitivity.GetValue()) /
126 2.0f * default_motion_sensitivity;
127 116
128 const float rotation_velocity = std::sqrt(last_motion_change.x * last_motion_change.x + 117 const float rotation_velocity = std::sqrt(last_motion_change.x * last_motion_change.x +
129 last_motion_change.y * last_motion_change.y); 118 last_motion_change.y * last_motion_change.y);
130 119
120 // Clamp rotation speed
131 if (rotation_velocity > maximum_rotation_speed / sensitivity) { 121 if (rotation_velocity > maximum_rotation_speed / sensitivity) {
132 const float multiplier = maximum_rotation_speed / rotation_velocity / sensitivity; 122 const float multiplier = maximum_rotation_speed / rotation_velocity / sensitivity;
133 last_motion_change.x = last_motion_change.x * multiplier; 123 last_motion_change.x = last_motion_change.x * multiplier;
@@ -144,7 +134,7 @@ void Mouse::UpdateMotionInput() {
144 .delta_timestamp = update_time * 1000, 134 .delta_timestamp = update_time * 1000,
145 }; 135 };
146 136
147 if (Settings::values.mouse_panning) { 137 if (IsMousePanningEnabled()) {
148 last_motion_change.x = 0; 138 last_motion_change.x = 0;
149 last_motion_change.y = 0; 139 last_motion_change.y = 0;
150 } 140 }
@@ -154,33 +144,42 @@ void Mouse::UpdateMotionInput() {
154} 144}
155 145
156void Mouse::Move(int x, int y, int center_x, int center_y) { 146void Mouse::Move(int x, int y, int center_x, int center_y) {
157 if (Settings::values.mouse_panning) { 147 if (IsMousePanningEnabled()) {
158 const auto mouse_change = 148 const auto mouse_change =
159 (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>(); 149 (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>();
160 const float x_sensitivity = 150 const float x_sensitivity =
161 Settings::values.mouse_panning_x_sensitivity.GetValue() * default_stick_sensitivity; 151 Settings::values.mouse_panning_x_sensitivity.GetValue() * default_panning_sensitivity;
162 const float y_sensitivity = 152 const float y_sensitivity =
163 Settings::values.mouse_panning_y_sensitivity.GetValue() * default_stick_sensitivity; 153 Settings::values.mouse_panning_y_sensitivity.GetValue() * default_panning_sensitivity;
154 const float deadzone_counterweight =
155 Settings::values.mouse_panning_deadzone_counterweight.GetValue() *
156 default_deadzone_counterweight;
157
158 last_motion_change += {-mouse_change.y * x_sensitivity, -mouse_change.x * y_sensitivity, 0};
159 last_mouse_change.x += mouse_change.x * x_sensitivity;
160 last_mouse_change.y += mouse_change.y * y_sensitivity;
164 161
165 last_motion_change += {-mouse_change.y, -mouse_change.x, 0}; 162 // Bind the mouse change to [0 <= deadzone_counterweight <= 1.0]
166 last_mouse_change.x += mouse_change.x * x_sensitivity * 0.09f; 163 if (last_mouse_change.Length() < deadzone_counterweight) {
167 last_mouse_change.y += mouse_change.y * y_sensitivity * 0.09f; 164 last_mouse_change /= last_mouse_change.Length();
165 last_mouse_change *= deadzone_counterweight;
166 }
168 167
169 return; 168 return;
170 } 169 }
171 170
172 if (button_pressed) { 171 if (button_pressed) {
173 const auto mouse_move = Common::MakeVec<int>(x, y) - mouse_origin; 172 const auto mouse_move = Common::MakeVec<int>(x, y) - mouse_origin;
174 const float x_sensitivity = Settings::values.mouse_panning_x_sensitivity.GetValue(); 173 const float x_sensitivity =
175 const float y_sensitivity = Settings::values.mouse_panning_y_sensitivity.GetValue(); 174 Settings::values.mouse_panning_x_sensitivity.GetValue() * default_stick_sensitivity;
176 SetAxis(identifier, mouse_axis_x, 175 const float y_sensitivity =
177 static_cast<float>(mouse_move.x) * x_sensitivity * 0.0012f); 176 Settings::values.mouse_panning_y_sensitivity.GetValue() * default_stick_sensitivity;
178 SetAxis(identifier, mouse_axis_y, 177 SetAxis(identifier, mouse_axis_x, static_cast<float>(mouse_move.x) * x_sensitivity);
179 static_cast<float>(-mouse_move.y) * y_sensitivity * 0.0012f); 178 SetAxis(identifier, mouse_axis_y, static_cast<float>(-mouse_move.y) * y_sensitivity);
180 179
181 last_motion_change = { 180 last_motion_change = {
182 static_cast<float>(-mouse_move.y) / 50.0f, 181 static_cast<float>(-mouse_move.y) * x_sensitivity,
183 static_cast<float>(-mouse_move.x) / 50.0f, 182 static_cast<float>(-mouse_move.x) * y_sensitivity,
184 last_motion_change.z, 183 last_motion_change.z,
185 }; 184 };
186 } 185 }
@@ -220,7 +219,7 @@ void Mouse::ReleaseButton(MouseButton button) {
220 SetButton(real_mouse_identifier, static_cast<int>(button), false); 219 SetButton(real_mouse_identifier, static_cast<int>(button), false);
221 SetButton(touch_identifier, static_cast<int>(button), false); 220 SetButton(touch_identifier, static_cast<int>(button), false);
222 221
223 if (!Settings::values.mouse_panning) { 222 if (!IsMousePanningEnabled()) {
224 SetAxis(identifier, mouse_axis_x, 0); 223 SetAxis(identifier, mouse_axis_x, 0);
225 SetAxis(identifier, mouse_axis_y, 0); 224 SetAxis(identifier, mouse_axis_y, 0);
226 } 225 }
@@ -234,7 +233,7 @@ void Mouse::ReleaseButton(MouseButton button) {
234void Mouse::MouseWheelChange(int x, int y) { 233void Mouse::MouseWheelChange(int x, int y) {
235 wheel_position.x += x; 234 wheel_position.x += x;
236 wheel_position.y += y; 235 wheel_position.y += y;
237 last_motion_change.z += static_cast<f32>(y) / 100.0f; 236 last_motion_change.z += static_cast<f32>(y);
238 SetAxis(identifier, wheel_axis_x, static_cast<f32>(wheel_position.x)); 237 SetAxis(identifier, wheel_axis_x, static_cast<f32>(wheel_position.x));
239 SetAxis(identifier, wheel_axis_y, static_cast<f32>(wheel_position.y)); 238 SetAxis(identifier, wheel_axis_y, static_cast<f32>(wheel_position.y));
240} 239}
@@ -244,6 +243,11 @@ void Mouse::ReleaseAllButtons() {
244 button_pressed = false; 243 button_pressed = false;
245} 244}
246 245
246bool Mouse::IsMousePanningEnabled() {
247 // Disable mouse panning when a real mouse is connected
248 return Settings::values.mouse_panning && !Settings::values.mouse_enabled;
249}
250
247std::vector<Common::ParamPackage> Mouse::GetInputDevices() const { 251std::vector<Common::ParamPackage> Mouse::GetInputDevices() const {
248 std::vector<Common::ParamPackage> devices; 252 std::vector<Common::ParamPackage> devices;
249 devices.emplace_back(Common::ParamPackage{ 253 devices.emplace_back(Common::ParamPackage{