Skip to content

Commit e15ddef

Browse files
committed
code changes requested in PR
1 parent 5321733 commit e15ddef

File tree

1 file changed

+36
-71
lines changed

1 file changed

+36
-71
lines changed

Assets/MixedRealityToolkit.SDK/Features/UX/Scripts/Slate/HandInteractionPanZoom.cs

Lines changed: 36 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Microsoft.MixedReality.Toolkit.Input
1414
{
15-
public class HandInteractionPanZoom : BaseFocusHandler, IMixedRealityTouchHandler, IMixedRealityInputHandler, IMixedRealitySourceStateHandler
15+
public class HandInteractionPanZoom : BaseFocusHandler, IMixedRealityTouchHandler, IMixedRealityPointerHandler, IMixedRealitySourceStateHandler
1616
{
1717
/// <summary>
1818
/// Internal data stored for each hand or pointer.
@@ -34,6 +34,7 @@ protected class HandPanData
3434
public Vector3 initialProjectedOffset = Vector3.zero;
3535
public IMixedRealityInputSource touchingSource = null;
3636
public IMixedRealityController currentController = null;
37+
public IMixedRealityPointer currentPointer = null;
3738
}
3839

3940
#region Serialized Fields
@@ -138,21 +139,6 @@ private bool scaleActive
138139
private List<Vector2> unTransformedUVs = new List<Vector2>();
139140
private Dictionary<uint, HandPanData> handDataMap = new Dictionary<uint, HandPanData>();
140141
private List<IMixedRealityHandPanHandler> handlerInterfaces = new List<IMixedRealityHandPanHandler>();
141-
private IMixedRealityInputSystem inputSystem = null;
142-
private IMixedRealityInputSystem InputSystem
143-
{
144-
get
145-
{
146-
if (inputSystem == null)
147-
{
148-
MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);
149-
}
150-
return inputSystem;
151-
}
152-
}
153-
154-
private IMixedRealityEyeGazeProvider EyeTrackingProvider => eyeTrackingProvider ?? (eyeTrackingProvider = InputSystem?.EyeGazeProvider);
155-
private IMixedRealityEyeGazeProvider eyeTrackingProvider = null;
156142
#endregion Private Properties
157143

158144
/// <summary>
@@ -211,8 +197,6 @@ private void Update()
211197
{
212198
rightPoint.transform.position = GetContactForHand(Handedness.Right);
213199
}
214-
215-
216200
}
217201
}
218202
}
@@ -222,20 +206,10 @@ private void Update()
222206
#region Private Methods
223207
private bool TryGetMRControllerRayPoint(HandPanData data, out Vector3 rayPoint)
224208
{
225-
if (data.currentController.InputSource.SourceName.Contains("Mixed Reality Controller"))
209+
if (data.currentPointer != null && data.currentController != null && data.currentController.IsPositionAvailable)
226210
{
227-
if (!(data.currentController.InputSource.Pointers[0] is GGVPointer))
228-
{
229-
Vector3 pos = data.currentController.InputSource.Pointers[0].Position;
230-
Vector3 dir = data.currentController.InputSource.Pointers[0].Rays[0].Direction * (data.currentController.InputSource.Pointers[0].SphereCastRadius);
231-
rayPoint = data.touchingInitialPt + (SnapFingerToQuad(pos + dir) - data.initialProjectedOffset);
232-
return true;
233-
}
234-
else//then it IS a GGVPointer
235-
{
236-
rayPoint = data.touchingInitialPt + (SnapFingerToQuad(data.currentController.InputSource.Pointers[0].Position) - data.initialProjectedOffset);
237-
return true;
238-
}
211+
rayPoint = data.touchingInitialPt + (SnapFingerToQuad(data.currentPointer.Position) - data.initialProjectedOffset);
212+
return true;
239213
}
240214

241215
rayPoint = Vector3.zero;
@@ -274,8 +248,6 @@ private bool UpdateHandTouchingPoint(uint sourceId)
274248
data.touchingPointSmoothed = (data.touchingPointSmoothed * runningAverageSmoothing) + unfilteredTouchPt;
275249
data.touchingPoint = data.touchingPointSmoothed;
276250
}
277-
278-
279251
}
280252
}
281253

@@ -637,13 +609,15 @@ private Vector3 SnapFingerToQuad(Vector3 pointToSnap)
637609
}
638610

639611

640-
private void SetHandDataFromController(IMixedRealityController controller, bool isNear)
612+
private void SetHandDataFromController(IMixedRealityController controller, IMixedRealityPointer pointer, bool isNear)
641613
{
642614
HandPanData data = new HandPanData();
643615
data.IsSourceNear = isNear;
644616
data.IsActive = true;
645617
data.touchingSource = controller.InputSource;
646618
data.currentController = controller;
619+
data.currentPointer = pointer;
620+
647621
if (isNear == true)
648622
{
649623
if (TryGetHandPositionFromController(data.currentController, TrackedHandJoint.IndexTip, out Vector3 touchPosition) == true)
@@ -653,7 +627,7 @@ private void SetHandDataFromController(IMixedRealityController controller, bool
653627
data.touchingPoint = data.touchingInitialPt;
654628
}
655629
}
656-
else
630+
else//is far
657631
{
658632
if (TryGetHandRayPoint(controller, out Vector3 handRayPt) == true)
659633
{
@@ -668,18 +642,18 @@ private void SetHandDataFromController(IMixedRealityController controller, bool
668642
}
669643

670644
//store value in case of MRController
671-
if (controller.InputSource.Pointers.Length > 0 )
672-
{
673-
Vector3 pt = controller.InputSource.Pointers[0].Position;
674-
if (!(controller.InputSource.Pointers[0] is GGVPointer))
675-
{
676-
Vector3 dir = controller.InputSource.Pointers[0].Rays[0].Direction * (controller.InputSource.Pointers[0].SphereCastRadius);
677-
data.initialProjectedOffset = SnapFingerToQuad(pt + dir);
678-
}
679-
else//pointer is GGVPOinter and has no SphereCastRadius
680-
{
645+
if (data.currentPointer != null)
646+
{
647+
Vector3 pt = data.currentPointer.Position;
648+
//if (data.currentController.IsRotationAvailable)
649+
//{
650+
// // Vector3 dir = controller.InputSource.Pointers[0].Rays[0].Direction * (controller.InputSource.Pointers[0].SphereCastRadius);
651+
// data.initialProjectedOffset = SnapFingerToQuad(pt);
652+
//}
653+
//else//pointer is GGVPOinter and has no SphereCastRadius
654+
//{
681655
data.initialProjectedOffset = SnapFingerToQuad(pt);
682-
}
656+
//}
683657
}
684658

685659
data.touchingQuadCoord = GetUVFromPoint(data.touchingPoint);
@@ -721,16 +695,6 @@ private bool TryGetHandPositionFromController(IMixedRealityController controller
721695
position = Vector3.zero;
722696
return false;
723697
}
724-
private void GetControllerPoints(List<Vector3> points)
725-
{
726-
foreach (IMixedRealityInputSource source in inputSystem.DetectedInputSources)
727-
{
728-
if (source.SourceType == InputSourceType.Controller && source.Pointers[0].Result != null)
729-
{
730-
points.Add(source.Pointers[0].Result.Details.Point);
731-
}
732-
}
733-
}
734698
private IMixedRealityHandPanHandler[] GetInterfaces()
735699
{
736700
List<IMixedRealityHandPanHandler> interfaces = new List<IMixedRealityHandPanHandler>();
@@ -843,7 +807,7 @@ public override void OnFocusExit(FocusEventData eventData)
843807
public void OnTouchStarted(HandTrackingInputEventData eventData)
844808
{
845809
EndTouch(eventData.SourceId);
846-
SetHandDataFromController(eventData.Controller, true);
810+
SetHandDataFromController(eventData.Controller, null, true);
847811
eventData.Use();
848812
}
849813
public void OnTouchCompleted(HandTrackingInputEventData eventData)
@@ -859,33 +823,34 @@ public void OnTouchUpdated(HandTrackingInputEventData eventData) { }
859823
/// <summary>
860824
/// The Input Event handlers receive Hand Ray events.
861825
/// </summary>
862-
public void OnInputDown(InputEventData eventData)
826+
public void OnPointerDown(MixedRealityPointerEventData eventData)
863827
{
864-
if (eventData.MixedRealityInputAction.Description != "None")
865-
{
866-
SetAffordancesActive(false);
867-
EndTouch(eventData.SourceId);
868-
SetHandDataFromController(eventData.InputSource.Pointers[0].Controller, false);
869-
eventData.Use();
870-
}
828+
SetAffordancesActive(false);
829+
EndTouch(eventData.SourceId);
830+
SetHandDataFromController(eventData.Pointer.Controller, eventData.Pointer, false);
831+
eventData.Use();
871832
}
872-
public void OnInputUp(InputEventData eventData)
833+
public void OnPointerUp(MixedRealityPointerEventData eventData)
873834
{
874835
EndTouch(eventData.SourceId);
875836
eventData.Use();
876-
}
877-
public void OnPositionInputChanged(InputEventData<Vector2> eventData) { }
878-
public void OnInputPressed(InputEventData<float> eventData) { }
837+
}
879838
#endregion IMixedRealityInputHandler Methods
880839

881-
882840
#region IMixedRealitySourceStateHandler Methods
883-
public void OnSourceDetected(SourceStateEventData eventData) { }
884841
public void OnSourceLost(SourceStateEventData eventData)
885842
{
886843
EndTouch(eventData.SourceId);
887844
eventData.Use();
888845
}
889846
#endregion IMixedRealitySourceStateHandler Methods
847+
848+
#region Unused Methods
849+
public void OnPositionInputChanged(InputEventData<Vector2> eventData) { }
850+
public void OnInputPressed(InputEventData<float> eventData) { }
851+
public void OnSourceDetected(SourceStateEventData eventData) { }
852+
public void OnPointerDragged(MixedRealityPointerEventData eventData) { }
853+
public void OnPointerClicked(MixedRealityPointerEventData eventData) { }
854+
#endregion Unused Methods
890855
}
891856
}

0 commit comments

Comments
 (0)