Skip to main content

RadialDeadzoneStrategy.ixx File

Radial (circular) deadzone strategy for gamepad analog stick input. More...

Included Headers

#include <cmath> #include <helios.math.utils> #include <helios.input.gamepad.DeadzoneStrategy>

Namespaces Index

namespacehelios
namespaceinput

Input handling and management. More...

namespacegamepad

Gamepad input handling and configuration. More...

Classes Index

classRadialDeadzoneStrategy

Implements a radial (circular) deadzone strategy for analog stick normalization. More...

Description

Radial (circular) deadzone strategy for gamepad analog stick input.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file RadialDeadzoneStrategy.ixx
3 * @brief Radial (circular) deadzone strategy for gamepad analog stick input.
4 */
5module;
6
7#include <cmath>
8
9export module helios.input.gamepad.RadialDeadzoneStrategy;
10
11import helios.input.gamepad.DeadzoneStrategy;
12import helios.math.utils;
13
14
15export namespace helios::input::gamepad {
16
17 /**
18 * @brief Implements a radial (circular) deadzone strategy for analog stick normalization.
19 *
20 * This strategy treats the deadzone as a circle centered at the origin. Input vectors
21 * with a magnitude less than or equal to the deadzone threshold are zeroed out completely.
22 * Input vectors exceeding the deadzone are rescaled so that the effective input range
23 * starts at the edge of the deadzone circle, providing a smooth and consistent response.
24 *
25 * The radial approach is generally preferred over axial deadzones because it eliminates
26 * diagonal movement artifacts and provides uniform sensitivity in all directions.
27 *
28 * **Algorithm:**
29 * 1 Calculate the magnitude (length) of the input vector.
30 * 2 If magnitude <= deadzone, set both axes to zero.
31 * 3 If magnitude > 1.0, normalize the vector to unit length.
32 * 4 Rescale the magnitude from [deadzone, 1.0] to [0.0, 1.0].
33 * 5 Apply the rescaled magnitude to the normalized direction vector.
34 *
35 * @see DeadzoneStrategy for the abstract interface.
36 */
38
39 public:
40
41 /**
42 * @copydoc helios::input::gamepad::DeadzoneStrategy::DeadzoneStrategy()
43 */
45
46 /**
47 * @copydoc helios::input::gamepad::DeadzoneStrategy::DeadzoneStrategy(float stickNoiseThreshold)
48 */
50
51 /**
52 * @brief Applies radial deadzone normalization to stick input.
53 *
54 * Modifies the input coordinates in-place. Values within the circular deadzone
55 * are zeroed, while values outside are rescaled for a smooth response curve.
56 *
57 * @param deadzone The deadzone radius threshold in the range [0.0, 1.0].
58 * @param x Reference to the x-axis value, modified in-place.
59 * @param y Reference to the y-axis value, modified in-place.
60 */
61 void normalize(float deadzone, float& x, float& y) const noexcept override {
62
63 auto len = std::hypot(x, y);
64
65 if (len <= stickNoiseThreshold() || len <= deadzone || deadzone >= 1.0f) {
66 x = 0;
67 y = 0;
68 return;
69 }
70
71 const float clampedLen = len > 1.0f ? 1.0f : len;
72
73 const float normalizedLen = (clampedLen - deadzone)/(1.0f - deadzone);
74
75 const float scale = normalizedLen / len;
76
77 x *= scale;
78 y *= scale;
79 }
80
81
82 };
83
84
85}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.