blob: 7f4c220087ac4abf6bd97e8eb46696a74fca73df (
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
|
#pragma once
#include <math.h>
#include "accel-base.hpp"
namespace rawaccel {
/// <summary> Struct to hold power (non-additive) acceleration implementation. </summary>
struct accel_power : accel_base {
double exponent;
double offset;
accel_power(const accel_args& args) {
verify(args);
weight = args.weight;
speed_coeff = args.power_scale;
exponent = args.exponent;
offset = args.offset;
}
inline double accelerate(double speed) const {
// f(x) = (mx)^k
return (offset > 0 && speed < 1) ? 1 : pow(speed * speed_coeff, exponent);
}
inline vec2d scale(double accel_val) const {
return {
weight.x * accel_val,
weight.y * accel_val
};
}
void verify(const accel_args& args) const {
if (args.power_scale <= 0) error("scale must be positive");
if (args.exponent <= 0) error("exponent must be greater than 0");
}
};
}
|