| 216 | } |
| 217 | |
| 218 | void XboxOneController::NormalizeAxis(int16_t x, |
| 219 | int16_t y, |
| 220 | uint8_t deadzonePercent, |
| 221 | float *x_out, |
| 222 | float *y_out) |
| 223 | { |
| 224 | float x_val = x; |
| 225 | float y_val = y; |
| 226 | // Determine how far the stick is pushed. |
| 227 | //This will never exceed 32767 because if the stick is |
| 228 | //horizontally maxed in one direction, vertically it must be neutral(0) and vice versa |
| 229 | float real_magnitude = std::sqrt(x_val * x_val + y_val * y_val); |
| 230 | float real_deadzone = (32767 * deadzonePercent) / 100; |
| 231 | // Check if the controller is outside a circular dead zone. |
| 232 | if (real_magnitude > real_deadzone) |
| 233 | { |
| 234 | // Clip the magnitude at its expected maximum value. |
| 235 | float magnitude = std::min(32767.0f, real_magnitude); |
| 236 | // Adjust magnitude relative to the end of the dead zone. |
| 237 | magnitude -= real_deadzone; |
| 238 | // Normalize the magnitude with respect to its expected range giving a |
| 239 | // magnitude value of 0.0 to 1.0 |
| 240 | //ratio = (currentValue / maxValue) / realValue |
| 241 | float ratio = (magnitude / (32767 - real_deadzone)) / real_magnitude; |
| 242 | |
| 243 | *x_out = x_val * ratio; |
| 244 | *y_out = y_val * ratio; |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | // If the controller is in the deadzone zero out the magnitude. |
| 249 | *x_out = *y_out = 0.0f; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | //Pass by value should hopefully be optimized away by RVO |
| 254 | NormalizedButtonData XboxOneController::GetNormalizedButtonData() |
nothing calls this directly
no outgoing calls
no test coverage detected