blob: 15f5a50f352f029050fc6331d3ec8c83b9d38e8c (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
#pragma once
#define _USE_MATH_DEFINES
#include <math.h>
namespace rawaccel {
// Error throwing calls std libraries which are unavailable in kernel mode.
#ifdef _KERNEL_MODE
inline void error(const char*) {}
#else
void error(const char* s);
#endif
using milliseconds = double;
/// <summary> Struct to hold arguments for an acceleration function. </summary>
struct accel_args {
milliseconds time_min = 0.4;
double offset = 0;
double accel = 0;
double lim_exp = 2;
double midpoint = 0;
};
/// <summary>
/// Struct to hold acceleration curve implementation details.
/// </summary>
/// <typeparam name="T">Type of acceleration.</typeparam>
template <typename T>
struct accel_implentation {
/// <summary> First constant for use in acceleration curves. Generally, the acceleration ramp rate.</summary>
double curve_constant_one = 0;
/// <summary> Second constant for use in acceleration curves. Generally, the limit or exponent in the curve. </summary>
double curve_constant_two = 0;
/// <summary> Third constant for use in acceleration curves. The midpoint in sigmoid mode. </summary>
double curve_constant_three = 0;
/// <summary> The offset past which acceleration is applied. Used in power mode. </summary>
double offset = 0;
/// <summary>
/// Initializes a new instance of the <see cref="accel_implementation{T}"/> struct.
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
accel_implentation(accel_args args)
{
curve_constant_one = args.accel;
curve_constant_two = args.lim_exp - 1;
curve_constant_three = args.midpoint;
offset = args.offset;
}
/// <summary>
/// Returns accelerated value of speed as a ratio of magnitude.
/// </summary>
/// <param name="speed">Mouse speed at which to calculate acceleration.</param>
/// <returns>Ratio of accelerated movement magnitude to input movement magnitude.</returns>
double accelerate(double speed) { return 0; }
/// <summary>
/// Verifies arguments as valid. Errors if not.
/// </summary>
/// <param name="args">Arguments to verified.</param>
void verify(accel_args args) {
if (args.accel < 0) error("accel can not be negative, use a negative weight to compensate");
if (args.time_min <= 0) error("min time must be positive");
}
/// <summary>
///
/// </summary>
/// <returns></returns>
accel_implentation() = default;
};
/// <summary> Struct to hold linear acceleration implementation. </summary>
struct accel_linear : accel_implentation<accel_linear> {
accel_linear(accel_args args);
double accelerate(double speed);
void verify(accel_args args);
};
/// <summary> Struct to hold "classic" (linear raised to power) acceleration implementation. </summary>
struct accel_classic : accel_implentation<accel_classic> {
accel_classic(accel_args args);
double accelerate(double speed);
void verify(accel_args args);
};
/// <summary> Struct to hold "natural" (vanishing difference) acceleration implementation. </summary>
struct accel_natural : accel_implentation<accel_natural> {
accel_natural(accel_args args);
double accelerate(double speed);
void verify(accel_args args);
};
/// <summary> Struct to hold logarithmic acceleration implementation. </summary>
struct accel_logarithmic : accel_implentation<accel_logarithmic> {
accel_logarithmic(accel_args args);
double accelerate(double speed);
void verify(accel_args args);
};
/// <summary> Struct to hold sigmoid (s-shaped) acceleration implementation. </summary>
struct accel_sigmoid : accel_implentation<accel_sigmoid> {
accel_sigmoid(accel_args args);
double accelerate(double speed);
void verify(accel_args args);
};
/// <summary> Struct to hold power (non-additive) acceleration implementation. </summary>
struct accel_power : accel_implentation<accel_power> {
accel_power(accel_args args);
double accelerate(double speed);
void verify(accel_args args);
};
/// <summary> Struct to hold acceleration implementation which applies no acceleration. </summary>
struct accel_noaccel : accel_implentation<accel_noaccel> {
accel_noaccel(accel_args args);
double accelerate(double speed);
void verify(accel_args args);
};
}
|