From 6d539f763259d6846c19c8c8fab61a122141d740 Mon Sep 17 00:00:00 2001 From: Jefferson Bledsoe Date: Fri, 22 Mar 2019 11:58:00 +0000 Subject: [PATCH 1/4] Fix compiler warning --- Source/LeapLogger.h | 2 +- Source/MainComponent.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/LeapLogger.h b/Source/LeapLogger.h index d501a4b..4f46c19 100644 --- a/Source/LeapLogger.h +++ b/Source/LeapLogger.h @@ -24,7 +24,7 @@ class LeapLogger : public HighResolutionTimer //========================================================================== Leap::Controller controller; - int lastFrameId = -1; + int64 lastFrameId = -1; //========================================================================== const StringArray jointTypes = { "/TYPE_THUMB", "/TYPE_INDEX", "/TYPE_MIDDLE", "/TYPE_RING", "/TYPE_PINKY" }; diff --git a/Source/MainComponent.h b/Source/MainComponent.h index 35c2db6..f7bf22c 100644 --- a/Source/MainComponent.h +++ b/Source/MainComponent.h @@ -28,7 +28,7 @@ class MainContentComponent : public Component, private: //============================================================================== Leap::Controller controller; - int lastFrameId = -1; + int64 lastFrameId = -1; //============================================================================== bool leftLed = false; From 870831ecbfea9b83db22cd5f27cbf85dc3a3ff89 Mon Sep 17 00:00:00 2001 From: Jefferson Bledsoe Date: Fri, 22 Mar 2019 11:58:52 +0000 Subject: [PATCH 2/4] Add isExtended message to fingers --- Source/MainComponent.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/MainComponent.cpp b/Source/MainComponent.cpp index f96822c..6421ac5 100644 --- a/Source/MainComponent.cpp +++ b/Source/MainComponent.cpp @@ -140,6 +140,8 @@ void MainContentComponent::timerCallback() for (auto& finger : hand.fingers()) { + sender.send ({ handedness + jointTypes[finger.type()] + "/extended", finger.isExtended() }); + for (auto i = 0; i <= 3; i++) { auto boneType = static_cast(i); From 9654142348cb8ab8a6ec770f5dc0e703bce0af9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2?= Date: Wed, 15 May 2019 11:26:14 +0100 Subject: [PATCH 3/4] Implemented normalised values and HMD optimisation Normalised values + toggle HMD optimisation + toggle --- ReachCpp.jucer | 2 +- Source/Main.cpp | 2 +- Source/MainComponent.cpp | 143 +++++++++++++++++++++++++++--------- Source/MainComponent.h | 8 +- Source/ReachLookAndFeel.cpp | 2 +- 5 files changed, 117 insertions(+), 40 deletions(-) diff --git a/ReachCpp.jucer b/ReachCpp.jucer index 864de4c..6aafc74 100644 --- a/ReachCpp.jucer +++ b/ReachCpp.jucer @@ -1,7 +1,7 @@ diff --git a/Source/Main.cpp b/Source/Main.cpp index bb9da54..41a7718 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -63,9 +63,9 @@ class ReachApplication : public JUCEApplication { setResizable (true, true); setUsingNativeTitleBar (true); + centreWithSize(getWidth(), getHeight()); setContentOwned (new MainContentComponent (), true); - centreWithSize (getWidth(), getHeight()); setVisible (true); } diff --git a/Source/MainComponent.cpp b/Source/MainComponent.cpp index 6421ac5..393e134 100644 --- a/Source/MainComponent.cpp +++ b/Source/MainComponent.cpp @@ -13,15 +13,27 @@ //============================================================================== MainContentComponent::MainContentComponent () { - setBoundsRelative(0.025f, 0.025f, 0.15f, 0.15f); + setBoundsRelative(0.025f, 0.025f, 0.25f, 0.25f); sender.connect (senderIP, senderPort); startTimer(throttleTime); addAndMakeVisible(ipAddress); + ipAddress.setJustificationType(Justification::centred); addAndMakeVisible(port); + port.setJustificationType(Justification::centred); addAndMakeVisible(throttleSpeed); + throttleSpeed.setJustificationType(Justification::centred); + addAndMakeVisible(normValueButton); + addAndMakeVisible(normValueButtonLabel); + normValueButtonLabel.attachToComponent(&normValueButton, true); + normValueButtonLabel.setColour(Label::backgroundColourId, Colours::transparentBlack); + normValueButtonLabel.setColour(Label::textColourId, Colours::white); + addAndMakeVisible(hmdButton); + addAndMakeVisible(hmdButtonLabel); + hmdButtonLabel.setColour(Label::backgroundColourId, Colours::transparentBlack); + hmdButtonLabel.setColour(Label::textColourId, Colours::white); ipAddress.addListener(this); port.addListener(this); @@ -38,9 +50,11 @@ MainContentComponent::MainContentComponent () throttleSpeed.setFont(Font(22.0f)); throttleSpeed.setEditable(true); throttleSpeed.setText((String)throttleTime, dontSendNotification); -} -MainContentComponent::~MainContentComponent() = default; + hmdButton.onStateChange = [this] {controller.setPolicy(hmdButton.getToggleState() ? Leap::Controller::POLICY_OPTIMIZE_HMD + : Leap::Controller::POLICY_DEFAULT); }; + +} void MainContentComponent::paint (Graphics& g) { @@ -81,6 +95,10 @@ void MainContentComponent::resized() labelarea1.removeFromRight(proportionOfWidth(0.27)); throttleSpeed.setBounds(labelarea1.removeFromRight(proportionOfWidth(0.4))); + + normValueButton.setBounds(area.removeFromRight(23).reduced(0, proportionOfHeight(0.08))); + hmdButton.setBounds(area.removeFromLeft(23).reduced(0, proportionOfHeight(0.08))); + hmdButtonLabel.setBounds(area.removeFromLeft(proportionOfWidth(0.3))); } void MainContentComponent::timerCallback() @@ -114,44 +132,12 @@ void MainContentComponent::timerCallback() handedness = "/Right"; } - OSCMessage oscPalm = OSCMessage(handedness + "/palm"); - oscPalm.addFloat32(hand.stabilizedPalmPosition().x); - oscPalm.addFloat32(hand.stabilizedPalmPosition().y); - oscPalm.addFloat32(hand.stabilizedPalmPosition().z); - sender.send(oscPalm); + normValueButton.getToggleState() ? sendNormalisedValues(hand, handedness) : sendDenormalisedValues(hand, handedness); - OSCMessage oscWrist = OSCMessage(handedness + "/wrist"); - oscWrist.addFloat32(hand.wristPosition().x); - oscWrist.addFloat32(hand.wristPosition().y); - oscWrist.addFloat32(hand.wristPosition().z); - sender.send(oscWrist); OSCMessage oscGrab = OSCMessage(handedness + "/grab"); oscGrab.addFloat32(hand.grabAngle()); sender.send(oscGrab); - - OSCMessage oscRotation = OSCMessage(handedness + "/rotation"); - oscRotation.addFloat32(hand.palmNormal().x); - oscRotation.addFloat32(hand.palmNormal().y); - oscRotation.addFloat32(hand.palmNormal().z); - sender.send(oscRotation); - - - - for (auto& finger : hand.fingers()) - { - sender.send ({ handedness + jointTypes[finger.type()] + "/extended", finger.isExtended() }); - - for (auto i = 0; i <= 3; i++) - { - auto boneType = static_cast(i); - auto bone = finger.bone(boneType); - OSCMessage oscJoint = OSCMessage(String(handedness + jointTypes[finger.type()] + joints[i])); - oscJoint.addFloat32(bone.nextJoint().x); - oscJoint.addFloat32(bone.nextJoint().y); - oscJoint.addFloat32(bone.nextJoint().z); - } - } } OSCMessage presenceL = OSCMessage("/Left/presence"); @@ -185,3 +171,88 @@ void MainContentComponent::labelTextChanged(Label* labelThatHasChanged) startTimer(throttleTime); } } + +void MainContentComponent::sendDenormalisedValues(Leap::Hand hand, StringRef handedness) +{ + OSCMessage oscPalm = OSCMessage(handedness + "/palm"); + oscPalm.addFloat32(hand.stabilizedPalmPosition().x); + oscPalm.addFloat32(hand.stabilizedPalmPosition().y); + oscPalm.addFloat32(hand.stabilizedPalmPosition().z); + sender.send(oscPalm); + + OSCMessage oscWrist = OSCMessage(handedness + "/wrist"); + oscWrist.addFloat32(hand.wristPosition().x); + oscWrist.addFloat32(hand.wristPosition().y); + oscWrist.addFloat32(hand.wristPosition().z); + sender.send(oscWrist); + + OSCMessage oscRotation = OSCMessage(handedness + "/rotation"); + oscRotation.addFloat32(hand.palmNormal().x); + oscRotation.addFloat32(hand.palmNormal().y); + oscRotation.addFloat32(hand.palmNormal().z); + sender.send(oscRotation); + + + + for (auto& finger : hand.fingers()) + { + sender.send({ handedness + jointTypes[finger.type()] + "/extended", finger.isExtended() }); + + for (auto i = 0; i <= 3; i++) + { + auto boneType = static_cast(i); + auto bone = finger.bone(boneType); + OSCMessage oscJoint = OSCMessage(String(handedness + jointTypes[finger.type()] + joints[i])); + oscJoint.addFloat32(bone.nextJoint().x); + oscJoint.addFloat32(bone.nextJoint().y); + oscJoint.addFloat32(bone.nextJoint().z); + sender.send(oscJoint); + } + } +} + +void MainContentComponent::sendNormalisedValues(Leap::Hand hand, StringRef handedness) +{ + auto normPalmPos = hand.stabilizedPalmPosition().normalized(); + + OSCMessage oscPalm = OSCMessage(handedness + "/palm"); + oscPalm.addFloat32(normPalmPos.x); + oscPalm.addFloat32(normPalmPos.y); + oscPalm.addFloat32(normPalmPos.z); + sender.send(oscPalm); + + auto normWristPos = hand.wristPosition().normalized(); + + OSCMessage oscWrist = OSCMessage(handedness + "/wrist"); + oscWrist.addFloat32(normWristPos.x); + oscWrist.addFloat32(normWristPos.y); + oscWrist.addFloat32(normWristPos.z); + sender.send(oscWrist); + + auto normRotation = hand.palmNormal().normalized(); + + OSCMessage oscRotation = OSCMessage(handedness + "/rotation"); + oscRotation.addFloat32(normRotation.x); + oscRotation.addFloat32(normRotation.y); + oscRotation.addFloat32(normRotation.z); + sender.send(oscRotation); + + for (auto& finger : hand.fingers()) + { + sender.send({ handedness + jointTypes[finger.type()] + "/extended", finger.isExtended() }); + + for (auto i = 0; i <= 3; i++) + { + auto boneType = static_cast(i); + auto bone = finger.bone(boneType); + + auto normJointPos = bone.nextJoint().normalized(); + + OSCMessage oscJoint = OSCMessage(String(handedness + jointTypes[finger.type()] + joints[i])); + oscJoint.addFloat32(normJointPos.x); + oscJoint.addFloat32(normJointPos.y); + oscJoint.addFloat32(normJointPos.z); + sender.send(oscJoint); + } + } +} \ No newline at end of file diff --git a/Source/MainComponent.h b/Source/MainComponent.h index f7bf22c..3758baa 100644 --- a/Source/MainComponent.h +++ b/Source/MainComponent.h @@ -20,7 +20,7 @@ class MainContentComponent : public Component, public: //============================================================================== MainContentComponent (); - ~MainContentComponent(); + ~MainContentComponent() = default; void paint (Graphics&) override; void resized() override; @@ -39,11 +39,17 @@ class MainContentComponent : public Component, //============================================================================== void timerCallback() override; + void sendNormalisedValues(Leap::Hand hand, StringRef handedness); + void sendDenormalisedValues(Leap::Hand hand, StringRef handedness); //============================================================================== Label ipAddress; Label port; Label throttleSpeed; + Label normValueButtonLabel{ {}, "Normalised Values" }; + ToggleButton normValueButton; + Label hmdButtonLabel{ {}, "Head Mounted" }; + ToggleButton hmdButton; //============================================================================== String currentSizeAsString; diff --git a/Source/ReachLookAndFeel.cpp b/Source/ReachLookAndFeel.cpp index 41f6840..5c60b22 100644 --- a/Source/ReachLookAndFeel.cpp +++ b/Source/ReachLookAndFeel.cpp @@ -42,7 +42,7 @@ void ReachLookAndFeel::drawLabel(Graphics& g, Label& label) Rectangle textArea(label.getBorderSize().subtractedFrom(label.getLocalBounds())); - g.drawFittedText(label.getText(), textArea, Justification::centred, + g.drawFittedText(label.getText(), textArea, label.getJustificationType(), jmax(1, (int)(textArea.getHeight() / font.getHeight())), label.getMinimumHorizontalScale()); From 1cf58014487926ebe149a5362424246218e627f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2?= Date: Wed, 15 May 2019 11:56:24 +0100 Subject: [PATCH 4/4] Update JUCE Bump JUCE version --- JUCE | 2 +- ReachCpp.jucer | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/JUCE b/JUCE index 2be9bc9..49c631e 160000 --- a/JUCE +++ b/JUCE @@ -1 +1 @@ -Subproject commit 2be9bc95c2f2b0b25b09c562c26895ca580dd0c2 +Subproject commit 49c631e916a9f0c747348e6fcd092dc6283e0fe9 diff --git a/ReachCpp.jucer b/ReachCpp.jucer index 6aafc74..194eafd 100644 --- a/ReachCpp.jucer +++ b/ReachCpp.jucer @@ -2,7 +2,7 @@