mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 16:14:35 +02:00
Merge pull request #6349 from jherico/marge
Prevent sixense manager from triggering continuous reset
This commit is contained in:
commit
53b231987c
2 changed files with 28 additions and 28 deletions
|
@ -108,19 +108,13 @@ void SixenseManager::setSixenseFilter(bool filter) {
|
||||||
|
|
||||||
void SixenseManager::pluginUpdate(float deltaTime, bool jointsCaptured) {
|
void SixenseManager::pluginUpdate(float deltaTime, bool jointsCaptured) {
|
||||||
_inputDevice->update(deltaTime, jointsCaptured);
|
_inputDevice->update(deltaTime, jointsCaptured);
|
||||||
if (_inputDevice->_calibrationState == CALIBRATION_STATE_COMPLETE) {
|
if (_inputDevice->_requestReset) {
|
||||||
_container->requestReset();
|
_container->requestReset();
|
||||||
_inputDevice->_calibrationState = CALIBRATION_STATE_IDLE;
|
_inputDevice->_requestReset = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SixenseManager::InputDevice::update(float deltaTime, bool jointsCaptured) {
|
void SixenseManager::InputDevice::update(float deltaTime, bool jointsCaptured) {
|
||||||
// FIXME - Some of the code in update() will crash if you haven't actually activated the
|
|
||||||
// plugin. But we want register with the UserInputMapper if we don't call this.
|
|
||||||
// We need to clean this up.
|
|
||||||
//if (!_activated) {
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
#ifdef HAVE_SIXENSE
|
#ifdef HAVE_SIXENSE
|
||||||
_buttonPressedMap.clear();
|
_buttonPressedMap.clear();
|
||||||
|
|
||||||
|
@ -153,14 +147,14 @@ void SixenseManager::InputDevice::update(float deltaTime, bool jointsCaptured) {
|
||||||
int maxControllers = sixenseGetMaxControllers();
|
int maxControllers = sixenseGetMaxControllers();
|
||||||
|
|
||||||
// we only support two controllers
|
// we only support two controllers
|
||||||
sixenseControllerData controllers[2];
|
SixenseControllerData controllers[2];
|
||||||
|
|
||||||
int numActiveControllers = 0;
|
int numActiveControllers = 0;
|
||||||
for (int i = 0; i < maxControllers && numActiveControllers < 2; i++) {
|
for (int i = 0; i < maxControllers && numActiveControllers < 2; i++) {
|
||||||
if (!sixenseIsControllerEnabled(i)) {
|
if (!sixenseIsControllerEnabled(i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sixenseControllerData* data = controllers + numActiveControllers;
|
SixenseControllerData* data = controllers + numActiveControllers;
|
||||||
++numActiveControllers;
|
++numActiveControllers;
|
||||||
sixenseGetNewestData(i, data);
|
sixenseGetNewestData(i, data);
|
||||||
|
|
||||||
|
@ -221,21 +215,23 @@ static const float MINIMUM_ARM_REACH = 0.3f; // meters
|
||||||
static const float MAXIMUM_NOISE_LEVEL = 0.05f; // meters
|
static const float MAXIMUM_NOISE_LEVEL = 0.05f; // meters
|
||||||
static const quint64 LOCK_DURATION = USECS_PER_SECOND / 4; // time for lock to be acquired
|
static const quint64 LOCK_DURATION = USECS_PER_SECOND / 4; // time for lock to be acquired
|
||||||
|
|
||||||
void SixenseManager::InputDevice::updateCalibration(void* controllersX) {
|
static bool calibrationRequested(SixenseControllerData* controllers) {
|
||||||
auto controllers = reinterpret_cast<sixenseControllerData*>(controllersX);
|
return (controllers[0].buttons == BUTTON_FWD && controllers[1].buttons == BUTTON_FWD);
|
||||||
const sixenseControllerData* dataLeft = controllers;
|
}
|
||||||
const sixenseControllerData* dataRight = controllers + 1;
|
|
||||||
|
|
||||||
// calibration only happpens while both hands are holding BUTTON_FORWARD
|
void SixenseManager::InputDevice::updateCalibration(SixenseControllerData* controllers) {
|
||||||
if (dataLeft->buttons != BUTTON_FWD || dataRight->buttons != BUTTON_FWD) {
|
const SixenseControllerData* dataLeft = controllers;
|
||||||
if (_calibrationState == CALIBRATION_STATE_IDLE) {
|
const SixenseControllerData* dataRight = controllers + 1;
|
||||||
return;
|
|
||||||
}
|
// Calibration buttons aren't set, so check the state, and request a reset if necessary.
|
||||||
|
if (!calibrationRequested(controllers)) {
|
||||||
switch (_calibrationState) {
|
switch (_calibrationState) {
|
||||||
case CALIBRATION_STATE_COMPLETE:
|
case CALIBRATION_STATE_IDLE:
|
||||||
{
|
return;
|
||||||
|
|
||||||
|
case CALIBRATION_STATE_COMPLETE: {
|
||||||
// compute calibration results
|
// compute calibration results
|
||||||
_avatarPosition = - 0.5f * (_reachLeft + _reachRight); // neck is midway between right and left hands
|
_avatarPosition = -0.5f * (_reachLeft + _reachRight); // neck is midway between right and left hands
|
||||||
glm::vec3 xAxis = glm::normalize(_reachRight - _reachLeft);
|
glm::vec3 xAxis = glm::normalize(_reachRight - _reachLeft);
|
||||||
glm::vec3 zAxis = glm::normalize(glm::cross(xAxis, Vectors::UNIT_Y));
|
glm::vec3 zAxis = glm::normalize(glm::cross(xAxis, Vectors::UNIT_Y));
|
||||||
xAxis = glm::normalize(glm::cross(Vectors::UNIT_Y, zAxis));
|
xAxis = glm::normalize(glm::cross(Vectors::UNIT_Y, zAxis));
|
||||||
|
@ -243,16 +239,19 @@ void SixenseManager::InputDevice::updateCalibration(void* controllersX) {
|
||||||
const float Y_OFFSET_CALIBRATED_HANDS_TO_AVATAR = -0.3f;
|
const float Y_OFFSET_CALIBRATED_HANDS_TO_AVATAR = -0.3f;
|
||||||
_avatarPosition.y += Y_OFFSET_CALIBRATED_HANDS_TO_AVATAR;
|
_avatarPosition.y += Y_OFFSET_CALIBRATED_HANDS_TO_AVATAR;
|
||||||
qCDebug(inputplugins, "succeess: sixense calibration");
|
qCDebug(inputplugins, "succeess: sixense calibration");
|
||||||
|
_requestReset = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
_calibrationState = CALIBRATION_STATE_IDLE;
|
|
||||||
qCDebug(inputplugins, "failed: sixense calibration");
|
qCDebug(inputplugins, "failed: sixense calibration");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_calibrationState = CALIBRATION_STATE_IDLE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calibration buttons are set, continue calibration work
|
||||||
// NOTE: Sixense API returns pos data in millimeters but we IMMEDIATELY convert to meters.
|
// NOTE: Sixense API returns pos data in millimeters but we IMMEDIATELY convert to meters.
|
||||||
const float* pos = dataLeft->pos;
|
const float* pos = dataLeft->pos;
|
||||||
glm::vec3 positionLeft(pos[0], pos[1], pos[2]);
|
glm::vec3 positionLeft(pos[0], pos[1], pos[2]);
|
||||||
|
@ -261,6 +260,7 @@ void SixenseManager::InputDevice::updateCalibration(void* controllersX) {
|
||||||
glm::vec3 positionRight(pos[0], pos[1], pos[2]);
|
glm::vec3 positionRight(pos[0], pos[1], pos[2]);
|
||||||
positionRight *= METERS_PER_MILLIMETER;
|
positionRight *= METERS_PER_MILLIMETER;
|
||||||
|
|
||||||
|
// Gather initial calibration data
|
||||||
if (_calibrationState == CALIBRATION_STATE_IDLE) {
|
if (_calibrationState == CALIBRATION_STATE_IDLE) {
|
||||||
float reach = glm::distance(positionLeft, positionRight);
|
float reach = glm::distance(positionLeft, positionRight);
|
||||||
if (reach > 2.0f * MINIMUM_ARM_REACH) {
|
if (reach > 2.0f * MINIMUM_ARM_REACH) {
|
||||||
|
@ -308,9 +308,6 @@ void SixenseManager::InputDevice::focusOutEvent() {
|
||||||
_buttonPressedMap.clear();
|
_buttonPressedMap.clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
void SixenseManager::InputDevice::handleAxisEvent(float stickX, float stickY, float trigger, bool left) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void SixenseManager::InputDevice::handleButtonEvent(unsigned int buttons, bool left) {
|
void SixenseManager::InputDevice::handleButtonEvent(unsigned int buttons, bool left) {
|
||||||
using namespace controller;
|
using namespace controller;
|
||||||
if (buttons & BUTTON_0) {
|
if (buttons & BUTTON_0) {
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
|
|
||||||
#include "InputPlugin.h"
|
#include "InputPlugin.h"
|
||||||
|
|
||||||
|
struct _sixenseControllerData;
|
||||||
|
using SixenseControllerData = _sixenseControllerData;
|
||||||
|
|
||||||
// Handles interaction with the Sixense SDK (e.g., Razer Hydra).
|
// Handles interaction with the Sixense SDK (e.g., Razer Hydra).
|
||||||
class SixenseManager : public InputPlugin {
|
class SixenseManager : public InputPlugin {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -65,9 +68,8 @@ private:
|
||||||
virtual void focusOutEvent() override;
|
virtual void focusOutEvent() override;
|
||||||
|
|
||||||
void handleButtonEvent(unsigned int buttons, bool left);
|
void handleButtonEvent(unsigned int buttons, bool left);
|
||||||
void handleAxisEvent(float x, float y, float trigger, bool left);
|
|
||||||
void handlePoseEvent(float deltaTime, glm::vec3 position, glm::quat rotation, bool left);
|
void handlePoseEvent(float deltaTime, glm::vec3 position, glm::quat rotation, bool left);
|
||||||
void updateCalibration(void* controllers);
|
void updateCalibration(SixenseControllerData* controllers);
|
||||||
|
|
||||||
friend class SixenseManager;
|
friend class SixenseManager;
|
||||||
|
|
||||||
|
@ -79,6 +81,7 @@ private:
|
||||||
glm::quat _avatarRotation; // in hydra-frame
|
glm::quat _avatarRotation; // in hydra-frame
|
||||||
|
|
||||||
float _lastDistance;
|
float _lastDistance;
|
||||||
|
bool _requestReset { false };
|
||||||
// these are measured values used to compute the calibration results
|
// these are measured values used to compute the calibration results
|
||||||
quint64 _lockExpiry;
|
quint64 _lockExpiry;
|
||||||
glm::vec3 _averageLeft;
|
glm::vec3 _averageLeft;
|
||||||
|
|
Loading…
Reference in a new issue