summaryrefslogtreecommitdiff
path: root/common/accel-natural.hpp
diff options
context:
space:
mode:
authorJacobPalecki <[email protected]>2020-08-31 23:03:46 -0700
committerGitHub <[email protected]>2020-08-31 23:03:46 -0700
commit471fe599bab6ba0632ddd1dacd20c7fc42db0eee (patch)
tree90a82ee14dbb112621657efbd2523ed35f59d154 /common/accel-natural.hpp
parentMerge pull request #16 from JacobPalecki/Misc (diff)
parentadd independent xy accel to driver (diff)
downloadrawaccel-471fe599bab6ba0632ddd1dacd20c7fc42db0eee.tar.xz
rawaccel-471fe599bab6ba0632ddd1dacd20c7fc42db0eee.zip
Merge pull request #17 from a1xd/indep
Indep
Diffstat (limited to 'common/accel-natural.hpp')
-rw-r--r--common/accel-natural.hpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/common/accel-natural.hpp b/common/accel-natural.hpp
index 8f002e4..c7d0dcd 100644
--- a/common/accel-natural.hpp
+++ b/common/accel-natural.hpp
@@ -7,25 +7,23 @@
namespace rawaccel {
/// <summary> Struct to hold "natural" (vanishing difference) acceleration implementation. </summary>
- struct accel_natural : accel_base {
- double limit = 1;
- double midpoint = 0;
-
- accel_natural(const accel_args& args) : accel_base(args) {
- verify(args);
-
- limit = args.limit - 1;
- speed_coeff /= limit;
+ struct natural_impl {
+ double rate;
+ double limit;
+
+ natural_impl(const accel_args& args) :
+ rate(args.accel), limit(args.limit - 1)
+ {
+ rate /= limit;
}
- inline double accelerate(double speed) const {
+ inline double operator()(double speed) const {
// f(x) = k(1-e^(-mx))
- return limit - (limit * exp(-speed_coeff * speed));
+ return limit - (limit * exp(-rate * speed));
}
- void verify(const accel_args& args) const {
- if (args.limit <= 1) bad_arg("limit must be greater than 1");
- }
};
+ using accel_natural = additive_accel<natural_impl>;
+
}