2016-06-25 21:59:34 +00:00
|
|
|
#ifndef BBGE_JOYSTICK_H
|
|
|
|
#define BBGE_JOYSTICK_H
|
|
|
|
|
|
|
|
#include <SDL_joystick.h>
|
|
|
|
|
2016-06-30 00:58:55 +00:00
|
|
|
#ifdef BBGE_BUILD_SDL2
|
|
|
|
#include <SDL_gamecontroller.h>
|
|
|
|
#include <SDL_haptic.h>
|
|
|
|
#endif
|
|
|
|
|
2016-06-25 21:59:34 +00:00
|
|
|
#include "Vector.h"
|
|
|
|
|
|
|
|
#define MAX_JOYSTICK_BTN 32
|
2016-06-30 00:58:55 +00:00
|
|
|
#define MAX_JOYSTICK_AXIS 32
|
2016-06-25 21:59:34 +00:00
|
|
|
|
|
|
|
class Joystick
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Joystick();
|
|
|
|
void init(int stick=0);
|
|
|
|
void shutdown();
|
2016-06-30 00:58:55 +00:00
|
|
|
//Ranges from 0 to 1 (full speed).
|
2016-06-25 21:59:34 +00:00
|
|
|
void rumble(float leftMotor, float rightMotor, float time);
|
|
|
|
void update(float dt);
|
2016-06-30 00:58:55 +00:00
|
|
|
Vector position;
|
2016-06-25 21:59:34 +00:00
|
|
|
|
|
|
|
float deadZone1, deadZone2;
|
|
|
|
float clearRumbleTime;
|
|
|
|
|
2016-06-30 00:58:55 +00:00
|
|
|
void calibrate(Vector &vec, float dead);
|
|
|
|
bool anyButton() const;
|
|
|
|
bool getButton(unsigned id) const { return !!(buttonBitmask & (1u << id)); }
|
|
|
|
int getIndex() const { return stickIndex; }
|
|
|
|
int getInstanceID() const { return instanceID; }
|
2016-06-25 21:59:34 +00:00
|
|
|
|
|
|
|
Vector rightStick;
|
|
|
|
|
|
|
|
int s1ax, s1ay, s2ax, s2ay;
|
|
|
|
|
|
|
|
private:
|
2016-06-30 00:58:55 +00:00
|
|
|
int stickIndex;
|
|
|
|
int instanceID;
|
2016-06-25 21:59:34 +00:00
|
|
|
unsigned buttonBitmask; // FIXME: this should go
|
2016-06-25 22:03:10 +00:00
|
|
|
SDL_Joystick *sdl_joy;
|
2016-06-25 21:59:34 +00:00
|
|
|
|
|
|
|
# ifdef BBGE_BUILD_SDL2
|
|
|
|
SDL_GameController *sdl_controller;
|
|
|
|
SDL_Haptic *sdl_haptic;
|
|
|
|
# endif
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|