Skip to content

Commit

Permalink
Merge pull request #248 from HodgsonSDAS/BasicCursor-fixes
Browse files Browse the repository at this point in the history
Basic cursor null ref and bitwise fixes
  • Loading branch information
NeerajW committed Oct 4, 2016
2 parents 0a94765 + c4c6cdf commit df08540
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions Assets/HoloToolkit/Input/Scripts/BasicCursor.cs
Expand Up @@ -26,17 +26,11 @@ public struct RaycastResult

private MeshRenderer meshRenderer;

private bool hasLoggedGazeManagerError;
private GazeManager gazeManager;

protected virtual void Awake()
{
if ((GazeManager.Instance.RaycastLayerMask & this.gameObject.layer) == 0)
{
Debug.LogError("The cursor has a layer that is checked in the GazeManager's Raycast Layer Mask. Change the cursor layer (e.g.: to Ignore Raycast) or uncheck the layer in GazeManager: " +
LayerMask.LayerToName(this.gameObject.layer));
}

meshRenderer = this.gameObject.GetComponent<MeshRenderer>();
meshRenderer = gameObject.GetComponent<MeshRenderer>();

if (meshRenderer == null)
{
Expand All @@ -48,21 +42,28 @@ protected virtual void Awake()
meshRenderer.enabled = false;

// Cache the cursor default rotation so the cursor can be rotated with respect to the original orientation.
cursorDefaultRotation = this.gameObject.transform.rotation;
cursorDefaultRotation = gameObject.transform.rotation;
}

protected virtual RaycastResult CalculateRayIntersect()
protected virtual void Start()
{
RaycastResult result = new RaycastResult();
if (GazeManager.Instance == null)
gazeManager = GazeManager.Instance;

if (gazeManager == null)
{
if (!hasLoggedGazeManagerError)
{
Debug.LogError("Must have a GazeManager somewhere in the scene.");
hasLoggedGazeManagerError = true;
}
return result;
Debug.LogError("Must have a GazeManager somewhere in the scene.");
}

if ((GazeManager.Instance.RaycastLayerMask & (1 << gameObject.layer)) != 0)
{
Debug.LogError("The cursor has a layer that is checked in the GazeManager's Raycast Layer Mask. Change the cursor layer (e.g.: to Ignore Raycast) or uncheck the layer in GazeManager: " +
LayerMask.LayerToName(gameObject.layer));
}
}

protected virtual RaycastResult CalculateRayIntersect()
{
RaycastResult result = new RaycastResult();
result.Hit = GazeManager.Instance.Hit;
result.Position = GazeManager.Instance.Position;
result.Normal = GazeManager.Instance.Normal;
Expand All @@ -71,7 +72,7 @@ protected virtual RaycastResult CalculateRayIntersect()

protected virtual void LateUpdate()
{
if (meshRenderer == null)
if (meshRenderer == null || gazeManager == null)
{
return;
}
Expand All @@ -83,11 +84,11 @@ protected virtual void LateUpdate()
meshRenderer.enabled = rayResult.Hit;

// Place the cursor at the calculated position.
this.gameObject.transform.position = rayResult.Position + rayResult.Normal * DistanceFromCollision;
gameObject.transform.position = rayResult.Position + rayResult.Normal * DistanceFromCollision;

// Reorient the cursor to match the hit object normal.
this.gameObject.transform.up = rayResult.Normal;
this.gameObject.transform.rotation *= cursorDefaultRotation;
gameObject.transform.up = rayResult.Normal;
gameObject.transform.rotation *= cursorDefaultRotation;
}
}
}

0 comments on commit df08540

Please sign in to comment.