summaryrefslogtreecommitdiff
path: root/src/input_common/drivers/mouse.cpp
diff options
context:
space:
mode:
authorGravatar Narr the Reg2023-06-28 20:15:00 -0600
committerGravatar german772023-06-28 21:04:33 -0600
commit3f407417c10d0937be74a804cb111b602a3b68f8 (patch)
treec7101293f5d64eb3f5c1576ce51f4654f635bd6b /src/input_common/drivers/mouse.cpp
parentMerge pull request #10933 from merryhime/dunno (diff)
downloadyuzu-3f407417c10d0937be74a804cb111b602a3b68f8.tar.gz
yuzu-3f407417c10d0937be74a804cb111b602a3b68f8.tar.xz
yuzu-3f407417c10d0937be74a804cb111b602a3b68f8.zip
input_common: Tune mouse controls
Diffstat (limited to 'src/input_common/drivers/mouse.cpp')
-rw-r--r--src/input_common/drivers/mouse.cpp73
1 files changed, 36 insertions, 37 deletions
diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp
index f07cf8a0e..e92ea878f 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;
@@ -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 = Settings::values.mouse_panning ? default_motion_panning_sensitivity
124 const float sensitivity = (Settings::values.mouse_panning_x_sensitivity.GetValue() + 115 : 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;
@@ -158,29 +148,38 @@ void Mouse::Move(int x, int y, int center_x, int center_y) {
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 }
@@ -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}