diff options
| author | a1xd <[email protected]> | 2021-01-21 22:35:37 -0500 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-01-21 22:35:37 -0500 |
| commit | 8dac6b3ff1d3fa434c4cd1db752ba34681cae8b4 (patch) | |
| tree | 6dee579d0928c5ef47247f60d526ce71306c9ba8 | |
| parent | direction/distance calc - small opts (diff) | |
| download | rawaccel-8dac6b3ff1d3fa434c4cd1db752ba34681cae8b4.tar.xz rawaccel-8dac6b3ff1d3fa434c4cd1db752ba34681cae8b4.zip | |
add angle snapping
probably works like interaccel
| -rw-r--r-- | common/rawaccel-settings.h | 1 | ||||
| -rw-r--r-- | common/rawaccel.hpp | 32 | ||||
| -rw-r--r-- | driver/driver.cpp | 1 | ||||
| -rw-r--r-- | grapher/Models/AccelGUI.cs | 1 | ||||
| -rw-r--r-- | grapher/Models/Serialized/RawAccelSettings.cs | 1 | ||||
| -rw-r--r-- | wrapper/wrapper.cpp | 3 |
6 files changed, 39 insertions, 0 deletions
diff --git a/common/rawaccel-settings.h b/common/rawaccel-settings.h index 6fa2aa9..dedef6d 100644 --- a/common/rawaccel-settings.h +++ b/common/rawaccel-settings.h @@ -19,6 +19,7 @@ namespace rawaccel { struct settings { double degrees_rotation = 0; + double degrees_snap = 0; bool combine_mags = true; vec2<accel_mode> modes = { accel_mode::noaccel, accel_mode::noaccel }; vec2<accel_args> argsv; diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index d17a460..4c1e597 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -42,6 +42,26 @@ namespace rawaccel { rotator() = default; }; + struct snapper { + double threshold = 0; + + inline vec2d apply(const vec2d& input) const { + if (input.x != 0 && input.y != 0) { + double angle = fabs(atan(input.y / input.x)); + auto mag = [&] { return sqrtsd(input.x * input.x + input.y * input.y); }; + + if (angle > M_PI_2 - threshold) return { 0, _copysign(mag(), input.y) }; + if (angle < threshold) return { _copysign(mag(), input.x), 0 }; + } + + return input; + } + + snapper(double degrees) : threshold(minsd(fabs(degrees), 45) * M_PI / 180) {} + + snapper() = default; + }; + /// <summary> Struct to hold clamp (min and max) details for acceleration application </summary> struct accel_scale_clamp { double lo = 0; @@ -296,9 +316,11 @@ namespace rawaccel { /// <summary> Struct to hold variables and methods for modifying mouse input </summary> struct mouse_modifier { bool apply_rotate = false; + bool apply_snap = false; bool apply_accel = false; bool combine_magnitudes = true; rotator rotate; + snapper snap; weighted_distance distance; direction_weight directional; vec2<accelerator> accels; @@ -313,6 +335,11 @@ namespace rawaccel { apply_rotate = true; } + if (args.degrees_snap != 0) { + snap = snapper(args.degrees_snap); + apply_snap = true; + } + if (args.sens.x != 0) sensitivity.x = args.sens.x; if (args.sens.y != 0) sensitivity.y = args.sens.y; @@ -336,6 +363,7 @@ namespace rawaccel { void modify(vec2d& movement, milliseconds time) { apply_rotation(movement); + apply_angle_snap(movement); apply_acceleration(movement, [=] { return time; }); apply_sensitivity(movement); } @@ -344,6 +372,10 @@ namespace rawaccel { if (apply_rotate) movement = rotate.apply(movement); } + inline void apply_angle_snap(vec2d& movement) { + if (apply_snap) movement = snap.apply(movement); + } + template <typename TimeSupplier> inline void apply_acceleration(vec2d& movement, TimeSupplier time_supp) { if (apply_accel) { diff --git a/driver/driver.cpp b/driver/driver.cpp index a92f773..0c21f34 100644 --- a/driver/driver.cpp +++ b/driver/driver.cpp @@ -74,6 +74,7 @@ Arguments: }; global.modifier.apply_rotation(input); + global.modifier.apply_angle_snap(input); if (enable_accel) { auto time_supplier = [=] { diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 5cd7012..4dd7caa 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -144,6 +144,7 @@ namespace grapher var settings = new DriverSettings { rotation = ApplyOptions.Rotation.Field.Data, + snap = driverSettings.snap, sensitivity = new Vec2<double> { x = ApplyOptions.Sensitivity.Fields.X, diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index f4fb1e2..17db910 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -131,6 +131,7 @@ namespace grapher.Models.Serialized accelSettings.directionalMultipliers.x <= 0 && accelSettings.directionalMultipliers.y <= 0 && accelSettings.rotation == 0 && + accelSettings.snap == 0 && accelSettings.modes.x == AccelMode.noaccel && wholeOrNoY; } diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index c7318b8..f5672a1 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -70,6 +70,9 @@ public ref struct DriverSettings [JsonProperty("Degrees of rotation")] double rotation; + [JsonProperty("Degrees of angle snapping", Required = Required::Default)] + double snap; + [JsonProperty("Use x as whole/combined accel")] [MarshalAs(UnmanagedType::U1)] bool combineMagnitudes; |