Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
Loading...
Searching...
No Matches
gamepad_input.c File Reference
#include "gamepad_input.h"
#include "bool_utils.h"
#include "gamepad_context.h"
#include "log.h"
#include <GLFW/glfw3.h>
#include <math.h>
Include dependency graph for gamepad_input.c:

Macros

#define GLFW_INCLUDE_NONE
 
#define TRIGGER_NORM_FACTOR   0.5F
 

Functions

void gamepad_input_init (GamepadState *state)
 Initializes gamepad state with default values.
 
float gamepad_apply_deadzone (float value, float deadzone)
 Applies a dead-zone filter to an axis value.
 
static void gamepad_poll_buttons (GamepadState *state, const GLFWgamepadstate *pad, GamepadActions *actions)
 Detects edge-triggered button presses and saves state.
 
void gamepad_input_poll (GamepadState *state, GamepadActions *actions)
 Polls GLFW gamepad state and detects button events.
 
void gamepad_write_input (const GamepadState *state, GamepadContext *ctx)
 Writes gamepad axes into a GamepadContext.
 

Macro Definition Documentation

◆ GLFW_INCLUDE_NONE

#define GLFW_INCLUDE_NONE

◆ TRIGGER_NORM_FACTOR

#define TRIGGER_NORM_FACTOR   0.5F

Factor to convert GLFW trigger range [-1,1] to normalised [0,1].

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_poll_buttons()

static void gamepad_poll_buttons ( GamepadState *  state,
const GLFWgamepadstate *  pad,
GamepadActions *  actions 
)
static

Detects edge-triggered button presses and saves state.

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