#pragma once #define _USE_MATH_DEFINES #include 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; /// Struct to hold arguments for an acceleration function. struct accel_args { milliseconds time_min = 0.4; double offset = 0; double accel = 0; double lim_exp = 2; double midpoint = 0; }; /// /// Struct to hold acceleration curve implementation details. /// /// Type of acceleration. template struct accel_implentation { /// First constant for use in acceleration curves. Generally, the acceleration ramp rate. double curve_constant_one = 0; /// Second constant for use in acceleration curves. Generally, the limit or exponent in the curve. double curve_constant_two = 0; /// Third constant for use in acceleration curves. The midpoint in sigmoid mode. double curve_constant_three = 0; /// The offset past which acceleration is applied. Used in power mode. double offset = 0; /// /// Initializes a new instance of the struct. /// /// /// 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; } /// /// Returns accelerated value of speed as a ratio of magnitude. /// /// Mouse speed at which to calculate acceleration. /// Ratio of accelerated movement magnitude to input movement magnitude. double accelerate(double speed) { return 0; } /// /// Verifies arguments as valid. Errors if not. /// /// Arguments to verified. 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"); } /// /// /// /// accel_implentation() = default; }; /// Struct to hold linear acceleration implementation. struct accel_linear : accel_implentation { accel_linear(accel_args args); double accelerate(double speed); void verify(accel_args args); }; /// Struct to hold "classic" (linear raised to power) acceleration implementation. struct accel_classic : accel_implentation { accel_classic(accel_args args); double accelerate(double speed); void verify(accel_args args); }; /// Struct to hold "natural" (vanishing difference) acceleration implementation. struct accel_natural : accel_implentation { accel_natural(accel_args args); double accelerate(double speed); void verify(accel_args args); }; /// Struct to hold logarithmic acceleration implementation. struct accel_logarithmic : accel_implentation { accel_logarithmic(accel_args args); double accelerate(double speed); void verify(accel_args args); }; /// Struct to hold sigmoid (s-shaped) acceleration implementation. struct accel_sigmoid : accel_implentation { accel_sigmoid(accel_args args); double accelerate(double speed); void verify(accel_args args); }; /// Struct to hold power (non-additive) acceleration implementation. struct accel_power : accel_implentation { accel_power(accel_args args); double accelerate(double speed); void verify(accel_args args); }; /// Struct to hold acceleration implementation which applies no acceleration. struct accel_noaccel : accel_implentation { accel_noaccel(accel_args args); double accelerate(double speed); void verify(accel_args args); }; }