From 218ae9c9d88c07ec8a43905aff94d548db5171e1 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 29 Dec 2014 22:24:16 -0800 Subject: [PATCH 1/2] Hydra hands deactivate when placed back on controller base, removed measuring non-movement for inactivity --- interface/src/devices/SixenseManager.cpp | 39 ++++++++---------------- interface/src/devices/SixenseManager.h | 3 +- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index e2b4fedd50..5fb4a71091 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -84,10 +84,8 @@ void SixenseManager::initialize() { #ifdef HAVE_SIXENSE if (!_isInitialized) { - _lastMovement = 0; - _amountMoved = glm::vec3(0.0f); _lowVelocityFilter = false; - + _controllersAtBase = true; _calibrationState = CALIBRATION_STATE_IDLE; // By default we assume the _neckBase (in orb frame) is as high above the orb // as the "torso" is below it. @@ -146,15 +144,11 @@ void SixenseManager::setFilter(bool filter) { void SixenseManager::update(float deltaTime) { #ifdef HAVE_SIXENSE + Hand* hand = Application::getInstance()->getAvatar()->getHand(); if (_isInitialized && _isEnabled) { - // if the controllers haven't been moved in a while, disable - const unsigned int MOVEMENT_DISABLE_SECONDS = 3; - if (usecTimestampNow() - _lastMovement > (MOVEMENT_DISABLE_SECONDS * USECS_PER_SECOND)) { - Hand* hand = Application::getInstance()->getAvatar()->getHand(); - for (std::vector::iterator it = hand->getPalms().begin(); it != hand->getPalms().end(); it++) { - it->setActive(false); - } - _lastMovement = usecTimestampNow(); + // Disable the hands (and return to default pose) if both controllers are at base station + for (std::vector::iterator it = hand->getPalms().begin(); it != hand->getPalms().end(); it++) { + it->setActive(!_controllersAtBase); } #ifdef __APPLE__ @@ -172,8 +166,6 @@ void SixenseManager::update(float deltaTime) { _hydrasConnected = true; UserActivityLogger::getInstance().connectedDevice("spatial_controller", "hydra"); } - MyAvatar* avatar = Application::getInstance()->getAvatar(); - Hand* hand = avatar->getHand(); #ifdef __APPLE__ SixenseBaseFunction sixenseGetMaxControllers = @@ -192,7 +184,7 @@ void SixenseManager::update(float deltaTime) { SixenseTakeIntAndSixenseControllerData sixenseGetNewestData = (SixenseTakeIntAndSixenseControllerData) _sixenseLibrary->resolve("sixenseGetNewestData"); #endif - + int numControllersAtBase = 0; int numActiveControllers = 0; for (int i = 0; i < maxControllers && numActiveControllers < 2; i++) { if (!sixenseIsControllerEnabled(i)) { @@ -221,14 +213,11 @@ void SixenseManager::update(float deltaTime) { qDebug("Found new Sixense controller, ID %i", data->controller_index); } - palm->setActive(true); - // Read controller buttons and joystick into the hand palm->setControllerButtons(data->buttons); palm->setTrigger(data->trigger); palm->setJoystick(data->joystick_x, data->joystick_y); - // Emulate the mouse so we can use scripts if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) { emulateMouse(palm, numActiveControllers - 1); @@ -238,6 +227,12 @@ void SixenseManager::update(float deltaTime) { glm::vec3 position(data->pos[0], data->pos[1], data->pos[2]); position *= METERS_PER_MILLIMETER; + // Check to see if this hand/controller is on the base + const float CONTROLLER_AT_BASE_DISTANCE = 0.075f; + if (glm::length(position) < CONTROLLER_AT_BASE_DISTANCE) { + numControllersAtBase++; + } + // Transform the measured position into body frame. glm::vec3 neck = _neckBase; // Zeroing y component of the "neck" effectively raises the measured position a little bit. @@ -274,14 +269,6 @@ void SixenseManager::update(float deltaTime) { palm->setRawRotation(rotation); } - // use the velocity to determine whether there's any movement (if the hand isn't new) - const float MOVEMENT_DISTANCE_THRESHOLD = 0.003f; - _amountMoved += rawVelocity * deltaTime; - if (glm::length(_amountMoved) > MOVEMENT_DISTANCE_THRESHOLD && foundHand) { - _lastMovement = usecTimestampNow(); - _amountMoved = glm::vec3(0.0f); - } - // Store the one fingertip in the palm structure so we can track velocity const float FINGER_LENGTH = 0.3f; // meters const glm::vec3 FINGER_VECTOR(0.0f, 0.0f, FINGER_LENGTH); @@ -298,7 +285,7 @@ void SixenseManager::update(float deltaTime) { if (numActiveControllers == 2) { updateCalibration(controllers); } - + _controllersAtBase = (numControllersAtBase == 2); } #endif // HAVE_SIXENSE } diff --git a/interface/src/devices/SixenseManager.h b/interface/src/devices/SixenseManager.h index 1954ac91bc..0a7ab78c0e 100644 --- a/interface/src/devices/SixenseManager.h +++ b/interface/src/devices/SixenseManager.h @@ -91,8 +91,6 @@ private: bool _isInitialized; bool _isEnabled; bool _hydrasConnected; - quint64 _lastMovement; - glm::vec3 _amountMoved; // for mouse emulation with the two controllers bool _triggerPressed[2]; @@ -101,6 +99,7 @@ private: int _oldY[2]; bool _lowVelocityFilter; + bool _controllersAtBase; }; #endif // hifi_SixenseManager_h From 89e499a78fde32d2e9e54f801b5d838463a5601b Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sun, 4 Jan 2015 12:26:30 -0800 Subject: [PATCH 2/2] only active sixsense palms --- interface/src/devices/SixenseManager.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 5fb4a71091..ea37469e8d 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -146,11 +146,6 @@ void SixenseManager::update(float deltaTime) { #ifdef HAVE_SIXENSE Hand* hand = Application::getInstance()->getAvatar()->getHand(); if (_isInitialized && _isEnabled) { - // Disable the hands (and return to default pose) if both controllers are at base station - for (std::vector::iterator it = hand->getPalms().begin(); it != hand->getPalms().end(); it++) { - it->setActive(!_controllersAtBase); - } - #ifdef __APPLE__ SixenseBaseFunction sixenseGetNumActiveControllers = (SixenseBaseFunction) _sixenseLibrary->resolve("sixenseGetNumActiveControllers"); @@ -213,6 +208,14 @@ void SixenseManager::update(float deltaTime) { qDebug("Found new Sixense controller, ID %i", data->controller_index); } + // Disable the hands (and return to default pose) if both controllers are at base station + if (foundHand) { + palm->setActive(!_controllersAtBase); + } else { + palm->setActive(false); // if this isn't a Sixsense ID palm, always make it inactive + } + + // Read controller buttons and joystick into the hand palm->setControllerButtons(data->buttons); palm->setTrigger(data->trigger);