-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented initial "LeapLook" input module (#7).
- Loading branch information
1 parent
7bd4394
commit ad0ce40
Showing
15 changed files
with
4,153 additions
and
12 deletions.
There are no files selected for viewing
3,955 changes: 3,955 additions & 0 deletions
3,955
Unity/Assets/Hovercast/Demo/Scenes/HovercastDemo-LeapLookVR.unity
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
Unity/Assets/Hovercast/Demo/Scenes/HovercastDemo-LeapLookVR.unity.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
Unity/Assets/Hovercast/Devices/LeapLook/HovercastLeapLookInputProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
Unity/Assets/Hovercast/Devices/LeapLook/HovercastLeapLookInputProvider.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
Unity/Assets/Hovercast/Devices/LeapLook/LeapLookInputCursor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
Unity/Assets/Hovercast/Devices/LeapLook/LeapLookInputCursor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
Unity/Assets/Hovercast/Devices/LeapLook/LeapLookInputSide.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
Unity/Assets/Hovercast/Devices/LeapLook/LeapLookInputSide.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters