blob: 9f76d1a117124e58efa18aff7b7b2ef51ad9add3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#pragma once
#include "rawaccel-base.hpp"
#include <math.h>
namespace rawaccel {
/// <summary> Struct to hold "natural" (vanishing difference) acceleration implementation. </summary>
struct natural_base {
double offset;
double accel;
double limit;
natural_base(const accel_args& args) :
offset(args.offset),
limit(args.limit - 1)
{
accel = args.decay_rate / fabs(limit);
}
};
struct natural_legacy : natural_base {
double operator()(double x) const
{
if (x <= offset) return 1;
double offset_x = offset - x;
double decay = exp(accel * offset_x);
return limit * (1 - (offset - decay * offset_x) / x) + 1;
}
using natural_base::natural_base;
};
struct natural : natural_base {
double constant;
double operator()(double x) const
{
if (x <= offset) return 1;
double offset_x = offset - x;
double decay = exp(accel * offset_x);
double output = limit * (decay / accel - offset_x) + constant;
return output / x + 1;
}
natural(const accel_args& args) :
natural_base(args),
constant(-limit / accel) {}
};
}
|