$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
gamepad_input.h File Reference

Gamepad/controller input adapter for camera control. More...

#include "gamepad_context.h"
Include dependency graph for gamepad_input.h:
This graph shows which files directly or indirectly include this file:

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...
 

Detailed Description

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.

Macro Definition Documentation

◆ GAMEPAD_AXIS_COUNT

#define GAMEPAD_AXIS_COUNT   6

Number of gamepad axes cached for per-step application.

◆ GAMEPAD_BUTTON_COUNT

#define GAMEPAD_BUTTON_COUNT   15

Maximum number of gamepad buttons tracked for edge detection.

◆ GAMEPAD_DEFAULT_DEADZONE

#define GAMEPAD_DEFAULT_DEADZONE   0.15F

Default dead-zone threshold for analog sticks (0.0–1.0).

◆ GAMEPAD_DEFAULT_LOOK_SENSITIVITY

#define GAMEPAD_DEFAULT_LOOK_SENSITIVITY   120.0F

Look speed for the right stick in degrees per second.

◆ GAMEPAD_DEFAULT_MOVE_SENSITIVITY

#define GAMEPAD_DEFAULT_MOVE_SENSITIVITY   1.0F

Sensitivity multiplier for the left stick (movement).

◆ GAMEPAD_DEFAULT_TRIGGER_THRESHOLD

#define GAMEPAD_DEFAULT_TRIGGER_THRESHOLD   0.1F

Trigger threshold to register as "pressed" (0.0–1.0).

Function Documentation

◆ gamepad_apply_deadzone()

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).

Parameters
valueRaw axis value in [-1, 1].
deadzoneDead-zone threshold in [0, 1).
Returns
Filtered axis value.

◆ gamepad_input_init()

void gamepad_input_init ( GamepadState *  state)

Initializes gamepad state with default values.

Parameters
statePointer to the gamepad state to initialize.

◆ gamepad_input_poll()

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.

Parameters
statePointer to the persistent gamepad state.
actionsOutput struct for edge-detected button events (may be NULL).
Here is the call graph for this function:

◆ gamepad_write_input()

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.

Parameters
statePointer to the gamepad state (with cached axes).
ctxPointer to the context to write into.