Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Dev focus updates #25

Merged
merged 5 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class GazeProvider : InputSystemGlobalListener, IMixedRealityGazeProvider
/// </summary>
[SerializeField]
[Tooltip("Stabilizer, if any, used to smooth out the gaze ray data.")]
private GazeStabilizer stabilizer = null;
private GenericStabilizer stabilizer = null;

/// <summary>
/// Transform that should be used as the source of the gaze position and rotation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using XRTK.SDK.Input.Handlers;
using XRTK.Services;
using XRTK.Utilities.Async;
using XRTK.Utilities.Physics;

namespace XRTK.SDK.UX.Pointers
{
Expand Down Expand Up @@ -276,7 +277,11 @@ public float PointerExtent

return pointerExtent;
}
set => pointerExtent = value;
set
{
pointerExtent = value;
overrideGlobalPointerExtent = false;
}
}

/// <inheritdoc />
Expand All @@ -292,7 +297,7 @@ public float PointerExtent
public IPointerResult Result { get; set; }

/// <inheritdoc />
public IBaseRayStabilizer RayStabilizer { get; set; }
public IBaseRayStabilizer RayStabilizer { get; set; } = new GenericStabilizer();

/// <inheritdoc />
public RaycastMode RaycastMode { get; set; } = RaycastMode.Simple;
Expand All @@ -309,12 +314,14 @@ public float PointerExtent
public virtual float PointerOrientation
{
get => pointerOrientation + (raycastOrigin != null ? raycastOrigin.eulerAngles.y : transform.eulerAngles.y);
set =>
pointerOrientation = value < 0
? Mathf.Clamp(value, -360f, 0f)
: Mathf.Clamp(value, 0f, 360f);
set => pointerOrientation = value < 0
? Mathf.Clamp(value, -360f, 0f)
: Mathf.Clamp(value, 0f, 360f);
}

/// <inheritdoc />
public bool IsTargetPositionLockedOnFocusLock { get; set; }

/// <inheritdoc />
public virtual void OnPreRaycast() { }

Expand All @@ -331,7 +338,7 @@ public virtual bool TryGetPointerPosition(out Vector3 position)
/// <inheritdoc />
public virtual bool TryGetPointingRay(out Ray pointingRay)
{
TryGetPointerPosition(out Vector3 pointerPosition);
TryGetPointerPosition(out var pointerPosition);
pointingRay = pointerRay;
pointingRay.origin = pointerPosition;
pointingRay.direction = PointerDirection;
Expand All @@ -343,7 +350,7 @@ public virtual bool TryGetPointingRay(out Ray pointingRay)
/// <inheritdoc />
public virtual bool TryGetPointerRotation(out Quaternion rotation)
{
Vector3 pointerRotation = raycastOrigin != null ? raycastOrigin.eulerAngles : transform.eulerAngles;
var pointerRotation = raycastOrigin != null ? raycastOrigin.eulerAngles : transform.eulerAngles;
rotation = Quaternion.Euler(pointerRotation.x, PointerOrientation, pointerRotation.z);
return true;
}
Expand Down Expand Up @@ -398,6 +405,31 @@ public override int GetHashCode()

#endregion IMixedRealityPointer Implementation

#region IMixedRealitySourcePoseHandler Implementation

/// <inheritdoc />
public override void OnSourceLost(SourceStateEventData eventData)
{
base.OnSourceLost(eventData);

if (eventData.SourceId == InputSourceParent.SourceId)
{
if (requiresHoldAction)
{
IsHoldPressed = false;
}

if (IsSelectPressed)
{
MixedRealityToolkit.InputSystem.RaisePointerUp(this, pointerAction);
}

IsSelectPressed = false;
}
}

#endregion IMixedRealitySourcePoseHandler Implementation

#region IMixedRealityInputHandler Implementation

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace XRTK.SDK.UX.Pointers
/// <summary>
/// A simple line pointer for drawing lines from the input source origin to the current pointer position.
/// </summary>
[RequireComponent(typeof(DistorterGravity))]
public class LinePointer : BaseControllerPointer
{
[SerializeField]
Expand Down Expand Up @@ -59,14 +58,6 @@ public BaseMixedRealityLineRenderer[] LineRenderers
set => lineRenderers = value;
}

[SerializeField]
private DistorterGravity gravityDistorter = null;

/// <summary>
/// The Gravity Distorter that is affecting the <see cref="BaseMixedRealityLineDataProvider"/> attached to this pointer.
/// </summary>
public DistorterGravity GravityDistorter => gravityDistorter;

private void CheckInitialization()
{
if (lineBase == null)
Expand All @@ -79,11 +70,6 @@ private void CheckInitialization()
Debug.LogError($"No Mixed Reality Line Data Provider found on {gameObject.name}. Did you forget to add a Line Data provider?");
}

if (gravityDistorter == null)
{
gravityDistorter = GetComponent<DistorterGravity>();
}

if (lineBase != null && (lineRenderers == null || lineRenderers.Length == 0))
{
lineRenderers = lineBase.GetComponentsInChildren<BaseMixedRealityLineRenderer>();
Expand Down Expand Up @@ -117,20 +103,27 @@ public override void OnPreRaycast()
{
Debug.Assert(lineBase != null);

TryGetPointerPosition(out Vector3 pointerPosition);

lineBase.UpdateMatrix();

if (RayStabilizer != null)
{
RayStabilizer.UpdateStability(Rays[0].Origin, Rays[0].Direction);
Rays[0].CopyRay(RayStabilizer.StableRay, PointerExtent);
}

TryGetPointerPosition(out var pointerPosition);
TryGetPointerRotation(out var pointerRotation);

// Set our first and last points
lineBase.FirstPoint = pointerPosition;

if (IsFocusLocked)
if (IsFocusLocked && Result != null)
{
lineBase.LastPoint = pointerPosition + ((Result.Details.Point - pointerPosition).normalized * PointerExtent);
}
else
{
lineBase.LastPoint = pointerPosition + (PointerDirection * PointerExtent);
lineBase.LastPoint = pointerPosition + pointerRotation * Vector3.forward * PointerExtent;
}

// Make sure our array will hold
Expand All @@ -139,19 +132,12 @@ public override void OnPreRaycast()
Rays = new RayStep[LineCastResolution];
}

// Set up our rays
if (!IsFocusLocked)
{
// Turn off gravity so we get accurate rays
gravityDistorter.enabled = false;
}

float stepSize = 1f / Rays.Length;
Vector3 lastPoint = lineBase.GetUnClampedPoint(0f);
var stepSize = 1f / Rays.Length;
var lastPoint = lineBase.GetUnClampedPoint(0f);

for (int i = 0; i < Rays.Length; i++)
{
Vector3 currentPoint = lineBase.GetUnClampedPoint(stepSize * (i + 1));
var currentPoint = lineBase.GetUnClampedPoint(stepSize * (i + 1));
Rays[i].UpdateRayStep(ref lastPoint, ref currentPoint);
lastPoint = currentPoint;
}
Expand All @@ -160,70 +146,67 @@ public override void OnPreRaycast()
/// <inheritdoc />
public override void OnPostRaycast()
{
// Use the results from the last update to set our NavigationResult
float clearWorldLength = 0f;
gravityDistorter.enabled = false;
Gradient lineColor = LineColorNoTarget;

if (IsInteractionEnabled)
{
lineBase.enabled = true;

if (IsSelectPressed)
{
lineColor = LineColorSelected;
}

// If we hit something
if (Result.CurrentPointerTarget != null)
{
// Use the step index to determine the length of the hit
for (int i = 0; i <= Result.RayStepIndex; i++)
{
if (i == Result.RayStepIndex)
{
// Only add the distance between the start point and the hit
clearWorldLength += Vector3.Distance(Rays[i].Origin, Result.Details.Point);
}
else if (i < Result.RayStepIndex)
{
// Add the full length of the step to our total distance
clearWorldLength += Rays[i].Length;
}
}

// Clamp the end of the line to the result hit's point
lineBase.LineEndClamp = lineBase.GetNormalizedLengthFromWorldLength(clearWorldLength, LineCastResolution);

if (FocusTarget != null)
{
lineColor = LineColorValid;
}

if (IsFocusLocked)
{
gravityDistorter.enabled = true;
gravityDistorter.WorldCenterOfGravity = Result.Details.Point;
}
}
else
{
lineBase.LineEndClamp = 1f;
}
base.OnPostRaycast();

Gradient lineColor;

if (!IsInteractionEnabled)
{
lineBase.enabled = false;
BaseCursor?.SetVisibility(false);
return;
}

lineBase.enabled = true;
BaseCursor?.SetVisibility(true);

// The distance the ray travels through the world before it hits something. Measured in world-units (as opposed to normalized distance).
float clearWorldLength;
// Used to ensure the line doesn't extend beyond the cursor
float cursorOffsetWorldLength = BaseCursor?.SurfaceCursorDistance ?? 0;

// If we hit something
if (Result?.CurrentPointerTarget != null)
{
clearWorldLength = Result.Details.RayDistance;

lineColor = IsSelectPressed ? LineColorSelected : LineColorValid;
}
else
{
lineBase.enabled = false;
clearWorldLength = PointerExtent;

lineColor = IsSelectPressed ? LineColorSelected : LineColorNoTarget;
}

if (IsFocusLocked)
{
lineColor = LineColorLockFocus;
}

for (int i = 0; i < lineRenderers.Length; i++)
int maxClampLineSteps = LineCastResolution;

for (var i = 0; i < lineRenderers.Length; i++)
{
var lineRenderer = lineRenderers[i];
// Renderers are enabled by default if line is enabled
lineRenderer.enabled = true;
maxClampLineSteps = Mathf.Max(maxClampLineSteps, lineRenderer.LineStepCount);
lineRenderer.LineColor = lineColor;
}

// If focus is locked, we're sticking to the target
// So don't clamp the world length
if (IsFocusLocked && IsTargetPositionLockedOnFocusLock)
{
float cursorOffsetLocalLength = LineBase.GetNormalizedLengthFromWorldLength(cursorOffsetWorldLength);
LineBase.LineEndClamp = 1 - cursorOffsetLocalLength;
}
else
{
lineRenderers[i].LineColor = lineColor;
// Otherwise clamp the line end by the clear distance
float clearLocalLength = lineBase.GetNormalizedLengthFromWorldLength(clearWorldLength - cursorOffsetWorldLength, maxClampLineSteps);
lineBase.LineEndClamp = clearLocalLength;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ public override void OnPreRaycast()
Rays = new RayStep[LineCastResolution];
}

// Set up our rays
// Turn off gravity so we get accurate rays
GravityDistorter.enabled = false;

float stepSize = 1f / Rays.Length;
Vector3 lastPoint = LineBase.GetUnClampedPoint(0f);

Expand All @@ -150,17 +146,13 @@ public override void OnPreRaycast()
Rays[i].UpdateRayStep(ref lastPoint, ref currentPoint);
lastPoint = currentPoint;
}

// Re-enable gravity if we're looking at a hotspot
GravityDistorter.enabled = (TeleportSurfaceResult == TeleportSurfaceResult.HotSpot);
}

public override void OnPostRaycast()
{
// Use the results from the last update to set our NavigationResult
float clearWorldLength = 0f;
TeleportSurfaceResult = TeleportSurfaceResult.None;
GravityDistorter.enabled = false;

if (IsInteractionEnabled)
{
Expand All @@ -176,9 +168,6 @@ public override void OnPostRaycast()
if (TeleportHotSpot != null && TeleportHotSpot.IsActive)
{
TeleportSurfaceResult = TeleportSurfaceResult.HotSpot;
// Turn on gravity, point it at hotspot
GravityDistorter.WorldCenterOfGravity = TeleportHotSpot.Position;
GravityDistorter.enabled = true;
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions XRTK.SDK/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"com.unity.textmeshpro": "2.0.0",
"com.unity.xr.legacyinputhelpers": "2.0.2",
"com.unity.xr.oculus.standalone": "1.29.1",
"com.xrtk.core": "https://github.com/XRTK/XRTK-Core.git#0.1.8",
"com.xrtk.core": "https://github.com/XRTK/XRTK-Core.git#0.1.9",
"com.xrtk.lumin": "https://github.com/XRTK/Lumin.git#0.1.1",
"com.xrtk.upm-git-extension": "https://github.com/XRTK/UpmGitExtension.git#0.9.5",
"com.xrtk.wmr": "https://github.com/XRTK/WindowsMixedReality.git#0.1.2",
Expand Down Expand Up @@ -42,8 +42,8 @@
},
"lock": {
"com.xrtk.core": {
"hash": "17e7e6673de647050f2c915d143fd042f40ad7c2",
"revision": "0.1.8"
"hash": "d4be87365d4a56d22bb908f3acc8b409cf10240c",
"revision": "0.1.9"
},
"com.xrtk.lumin": {
"hash": "45da20dee3740ee5781aa380c962f1aa361c7a7c",
Expand Down