From deae33fd1e6198854b9464bd605a2aed13b4b5f6 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sun, 18 Jun 2017 17:43:52 +1200 Subject: [PATCH] Add setting for desktop "zero" height offset --- .../hifiLeapMotion/src/LeapMotionPlugin.cpp | 30 +++++++++++++++++-- plugins/hifiLeapMotion/src/LeapMotionPlugin.h | 8 +++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/plugins/hifiLeapMotion/src/LeapMotionPlugin.cpp b/plugins/hifiLeapMotion/src/LeapMotionPlugin.cpp index 4a6ccb9b9b..6fd94c0ed0 100644 --- a/plugins/hifiLeapMotion/src/LeapMotionPlugin.cpp +++ b/plugins/hifiLeapMotion/src/LeapMotionPlugin.cpp @@ -181,8 +181,7 @@ void LeapMotionPlugin::InputDevice::update(float deltaTime, const controller::In // front of avatar. float halfShouldToHandLength = fabsf(extractTranslation(inputCalibrationData.defaultLeftHand).x - extractTranslation(inputCalibrationData.defaultLeftArm).x) / 2.0f; - const float ZERO_HEIGHT_OFFSET = 0.2f; - glm::vec3 leapMotionOffset = glm::vec3(0.0f, ZERO_HEIGHT_OFFSET, halfShouldToHandLength); + glm::vec3 leapMotionOffset = glm::vec3(0.0f, _desktopHeightOffset, halfShouldToHandLength); for (size_t i = 0; i < joints.size(); i++) { int poseIndex = LeapMotionJointIndexToPoseIndex((LeapMotionJointIndex)i); @@ -239,6 +238,24 @@ void LeapMotionPlugin::init() { preference->setItems(list); preferences->addPreference(preference); } + { + auto getter = [this]()->float { return _desktopHeightOffset; }; + auto setter = [this](float value) { + _desktopHeightOffset = value; + saveSettings(); + applyDesktopHeightOffset(); + }; + auto preference = new SpinnerPreference(LEAPMOTION_PLUGIN, "Desktop height offset", getter, setter); + float MIN_VALUE = 0.0f; + float MAX_VALUE = 1.0f; + float DECIMALS = 2.0f; + float STEP = 0.01f; + preference->setMin(MIN_VALUE); + preference->setMax(MAX_VALUE); + preference->setDecimals(DECIMALS); + preference->setStep(STEP); + preferences->addPreference(preference); + } } bool LeapMotionPlugin::activate() { @@ -271,6 +288,7 @@ void LeapMotionPlugin::deactivate() { const char* SETTINGS_ENABLED_KEY = "enabled"; const char* SETTINGS_SENSOR_LOCATION_KEY = "sensorLocation"; +const char* SETTINGS_DESKTOP_HEIGHT_OFFSET_KEY = "desktopHeightOffset"; void LeapMotionPlugin::saveSettings() const { Settings settings; @@ -279,6 +297,7 @@ void LeapMotionPlugin::saveSettings() const { { settings.setValue(QString(SETTINGS_ENABLED_KEY), _enabled); settings.setValue(QString(SETTINGS_SENSOR_LOCATION_KEY), _sensorLocation); + settings.setValue(QString(SETTINGS_DESKTOP_HEIGHT_OFFSET_KEY), _desktopHeightOffset); } settings.endGroup(); } @@ -290,7 +309,10 @@ void LeapMotionPlugin::loadSettings() { { _enabled = settings.value(SETTINGS_ENABLED_KEY, QVariant(DEFAULT_ENABLED)).toBool(); _sensorLocation = settings.value(SETTINGS_SENSOR_LOCATION_KEY, QVariant(DEFAULT_SENSOR_LOCATION)).toString(); + _desktopHeightOffset = + settings.value(SETTINGS_DESKTOP_HEIGHT_OFFSET_KEY, QVariant(DEFAULT_DESKTOP_HEIGHT_OFFSET)).toFloat(); applySensorLocation(); + applyDesktopHeightOffset(); } settings.endGroup(); } @@ -310,6 +332,10 @@ void LeapMotionPlugin::applySensorLocation() { } } +void LeapMotionPlugin::applyDesktopHeightOffset() { + _inputDevice->setDektopHeightOffset(_desktopHeightOffset); +} + const float LEFT_SIDE_SIGN = -1.0f; const float RIGHT_SIDE_SIGN = 1.0f; diff --git a/plugins/hifiLeapMotion/src/LeapMotionPlugin.h b/plugins/hifiLeapMotion/src/LeapMotionPlugin.h index 5e9e0da42b..a089bcf87d 100644 --- a/plugins/hifiLeapMotion/src/LeapMotionPlugin.h +++ b/plugins/hifiLeapMotion/src/LeapMotionPlugin.h @@ -42,9 +42,11 @@ public: protected: static const char* NAME; static const char* LEAPMOTION_ID_STRING; + const float DEFAULT_DESKTOP_HEIGHT_OFFSET = 0.2f; bool _enabled { false }; QString _sensorLocation; + float _desktopHeightOffset { DEFAULT_DESKTOP_HEIGHT_OFFSET }; struct LeapMotionJoint { glm::vec3 position; @@ -71,12 +73,18 @@ protected: const std::vector& prevJoints); void clearState(); + + void setDektopHeightOffset(float desktopHeightOffset) { _desktopHeightOffset = desktopHeightOffset; }; + + private: + float _desktopHeightOffset { 0.0f }; }; std::shared_ptr _inputDevice { std::make_shared() }; private: void applySensorLocation(); + void applyDesktopHeightOffset(); void processFrame(const Leap::Frame& frame);