diff options
| author | a1xd <[email protected]> | 2020-07-31 05:12:04 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-07-31 05:12:04 -0400 |
| commit | d5c012bcd5b7321671f9591a3e58d0b2c9507467 (patch) | |
| tree | fe64110f7678607947d19c5ba0b46ea2b15d69c4 /common/accel-base.hpp | |
| parent | Merge pull request #5 from JacobPalecki/WrapperAndGrapher (diff) | |
| parent | update grapher/wrapper for st-refactor (diff) | |
| download | rawaccel-d5c012bcd5b7321671f9591a3e58d0b2c9507467.tar.xz rawaccel-d5c012bcd5b7321671f9591a3e58d0b2c9507467.zip | |
Merge pull request #6 from a1xd/st-refactor
Refactor
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; + }; + +} |