summaryrefslogtreecommitdiff
path: root/common/accel-natural.hpp
blob: c87fda84e5592d120c7626f459a5cb458cfe96de (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
#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(const 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(const accel_args& args) const {
			if (args.limit <= 1) error("limit must be greater than 1");
		}
	};

}