Skip to content

Commit

Permalink
Updated FollowEyeGaze.cs to account for changes in EyeTrackingTarget.
Browse files Browse the repository at this point in the history
  • Loading branch information
sostel committed May 30, 2019
1 parent ffe8d42 commit c63617c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class FollowEyeGaze : MonoBehaviour
[Tooltip("Display the game object along the eye gaze ray at a default distance (in meters).")]
[SerializeField]
private float defaultDistanceInMeters = 2f;

private IMixedRealityInputSystem inputSystem = null;

/// <summary>
/// The active instance of the input system.
/// </summary>
Expand All @@ -36,34 +36,33 @@ private IMixedRealityInputSystem InputSystem

private void Update()
{
gameObject.transform.position = InputSystem.EyeGazeProvider.GazeOrigin + InputSystem.EyeGazeProvider.GazeDirection.normalized * defaultDistanceInMeters;

EyeTrackingTarget lookedAtEyeTarget = EyeTrackingTarget.LookedAtEyeTarget;

// Update GameObject to the current eye gaze position at a given distance
if (InputSystem?.EyeGazeProvider?.IsEyeGazeValid == true)
if (lookedAtEyeTarget != null)
{
GameObject target = InputSystem.EyeGazeProvider.GazeTarget;
if (target != null)
// Show the object at the center of the currently looked at target.
if (lookedAtEyeTarget.eyeCursorSnapToTargetCenter)
{
// Show the object at the center of the currently looked at target.
EyeTrackingTarget etTarget = target.GetComponent<EyeTrackingTarget>();
if ((etTarget != null) && (etTarget.cursor_snapToCenter))
{
Ray rayToCenter = new Ray(CameraCache.Main.transform.position, target.transform.position - CameraCache.Main.transform.position);
RaycastHit hitInfo;
UnityEngine.Physics.Raycast(rayToCenter, out hitInfo);
gameObject.transform.position = hitInfo.point;
}
else
{
// Show the object at the hit position of the user's eye gaze ray with the target.
gameObject.transform.position = InputSystem.EyeGazeProvider.HitPosition;

}
Ray rayToCenter = new Ray(CameraCache.Main.transform.position, lookedAtEyeTarget.transform.position - CameraCache.Main.transform.position);
RaycastHit hitInfo;
UnityEngine.Physics.Raycast(rayToCenter, out hitInfo);
gameObject.transform.position = hitInfo.point;
}
else
{
// If no target is hit, show the object at a default distance along the gaze ray.
// Show the object at the hit position of the user's eye gaze ray with the target.
//gameObject.transform.position = EyeTrackingTarget.LookedAtPoint;
gameObject.transform.position = InputSystem.EyeGazeProvider.GazeOrigin + InputSystem.EyeGazeProvider.GazeDirection.normalized * defaultDistanceInMeters;
}
}
else
{
// If no target is hit, show the object at a default distance along the gaze ray.
gameObject.transform.position = InputSystem.EyeGazeProvider.GazeOrigin + InputSystem.EyeGazeProvider.GazeDirection.normalized * defaultDistanceInMeters;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,13 @@ private void UpdateHitTarget()
else
{
LookedAtTarget = null;
LookedAtEyeTarget = null;
}
}
else if ((DateTime.UtcNow - InputSystem.EyeGazeProvider.Timestamp).TotalMilliseconds > EyeTrackingTimeoutInMilliseconds)
{
LookedAtTarget = null;
LookedAtEyeTarget = null;
IsLookedAt = false;
}

Expand Down

0 comments on commit c63617c

Please sign in to comment.