Unravel Engine C++ Reference
Loading...
Searching...
No Matches
deadzone.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "point.hpp"
4#include <cmath>
5#include <functional>
6
7namespace input
8{
9// Deadzone filter functions for a single value
10using deadzone_float_filter = std::function<float(const float, const float)>;
11
12// Deadzone filter functions for two values (XY)
13using deadzone_point_filter = std::function<point(const float, const float, const float)>;
14
15// ----------------------------------------------------------------------------
16static auto no_deadzone(const float deadzone, const float value) -> float
17{
18 return value;
19}
20
21// ----------------------------------------------------------------------------
22static auto basic_deadzone(const float deadzone, const float value) -> float
23{
24 if(std::abs(value) >= deadzone)
25 {
26 return value;
27 }
28
29 return 0.0f;
30}
31
32// ----------------------------------------------------------------------------
33static auto no_deadzone(const float deadzone, const float x, const float y) -> point
34{
35 return {x, y};
36}
37
38// ----------------------------------------------------------------------------
39static auto radial_deadzone(const float deadzone, const float x, const float y) -> point
40{
41 // Calculate vector length
42 const double length = std::sqrt(x * x + y * y);
43
44 // Normalize if needed
45 if(length > 1.0f)
46 {
47 const float nx = x / length;
48 const float ny = y / length;
49 return radial_deadzone(deadzone, nx, ny);
50 }
51
52 if(length >= deadzone)
53 {
54 return {x, y};
55 }
56
57 return {0.0f, 0.0f};
58}
59} // namespace input
std::function< point(const float, const float, const float)> deadzone_point_filter
Definition deadzone.hpp:13
std::function< float(const float, const float)> deadzone_float_filter
Definition deadzone.hpp:10
managed_vector3 point