diff options
| author | a1xd <[email protected]> | 2020-07-30 17:07:35 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2020-07-30 17:07:35 -0400 |
| commit | e8417a29fb2153ea035a757f36bfa300cf8b480d (patch) | |
| tree | 802905bbf262196678e140463150e66d0a674b01 /common/accel-natural.hpp | |
| parent | Merge remote-tracking branch 'downstream/Inheritance' into st-refactor (diff) | |
| download | rawaccel-e8417a29fb2153ea035a757f36bfa300cf8b480d.tar.xz rawaccel-e8417a29fb2153ea035a757f36bfa300cf8b480d.zip | |
add tweaks for st-refactor
Diffstat (limited to 'common/accel-natural.hpp')
| -rw-r--r-- | common/accel-natural.hpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/common/accel-natural.hpp b/common/accel-natural.hpp new file mode 100644 index 0000000..6ccb193 --- /dev/null +++ b/common/accel-natural.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include <math.h> + +#include "accel-base.hpp" + +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(accel_args args) : accel_base(args) { + verify(args); + + limit = args.limit - 1; + speed_coeff /= limit; + } + + inline double accelerate(double speed) const { + // f(x) = k(1-e^(-mx)) + return limit - (limit * exp(-speed_coeff * speed)); + } + + void verify(accel_args args) const { + if (args.limit <= 1) error("limit must be greater than 1"); + } + }; + +} |