diff options
| author | a1xd <[email protected]> | 2021-07-05 23:33:41 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-07-05 23:33:41 -0400 |
| commit | 31efc792f5895d7ef3533390875de3c480add996 (patch) | |
| tree | 8db5b16a88f50448cb525ba8ae56801985294f63 /common/accel-natural.hpp | |
| parent | Merge pull request #87 from matthewstrasiotto/streamer_mode (diff) | |
| parent | Handle power\exponent correctly in GUI (diff) | |
| download | rawaccel-31efc792f5895d7ef3533390875de3c480add996.tar.xz rawaccel-31efc792f5895d7ef3533390875de3c480add996.zip | |
merge lut2
Diffstat (limited to 'common/accel-natural.hpp')
| -rw-r--r-- | common/accel-natural.hpp | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/common/accel-natural.hpp b/common/accel-natural.hpp index 03700c1..9f76d1a 100644 --- a/common/accel-natural.hpp +++ b/common/accel-natural.hpp @@ -1,35 +1,55 @@ #pragma once -#include <math.h> +#include "rawaccel-base.hpp" -#include "accel-base.hpp" +#include <math.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.decay_rate / 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 = offset - x; + double decay = exp(accel * offset_x); + return limit * (1 - (offset - decay * offset_x) / 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 = offset - x; + double decay = exp(accel * offset_x); + double output = limit * (decay / accel - offset_x) + constant; + return output / x + 1; + } + + natural(const accel_args& args) : + natural_base(args), + constant(-limit / accel) {} + }; } |