Skip to content

Commit

Permalink
Updated the existing input modules to use the new "FollowCursor" (rat…
Browse files Browse the repository at this point in the history
…her than duplicating that functionality in each module).
  • Loading branch information
zachkinstner committed Dec 19, 2016
1 parent 4145103 commit f154f31
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ MonoBehaviour:
m_EditorClassIdentifier:
CursorDataProvider: {fileID: 0}
LeapServiceProvider: {fileID: 163789564}
LookCursorTransform: {fileID: 163789565}
UseStabilizedPositions: 0
ExtendFingertipDistance: 0
Look:
FollowTransform: {fileID: 163789565}
--- !u!1 &1705083161
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using Hover.Core.Cursors;
using Hover.Core.Utils;
using Hover.InputModules.Follow;
using Leap;
using Leap.Unity;
using UnityEngine;
Expand All @@ -18,12 +19,15 @@ public class HoverInputLeapMotion : MonoBehaviour {

public HoverCursorDataProvider CursorDataProvider;
public LeapServiceProvider LeapServiceProvider;
public Transform LookCursorTransform;
public bool UseStabilizedPositions = false;

[Range(0, 0.04f)]
public float ExtendFingertipDistance = 0;

[Space(12)]

public FollowCursor Look = new FollowCursor(CursorType.Look);


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
Expand All @@ -34,9 +38,9 @@ public void Awake() {
LeapServiceProvider = FindObjectOfType<LeapServiceProvider>();
}

if ( LookCursorTransform == null ) {
if ( Look.FollowTransform == null ) {
GameObject lookGo = GameObject.Find("CenterEyeAnchor");
LookCursorTransform = (lookGo == null ? null : lookGo.transform);
Look.FollowTransform = (lookGo == null ? null : lookGo.transform);
}
}

Expand All @@ -52,7 +56,7 @@ public void Update() {

CursorDataProvider.MarkAllCursorsUnused();
UpdateCursorsWithHands(LeapServiceProvider.CurrentFrame.Hands);
UpdateCursorWithCamera();
Look.UpdateData(CursorDataProvider);
CursorDataProvider.ActivateAllCursorsBasedOnUsage();
}

Expand Down Expand Up @@ -119,18 +123,6 @@ private void UpdateCursorsWithFinger(Hand pLeapHand, Finger pLeapFinger) {
data.SetUsedByInput(true);
}

/*--------------------------------------------------------------------------------------------*/
private void UpdateCursorWithCamera() {
if ( !CursorDataProvider.HasCursorData(CursorType.Look) ) {
return;
}

ICursorDataForInput data = CursorDataProvider.GetCursorDataForInput(CursorType.Look);
data.SetWorldPosition(LookCursorTransform.position);
data.SetWorldRotation(LookCursorTransform.rotation);
data.SetUsedByInput(true);
}


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using Hover.Core.Cursors;
using Hover.Core.Utils;
using Hover.InputModules.Follow;
using Leap;
using UnityEngine;

Expand All @@ -16,12 +17,15 @@ public class HoverInputLeapMotionOld : MonoBehaviour {

public HoverCursorDataProvider CursorDataProvider;
public HandController LeapControl;
public Transform LookCursorTransform;
public bool UseStabilizedPositions = false;

[Range(0, 0.04f)]
public float ExtendFingertipDistance = 0;

[Space(12)]

public FollowCursor Look = new FollowCursor(CursorType.Look);


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
Expand All @@ -32,9 +36,9 @@ public void Awake() {
LeapControl = FindObjectOfType<HandController>();
}

if ( LookCursorTransform == null ) {
if ( Look.FollowTransform == null ) {
GameObject lookGo = GameObject.Find("CenterEyeAnchor");
LookCursorTransform = (lookGo == null ? null : lookGo.transform);
Look.FollowTransform = (lookGo == null ? null : lookGo.transform);
}
}

Expand All @@ -50,7 +54,7 @@ public void Update() {

CursorDataProvider.MarkAllCursorsUnused();
UpdateCursorsWithHands(LeapControl.GetFrame().Hands);
UpdateCursorWithCamera();
Look.UpdateData(CursorDataProvider);
CursorDataProvider.ActivateAllCursorsBasedOnUsage();
}

Expand Down Expand Up @@ -119,18 +123,6 @@ private void UpdateCursorsWithFinger(Hand pLeapHand, Finger pLeapFinger) {
data.SetUsedByInput(true);
}

/*--------------------------------------------------------------------------------------------*/
private void UpdateCursorWithCamera() {
if ( !CursorDataProvider.HasCursorData(CursorType.Look) ) {
return;
}

ICursorDataForInput data = CursorDataProvider.GetCursorDataForInput(CursorType.Look);
data.SetWorldPosition(LookCursorTransform.position);
data.SetWorldRotation(LookCursorTransform.rotation);
data.SetUsedByInput(true);
}


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
CursorDataProvider: {fileID: 0}
Avatar: {fileID: 1730406492}
LookCursorTransform: {fileID: 1351449442}
Look:
FollowTransform: {fileID: 1351449442}
LeftPalm:
LocalPosition: {x: 0, y: 0.01, z: 0}
LocalRotation: {x: -90, y: 0, z: 180}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Hover.Core.Cursors;
using Hover.Core.Utils;
using Hover.InputModules.Follow;
using UnityEngine;

namespace Hover.InputModules.OculusTouch {
Expand Down Expand Up @@ -29,7 +30,10 @@ public struct ControlState {

public HoverCursorDataProvider CursorDataProvider;
public OvrAvatar Avatar;
public Transform LookCursorTransform;

[Space(12)]

public FollowCursor Look = new FollowCursor(CursorType.Look);

[Space(12)]

Expand Down Expand Up @@ -121,8 +125,8 @@ public void Awake() {
Avatar = FindObjectOfType<OvrAvatar>();
}

if ( LookCursorTransform == null ) {
LookCursorTransform = Camera.main.transform;
if ( Look.FollowTransform == null ) {
Look.FollowTransform = Camera.main.transform;
}

LeftPalm.OriginTransform = transform;
Expand Down Expand Up @@ -152,7 +156,7 @@ public void Update() {

CursorDataProvider.MarkAllCursorsUnused();
UpdateCursorsWithControllers();
UpdateCursorWithCamera();
Look.UpdateData(CursorDataProvider);
CursorDataProvider.ActivateAllCursorsBasedOnUsage();
}

Expand Down Expand Up @@ -223,18 +227,6 @@ private ControlState GetControllerState(OVRInput.Controller pType) {
return state;
}

/*--------------------------------------------------------------------------------------------*/
private void UpdateCursorWithCamera() {
if ( !CursorDataProvider.HasCursorData(CursorType.Look) ) {
return;
}

ICursorDataForInput data = CursorDataProvider.GetCursorDataForInput(CursorType.Look);
data.SetWorldPosition(LookCursorTransform.position);
data.SetWorldRotation(LookCursorTransform.rotation);
data.SetUsedByInput(true);
}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
CursorDataProvider: {fileID: 0}
SteamControllers: {fileID: 1127804386}
LookCursorTransform: {fileID: 466971082}
Look:
FollowTransform: {fileID: 466971082}
LeftPalm:
LocalPosition: {x: 0, y: 0.01, z: 0}
LocalRotation: {x: 90, y: 0, z: 0}
Expand Down
24 changes: 8 additions & 16 deletions Unity/Assets/Hover/InputModules/Vive/Scripts/HoverInputVive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Hover.Core.Cursors;
using Hover.Core.Utils;
using Hover.InputModules.Follow;
using UnityEngine;
using Valve.VR;

Expand All @@ -28,7 +29,10 @@ public struct ControlState {

public HoverCursorDataProvider CursorDataProvider;
public SteamVR_ControllerManager SteamControllers;
public Transform LookCursorTransform;

[Space(12)]

public FollowCursor Look = new FollowCursor(CursorType.Look);

[Space(12)]

Expand Down Expand Up @@ -108,8 +112,8 @@ public struct ControlState {
public void Awake() {
InputModuleUtil.FindCursorReference(this, ref CursorDataProvider, false);

if ( LookCursorTransform == null ) {
LookCursorTransform = Camera.main.transform;
if ( Look.FollowTransform == null ) {
Look.FollowTransform = Camera.main.transform;
}

if ( SteamControllers == null ) {
Expand All @@ -129,7 +133,7 @@ public void Update() {

CursorDataProvider.MarkAllCursorsUnused();
UpdateCursorsWithControllers();
UpdateCursorWithCamera();
Look.UpdateData(CursorDataProvider);
CursorDataProvider.ActivateAllCursorsBasedOnUsage();
}

Expand Down Expand Up @@ -185,18 +189,6 @@ private ControlState GetControllerState(GameObject pControlGo) {
return state;
}

/*--------------------------------------------------------------------------------------------*/
private void UpdateCursorWithCamera() {
if ( !CursorDataProvider.HasCursorData(CursorType.Look) ) {
return;
}

ICursorDataForInput data = CursorDataProvider.GetCursorDataForInput(CursorType.Look);
data.SetWorldPosition(LookCursorTransform.position);
data.SetWorldRotation(LookCursorTransform.rotation);
data.SetUsedByInput(true);
}

}

}
Expand Down

1 comment on commit f154f31

@zachkinstner
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See issue #53.

Please sign in to comment.