diff options
| author | Jacob Palecki <[email protected]> | 2020-08-19 15:26:25 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-08-19 15:26:25 -0700 |
| commit | 53c9025337166a408febc15078af3e9b136b3bab (patch) | |
| tree | c124a399bf5ae56abf9405a41c2908fd753acfbe /common | |
| parent | Merge pull request #15 from JacobPalecki/GUI (diff) | |
| download | rawaccel-53c9025337166a408febc15078af3e9b136b3bab.tar.xz rawaccel-53c9025337166a408febc15078af3e9b136b3bab.zip | |
Add natural gain accel; add scale by DPI, poll rate in GUI
Diffstat (limited to 'common')
| -rw-r--r-- | common/accel-base.hpp | 2 | ||||
| -rw-r--r-- | common/accel-naturalgain.hpp | 32 | ||||
| -rw-r--r-- | common/common.vcxitems | 1 | ||||
| -rw-r--r-- | common/rawaccel.hpp | 3 |
4 files changed, 36 insertions, 2 deletions
diff --git a/common/accel-base.hpp b/common/accel-base.hpp index 60b7362..f280e3e 100644 --- a/common/accel-base.hpp +++ b/common/accel-base.hpp @@ -36,7 +36,7 @@ namespace rawaccel { /// <summary> Coefficients applied to acceleration per axis.</summary> vec2d weight = { 1, 1 }; - /// <summary> Generally, the acceleration ramp rate. + /// <summary> Generally, the acceleration ramp rate.</summary> double speed_coeff = 0; accel_base(const accel_args& args) { 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"); + } + }; + +} diff --git a/common/common.vcxitems b/common/common.vcxitems index 9696ac6..0471b5f 100644 --- a/common/common.vcxitems +++ b/common/common.vcxitems @@ -19,6 +19,7 @@ <ClInclude Include="$(MSBuildThisFileDirectory)accel-linear.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-logarithmic.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-natural.hpp" /> + <ClInclude Include="$(MSBuildThisFileDirectory)accel-naturalgain.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-noaccel.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-power.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-sigmoid.hpp" /> diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index 8dc4825..37418cd 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -9,6 +9,7 @@ #include "accel-linear.hpp" #include "accel-classic.hpp" #include "accel-natural.hpp" +#include "accel-naturalgain.hpp" #include "accel-logarithmic.hpp" #include "accel-sigmoid.hpp" #include "accel-power.hpp" @@ -76,7 +77,7 @@ namespace rawaccel { }; /// <summary> Tagged union to hold all accel implementations and allow "polymorphism" via a visitor call. </summary> - using accel_impl_t = tagged_union<accel_linear, accel_classic, accel_natural, accel_logarithmic, accel_sigmoid, accel_power, accel_noaccel>; + using accel_impl_t = tagged_union<accel_linear, accel_classic, accel_natural, accel_logarithmic, accel_sigmoid, accel_power, accel_naturalgain, accel_noaccel>; /// <summary> Struct to hold information about applying a gain cap. </summary> struct velocity_gain_cap { |