$darkmode
Gamepad/controller input adapter for camera control. More...
#include "gamepad_context.h"Go to the source code of this file.
Data Structures | |
| struct | GamepadActions |
| Edge-detected button events produced by a single poll. More... | |
| struct | GamepadState |
Macros | |
| #define | GAMEPAD_BUTTON_COUNT 15 |
| #define | GAMEPAD_DEFAULT_DEADZONE 0.15F |
| #define | GAMEPAD_DEFAULT_LOOK_SENSITIVITY 120.0F |
| #define | GAMEPAD_DEFAULT_MOVE_SENSITIVITY 1.0F |
| #define | GAMEPAD_DEFAULT_TRIGGER_THRESHOLD 0.1F |
| #define | GAMEPAD_AXIS_COUNT 6 |
Functions | |
| void | gamepad_input_init (GamepadState *state) |
| Initializes gamepad state with default values. More... | |
| void | gamepad_input_poll (GamepadState *state, GamepadActions *actions) |
| Polls GLFW gamepad state and detects button events. More... | |
| void | gamepad_write_input (const GamepadState *state, GamepadContext *ctx) |
| Writes gamepad axes into a GamepadContext. More... | |
| float | gamepad_apply_deadzone (float value, float deadzone) |
| Applies a dead-zone filter to an axis value. More... | |
Gamepad/controller input adapter for camera control.
Polls GLFW gamepad state and translates stick axes and buttons into camera movement and orientation, with configurable dead-zones. Designed for DualShock 4 / DualSense but works with any SDL_GameControllerDB-mapped controller.
| #define GAMEPAD_AXIS_COUNT 6 |
Number of gamepad axes cached for per-step application.
| #define GAMEPAD_BUTTON_COUNT 15 |
Maximum number of gamepad buttons tracked for edge detection.
| #define GAMEPAD_DEFAULT_DEADZONE 0.15F |
Default dead-zone threshold for analog sticks (0.0–1.0).
| #define GAMEPAD_DEFAULT_LOOK_SENSITIVITY 120.0F |
Look speed for the right stick in degrees per second.
| #define GAMEPAD_DEFAULT_MOVE_SENSITIVITY 1.0F |
Sensitivity multiplier for the left stick (movement).
| #define GAMEPAD_DEFAULT_TRIGGER_THRESHOLD 0.1F |
Trigger threshold to register as "pressed" (0.0–1.0).
| float gamepad_apply_deadzone | ( | float | value, |
| float | deadzone | ||
| ) |
Applies a dead-zone filter to an axis value.
Returns 0.0 if |value| < deadzone, otherwise rescales linearly so the usable range is [0, 1] (preserving sign).
| value | Raw axis value in [-1, 1]. |
| deadzone | Dead-zone threshold in [0, 1). |
| void gamepad_input_init | ( | GamepadState * | state | ) |
Initializes gamepad state with default values.
| state | Pointer to the gamepad state to initialize. |
| void gamepad_input_poll | ( | GamepadState * | state, |
| GamepadActions * | actions | ||
| ) |
Polls GLFW gamepad state and detects button events.
Reads axes (with deadzone) into state->axes for later use by gamepad_write_input. Detects edge-triggered button presses. Call once per frame, before the physics accumulator loop.
| state | Pointer to the persistent gamepad state. |
| actions | Output struct for edge-detected button events (may be NULL). |
| void gamepad_write_input | ( | const GamepadState * | state, |
| GamepadContext * | ctx | ||
| ) |
Writes gamepad axes into a GamepadContext.
Overlays analog stick values onto move_input and applies look (yaw/pitch). The caller bridges Camera ↔ GamepadContext.
| state | Pointer to the gamepad state (with cached axes). |
| ctx | Pointer to the context to write into. |