Skip to content

Commit

Permalink
Added "Cursor Horizontal Offset" feature to the "Leap Look" input mod…
Browse files Browse the repository at this point in the history
…ule (#7).
  • Loading branch information
zachkinstner committed Feb 16, 2015
1 parent ad0ce40 commit 81c793f
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3439,6 +3439,7 @@ MonoBehaviour:
NavigationBackGrabThreshold: .300000012
NavigationBackUngrabThreshold: .150000006
HeadsetCameraTransform: {fileID: 1403731239}
CursorHorizontalOffset: .400000006
--- !u!1 &1855087118
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class HovercastLeapInputProvider : HovercastInputProvider {

////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
private void UpdateSettings() {
protected virtual void UpdateSettings() {
vSettings.PalmDirection = ActivePalmDirection;
vSettings.CursorFinger = CursorFinger;
vSettings.NavBackGrabThreshold = NavigationBackGrabThreshold;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Hovercast.Devices.LeapLook {
public class HovercastLeapLookInputProvider : HovercastLeapInputProvider {

public Transform HeadsetCameraTransform;
public float CursorHorizontalOffset = 0.4f;


////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -20,10 +21,13 @@ public class HovercastLeapLookInputProvider : HovercastLeapInputProvider {
"'Headset Camera Transform' to be set.");
}

Transform leapTx = gameObject.transform;
var sett = new LeapLookInputSettings();
sett.LeapTransform = gameObject.transform;
vSettings = sett;
UpdateSettings();

var sideL = new LeapLookInputSide(true, HeadsetCameraTransform, leapTx, vSettings);
var sideR = new LeapLookInputSide(false, HeadsetCameraTransform, leapTx, vSettings);
var sideL = new LeapLookInputSide(true, sett);
var sideR = new LeapLookInputSide(false, sett);

sideL.SetOppositeHandMenu(sideR.Menu);
sideR.SetOppositeHandMenu(sideL.Menu);
Expand All @@ -32,6 +36,22 @@ public class HovercastLeapLookInputProvider : HovercastLeapInputProvider {
vSideR = sideR;
}


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
protected override void UpdateSettings() {
base.UpdateSettings();

LeapLookInputSettings sett = (vSettings as LeapLookInputSettings);

if ( sett == null ) { //will only happen upon first UpdateSettings() call
return;
}

sett.CameraTransform = HeadsetCameraTransform;
sett.CursorHorizontalOffset = CursorHorizontalOffset;
}

}

}
22 changes: 14 additions & 8 deletions Unity/Assets/Hovercast/Devices/LeapLook/LeapLookInputCursor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Hovercast.Core.Input;
using Hovercast.Devices.Leap;
using UnityEngine;

namespace Hovercast.Devices.LeapLook {
Expand All @@ -12,18 +13,15 @@ internal class LeapLookInputCursor : IInputCursor {
public Vector3 Position { get; private set; }
public Quaternion Rotation { get; private set; }

private readonly Transform vCameraTx;
private readonly Transform vLeapTx;

private readonly LeapLookInputSettings vSettings;
private IInputMenu vOppositeHandMenu;


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
public LeapLookInputCursor(bool pIsLeft, Transform pCameraTx, Transform pLeapTx) {
public LeapLookInputCursor(bool pIsLeft, LeapLookInputSettings pSettings) {
IsLeft = pIsLeft;
vCameraTx = pCameraTx;
vLeapTx = pLeapTx;
vSettings = pSettings;
}


Expand All @@ -47,10 +45,18 @@ internal class LeapLookInputCursor : IInputCursor {
//becomes the input module's responsibility to offset the menu position to provide enough
//space for things like 3D hand models.

Vector3 camPos = vLeapTx.InverseTransformPoint(vCameraTx.position);
Vector3 camDir = vLeapTx.InverseTransformDirection(vCameraTx.rotation*Vector3.forward);
Transform leapTx = vSettings.LeapTransform;
Transform camTx = vSettings.CameraTransform;

Vector3 camPos = leapTx.InverseTransformPoint(camTx.position);
Vector3 camDir = leapTx.InverseTransformDirection(camTx.rotation*Vector3.forward);
Vector3 camHoriz = leapTx.InverseTransformDirection(camTx.rotation*Vector3.left);

camPos += camHoriz*vSettings.CursorHorizontalOffset*(IsLeft ? 1 : -1)*0.1f;

Vector3 planeNorm = vOppositeHandMenu.Rotation*Vector3.up;
Vector3 planePos = vOppositeHandMenu.Position - planeNorm*0.025f;

float numer = Vector3.Dot(planePos-camPos, planeNorm);
float denom = Vector3.Dot(camDir, planeNorm);

Expand Down
18 changes: 18 additions & 0 deletions Unity/Assets/Hovercast/Devices/LeapLook/LeapLookInputSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Hovercast.Devices.Leap;
using UnityEngine;

namespace Hovercast.Devices.LeapLook {

/*================================================================================================*/
public class LeapLookInputSettings : LeapInputSettings {

//TODO: hide the "Cursor Finger" setting
//TODO: custom editor with a slider with range [0,1] for "Cursor Horizontal Offset"

public Transform LeapTransform { get; set; }
public Transform CameraTransform { get; set; }
public float CursorHorizontalOffset { get; set; }

}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Unity/Assets/Hovercast/Devices/LeapLook/LeapLookInputSide.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Hovercast.Core.Input;
using Hovercast.Devices.Leap;
using UnityEngine;

namespace Hovercast.Devices.LeapLook {

Expand All @@ -13,9 +12,9 @@ internal class LeapLookInputSide : LeapInputSide {

////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
public LeapLookInputSide(bool pIsLeft, Transform pCameraTx, Transform pLeapTx,
LeapInputSettings pSettings) : base(pIsLeft, pSettings) {
vCursor = new LeapLookInputCursor(pIsLeft, pCameraTx, pLeapTx);
public LeapLookInputSide(bool pIsLeft, LeapLookInputSettings pSettings) :
base(pIsLeft, pSettings) {
vCursor = new LeapLookInputCursor(pIsLeft, pSettings);
}


Expand Down

0 comments on commit 81c793f

Please sign in to comment.