Skip to content

Commit e3124dc

Browse files
Stephen HodgsonStephen Hodgson
authored andcommitted
Added GazeStabilizer.UpdateHeadStability to GazeManagers update.
Updated RayCast Hit Calc to use the stabilized head ray from GazeStabilizer Removed redundant using of UnityEngine.VR.WSA. Added GazeStabilizer as a required component. Added XML Documentation. Minor formatting.
1 parent 67b80dd commit e3124dc

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

Assets/HoloToolkit/Input/Scripts/GazeManager.cs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using UnityEngine;
5-
using UnityEngine.VR.WSA;
65

76
namespace HoloToolkit.Unity
87
{
98
/// <summary>
109
/// GazeManager determines the location of the user's gaze, hit position and normals.
1110
/// </summary>
11+
[RequireComponent(typeof(GazeStabilizer))]
1212
public partial class GazeManager : Singleton<GazeManager>
1313
{
14+
/// <summary>
15+
/// Maximum gaze distance, in meters, for calculating a hit from a GameOjects Collider.
16+
/// </summary>
1417
[Tooltip("Maximum gaze distance, in meters, for calculating a hit.")]
1518
public float MaxGazeDistance = 15.0f;
1619

20+
/// <summary>
21+
/// Select the layers raycast should target.
22+
/// </summary>
1723
[Tooltip("Select the layers raycast should target.")]
1824
public LayerMask RaycastLayerMask = Physics.DefaultRaycastLayers;
1925

@@ -23,8 +29,7 @@ public partial class GazeManager : Singleton<GazeManager>
2329
public bool Hit { get; private set; }
2430

2531
/// <summary>
26-
/// HitInfo property gives access
27-
/// to RaycastHit public members.
32+
/// HitInfo property gives access to RaycastHit public members.
2833
/// </summary>
2934
public RaycastHit HitInfo { get; private set; }
3035

@@ -43,21 +48,46 @@ public partial class GazeManager : Singleton<GazeManager>
4348
/// </summary>
4449
public GameObject FocusedObject { get; private set; }
4550

51+
/// <summary>
52+
/// Checking enables SetFocusPointForFrame to set the stabilization plane.
53+
/// </summary>
4654
[Tooltip("Checking enables SetFocusPointForFrame to set the stabilization plane.")]
4755
public bool SetStabilizationPlane = true;
56+
57+
/// <summary>
58+
/// Lerp speed when moving focus point closer.
59+
/// </summary>
4860
[Tooltip("Lerp speed when moving focus point closer.")]
4961
public float LerpStabilizationPlanePowerCloser = 4.0f;
62+
63+
/// <summary>
64+
/// Lerp speed when moving focus point farther away.
65+
/// </summary>
5066
[Tooltip("Lerp speed when moving focus point farther away.")]
5167
public float LerpStabilizationPlanePowerFarther = 7.0f;
5268

69+
/// <summary>
70+
/// Helper class that stabilizes gaze using gravity wells
71+
/// </summary>
72+
public GazeStabilizer GazeStabilization;
73+
5374
private Vector3 gazeOrigin;
5475
private Vector3 gazeDirection;
76+
private Quaternion gazeRotation;
5577
private float lastHitDistance = 15.0f;
5678

79+
private void Awake()
80+
{
81+
GazeStabilization = gameObject.GetComponent<GazeStabilizer>();
82+
}
83+
5784
private void Update()
5885
{
5986
gazeOrigin = Camera.main.transform.position;
6087
gazeDirection = Camera.main.transform.forward;
88+
gazeRotation = Camera.main.transform.rotation;
89+
90+
GazeStabilization.UpdateHeadStability(gazeOrigin, gazeRotation);
6191

6292
UpdateRaycast();
6393
UpdateStabilizationPlane();
@@ -70,13 +100,10 @@ private void UpdateRaycast()
70100
{
71101
// Get the raycast hit information from Unity's physics system.
72102
RaycastHit hitInfo;
73-
Hit = Physics.Raycast(gazeOrigin,
74-
gazeDirection,
75-
out hitInfo,
76-
MaxGazeDistance,
77-
RaycastLayerMask);
103+
Hit = Physics.Raycast(GazeStabilization.StableHeadRay, out hitInfo, MaxGazeDistance, RaycastLayerMask);
78104

79105
GameObject oldFocusedObject = FocusedObject;
106+
80107
// Update the HitInfo property so other classes can use this hit information.
81108
HitInfo = hitInfo;
82109

@@ -127,7 +154,7 @@ private void UpdateStabilizationPlane()
127154
}
128155
}
129156

130-
if (StabilizationPlaneModifier.Instance)
157+
if (StabilizationPlaneModifier.Instance != null)
131158
{
132159
StabilizationPlaneModifier.Instance.SetStabilizationPlane = SetStabilizationPlane;
133160
}

0 commit comments

Comments
 (0)