mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 21:36:47 +02:00
Basic joystick integration.
This commit is contained in:
parent
e415006526
commit
c29708f22c
5 changed files with 39 additions and 12 deletions
|
@ -1990,6 +1990,7 @@ void Application::update(float deltaTime) {
|
||||||
_myAvatar->updateLookAtTargetAvatar();
|
_myAvatar->updateLookAtTargetAvatar();
|
||||||
updateMyAvatarLookAtPosition();
|
updateMyAvatarLookAtPosition();
|
||||||
_sixenseManager.update(deltaTime);
|
_sixenseManager.update(deltaTime);
|
||||||
|
_joystickManager.update();
|
||||||
_prioVR.update();
|
_prioVR.update();
|
||||||
updateMyAvatar(deltaTime); // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes
|
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...
|
updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process...
|
||||||
|
|
|
@ -52,7 +52,9 @@ void JoystickManager::update() {
|
||||||
SDL_Joystick* joystick = _joysticks.at(i);
|
SDL_Joystick* joystick = _joysticks.at(i);
|
||||||
JoystickState& state = _joystickStates[i];
|
JoystickState& state = _joystickStates[i];
|
||||||
for (int j = 0; j < state.axes.size(); j++) {
|
for (int j = 0; j < state.axes.size(); j++) {
|
||||||
state.axes[j] = glm::round(SDL_JoystickGetAxis(joystick, j) + 0.5f) / numeric_limits<short>::max();
|
float value = glm::round(SDL_JoystickGetAxis(joystick, j) + 0.5f) / numeric_limits<short>::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++) {
|
for (int j = 0; j < state.buttons.size(); j++) {
|
||||||
state.buttons[j] = SDL_JoystickGetButton(joystick, j);
|
state.buttons[j] = SDL_JoystickGetButton(joystick, j);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
#include <FBXReader.h>
|
#include <FBXReader.h>
|
||||||
|
@ -52,6 +53,8 @@ PrioVR::PrioVR() {
|
||||||
for (int i = 0; i < LIST_LENGTH; i++) {
|
for (int i = 0; i < LIST_LENGTH; i++) {
|
||||||
_humanIKJointIndices.append(jointsDiscovered[i] ? indexOfHumanIKJoint(JOINT_NAMES[i]) : -1);
|
_humanIKJointIndices.append(jointsDiscovered[i] ? indexOfHumanIKJoint(JOINT_NAMES[i]) : -1);
|
||||||
}
|
}
|
||||||
|
const int INITIAL_RESET_DELAY = 5000;
|
||||||
|
QTimer::singleShot(INITIAL_RESET_DELAY, this, SLOT(reset()));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,9 @@ public:
|
||||||
const QVector<glm::quat>& getJointRotations() const { return _jointRotations; }
|
const QVector<glm::quat>& getJointRotations() const { return _jointRotations; }
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
@ -90,19 +90,20 @@ glm::vec2 ControllerScriptingInterface::getPrimaryJoystickPosition() const {
|
||||||
int ControllerScriptingInterface::getNumberOfButtons() const {
|
int ControllerScriptingInterface::getNumberOfButtons() const {
|
||||||
int buttonCount = 0;
|
int buttonCount = 0;
|
||||||
foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) {
|
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;
|
return buttonCount + getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const {
|
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;
|
int managedButtonIndex = buttonIndex - getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM;
|
||||||
if (managedButtonIndex >= 0) {
|
if (managedButtonIndex >= 0) {
|
||||||
foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) {
|
foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) {
|
||||||
if (managedButtonIndex < state.buttons.size()) {
|
if (managedButtonIndex * 2 + 1 < state.buttons.size()) {
|
||||||
return state.buttons.at(managedButtonIndex);
|
return state.buttons.at(managedButtonIndex * 2 + 1);
|
||||||
}
|
}
|
||||||
managedButtonIndex -= state.buttons.size();
|
managedButtonIndex -= state.buttons.size() / 2;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -129,10 +130,24 @@ bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int ControllerScriptingInterface::getNumberOfTriggers() 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 {
|
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
|
// we know there's one trigger per palm, so the triggerIndex is the palm Index
|
||||||
int palmIndex = triggerIndex;
|
int palmIndex = triggerIndex;
|
||||||
const PalmData* palmData = getActivePalm(palmIndex);
|
const PalmData* palmData = getActivePalm(palmIndex);
|
||||||
|
@ -149,12 +164,15 @@ int ControllerScriptingInterface::getNumberOfJoysticks() const {
|
||||||
|
|
||||||
glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const {
|
glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const {
|
||||||
// we know there's one joystick per palm, so the joystickIndex is the palm Index
|
// we know there's one joystick per palm, so the joystickIndex is the palm Index
|
||||||
int managedJoystickIndex = joystickIndex - getNumberOfActivePalms();
|
int managedAxisIndex = (joystickIndex - getNumberOfActivePalms()) * 2;
|
||||||
if (managedJoystickIndex >= 0 && managedJoystickIndex <
|
if (managedAxisIndex >= 0) {
|
||||||
Application::getInstance()->getJoystickManager()->getJoystickStates().size()) {
|
foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) {
|
||||||
const JoystickState& state = Application::getInstance()->getJoystickManager()->getJoystickStates().at(
|
if (managedAxisIndex + 1 < state.axes.size()) {
|
||||||
managedJoystickIndex);
|
return glm::vec2(state.axes.at(managedAxisIndex), -state.axes.at(managedAxisIndex + 1));
|
||||||
return glm::vec2(state.axes.size() > 0 ? state.axes.at(0) : 0.0f, state.axes.size() > 1 ? state.axes.at(1) : 0.0f);
|
}
|
||||||
|
managedAxisIndex -= state.axes.size();
|
||||||
|
}
|
||||||
|
return glm::vec2();
|
||||||
}
|
}
|
||||||
int palmIndex = joystickIndex;
|
int palmIndex = joystickIndex;
|
||||||
const PalmData* palmData = getActivePalm(palmIndex);
|
const PalmData* palmData = getActivePalm(palmIndex);
|
||||||
|
|
Loading…
Reference in a new issue