Skip to content

Commit

Permalink
Merge pull request #19 from NeerajW/master
Browse files Browse the repository at this point in the history
Add SetFocusPointForFrame stability plane to GazeManager
  • Loading branch information
keveleigh committed Apr 25, 2016
2 parents b665a2e + bfd443a commit 2fe3eb0
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion Assets/HoloToolkit/Input/Scripts/GazeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;
using UnityEngine.VR.WSA;

namespace HoloToolkit.Unity
{
Expand Down Expand Up @@ -37,6 +38,13 @@ public partial class GazeManager : Singleton<GazeManager>
/// </summary>
public Vector3 Normal { get; private set; }

[Tooltip("Checking enables SetFocusPointForFrame to set the stabilization plane.")]
public bool SetStabilizationPlane = true;
[Tooltip("Lerp speed when moving focus point closer.")]
public float LerpStabilizationPlanePowerCloser = 4.0f;
[Tooltip("Lerp speed when moving focus point farther away.")]
public float LerpStabilizationPlanePowerFarther = 7.0f;

private Vector3 gazeOrigin;
private Vector3 gazeDirection;
private float lastHitDistance = 15.0f;
Expand All @@ -48,6 +56,8 @@ private void Update()
gazeDirection = Camera.main.transform.forward;

UpdateRaycast();

UpdateStabilizationPlane();
}

/// <summary>
Expand Down Expand Up @@ -83,7 +93,9 @@ private void UpdateRaycast()
Normal = gazeDirection;
focusedObject = null;
}
if(oldFocusedObject != focusedObject) //The currently hit object has changed

// Check if the currently hit object has changed
if (oldFocusedObject != focusedObject)
{
if (oldFocusedObject != null)
{
Expand All @@ -95,5 +107,27 @@ private void UpdateRaycast()
}
}
}

/// <summary>
/// Updates the focus point for every frame.
/// </summary>
private void UpdateStabilizationPlane()
{
if (SetStabilizationPlane)
{
// Calculate the delta between between camera's position and current hit position.
float focusPointDistance = (gazeOrigin - Position).magnitude;
float lerpPower = focusPointDistance > lastHitDistance
? LerpStabilizationPlanePowerFarther
: LerpStabilizationPlanePowerCloser;

// Smoothly move the focus point from previous hit position to new position.
lastHitDistance = Mathf.Lerp(lastHitDistance, focusPointDistance, lerpPower * Time.deltaTime);

Vector3 newFocusPointPosition = gazeOrigin + (gazeDirection * lastHitDistance);

HolographicSettings.SetFocusPointForFrame(newFocusPointPosition, -gazeDirection);
}
}
}
}

0 comments on commit 2fe3eb0

Please sign in to comment.