map PrioVR to new JoystickScriptingInterface

This commit is contained in:
Stephen Birarda 2014-09-23 17:42:48 -07:00
parent 13d3eb02e3
commit 9348888ae5
2 changed files with 17 additions and 9 deletions

View file

@ -39,6 +39,9 @@ public:
const QString& getName() const { return _name; } const QString& getName() const { return _name; }
const QVector<float>& getAxes() const { return _axes; }
const QVector<bool>& getButtons() const { return _buttons; }
int getNumAxes() const { return _axes.size(); } int getNumAxes() const { return _axes.size(); }
int getNumButtons() const { return _buttons.size(); } int getNumButtons() const { return _buttons.size(); }

View file

@ -17,6 +17,7 @@
#include "Application.h" #include "Application.h"
#include "PrioVR.h" #include "PrioVR.h"
#include "scripting/JoystickScriptingInterface.h"
#include "ui/TextRenderer.h" #include "ui/TextRenderer.h"
#ifdef HAVE_PRIOVR #ifdef HAVE_PRIOVR
@ -61,18 +62,22 @@ static void setPalm(float deltaTime, int index) {
palm->setActive(true); palm->setActive(true);
// Read controller buttons and joystick into the hand // Read controller buttons and joystick into the hand
if (!Application::getInstance()->getJoystickManager()->getJoysticks().isEmpty()) { const QString PRIO_JOYSTICK_NAME = "PrioVR";
const JoystickState& state = Application::getInstance()->getJoystickManager()->getJoystickStates().at(0); Joystick* prioJoystick = JoystickScriptingInterface::getInstance().joystickWithName(PRIO_JOYSTICK_NAME);
if (state.axes.size() >= 4 && state.buttons.size() >= 4) { if (prioJoystick) {
const QVector<float> axes = prioJoystick->getAxes();
const QVector<bool> buttons = prioJoystick->getButtons();
if (axes.size() >= 4 && buttons.size() >= 4) {
if (index == LEFT_HAND_INDEX) { if (index == LEFT_HAND_INDEX) {
palm->setControllerButtons(state.buttons.at(1) ? BUTTON_FWD : 0); palm->setControllerButtons(buttons[1] ? BUTTON_FWD : 0);
palm->setTrigger(state.buttons.at(0) ? 1.0f : 0.0f); palm->setTrigger(buttons[0] ? 1.0f : 0.0f);
palm->setJoystick(state.axes.at(0), -state.axes.at(1)); palm->setJoystick(axes[0], -axes[1]);
} else { } else {
palm->setControllerButtons(state.buttons.at(3) ? BUTTON_FWD : 0); palm->setControllerButtons(buttons[3] ? BUTTON_FWD : 0);
palm->setTrigger(state.buttons.at(2) ? 1.0f : 0.0f); palm->setTrigger(buttons[2] ? 1.0f : 0.0f);
palm->setJoystick(state.axes.at(2), -state.axes.at(3)); palm->setJoystick(axes[2], -axes[3]);
} }
} }
} }