Skip to content

Commit

Permalink
Merge pull request #20 from leapmotion/issue-14
Browse files Browse the repository at this point in the history
Issue 14
  • Loading branch information
getnamo authored Oct 6, 2018
2 parents 8b066dc + 2f3fb44 commit 4878118
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
Binary file modified Content/Examples/LeapHandsPawn.uasset
Binary file not shown.
2 changes: 1 addition & 1 deletion LeapMotion.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "3.0.0",
"VersionName": "3.0.1",
"FriendlyName": "Leap Motion Plugin",
"Description": "Support for the Leap Motion input device.",
"Category": "Input Devices",
Expand Down
22 changes: 15 additions & 7 deletions Source/LeapMotion/Private/LeapUtility.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.

#include "LeapUtility.h"
#include "Engine.h"
#include "IHeadMountedDisplay.h"

DEFINE_LOG_CATEGORY(LeapMotionLog);

//Static vars
#define LEAP_TO_UE_SCALE 0.1f
#define UE_TO_LEAP_SCALE 10.f

FVector LeapMountTranslationOffset = FVector(8.f, 0, 0);
FQuat LeapMountRotationOffset = FQuat(FRotator(0, 0, 0));

FQuat FacingAdjustQuat = FQuat(FRotator(90.f, 0.f, 0.f));
FQuat LeapRotationOffset = FQuat(FRotator(90.f, 0.f, 180.f));
//Defaults - NB: these don't get automatically set in a development context since 4.20
FVector FLeapUtility::LeapMountTranslationOffset = FVector(8.f, 0, 0);
FQuat FLeapUtility::LeapMountRotationOffset = FQuat(FRotator(0, 0, 0));

FQuat FLeapUtility::FacingAdjustQuat = FQuat(FRotator(90.f, 0.f, 0.f));
FQuat FLeapUtility::LeapRotationOffset = FQuat(FRotator(90.f, 0.f, 180.f));

//Todo: use and verify this for all values
float LeapGetWorldScaleFactor()
Expand All @@ -37,6 +41,10 @@ void FLeapUtility::SetLeapGlobalOffsets(const FVector& TranslationOffset, const
{
LeapMountTranslationOffset = TranslationOffset;
LeapMountRotationOffset = RotationOffset.Quaternion();

//These need to be set from a call due to static constants not being set since 4.20
FacingAdjustQuat = FQuat(FRotator(90.f, 0.f, 0.f));
LeapRotationOffset = FQuat(FRotator(90.f, 0.f, 180.f));
}

//Single point to handle leap conversion
Expand All @@ -56,12 +64,12 @@ FQuat FLeapUtility::ConvertLeapQuatToFQuat(const LEAP_QUATERNION& Quaternion)
Quat.Z = Quaternion.z;
Quat.W = Quaternion.w;

return Quat * LeapRotationOffset;
return Quat * FLeapUtility::LeapRotationOffset;
}

FVector AdjustForLeapFacing(FVector In)
{
return FacingAdjustQuat.RotateVector(In);
return FLeapUtility::FacingAdjustQuat.RotateVector(In);
}

FVector AdjustForHMD(FVector In)
Expand All @@ -72,7 +80,7 @@ FVector AdjustForHMD(FVector In)
FVector Position;
GEngine->XRSystem->GetCurrentPose(IXRTrackingSystem::HMDDeviceId, OrientationQuat, Position);
FVector Out = OrientationQuat.RotateVector(In);
Position += OrientationQuat.RotateVector(LeapMountTranslationOffset);
Position += OrientationQuat.RotateVector(FLeapUtility::LeapMountTranslationOffset);
Out += Position;
return Out;
}
Expand Down
7 changes: 7 additions & 0 deletions Source/LeapMotion/Private/LeapUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class FLeapUtility

static float ScaleLeapFloatToUE(float LeapFloat);
static float ScaleUEToLeap(float UEFloat);


static FVector LeapMountTranslationOffset;
static FQuat LeapMountRotationOffset;
static FQuat FacingAdjustQuat;
static FQuat LeapRotationOffset;

};

class LeapUtilityTimer
Expand Down

0 comments on commit 4878118

Please sign in to comment.