diff options
| author | a1xd <[email protected]> | 2020-07-30 22:04:44 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2020-07-30 22:04:44 -0400 |
| commit | b59cf98c2f326abeb6b993d8ecc5759d23096253 (patch) | |
| tree | 4ac15ce9945e46e135e8a2f1cc1bad619e94856d /common | |
| parent | add tweaks for st-refactor (diff) | |
| download | rawaccel-b59cf98c2f326abeb6b993d8ecc5759d23096253.tar.xz rawaccel-b59cf98c2f326abeb6b993d8ecc5759d23096253.zip | |
Make weight a member of accel_base
This exposes weight to derived accel types, which now supply a method to transform acceleration into scale.
Diffstat (limited to 'common')
| -rw-r--r-- | common/accel-base.hpp | 21 | ||||
| -rw-r--r-- | common/accel-power.hpp | 10 | ||||
| -rw-r--r-- | common/rawaccel-userspace.hpp | 2 | ||||
| -rw-r--r-- | common/rawaccel.hpp | 24 |
4 files changed, 35 insertions, 22 deletions
diff --git a/common/accel-base.hpp b/common/accel-base.hpp index ed79bdb..e87b463 100644 --- a/common/accel-base.hpp +++ b/common/accel-base.hpp @@ -1,5 +1,7 @@ #pragma once +#include "vec2.h" + namespace rawaccel { // Error throwing calls std libraries which are unavailable in kernel mode. @@ -15,14 +17,18 @@ namespace rawaccel { double exponent = 2; double midpoint = 0; double power_scale = 1; + vec2d weight = { 1, 1 }; }; /// <summary> /// Struct to hold common acceleration curve implementation details. /// </summary> struct accel_base { - - /// <summary> Generally, the acceleration ramp rate.</summary> + + /// <summary> Coefficients applied to acceleration per axis.</summary> + vec2d weight = { 1, 1 }; + + /// <summary> Generally, the acceleration ramp rate. double speed_coeff = 0; /// <summary> @@ -34,6 +40,17 @@ namespace rawaccel { verify(args); speed_coeff = args.accel; + weight = args.weight; + } + + /// <summary> + /// Default transformation of acceleration -> mouse input multipliers. + /// </summary> + inline vec2d scale(double accel_val) const { + return { + weight.x * accel_val + 1, + weight.y * accel_val + 1 + }; } /// <summary> diff --git a/common/accel-power.hpp b/common/accel-power.hpp index c8b12cd..d96cb96 100644 --- a/common/accel-power.hpp +++ b/common/accel-power.hpp @@ -14,6 +14,7 @@ namespace rawaccel { accel_power(accel_args args) { verify(args); + weight = args.weight; speed_coeff = args.power_scale; exponent = args.exponent; offset = args.offset; @@ -24,8 +25,15 @@ namespace rawaccel { return (offset > 0 && speed < 1) ? 1 : pow(speed * speed_coeff, exponent); } + inline vec2d scale(double accel_val) const { + return { + weight.x * accel_val, + weight.y * accel_val + }; + } + void verify(accel_args args) const { - if (args.power_scale < 0) error("scale can not be negative"); + if (args.power_scale <= 0) error("scale must be positive"); if (args.exponent <= 0) error("exponent must be greater than 0"); } }; diff --git a/common/rawaccel-userspace.hpp b/common/rawaccel-userspace.hpp index 49c0fcd..6a79d23 100644 --- a/common/rawaccel-userspace.hpp +++ b/common/rawaccel-userspace.hpp @@ -50,7 +50,7 @@ mouse_modifier parse(int argc, char** argv) { // mode-independent accel options auto opt_weight = "accel multiplier (default = 1)" % - make_opt_vec(args.acc_fn_args.weight, "weight"); + make_opt_vec(args.acc_fn_args.acc_args.weight, "weight"); auto opt_offset = "speed (dots/ms) where accel kicks in (default = 0)" % ( clipp::option("offset") & clipp::number("speed", args.acc_fn_args.acc_args.offset) diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index 0aeb42d..7be37c2 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -81,7 +81,6 @@ namespace rawaccel { accel_args acc_args; int accel_mode = accel_impl_t::id<accel_noaccel>; milliseconds time_min = 0.4; - vec2d weight = { 1, 1 }; vec2d cap = { 0, 0 }; }; @@ -102,26 +101,17 @@ namespace rawaccel { /// <summary> The acceleration implementation (i.e. curve) </summary> accel_impl_t accel; - /// <summary> The weight of acceleration applied in {x, y} dimensions. </summary> - vec2d weight = { 1, 1 }; - - /// <summary> The constant added to weighted accel values to get the acceleration scale. </summary> - double scale_base = 1; - /// <summary> The object which sets a min and max for the acceleration scale. </summary> vec2<accel_scale_clamp> clamp; - accel_function(accel_fn_args args) : accel_function() { + accel_function(accel_fn_args args) { verify(args); accel.tag = args.accel_mode; accel.visit([&](auto& impl){ impl = { args.acc_args }; }); - if (accel.tag == accel_impl_t::id<accel_power>) scale_base = 0; - time_min = args.time_min; speed_offset = args.acc_args.offset; - weight = args.weight; clamp.x = accel_scale_clamp(args.cap.x); clamp.y = accel_scale_clamp(args.cap.y); } @@ -146,16 +136,14 @@ namespace rawaccel { double time_clamped = clampsd(time, time_min, 100); double speed = maxsd(mag / time_clamped - speed_offset, 0); - double accel_val = accel.visit([=](auto&& impl) { - return impl.accelerate(speed); + vec2d scale = accel.visit([=](auto&& impl) { + double accel_val = impl.accelerate(speed); + return impl.scale(accel_val); }); - double scale_x = weight.x * accel_val + scale_base; - double scale_y = weight.y * accel_val + scale_base; - return { - input.x * clamp.x(scale_x), - input.y * clamp.y(scale_y) + input.x * clamp.x(scale.x), + input.y * clamp.y(scale.y) }; } |