diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 91e95bb4e3..85fb77908a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1990,6 +1990,7 @@ void Application::update(float deltaTime) { _myAvatar->updateLookAtTargetAvatar(); updateMyAvatarLookAtPosition(); _sixenseManager.update(deltaTime); + _joystickManager.update(); _prioVR.update(); updateMyAvatar(deltaTime); // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process... diff --git a/interface/src/devices/JoystickManager.cpp b/interface/src/devices/JoystickManager.cpp index da3c1834af..005505441c 100644 --- a/interface/src/devices/JoystickManager.cpp +++ b/interface/src/devices/JoystickManager.cpp @@ -52,7 +52,9 @@ void JoystickManager::update() { 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::max(); + float value = glm::round(SDL_JoystickGetAxis(joystick, j) + 0.5f) / numeric_limits::max(); + const float DEAD_ZONE = 0.1f; + state.axes[j] = glm::abs(value) < DEAD_ZONE ? 0.0f : value; } for (int j = 0; j < state.buttons.size(); j++) { state.buttons[j] = SDL_JoystickGetButton(joystick, j); diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp index e6e948422e..c97d35b9d2 100644 --- a/interface/src/devices/PrioVR.cpp +++ b/interface/src/devices/PrioVR.cpp @@ -9,6 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include #include @@ -52,6 +53,8 @@ PrioVR::PrioVR() { for (int i = 0; i < LIST_LENGTH; i++) { _humanIKJointIndices.append(jointsDiscovered[i] ? indexOfHumanIKJoint(JOINT_NAMES[i]) : -1); } + const int INITIAL_RESET_DELAY = 5000; + QTimer::singleShot(INITIAL_RESET_DELAY, this, SLOT(reset())); #endif } diff --git a/interface/src/devices/PrioVR.h b/interface/src/devices/PrioVR.h index 8f01574356..59352d2ac4 100644 --- a/interface/src/devices/PrioVR.h +++ b/interface/src/devices/PrioVR.h @@ -44,6 +44,9 @@ public: const QVector& getJointRotations() const { return _jointRotations; } void update(); + +public slots: + void reset(); private slots: diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index df97af1a16..b5619191fa 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -90,19 +90,20 @@ glm::vec2 ControllerScriptingInterface::getPrimaryJoystickPosition() const { int ControllerScriptingInterface::getNumberOfButtons() const { int buttonCount = 0; foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { - buttonCount += state.buttons.size(); + buttonCount += state.buttons.size() / 2; } return buttonCount + getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; } bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const { + // as a temporary hack, we consider every other button a trigger int managedButtonIndex = buttonIndex - getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; if (managedButtonIndex >= 0) { foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { - if (managedButtonIndex < state.buttons.size()) { - return state.buttons.at(managedButtonIndex); + if (managedButtonIndex * 2 + 1 < state.buttons.size()) { + return state.buttons.at(managedButtonIndex * 2 + 1); } - managedButtonIndex -= state.buttons.size(); + managedButtonIndex -= state.buttons.size() / 2; } return false; } @@ -129,10 +130,24 @@ bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const { } int ControllerScriptingInterface::getNumberOfTriggers() const { - return getNumberOfActivePalms() * NUMBER_OF_TRIGGERS_PER_PALM; + int buttonCount = 0; + foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { + buttonCount += state.buttons.size() / 2; + } + return buttonCount + getNumberOfActivePalms() * NUMBER_OF_TRIGGERS_PER_PALM; } float ControllerScriptingInterface::getTriggerValue(int triggerIndex) const { + int managedButtonIndex = triggerIndex - getNumberOfActivePalms() * NUMBER_OF_TRIGGERS_PER_PALM; + if (managedButtonIndex >= 0) { + foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { + if (managedButtonIndex * 2 < state.buttons.size()) { + return state.buttons.at(managedButtonIndex * 2) ? 1.0f : 0.0f; + } + managedButtonIndex -= state.buttons.size() / 2; + } + return false; + } // we know there's one trigger per palm, so the triggerIndex is the palm Index int palmIndex = triggerIndex; const PalmData* palmData = getActivePalm(palmIndex); @@ -149,12 +164,15 @@ int ControllerScriptingInterface::getNumberOfJoysticks() const { glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const { // we know there's one joystick per palm, so the joystickIndex is the palm Index - int managedJoystickIndex = joystickIndex - getNumberOfActivePalms(); - if (managedJoystickIndex >= 0 && managedJoystickIndex < - Application::getInstance()->getJoystickManager()->getJoystickStates().size()) { - const JoystickState& state = Application::getInstance()->getJoystickManager()->getJoystickStates().at( - managedJoystickIndex); - return glm::vec2(state.axes.size() > 0 ? state.axes.at(0) : 0.0f, state.axes.size() > 1 ? state.axes.at(1) : 0.0f); + int managedAxisIndex = (joystickIndex - getNumberOfActivePalms()) * 2; + if (managedAxisIndex >= 0) { + foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { + if (managedAxisIndex + 1 < state.axes.size()) { + return glm::vec2(state.axes.at(managedAxisIndex), -state.axes.at(managedAxisIndex + 1)); + } + managedAxisIndex -= state.axes.size(); + } + return glm::vec2(); } int palmIndex = joystickIndex; const PalmData* palmData = getActivePalm(palmIndex);