diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 5920543dca..7d0f9edaa0 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -524,6 +524,42 @@ void MyAvatar::updateFromTrackers(float deltaTime) { } +// FIXME - this is super duper dumb... but this is how master works. When you have +// hydras plugged in, you'll get 4 "palms" but only the number of controllers lifted +// of the base station are considered active. So when you ask for "left" you get the +// first active controller. If you have both controllers held up or just the left, that +// will be correct. But if you lift the right controller, then it will be reported +// as "left"... you also see this in the avatars hands. +const PalmData* MyAvatar::getActivePalm(int palmIndex) const { + const HandData* handData = DependencyManager::get()->getMyAvatar()->getHandData(); + int numberOfPalms = handData->getNumPalms(); + int numberOfActivePalms = 0; + for (int i = 0; i < numberOfPalms; i++) { + auto palm = handData->getPalms()[i]; + if (palm.isActive()) { + // if we've reached the requested "active" palm, then we will return it + if (numberOfActivePalms == palmIndex) { + return &handData->getPalms()[i]; + } + numberOfActivePalms++; + } + } + return NULL; +} + + +glm::vec3 MyAvatar::getLeftHandPosition() const { + const int LEFT_HAND = 0; + auto palmData = getActivePalm(LEFT_HAND); + return palmData ? palmData->getPosition() : glm::vec3(0.0f); +} + +glm::vec3 MyAvatar::getRightHandPosition() const { + const int RIGHT_HAND = 1; + auto palmData = getActivePalm(RIGHT_HAND); + return palmData ? palmData->getPosition() : glm::vec3(0.0f); +} + // virtual void MyAvatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { // don't render if we've been asked to disable local rendering diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 7347419fee..d9ac2db271 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -34,7 +34,6 @@ enum AudioListenerMode { }; Q_DECLARE_METATYPE(AudioListenerMode); - class MyAvatar : public Avatar { Q_OBJECT Q_PROPERTY(bool shouldRenderLocally READ getShouldRenderLocally WRITE setShouldRenderLocally) @@ -50,6 +49,10 @@ class MyAvatar : public Avatar { Q_PROPERTY(AudioListenerMode CUSTOM READ getAudioListenerModeCustom) //TODO: make gravity feature work Q_PROPERTY(glm::vec3 gravity READ getGravity WRITE setGravity) + + Q_PROPERTY(glm::vec3 leftHandPosition READ getLeftHandPosition) + Q_PROPERTY(glm::vec3 rightHandPosition READ getRightHandPosition) + public: MyAvatar(RigPointer rig); ~MyAvatar(); @@ -136,6 +139,9 @@ public: Q_INVOKABLE glm::vec3 getTargetAvatarPosition() const { return _targetAvatarPosition; } + Q_INVOKABLE glm::vec3 getLeftHandPosition() const; + Q_INVOKABLE glm::vec3 getRightHandPosition() const; + AvatarWeakPointer getLookAtTargetAvatar() const { return _lookAtTargetAvatar; } void updateLookAtTargetAvatar(); void clearLookAtTargetAvatar(); @@ -274,6 +280,9 @@ private: void setVisibleInSceneIfReady(Model* model, render::ScenePointer scene, bool visiblity); + const PalmData* getActivePalm(int palmIndex) const; + + // derive avatar body position and orientation from the current HMD Sensor location. // results are in sensor space glm::mat4 deriveBodyFromHMDSensor() const;