diff options
| author | a1xd <[email protected]> | 2020-08-22 22:33:45 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-08-22 22:33:45 -0400 |
| commit | 252637e53ca42353061dc3118e8625af6edc348f (patch) | |
| tree | 26ea73edae996242eaef559485309fb9c66f4d30 /common/accel-naturalgain.hpp | |
| parent | Merge pull request #15 from JacobPalecki/GUI (diff) | |
| parent | delete personal settings.json left in repo (diff) | |
| download | rawaccel-252637e53ca42353061dc3118e8625af6edc348f.tar.xz rawaccel-252637e53ca42353061dc3118e8625af6edc348f.zip | |
Merge pull request #16 from JacobPalecki/Misc
Gain Styles, Settings File, and other miscellaneous
Diffstat (limited to 'common/accel-naturalgain.hpp')
| -rw-r--r-- | common/accel-naturalgain.hpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/common/accel-naturalgain.hpp b/common/accel-naturalgain.hpp new file mode 100644 index 0000000..95c0be2 --- /dev/null +++ b/common/accel-naturalgain.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include <math.h> + +#include "accel-base.hpp" + +namespace rawaccel { + + /// <summary> Struct to hold "natural" (vanishing difference) gain implementation. </summary> + struct accel_naturalgain : accel_base { + double limit = 1; + double midpoint = 0; + + accel_naturalgain(const accel_args& args) : accel_base(args) { + verify(args); + + limit = args.limit - 1; + speed_coeff /= limit; + } + + inline double accelerate(double speed) const { + // f(x) = k((e^(-mx)-1)/mx + 1) + double scaled_speed = speed_coeff * speed; + return limit * (((exp(-scaled_speed) - 1) / scaled_speed) + 1); + } + + void verify(const accel_args& args) const { + if (args.limit <= 1) bad_arg("limit must be greater than 1"); + } + }; + +} |