From 5f58c76842879b8b15e6f8c3a317a45b82c82df1 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 26 Nov 2014 12:03:10 -0800 Subject: [PATCH 1/2] Fix hands being put in face if Leap on HMD is set but Leap not connected The joints were reporting themselves as "active" even though the Leap wasn't connected, both at startup if not connected and after unplugging. --- interface/src/devices/Leapmotion.cpp | 18 +++++++++++------- interface/src/devices/MotionTracker.cpp | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/interface/src/devices/Leapmotion.cpp b/interface/src/devices/Leapmotion.cpp index 62037ae7f6..6a47eadb96 100644 --- a/interface/src/devices/Leapmotion.cpp +++ b/interface/src/devices/Leapmotion.cpp @@ -135,16 +135,20 @@ glm::vec3 vec3FromLeapVector(const Leap::Vector& vec) { void Leapmotion::update() { #ifdef HAVE_LEAPMOTION - // Check that the controller is actually active + bool wasActive = _active; _active = _controller.isConnected(); - if (!_active) { - return; + + if (_active || wasActive) { + // Go through all the joints and increment their counter since last update. + // Increment all counters once after controller first becomes inactive so that each joint reports itself as inactive. + // TODO C++11 for (auto jointIt = _jointsArray.begin(); jointIt != _jointsArray.end(); jointIt++) { + for (JointTracker::Vector::iterator jointIt = _jointsArray.begin(); jointIt != _jointsArray.end(); jointIt++) { + (*jointIt).tickNewFrame(); + } } - // go through all the joints and increment their counter since last update - // TODO C++11 for (auto jointIt = _jointsArray.begin(); jointIt != _jointsArray.end(); jointIt++) { - for (JointTracker::Vector::iterator jointIt = _jointsArray.begin(); jointIt != _jointsArray.end(); jointIt++) { - (*jointIt).tickNewFrame(); + if (!_active) { + return; } // Get the most recent frame and report some basic information diff --git a/interface/src/devices/MotionTracker.cpp b/interface/src/devices/MotionTracker.cpp index 6b81c94f82..d5272888e7 100644 --- a/interface/src/devices/MotionTracker.cpp +++ b/interface/src/devices/MotionTracker.cpp @@ -119,14 +119,14 @@ MotionTracker::JointTracker::JointTracker() : _absFrame(), _semantic(""), _parent(INVALID_PARENT), - _lastUpdate(0) + _lastUpdate(1) // Joint inactive { } MotionTracker::JointTracker::JointTracker(const Semantic& semantic, Index parent) : _semantic(semantic), _parent(parent), - _lastUpdate(0) + _lastUpdate(1) // Joint inactive { } From 5871ecd85cc72997d17f16a08aab9ea600af2b12 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 26 Nov 2014 12:03:27 -0800 Subject: [PATCH 2/2] Stop incrementing counter after limit reached --- examples/leapHands.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/leapHands.js b/examples/leapHands.js index 04253c8ab6..6bdca051be 100644 --- a/examples/leapHands.js +++ b/examples/leapHands.js @@ -471,17 +471,20 @@ var leapHands = (function () { } else { - hands[h].inactiveCount += 1; + if (hands[h].inactiveCount < MAX_HAND_INACTIVE_COUNT) { - if (hands[h].inactiveCount === MAX_HAND_INACTIVE_COUNT) { - if (h === 0) { - MyAvatar.clearJointData("LeftHand"); - MyAvatar.clearJointData("LeftForeArm"); - MyAvatar.clearJointData("LeftArm"); - } else { - MyAvatar.clearJointData("RightHand"); - MyAvatar.clearJointData("RightForeArm"); - MyAvatar.clearJointData("RightArm"); + hands[h].inactiveCount += 1; + + if (hands[h].inactiveCount === MAX_HAND_INACTIVE_COUNT) { + if (h === 0) { + MyAvatar.clearJointData("LeftHand"); + MyAvatar.clearJointData("LeftForeArm"); + MyAvatar.clearJointData("LeftArm"); + } else { + MyAvatar.clearJointData("RightHand"); + MyAvatar.clearJointData("RightForeArm"); + MyAvatar.clearJointData("RightArm"); + } } } }