Skip to content

Commit

Permalink
Implemented initial "LeapLook" input module (#7).
Browse files Browse the repository at this point in the history
  • Loading branch information
zachkinstner committed Feb 16, 2015
1 parent 7bd4394 commit ad0ce40
Show file tree
Hide file tree
Showing 15 changed files with 4,153 additions and 12 deletions.
3,955 changes: 3,955 additions & 0 deletions Unity/Assets/Hovercast/Demo/Scenes/HovercastDemo-LeapLookVR.unity

Large diffs are not rendered by default.

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

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Linq;
using Hovercast.Core;
using Hovercast.Core.Input;
using Leap;
using UnityEngine;
Expand All @@ -16,15 +15,15 @@ public class HovercastLeapInputProvider : HovercastInputProvider {
public float NavigationBackUngrabThreshold = 0.15f;

private HandController vHandControl;
private LeapInputSettings vSettings;
private LeapInputSide vSideL;
private LeapInputSide vSideR;
protected LeapInputSettings vSettings;
protected LeapInputSide vSideL;
protected LeapInputSide vSideR;
private Frame vFrame;


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
public void Awake() {
public virtual void Awake() {
vHandControl = gameObject.GetComponent<HandController>();

if ( vHandControl == null ) {
Expand Down
2 changes: 1 addition & 1 deletion Unity/Assets/Hovercast/Devices/Leap/LeapInputCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Hovercast.Devices.Leap {

/*================================================================================================*/
internal class LeapInputCursor : IInputCursor {
public class LeapInputCursor : IInputCursor {

public bool IsLeft { get; private set; }
public bool IsActive { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion Unity/Assets/Hovercast/Devices/Leap/LeapInputMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Hovercast.Devices.Leap {

/*================================================================================================*/
internal class LeapInputMenu : IInputMenu {
public class LeapInputMenu : IInputMenu {

public bool IsLeft { get; private set; }
public bool IsActive { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion Unity/Assets/Hovercast/Devices/Leap/LeapInputSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Hovercast.Devices.Leap {

/*================================================================================================*/
internal class LeapInputSettings {
public class LeapInputSettings {

public Vector3 PalmDirection { get; set; }
public Finger.FingerType CursorFinger { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions Unity/Assets/Hovercast/Devices/Leap/LeapInputSide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Hovercast.Devices.Leap {

/*================================================================================================*/
internal class LeapInputSide : IInputSide {
public class LeapInputSide : IInputSide {

public bool IsLeft { get; private set; }

Expand All @@ -15,7 +15,7 @@ internal class LeapInputSide : IInputSide {

private Hand vLeapHand;
private bool vIsMenuStale;
private bool vIsCursorStale;
protected bool vIsCursorStale;


////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -43,7 +43,7 @@ internal class LeapInputSide : IInputSide {
}

/*--------------------------------------------------------------------------------------------*/
public IInputCursor Cursor {
public virtual IInputCursor Cursor {
get {
if ( vIsCursorStale ) {
vCursor.Rebuild(GetCursorLeapFinger());
Expand Down
5 changes: 5 additions & 0 deletions Unity/Assets/Hovercast/Devices/LeapLook.meta

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using Hovercast.Devices.Leap;
using UnityEngine;

namespace Hovercast.Devices.LeapLook {

/*================================================================================================*/
public class HovercastLeapLookInputProvider : HovercastLeapInputProvider {

public Transform HeadsetCameraTransform;


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
public override void Awake() {
base.Awake();

if ( HeadsetCameraTransform == null ) {
throw new Exception("The HovercastLeapLookInputProvider component requires the "+
"'Headset Camera Transform' to be set.");
}

Transform leapTx = gameObject.transform;

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

sideL.SetOppositeHandMenu(sideR.Menu);
sideR.SetOppositeHandMenu(sideL.Menu);

vSideL = sideL;
vSideR = sideR;
}

}

}

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

71 changes: 71 additions & 0 deletions Unity/Assets/Hovercast/Devices/LeapLook/LeapLookInputCursor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Hovercast.Core.Input;
using UnityEngine;

namespace Hovercast.Devices.LeapLook {

/*================================================================================================*/
internal class LeapLookInputCursor : IInputCursor {

public bool IsLeft { get; private set; }
public bool IsActive { get; private set; }

public Vector3 Position { get; private set; }
public Quaternion Rotation { get; private set; }

private readonly Transform vCameraTx;
private readonly Transform vLeapTx;

private IInputMenu vOppositeHandMenu;


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


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
public void SetOppositeHandMenu(IInputMenu pMenu) {
vOppositeHandMenu = pMenu;
}

/*--------------------------------------------------------------------------------------------*/
public void Rebuild() {
if ( !vOppositeHandMenu.IsActive ) {
IsActive = false;
Position = Vector3.zero;
return;
}

//TODO: "planePos" is shifted forward slighty to negate the effect of UiLevel.PushFromHand.
//This isn't exact. Could probably improve this by moving this "push" effect into the Leap
//input module. That way, the menu would appear exactly where the input data specifies. It
//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);
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);

if ( denom == 0 ) { //exactly parallel (very unlikely scenario)
IsActive = false;
Position = Vector3.zero;
return;
}

float t = numer/denom;

IsActive = true;
Position = camPos+camDir*t;
}

}

}

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

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

namespace Hovercast.Devices.LeapLook {

/*================================================================================================*/
internal class LeapLookInputSide : LeapInputSide {

private readonly LeapLookInputCursor vCursor;



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


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
public override IInputCursor Cursor {
get {
if ( vIsCursorStale ) {
vCursor.Rebuild();
vIsCursorStale = false;
}

return vCursor;
}
}


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
public void SetOppositeHandMenu(IInputMenu pMenu) {
vCursor.SetOppositeHandMenu(pMenu);
}

}

}

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

4 changes: 3 additions & 1 deletion Unity/ProjectSettings/EditorBuildSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes:
- enabled: 1
- enabled: 0
path: Assets/Hovercast/Demo/Scenes/HovercastDemo-LeapVR.unity
- enabled: 0
path: Assets/Hovercast/Demo/Scenes/HovercastDemo-LeapOnly-HeadMount.unity
- enabled: 0
path: Assets/Hovercast/Demo/Scenes/HovercastDemo-LeapOnly-TableMount.unity
- enabled: 1
path: Assets/Hovercast/Demo/Scenes/HovercastDemo-LeapLookVR.unity

0 comments on commit ad0ce40

Please sign in to comment.