FPLBase
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
fplbase::Joystick Class Reference

Represents the state of a Joystick. More...

#include <input.h>

Detailed Description

Represents the state of a Joystick.

Public Member Functions

ButtonGetButton (size_t button_index)
 Get the current state of a button. More...
 
float GetAxis (size_t axis_index)
 Get the current state of a joystick axis control. More...
 
mathfu::vec2 GetHat (size_t hat_index)
 Get the current state of a joystick hat control. More...
 
void SetAxis (size_t axis_index, float axis)
 Sets the value of an axis. More...
 
void SetHat (size_t hat_index, const mathfu::vec2 &hat)
 Sets the position of a hat. More...
 
void AdvanceFrame ()
 Updates the internal state of the joystick by one frame. More...
 
JoystickData joystick_data ()
 Returns the pointer to the raw joystick data. More...
 
void set_joystick_data (JoystickData joy)
 Sets the pointer to the raw joystick data. More...
 
JoystickId GetJoystickId () const
 Gets the ID of the joystick. More...
 
int GetNumButtons () const
 Returns the number of buttons available on the joystick.
 
int GetNumAxes () const
 Returns the number of control axes available on the joystick.
 
int GetNumHats () const
 Returns the number of hats available on the joystick.
 

Member Function Documentation

void fplbase::Joystick::AdvanceFrame ( )

Updates the internal state of the joystick by one frame.

This function ensures that the joystick readings are up-to-date, and that buttons have their change-bits set correctly. Normally called automatically by InputSystem::AdvanceFrame().

float fplbase::Joystick::GetAxis ( size_t  axis_index)

Get the current state of a joystick axis control.

Parameters
axis_indexThe index of the axis to querry.
Returns
A float representing the position of the axis control. Axis data is automatically normalized to be within the range of [-1, 1].
Button& fplbase::Joystick::GetButton ( size_t  button_index)

Get the current state of a button.

Parameters
button_indexThe index of the button to querry.
Returns
A button object representing the current button state.
mathfu::vec2 fplbase::Joystick::GetHat ( size_t  hat_index)

Get the current state of a joystick hat control.

Parameters
hat_indexThe index of the hat to querry.
Returns
A vec2 representing the direction the hat is pointing.

The returned vector will always have an X, Y component of -1, 0, or 1. (And thus will always be pointing in one of 8 possible directions, or in the neutral position.)

JoystickId fplbase::Joystick::GetJoystickId ( ) const

Gets the ID of the joystick.

Joystick IDs are guaranteed to be unique between joysticks, and on some platforms, will be preserved even if the same controller is unplugged and reconnected. (Platform dependent.) The Joystick ID is used to reference a particular device.

JoystickData fplbase::Joystick::joystick_data ( )
inline

Returns the pointer to the raw joystick data.

The type and layout of the joystick_data are implementation specific, and should not generally be used by code outside of the FPLBase library.

void fplbase::Joystick::set_joystick_data ( JoystickData  joy)
inline

Sets the pointer to the raw joystick data.

Parameters
joyA pointer to the joystick data.

The type and layout of the joystick_data are implementation specific, and should not generally be used by code outside of the FPLBase library.

void fplbase::Joystick::SetAxis ( size_t  axis_index,
float  axis 
)

Sets the value of an axis.

Parameters
axis_indexThe index of the axis to modify.
axisThe new value to record for the axis.

Normally only called by input handlers in the Input class.

void fplbase::Joystick::SetHat ( size_t  hat_index,
const mathfu::vec2 &  hat 
)

Sets the position of a hat.

Parameters
hat_indexThe index of the hat to modify.
hatThe new value to record for the hat.

Normally only called by input handlers in the Input class.


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