Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
NiccoloGranieri committed May 15, 2019
2 parents bdbd9d5 + 1cf5801 commit 559567a
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 42 deletions.
4 changes: 2 additions & 2 deletions ReachCpp.jucer
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<JUCERPROJECT id="Oi0NjZ" name="Reach" splashScreenColour="Dark" projectType="guiapp"
version="0.2.1" bundleIdentifier="com.IntegraLab.Reach" includeBinaryInAppConfig="1"
cppLanguageStandard="11" companyCopyright="Integra Lab" jucerVersion="5.4.0"
version="1.0" bundleIdentifier="com.IntegraLab.Reach" includeBinaryInAppConfig="1"
cppLanguageStandard="11" companyCopyright="Integra Lab" jucerVersion="5.4.3"
companyName="Integra Lab" reportAppUsage="0" headerPath="../../JuceLibraryCode/&#10;../../LeapSDK/include">
<MAINGROUP id="dja4JP" name="Reach">
<GROUP id="{16C39C49-29A4-5EA4-64BB-9F3BADD97C81}" name="Source">
Expand Down
2 changes: 1 addition & 1 deletion Source/LeapLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down
2 changes: 1 addition & 1 deletion Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
142 changes: 107 additions & 35 deletions Source/MainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -114,43 +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())
{
for (auto i = 0; i <= 3; i++)
{
auto boneType = static_cast<Leap::Bone::Type>(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);
}
}
}

OSCMessage presenceL = OSCMessage("/Left/presence");
Expand Down Expand Up @@ -184,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<Leap::Bone::Type>(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<Leap::Bone::Type>(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);
}
}
}
10 changes: 8 additions & 2 deletions Source/MainComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ class MainContentComponent : public Component,
public:
//==============================================================================
MainContentComponent ();
~MainContentComponent();
~MainContentComponent() = default;

void paint (Graphics&) override;
void resized() override;

private:
//==============================================================================
Leap::Controller controller;
int lastFrameId = -1;
int64 lastFrameId = -1;

//==============================================================================
bool leftLed = false;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Source/ReachLookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void ReachLookAndFeel::drawLabel(Graphics& g, Label& label)

Rectangle<int> 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());

Expand Down

0 comments on commit 559567a

Please sign in to comment.