diff options
| author | Jacob Palecki <[email protected]> | 2020-09-20 21:52:01 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-09-20 21:52:01 -0700 |
| commit | ac8df552951ba6265a71f827bc8b975eecfbcdd4 (patch) | |
| tree | 2503621b64c91c05d07439b8917d6f16751d27b0 /common | |
| parent | log sigmoid sens done (diff) | |
| download | rawaccel-ac8df552951ba6265a71f827bc8b975eecfbcdd4.tar.xz rawaccel-ac8df552951ba6265a71f827bc8b975eecfbcdd4.zip | |
Add icon and second experiment
Diffstat (limited to 'common')
| -rw-r--r-- | common/accel-experimenttwo.hpp | 77 | ||||
| -rw-r--r-- | common/common.vcxitems | 1 |
2 files changed, 78 insertions, 0 deletions
diff --git a/common/accel-experimenttwo.hpp b/common/accel-experimenttwo.hpp new file mode 100644 index 0000000..8359cc2 --- /dev/null +++ b/common/accel-experimenttwo.hpp @@ -0,0 +1,77 @@ +#pragma once + +#include <math.h> + +#include "accel-base.hpp" + +namespace rawaccel { + + /// <summary> Struct to hold sigmoid (s-shaped) gain implementation. </summary> + struct experimenttwo_impl { + double rate; + double limit; + double midpoint; + double subtractive_constant; + + experimenttwo_impl(const accel_args& args) : + rate(pow(10,args.rate)), limit(2*log10(args.limit)), midpoint(log10(args.midpoint)) + { + subtractive_constant = limit / 2; + } + + inline double operator()(double speed) const { + double log_speed = log10(speed); + return pow(10, limit / (exp(-rate * (log_speed - midpoint)) + 1) - subtractive_constant); + + } + + inline double legacy_offset(double speed) const { return operator()(speed); } + + inline double apply(double* lookup, double speed) + { + int index = map(speed); + double slope = lookup[index]; + double intercept = lookup[index + 1]; + return slope + intercept / speed; + } + + inline int map(double speed) + { + return speed > 0 ? (int)floor(200*log10(speed)+402) : 0; + } + + inline double fill(double* lookup) + { + double lookup_speed = 0; + double gain_integral_speed = 0; + double gain = 0; + double intercept = 0; + double output = 0; + int index = 0; + + lookup[index] = gain; + lookup[index + 1] = intercept; + + for (double x = -2.0; x <= 4.0; x += 0.01) + { + index+=2; + lookup_speed = pow(10,x); + + while (gain_integral_speed < lookup_speed) + { + gain_integral_speed += 0.001; + gain = operator()(gain_integral_speed); + output += gain*0.001; + } + + intercept = gain * lookup_speed - output; + lookup[index] = gain; + lookup[index + 1] = intercept; + } + + } + }; + + using accel_experimentone = nonadditive_accel<experimenttwo_impl>; + +} diff --git a/common/common.vcxitems b/common/common.vcxitems index 21a58aa..b5cd374 100644 --- a/common/common.vcxitems +++ b/common/common.vcxitems @@ -17,6 +17,7 @@ <ClInclude Include="$(MSBuildThisFileDirectory)accel-base.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-classic.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-experimentone.hpp" /> + <ClInclude Include="$(MSBuildThisFileDirectory)accel-experimenttwo.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-linear.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-logarithm.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-natural.hpp" /> |