3
0
Fork 0
mirror of https://github.com/lubosz/overte.git synced 2025-04-27 21:35:29 +02:00

Working on joystick support using SDL.

This commit is contained in:
Andrzej Kapolka 2014-05-15 17:09:28 -07:00
parent 074a6b7f38
commit 6dd08ca1bf
4 changed files with 126 additions and 0 deletions

View file

@ -136,6 +136,7 @@ find_package(Faceplus)
find_package(Faceshift)
find_package(LibOVR)
find_package(PrioVR)
find_package(SDL)
find_package(Sixense)
find_package(Visage)
find_package(ZLIB)
@ -193,6 +194,13 @@ if (PRIOVR_FOUND AND NOT DISABLE_PRIOVR)
target_link_libraries(${TARGET_NAME} "${PRIOVR_LIBRARIES}")
endif (PRIOVR_FOUND AND NOT DISABLE_PRIOVR)
# and with SDL for joysticks
if (SDL_FOUND AND NOT DISABLE_SDL)
add_definitions(-DHAVE_SDL)
include_directories(SYSTEM "${SDL_INCLUDE_DIR}")
target_link_libraries(${TARGET_NAME} "${SDL_LIBRARY}")
endif (SDL_FOUND AND NOT DISABLE_SDL)
# and with qxmpp for chat
if (QXMPP_FOUND AND NOT DISABLE_QXMPP)
add_definitions(-DHAVE_QXMPP -DQXMPP_STATIC)

View file

@ -58,6 +58,7 @@
#include "avatar/MyAvatar.h"
#include "devices/Faceplus.h"
#include "devices/Faceshift.h"
#include "devices/JoystickManager.h"
#include "devices/PrioVR.h"
#include "devices/SixenseManager.h"
#include "devices/Visage.h"
@ -196,6 +197,7 @@ public:
FaceTracker* getActiveFaceTracker();
SixenseManager* getSixenseManager() { return &_sixenseManager; }
PrioVR* getPrioVR() { return &_prioVR; }
JoystickManager* getJoystickManager() { return &_joystickManager; }
BandwidthMeter* getBandwidthMeter() { return &_bandwidthMeter; }
QUndoStack* getUndoStack() { return &_undoStack; }
@ -449,6 +451,7 @@ private:
SixenseManager _sixenseManager;
PrioVR _prioVR;
JoystickManager _joystickManager;
Camera _myCamera; // My view onto the world
Camera _viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode

View file

@ -0,0 +1,63 @@
//
// JoystickManager.cpp
// interface/src/devices
//
// Created by Andrzej Kapolka on 5/15/14.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <limits>
#include <QtDebug>
#include <glm/glm.hpp>
#include "JoystickManager.h"
using namespace std;
JoystickManager::JoystickManager() {
#ifdef HAVE_SDL
SDL_Init(SDL_INIT_JOYSTICK);
int joystickCount = SDL_NumJoysticks();
for (int i = 0; i < joystickCount; i++) {
SDL_Joystick* joystick = SDL_JoystickOpen(i);
if (joystick) {
JoystickState state = { SDL_JoystickName(i), QVector<float>(SDL_JoystickNumAxes(joystick)),
QVector<bool>(SDL_JoystickNumButtons(joystick)) };
qDebug() << state.name << state.axes.size() << state.buttons.size();
_joystickStates.append(state);
_joysticks.append(joystick);
}
}
#endif
}
JoystickManager::~JoystickManager() {
#ifdef HAVE_SDL
foreach (SDL_Joystick* joystick, _joysticks) {
SDL_JoystickClose(joystick);
}
SDL_Quit();
#endif
}
void JoystickManager::update() {
#ifdef HAVE_SDL
SDL_JoystickUpdate();
for (int i = 0; i < _joystickStates.size(); i++) {
SDL_Joystick* joystick = _joysticks.at(i);
JoystickState& state = _joystickStates[i];
for (int j = 0; j < state.axes.size(); j++) {
state.axes[j] = glm::round(SDL_JoystickGetAxis(joystick, j) + 0.5f) / numeric_limits<short>::max();
}
for (int j = 0; j < state.buttons.size(); j++) {
state.buttons[j] = SDL_JoystickGetButton(joystick, j);
}
}
#endif
}

View file

@ -0,0 +1,52 @@
//
// JoystickManager.h
// interface/src/devices
//
// Created by Andrzej Kapolka on 5/15/14.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_JoystickManager_h
#define hifi_JoystickManager_h
#include <QObject>
#include <QVector>
#ifdef HAVE_SDL
#include <SDL.h>
#endif
class JoystickState;
/// Handles joystick input through SDL.
class JoystickManager : public QObject {
Q_OBJECT
public:
JoystickManager();
virtual ~JoystickManager();
const QVector<JoystickState>& getJoystickStates() const { return _joystickStates; }
void update();
private:
QVector<JoystickState> _joystickStates;
#ifdef HAVE_SDL
QVector<SDL_Joystick*> _joysticks;
#endif
};
class JoystickState {
public:
QString name;
QVector<float> axes;
QVector<bool> buttons;
};
#endif // hifi_JoystickManager_h