diff options
| author | a1xd <[email protected]> | 2021-03-29 17:14:49 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-03-29 17:14:49 -0400 |
| commit | 16dc4df3d438142ae378c9c6983585d06e0c6a33 (patch) | |
| tree | 1080b11b6ec98d6f47509ced922f2c338e0068bd /common/accel-natural.hpp | |
| parent | Merge pull request #81 from a1xd/log-unhandled-ex (diff) | |
| download | rawaccel-16dc4df3d438142ae378c9c6983585d06e0c6a33.tar.xz rawaccel-16dc4df3d438142ae378c9c6983585d06e0c6a33.zip | |
refactor common/settings
only driver compiles
remove accel-base types
merge linear + classic
move gain cap logic into classic impl, cap is now set in terms of output
use cap/limit to determine negation
remove weight, add replacement for power mode only
remove legacy offset option
remove naturalgain mode
add legacy mode flag
naturalgain -> natural
natural -> natural + legacy flag
add dpi setting and more accel args + defaults (prep for ips mode)
replace output speed cap with input cap
Diffstat (limited to 'common/accel-natural.hpp')
| -rw-r--r-- | common/accel-natural.hpp | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/common/accel-natural.hpp b/common/accel-natural.hpp index 03700c1..2939dbd 100644 --- a/common/accel-natural.hpp +++ b/common/accel-natural.hpp @@ -2,34 +2,52 @@ #include <math.h> -#include "accel-base.hpp" +#include "rawaccel-settings.h" namespace rawaccel { /// <summary> Struct to hold "natural" (vanishing difference) acceleration implementation. </summary> - struct natural_impl { - double rate; - double limit; + struct natural_base { double offset; + double accel; + double limit; - natural_impl(const accel_args& args) : - rate(args.accel), limit(args.limit - 1), offset(args.offset) + natural_base(const accel_args& args) : + offset(args.offset), + limit(args.limit - 1) { - rate /= limit; + accel = args.accel_natural / fabs(limit); } + }; - inline double operator()(double speed) const { - // f(x) = k(1-e^(-mx)) - double base_speed = speed + offset; - return limit * (1 - ((exp(-rate * speed) * speed + offset) / base_speed)); - } + struct natural_legacy : natural_base { + + double operator()(double x) const { + if (x <= offset) return 1; - inline double legacy_offset(double speed) const { - return limit - (limit * exp(-rate * speed)); + double offset_x = x - offset; + double decay = exp(-accel * offset_x); + return limit * (1 - (decay * offset_x + offset) / x) + 1; } + using natural_base::natural_base; }; - using accel_natural = additive_accel<natural_impl>; + struct natural : natural_base { + double constant; + + double operator()(double x) const { + if (x <= offset) return 1; + + double offset_x = x - offset; + double decay = exp(-accel * offset_x); + double output = limit * (offset_x + decay / accel) + constant; + return output / x + 1; + } + + natural(const accel_args& args) : + natural_base(args), + constant(-limit / accel) {} + }; } |