sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
sgltk::Gamepad Class Reference

Manages and handles gamepads. More...

#include <gamepad.h>

Public Member Functions

 Gamepad (unsigned int device_id)
void set_button_state (int button, bool state)
 Sets the state of a button.
void set_deadzone (unsigned int deadzone)
 Sets a dedzone for all axes.
int get_axis_value (unsigned int axis)
 Call this function to get the current value of an axis.
void play_rumble (float magnitude, unsigned int duration)
 Plays a rumble effect.
void stop_rumble ()
 Stops the rumble effect.

Public Attributes

unsigned int id
 The gamepad id. When a new gamepad is attached it is assigned the first free ID starting at 0.
unsigned int instance_id
 The instance ID of the gamepad as provided by an SDL2 event.
unsigned int num_axes
 The number of axes the gamepad has.
unsigned int num_buttons
 The number of buttons the gamepad has.
unsigned int deadzone
 The axis deadzone.
std::vector< int > buttons_pressed
 A list of all buttons currently pressed.

Detailed Description

Manages and handles gamepads.

Note
You should never have to create or delete objects of this class directly

Definition at line 14 of file gamepad.h.

Constructor & Destructor Documentation

◆ Gamepad()

Gamepad::Gamepad ( unsigned int device_id)
Parameters
device_idThe device id as provided by the SDL_CONTROLLERDEVICEADDED event

Definition at line 8 of file gamepad.cpp.

◆ ~Gamepad()

Gamepad::~Gamepad ( )

Definition at line 51 of file gamepad.cpp.

Member Function Documentation

◆ get_axis_value()

int Gamepad::get_axis_value ( unsigned int axis)

Call this function to get the current value of an axis.

Parameters
axisThe axis the value of which to get
Returns
The current value of the axis in the range from 0 to 32767 for a trigger and -32768 to 32767 for an analog stick

Definition at line 76 of file gamepad.cpp.

◆ play_rumble()

void Gamepad::play_rumble ( float magnitude,
unsigned int duration )

Plays a rumble effect.

Parameters
magnitudeThe strength of the rumble on a scale from 0 to 1
durationThe duration of the effect in milliseconds

Definition at line 83 of file gamepad.cpp.

◆ set_button_state()

void Gamepad::set_button_state ( int button,
bool state )

Sets the state of a button.

Parameters
buttonThe button the state of which is to be set
stateThe new state of the button

Definition at line 60 of file gamepad.cpp.

◆ set_deadzone()

void Gamepad::set_deadzone ( unsigned int deadzone)

Sets a dedzone for all axes.

Parameters
deadzoneThe deadzone

Definition at line 72 of file gamepad.cpp.

◆ stop_rumble()

void Gamepad::stop_rumble ( )

Stops the rumble effect.

Definition at line 89 of file gamepad.cpp.

Member Data Documentation

◆ buttons_pressed

std::vector<int> sgltk::Gamepad::buttons_pressed

A list of all buttons currently pressed.

Definition at line 48 of file gamepad.h.

◆ deadzone

unsigned int sgltk::Gamepad::deadzone

The axis deadzone.

Definition at line 44 of file gamepad.h.

◆ id

unsigned int sgltk::Gamepad::id

The gamepad id. When a new gamepad is attached it is assigned the first free ID starting at 0.

Definition at line 27 of file gamepad.h.

◆ instance_id

unsigned int sgltk::Gamepad::instance_id

The instance ID of the gamepad as provided by an SDL2 event.

Definition at line 32 of file gamepad.h.

◆ num_axes

unsigned int sgltk::Gamepad::num_axes

The number of axes the gamepad has.

Definition at line 36 of file gamepad.h.

◆ num_buttons

unsigned int sgltk::Gamepad::num_buttons

The number of buttons the gamepad has.

Definition at line 40 of file gamepad.h.


The documentation for this class was generated from the following files: