summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJacobPalecki <[email protected]>2020-09-22 19:59:47 -0700
committerGitHub <[email protected]>2020-09-22 19:59:47 -0700
commit77f420cf45a1a0bee00602965e687097367e2a70 (patch)
treefa088af8f2feb54df5bcb6a036715fd32d0511e8 /common
parentMerge pull request #21 from JacobPalecki/GUI (diff)
parentUpdate credits (diff)
downloadrawaccel-77f420cf45a1a0bee00602965e687097367e2a70.tar.xz
rawaccel-77f420cf45a1a0bee00602965e687097367e2a70.zip
Merge pull request #22 from JacobPalecki/GUI
Replace SigmoidGain with Motivity & Cleanup
Diffstat (limited to 'common')
-rw-r--r--common/accel-experimentone.hpp33
-rw-r--r--common/accel-motivity.hpp89
-rw-r--r--common/accel-sigmoidgain.hpp34
-rw-r--r--common/common.vcxitems3
-rw-r--r--common/rawaccel-settings.h2
-rw-r--r--common/rawaccel.hpp31
6 files changed, 146 insertions, 46 deletions
diff --git a/common/accel-experimentone.hpp b/common/accel-experimentone.hpp
new file mode 100644
index 0000000..7d21b58
--- /dev/null
+++ b/common/accel-experimentone.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <math.h>
+
+#include "accel-base.hpp"
+
+namespace rawaccel {
+
+ /// <summary> Struct to hold sigmoid (s-shaped) gain implementation. </summary>
+ struct experimentone_impl {
+ double rate;
+ double limit;
+ double midpoint;
+ double subtractive_constant;
+
+ experimentone_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); }
+ };
+
+ using accel_experimentone = nonadditive_accel<experimentone_impl>;
+
+}
diff --git a/common/accel-motivity.hpp b/common/accel-motivity.hpp
new file mode 100644
index 0000000..a37d1ce
--- /dev/null
+++ b/common/accel-motivity.hpp
@@ -0,0 +1,89 @@
+#pragma once
+
+#include <math.h>
+
+#include "accel-base.hpp"
+
+#define RA_LOOKUP
+
+namespace rawaccel {
+
+ constexpr size_t LUT_SIZE = 601;
+
+ struct si_pair {
+ double slope = 0;
+ double intercept = 0;
+ };
+
+ /// <summary> Struct to hold sigmoid (s-shaped) gain implementation. </summary>
+ struct motivity_impl {
+ double rate;
+ double limit;
+ double midpoint;
+ double subtractive_constant;
+
+ motivity_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(si_pair* lookup, double speed) const
+ {
+ si_pair pair = lookup[map(speed)];
+ return pair.slope + pair.intercept / speed;
+ }
+
+ inline int map(double speed) const
+ {
+ int index = speed > 0 ? (int)(100 * log10(speed) + 201) : 0;
+
+ if (index < 0) return 0;
+ if (index >= LUT_SIZE) return LUT_SIZE - 1;
+
+ return index;
+ }
+
+ inline void fill(si_pair* lookup) const
+ {
+ double lookup_speed = 0;
+ double gain_integral_speed = 0;
+ double gain = 0;
+ double intercept = 0;
+ double output = 0;
+ double x = -2;
+
+ lookup[0] = {};
+
+ for (size_t i = 1; i < LUT_SIZE; i++)
+ {
+ x += 0.01;
+
+ 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 = output - gain * lookup_speed;
+
+ lookup[i] = { gain, intercept };
+ }
+
+ }
+ };
+
+ using accel_motivity = nonadditive_accel<motivity_impl>;
+
+}
diff --git a/common/accel-sigmoidgain.hpp b/common/accel-sigmoidgain.hpp
deleted file mode 100644
index bed2f16..0000000
--- a/common/accel-sigmoidgain.hpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#pragma once
-
-#include <math.h>
-
-#include "accel-base.hpp"
-
-namespace rawaccel {
-
- /// <summary> Struct to hold sigmoid (s-shaped) gain implementation. </summary>
- struct sigmoidgain_impl {
- double rate;
- double limit;
- double additive_constant;
- double integration_constant;
-
- sigmoidgain_impl(const accel_args& args) :
- rate(args.rate), limit(args.limit - 1)
- {
- additive_constant = exp(rate * args.midpoint);
- integration_constant = log(1 + additive_constant);
- }
-
- inline double operator()(double speed) const {
- //f(x) = k/(1+e^(-m(c-x)))
- double scaled_speed = rate * speed;
- return limit * ((log(additive_constant+exp(scaled_speed)) - integration_constant)/scaled_speed);
- }
-
- inline double legacy_offset(double speed) const { return operator()(speed); }
- };
-
- using accel_sigmoidgain = additive_accel<sigmoidgain_impl>;
-
-}
diff --git a/common/common.vcxitems b/common/common.vcxitems
index fcd3ae8..3407cf2 100644
--- a/common/common.vcxitems
+++ b/common/common.vcxitems
@@ -16,13 +16,14 @@
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)accel-base.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)accel-classic.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-experimentone.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-motivity.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)accel-linear.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)accel-logarithm.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-sigmoidgain.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-error.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-io.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-settings.h" />
diff --git a/common/rawaccel-settings.h b/common/rawaccel-settings.h
index 8c483eb..2ba6a98 100644
--- a/common/rawaccel-settings.h
+++ b/common/rawaccel-settings.h
@@ -6,7 +6,7 @@
namespace rawaccel {
enum class accel_mode {
- linear, classic, natural, naturalgain, sigmoidgain, power, logarithm, noaccel
+ linear, classic, natural, naturalgain, power, logarithm, motivity, noaccel
};
struct settings {
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index 8819302..2e627c9 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -12,7 +12,7 @@
#include "accel-natural.hpp"
#include "accel-naturalgain.hpp"
#include "accel-power.hpp"
-#include "accel-sigmoidgain.hpp"
+#include "accel-motivity.hpp"
#include "accel-noaccel.hpp"
namespace rawaccel {
@@ -83,14 +83,16 @@ namespace rawaccel {
case accel_mode::classic: return vis(var.u.classic);
case accel_mode::natural: return vis(var.u.natural);
case accel_mode::naturalgain: return vis(var.u.naturalgain);
- case accel_mode::sigmoidgain: return vis(var.u.sigmoidgain);
case accel_mode::power: return vis(var.u.power);
case accel_mode::logarithm: return vis(var.u.logarithm);
+ case accel_mode::motivity: return vis(var.u.motivity);
default: return vis(var.u.noaccel);
}
}
struct accel_variant {
+ si_pair* lookup;
+
accel_mode tag = accel_mode::noaccel;
union union_t {
@@ -98,21 +100,30 @@ namespace rawaccel {
accel_classic classic;
accel_natural natural;
accel_naturalgain naturalgain;
- accel_sigmoidgain sigmoidgain;
accel_power power;
accel_logarithm logarithm;
+ accel_motivity motivity;
accel_noaccel noaccel = {};
} u = {};
- accel_variant(const accel_args& args, accel_mode mode) :
- tag(mode)
+ accel_variant(const accel_args& args, accel_mode mode, si_pair* lut = nullptr) :
+ tag(mode), lookup(lut)
{
visit_accel([&](auto& impl) {
impl = { args };
}, *this);
+
+ if (lookup && tag == accel_mode::motivity) {
+ u.motivity.fn.fill(lookup);
+ }
+
}
inline double apply(double speed) const {
+ if (lookup && tag == accel_mode::motivity) {
+ return u.motivity.fn.apply(lookup, speed);
+ }
+
return visit_accel([=](auto&& impl) {
return impl(speed);
}, *this);
@@ -190,8 +201,8 @@ namespace rawaccel {
velocity_gain_cap gain_cap;
accel_scale_clamp clamp;
- accelerator(const accel_args& args, accel_mode mode) :
- accel(args, mode), gain_cap(args.gain_cap, accel), clamp(args.scale_cap)
+ accelerator(const accel_args& args, accel_mode mode, si_pair* lut = nullptr) :
+ accel(args, mode, lut), gain_cap(args.gain_cap, accel), clamp(args.scale_cap)
{}
inline double apply(double speed) const {
@@ -213,7 +224,7 @@ namespace rawaccel {
vec2<accelerator> accels;
vec2d sensitivity = { 1, 1 };
- mouse_modifier(const settings& args) :
+ mouse_modifier(const settings& args, vec2<si_pair*> luts = {}) :
combine_magnitudes(args.combine_mags)
{
if (args.degrees_rotation != 0) {
@@ -230,8 +241,8 @@ namespace rawaccel {
return;
}
- accels.x = accelerator(args.argsv.x, args.modes.x);
- accels.y = accelerator(args.argsv.y, args.modes.y);
+ accels.x = accelerator(args.argsv.x, args.modes.x, luts.x);
+ accels.y = accelerator(args.argsv.y, args.modes.y, luts.y);
apply_accel = true;
}