Skip to content

Commit

Permalink
Merge pull request #7 from microsoft/mrtk_development
Browse files Browse the repository at this point in the history
Merge from mrtk_development
  • Loading branch information
djohnsomsft authored May 14, 2019
2 parents ec84669 + 90913e2 commit 9fe4e75
Show file tree
Hide file tree
Showing 54 changed files with 561 additions and 219 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Microsoft.MixedReality.Toolkit.Input;
using UnityEngine;

namespace Microsoft.MixedReality.Toolkit.Examples.Demos.EyeTracking
Expand All @@ -15,12 +16,29 @@ public class FollowEyeGazeGazeProvider : MonoBehaviour
[SerializeField]
private float defaultDistanceInMeters = 2f;

private IMixedRealityInputSystem inputSystem = null;

/// <summary>
/// The active instance of the input system.
/// </summary>
private IMixedRealityInputSystem InputSystem
{
get
{
if (inputSystem == null)
{
MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);
}
return inputSystem;
}
}

private void Update()
{
if (MixedRealityToolkit.InputSystem?.GazeProvider != null)
if (InputSystem?.GazeProvider != null)
{
gameObject.transform.position = MixedRealityToolkit.InputSystem.GazeProvider.GazeOrigin + MixedRealityToolkit.InputSystem.GazeProvider.GazeDirection.normalized * defaultDistanceInMeters;
gameObject.transform.position = InputSystem.GazeProvider.GazeOrigin + InputSystem.GazeProvider.GazeDirection.normalized * defaultDistanceInMeters;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ public abstract class PanZoomBase : MonoBehaviour,
private IMixedRealityEyeSaccadeProvider eyeSaccadeProvider = null;
#endregion

private IMixedRealityInputSystem inputSystem = null;

/// <summary>
/// The active instance of the input system.
/// </summary>
protected IMixedRealityInputSystem InputSystem
{
get
{
if (inputSystem == null)
{
MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);
}
return inputSystem;
}
}

public abstract void Initialize();
public abstract float ComputePanSpeed(float cursorPosInOneDir, float maxSpeed, float minDistFromCenterForAutoPan);
public abstract int ZoomDir(bool zoomIn);
Expand Down Expand Up @@ -567,7 +584,7 @@ void IMixedRealitySourceStateHandler.OnSourceDetected(SourceStateEventData event

void IMixedRealitySourceStateHandler.OnSourceLost(SourceStateEventData eventData)
{
foreach (var pointer in MixedRealityToolkit.InputSystem.GazeProvider.GazeInputSource.Pointers)
foreach (var pointer in InputSystem.GazeProvider.GazeInputSource.Pointers)
{
pointer.IsFocusLocked = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public override bool UpdateCursorPosInHitBox()
Vector3 halfsize = gameObject.transform.lossyScale / 2;

// Let's transform back to the origin: Translate & Rotate
Vector3 transfHitPnt = MixedRealityToolkit.InputSystem.EyeGazeProvider.HitPosition - center;
Vector3 transfHitPnt = InputSystem.EyeGazeProvider.HitPosition - center;

// Rotate around the y axis
transfHitPnt = Quaternion.AngleAxis(-(gameObject.transform.rotation.eulerAngles.y - 180), Vector3.up) * transfHitPnt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public override bool UpdateCursorPosInHitBox()
Vector3 halfsize = gameObject.transform.lossyScale / 2;

// Let's transform back to the origin: Translate & Rotate
Vector3 transfHitPnt = MixedRealityToolkit.InputSystem.EyeGazeProvider.HitPosition - center;
Vector3 transfHitPnt = InputSystem.EyeGazeProvider.HitPosition - center;

// Rotate around the y axis
transfHitPnt = Quaternion.AngleAxis(gameObject.transform.rotation.eulerAngles.y, Vector3.down) * transfHitPnt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,24 @@ public class MoveObjByEyeGaze : MonoBehaviour,
IMixedRealityPointerHandler,
IMixedRealityHandJointHandler
{
private IMixedRealityEyeGazeProvider EyeTrackingProvider => eyeTrackingProvider ?? (eyeTrackingProvider = MixedRealityToolkit.InputSystem?.EyeGazeProvider);
private IMixedRealityInputSystem inputSystem = null;

/// <summary>
/// The active instance of the input system.
/// </summary>
private IMixedRealityInputSystem InputSystem
{
get
{
if (inputSystem == null)
{
MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);
}
return inputSystem;
}
}

private IMixedRealityEyeGazeProvider EyeTrackingProvider => eyeTrackingProvider ?? (eyeTrackingProvider = InputSystem?.EyeGazeProvider);
private IMixedRealityEyeGazeProvider eyeTrackingProvider = null;

#region Serialized variables
Expand Down Expand Up @@ -242,12 +259,12 @@ void IMixedRealitySpeechHandler.OnSpeechKeywordRecognized(SpeechEventData eventD
if (voiceAction_PutThis == eventData.MixedRealityInputAction)
{
DragAndDrop_Start();
MixedRealityToolkit.InputSystem.PushModalInputHandler(gameObject);
InputSystem.PushModalInputHandler(gameObject);
}
else if (voiceAction_OverHere == eventData.MixedRealityInputAction)
{
DragAndDrop_Finish();
MixedRealityToolkit.InputSystem.PopModalInputHandler();
InputSystem.PopModalInputHandler();
}
}
#endregion
Expand Down Expand Up @@ -351,7 +368,7 @@ private void HandDrag_Start()
handPos_relative = Vector3.zero;
handPos_absolute = Vector3.zero;
DragAndDrop_Start();
MixedRealityToolkit.InputSystem.PushModalInputHandler(gameObject);
InputSystem.PushModalInputHandler(gameObject);
}
}

Expand All @@ -366,7 +383,7 @@ private void HandDrag_Stop()
handIsPinching = false;
handPos_relative = Vector3.zero;
DragAndDrop_Finish();
MixedRealityToolkit.InputSystem.PopModalInputHandler();
InputSystem.PopModalInputHandler();
currEngagedHand = Handedness.None;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Microsoft.MixedReality.Toolkit.Input;
using System.Collections;
using UnityEngine;

Expand All @@ -26,11 +27,28 @@ public class DrawOnTexture : MonoBehaviour

public Material HeatmapOverlayMaterialTemplate;

private IMixedRealityInputSystem inputSystem = null;

/// <summary>
/// The active instance of the input system.
/// </summary>
private IMixedRealityInputSystem InputSystem
{
get
{
if (inputSystem == null)
{
MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);
}
return inputSystem;
}
}

private void Update()
{
if (UseLiveInputStream && MixedRealityToolkit.InputSystem?.EyeGazeProvider?.GazeTarget == gameObject && MixedRealityToolkit.InputSystem.EyeGazeProvider.IsEyeGazeValid)
if (UseLiveInputStream && InputSystem?.EyeGazeProvider?.GazeTarget == gameObject && InputSystem.EyeGazeProvider.IsEyeGazeValid)
{
DrawAtThisHitPos(MixedRealityToolkit.InputSystem.EyeGazeProvider.HitPosition);
DrawAtThisHitPos(InputSystem.EyeGazeProvider.HitPosition);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ public enum VisModes
private bool isPaused = false;
private int numberOfTraceSamples;

private IMixedRealityInputSystem inputSystem = null;

/// <summary>
/// The active instance of the input system.
/// </summary>
private IMixedRealityInputSystem InputSystem
{
get
{
if (inputSystem == null)
{
MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);
}
return inputSystem;
}
}

void Start()
{
AmountOfSamples = (int)nhist;
Expand Down Expand Up @@ -327,7 +344,7 @@ public void UpdateDataVis(Ray cursorRay)

void Update()
{
if (MixedRealityToolkit.InputSystem?.EyeGazeProvider == null)
if (InputSystem?.EyeGazeProvider == null)
{
return;
}
Expand All @@ -339,7 +356,7 @@ void Update()

if ((!isPaused) && (useLiveInputStream))
{
UpdateDataVis(new Ray(MixedRealityToolkit.InputSystem.EyeGazeProvider.GazeOrigin, MixedRealityToolkit.InputSystem.EyeGazeProvider.GazeDirection));
UpdateDataVis(new Ray(InputSystem.EyeGazeProvider.GazeOrigin, InputSystem.EyeGazeProvider.GazeDirection));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.MixedReality.Toolkit.Examples.Demos.EyeTracking.Logging
{
public class LogStructureEyeGaze : LogStructure
{
private IMixedRealityEyeGazeProvider EyeTrackingProvider => eyeTrackingProvider ?? (eyeTrackingProvider = MixedRealityToolkit.InputSystem?.EyeGazeProvider);
private IMixedRealityEyeGazeProvider EyeTrackingProvider => eyeTrackingProvider ?? (eyeTrackingProvider = InputSystem?.EyeGazeProvider);
private IMixedRealityEyeGazeProvider eyeTrackingProvider = null;

public override string[] GetHeaderColumns()
Expand Down Expand Up @@ -41,6 +41,23 @@ public override string[] GetHeaderColumns()
};
}

private IMixedRealityInputSystem inputSystem = null;

/// <summary>
/// The active instance of the input system.
/// </summary>
private IMixedRealityInputSystem InputSystem
{
get
{
if (inputSystem == null)
{
MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);
}
return inputSystem;
}
}

public override object[] GetData(string inputType, string inputStatus, EyeTrackingTarget intTarget)
{
// Let's prepare all the data we wanna log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,29 @@ public class FollowEyeGaze : MonoBehaviour
[SerializeField]
private float defaultDistanceInMeters = 2f;

private IMixedRealityInputSystem inputSystem = null;

/// <summary>
/// The active instance of the input system.
/// </summary>
private IMixedRealityInputSystem InputSystem
{
get
{
if (inputSystem == null)
{
MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);
}
return inputSystem;
}
}

private void Update()
{
// Update GameObject to the current eye gaze position at a given distance
if (MixedRealityToolkit.InputSystem?.EyeGazeProvider?.IsEyeGazeValid == true)
if (InputSystem?.EyeGazeProvider?.IsEyeGazeValid == true)
{
GameObject target = MixedRealityToolkit.InputSystem.EyeGazeProvider.GazeTarget;
GameObject target = InputSystem.EyeGazeProvider.GazeTarget;
if (target != null)
{
// Show the object at the center of the currently looked at target.
Expand All @@ -37,14 +54,14 @@ private void Update()
else
{
// Show the object at the hit position of the user's eye gaze ray with the target.
gameObject.transform.position = MixedRealityToolkit.InputSystem.EyeGazeProvider.HitPosition;
gameObject.transform.position = InputSystem.EyeGazeProvider.HitPosition;

}
}
else
{
// If no target is hit, show the object at a default distance along the gaze ray.
gameObject.transform.position = MixedRealityToolkit.InputSystem.EyeGazeProvider.GazeOrigin + MixedRealityToolkit.InputSystem.EyeGazeProvider.GazeDirection.normalized * defaultDistanceInMeters;
gameObject.transform.position = InputSystem.EyeGazeProvider.GazeOrigin + InputSystem.EyeGazeProvider.GazeDirection.normalized * defaultDistanceInMeters;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ private TextMesh MyTextMesh
}
}

private IMixedRealityInputSystem inputSystem = null;

/// <summary>
/// The active instance of the input system.
/// </summary>
private IMixedRealityInputSystem InputSystem
{
get
{
if (inputSystem == null)
{
MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);
}
return inputSystem;
}
}

/// <summary>
/// Update text to be displayed
/// </summary>
Expand All @@ -62,10 +79,10 @@ public void ShowVisualFeedback(string msg)
// Update text to be displayed
UpdateTextMesh(msg);

if (MixedRealityToolkit.InputSystem.GazeProvider != null)
if (InputSystem.GazeProvider != null)
{
// Show the visual feedback at 2m in the direction the user is looking
visualFeedbackTemplate.transform.position = CameraCache.Main.transform.position + MixedRealityToolkit.InputSystem.GazeProvider.GazeDirection.normalized * 2f;
visualFeedbackTemplate.transform.position = CameraCache.Main.transform.position + InputSystem.GazeProvider.GazeDirection.normalized * 2f;
visualFeedbackTemplate.transform.LookAt(CameraCache.Main.transform.position);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ public class OnLookAtRotateByEyeGaze : BaseEyeFocusHandler
private float maxRotY = 180.0f;
#endregion

private IMixedRealityInputSystem inputSystem = null;

/// <summary>
/// The active instance of the input system.
/// </summary>
private IMixedRealityInputSystem InputSystem
{
get
{
if (inputSystem == null)
{
MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);
}
return inputSystem;
}
}

protected override void OnEyeFocusStay()
{
// Update target rotation
Expand All @@ -60,7 +77,7 @@ protected override void OnEyeFocusStay()

private void RotateHitTarget()
{
Vector3 TargetToHit = (this.gameObject.transform.position - MixedRealityToolkit.InputSystem.EyeGazeProvider.HitPosition).normalized;
Vector3 TargetToHit = (this.gameObject.transform.position - InputSystem.EyeGazeProvider.HitPosition).normalized;
Vector3 TargetToCam = (this.gameObject.transform.position - CameraCache.Main.transform.position).normalized;

float angle1x, angle1y, angle1z, angle2x, angle2y;
Expand Down
Loading

0 comments on commit 9fe4e75

Please sign in to comment.