Applies the deadzone settings for the axis @a id to @a axis and returns its value.
| 296 | |
| 297 | /// Applies the deadzone settings for the axis @a id to @a axis and returns its value. |
| 298 | static Vector3 deadzone(const InputDevice *dev, u8 id, const Vector3 &axis) |
| 299 | { |
| 300 | Vector3 out; |
| 301 | |
| 302 | switch (dev->_deadzone_mode[id]) { |
| 303 | case DeadzoneMode::RAW: |
| 304 | out = axis; |
| 305 | break; |
| 306 | |
| 307 | case DeadzoneMode::INDEPENDENT: |
| 308 | out.x = fabs(axis.x) < dev->_deadzone_size[id] ? 0.0f : axis.x; |
| 309 | out.y = fabs(axis.y) < dev->_deadzone_size[id] ? 0.0f : axis.y; |
| 310 | out.z = fabs(axis.z) < dev->_deadzone_size[id] ? 0.0f : axis.z; |
| 311 | break; |
| 312 | |
| 313 | case DeadzoneMode::CIRCULAR: |
| 314 | if (length(axis) < dev->_deadzone_size[id]) { |
| 315 | out = VECTOR3_ZERO; |
| 316 | } else { |
| 317 | const f32 size = 1.0f - dev->_deadzone_size[id]; |
| 318 | const f32 size_inv = 1.0f / size; |
| 319 | const f32 axis_len = length(axis); |
| 320 | out = axis; |
| 321 | out = normalize(out) * (axis_len - dev->_deadzone_size[id]) * size_inv; |
| 322 | } |
| 323 | break; |
| 324 | |
| 325 | default: |
| 326 | CE_FATAL("Unknown deadzone mode"); |
| 327 | out = axis; |
| 328 | break; |
| 329 | } |
| 330 | |
| 331 | return out; |
| 332 | } |
| 333 | |
| 334 | void InputManager::read(const OsEvent &event) |
| 335 | { |