From abca79ea3e7208afdd2080c852b17e04c1e2547c Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 29 Nov 2013 16:20:43 -0800 Subject: [PATCH] Add button detection for hydra controller to palmData --- interface/src/avatar/Hand.cpp | 9 +++++++++ interface/src/avatar/Hand.h | 7 +++++-- interface/src/devices/SixenseManager.cpp | 3 +++ libraries/avatars/src/HandData.cpp | 2 ++ libraries/avatars/src/HandData.h | 12 ++++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 43fc8cc0de..61aa30af21 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -157,6 +157,15 @@ void Hand::render() { } } + // If hand controller buttons pressed, render stuff + if (getPalms().size() > 0) { + for (size_t i = 0; i < getPalms().size(); ++i) { + PalmData& palm = getPalms()[i]; + //printf("buttons = %i\n", palm.getControllerButtons()); + } + } + + glEnable(GL_DEPTH_TEST); glEnable(GL_RESCALE_NORMAL); diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index 36573cfc86..336cb30350 100755 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -30,6 +30,7 @@ enum RaveLightsSetting { RAVE_LIGHTS_PARTICLES }; + class Avatar; class ProgramObject; @@ -46,7 +47,7 @@ public: bool isCollidable; // whether or not the ball responds to collisions float touchForce; // a scalar determining the amount that the cursor (or hand) is penetrating the ball }; - + void init(); void reset(); void simulate(float deltaTime, bool isMine); @@ -62,7 +63,7 @@ public: // getters const glm::vec3& getLeapFingerTipBallPosition (int ball) const { return _leapFingerTipBalls [ball].position;} const glm::vec3& getLeapFingerRootBallPosition(int ball) const { return _leapFingerRootBalls[ball].position;} - + private: // disallow copies of the Hand, copy of owning Avatar is disallowed too Hand(const Hand&); @@ -72,6 +73,8 @@ private: float _raveGloveClock; bool _raveGloveInitialized; int _raveGloveEmitter[NUM_FINGERS]; + + int _controllerButtons; /// Button states read from hand-held controllers Avatar* _owningAvatar; float _renderAlpha; diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 8322c589c9..361f756206 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -66,6 +66,9 @@ void SixenseManager::update(float deltaTime) { // Compute current velocity from position change palm.setVelocity((position - palm.getPosition()) / deltaTime); + // Read controller buttons into the hand + palm.setControllerButtons(data.buttons); + // Adjust for distance between acquisition 'orb' and the user's torso // (distance to the right of body center, distance below torso, distance behind torso) const glm::vec3 SPHERE_TO_TORSO(-250.f, -300.f, -300.f); diff --git a/libraries/avatars/src/HandData.cpp b/libraries/avatars/src/HandData.cpp index f00dbff327..cfa43725b8 100644 --- a/libraries/avatars/src/HandData.cpp +++ b/libraries/avatars/src/HandData.cpp @@ -37,6 +37,8 @@ PalmData& HandData::addNewPalm() { PalmData::PalmData(HandData* owningHandData) : _rawPosition(0, 0, 0), _rawNormal(0, 1, 0), +_velocity(0, 0, 0), +_controllerButtons(0), _isActive(false), _leapID(LEAPID_INVALID), _numFramesWithoutData(0), diff --git a/libraries/avatars/src/HandData.h b/libraries/avatars/src/HandData.h index ad32d068bc..ca8f97d40a 100755 --- a/libraries/avatars/src/HandData.h +++ b/libraries/avatars/src/HandData.h @@ -41,6 +41,12 @@ enum RaveGloveEffectsMode NUM_RAVE_GLOVE_EFFECTS_MODES }; +const int BUTTON_1 = 32; +const int BUTTON_2 = 64; +const int BUTTON_3 = 8; +const int BUTTON_4 = 16; +const int BUTTON_FWD = 128; + class HandData { public: HandData(AvatarData* owningAvatar); @@ -150,12 +156,18 @@ public: void incrementFramesWithoutData() { _numFramesWithoutData++; } void resetFramesWithoutData() { _numFramesWithoutData = 0; } int getFramesWithoutData() const { return _numFramesWithoutData; } + + // Controller buttons + void setControllerButtons(int controllerButtons) { _controllerButtons = controllerButtons; } + int getControllerButtons() { return _controllerButtons; } private: std::vector _fingers; glm::vec3 _rawPosition; glm::vec3 _rawNormal; glm::vec3 _velocity; + int _controllerButtons; + bool _isActive; // This has current valid data int _leapID; // the Leap's serial id for this tracked object int _numFramesWithoutData; // after too many frames without data, this tracked object assumed lost.