diff options
| author | Jacob Palecki <[email protected]> | 2020-07-31 12:20:11 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-07-31 12:20:11 -0700 |
| commit | 6537db04f7e717eda2f21e007cdba7e13b7f559e (patch) | |
| tree | efb65bf3f305f376ea75f4f687b08bf8998c020f /common/accel-base.hpp | |
| parent | Add class for storing settings from file (diff) | |
| parent | Merge pull request #6 from a1xd/st-refactor (diff) | |
| download | rawaccel-6537db04f7e717eda2f21e007cdba7e13b7f559e.tar.xz rawaccel-6537db04f7e717eda2f21e007cdba7e13b7f559e.zip | |
Show no settings for off, remove unused class for PR
Diffstat (limited to 'common/accel-base.hpp')
| -rw-r--r-- | common/accel-base.hpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/common/accel-base.hpp b/common/accel-base.hpp new file mode 100644 index 0000000..da2c96b --- /dev/null +++ b/common/accel-base.hpp @@ -0,0 +1,69 @@ +#pragma once + +#include "vec2.h" + +namespace rawaccel { + + // Error throwing calls std libraries which are unavailable in kernel mode. + void error(const char* s); + + using milliseconds = double; + + /// <summary> Struct to hold arguments for an acceleration function. </summary> + struct accel_args { + double offset = 0; + double accel = 0; + double limit = 2; + double exponent = 2; + double midpoint = 0; + double power_scale = 1; + vec2d weight = { 1, 1 }; + }; + + /// <summary> + /// Struct to hold common acceleration curve implementation details. + /// </summary> + struct accel_base { + + /// <summary> Coefficients applied to acceleration per axis.</summary> + vec2d weight = { 1, 1 }; + + /// <summary> Generally, the acceleration ramp rate. + double speed_coeff = 0; + + accel_base(const accel_args& args) { + verify(args); + + speed_coeff = args.accel; + weight = args.weight; + } + + /// <summary> + /// Default transformation of speed -> acceleration. + /// </summary> + inline double accelerate(double speed) const { + return speed_coeff * speed; + } + + /// <summary> + /// Default transformation of acceleration -> mouse input multipliers. + /// </summary> + inline vec2d scale(double accel_val) const { + return { + weight.x * accel_val + 1, + weight.y * accel_val + 1 + }; + } + + /// <summary> + /// Verifies arguments as valid. Errors if not. + /// </summary> + /// <param name="args">Arguments to verified.</param> + void verify(const accel_args& args) const { + if (args.accel < 0) error("accel can not be negative, use a negative weight to compensate"); + } + + accel_base() = default; + }; + +} |