Skip to content

Commit 5ed9e04

Browse files
committed
changes for PR as well as removal of unused functions
1 parent 0e26858 commit 5ed9e04

File tree

1 file changed

+10
-96
lines changed

1 file changed

+10
-96
lines changed

Assets/MixedRealityToolkit.Examples/Demos/HandTracking/Script/HandInteractionPan.cs

Lines changed: 10 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ private enum TouchType
4444
#endregion Serialized Fields
4545

4646
#region Private Properties
47-
4847
private List<Vector2> uvs = new List<Vector2>();
4948
private List<Vector2> uvsTouchStart = new List<Vector2>();
5049
private MeshFilter meshFilter;
@@ -60,40 +59,32 @@ private enum TouchType
6059
private Vector2 touchingUVTotalOffset;
6160
private List<IMixedRealityHandPanHandler> handlerInterfaces = new List<IMixedRealityHandPanHandler>();
6261
private IMixedRealityController currentController = null;
63-
private IMixedRealityPointer currentPointer = null;
64-
6562
private bool TouchActive
6663
{
6764
get
6865
{
6966
return touchingPoint != Vector3.zero;
7067
}
7168
}
72-
7369
#endregion Private Properties
7470

7571
#region MonoBehaviour Handlers
76-
7772
private void Awake()
7873
{
7974
ValidityCheck();
8075
}
81-
8276
private void Update()
8377
{
8478
if (isEnabled == false)
8579
{
8680
return;
8781
}
8882

89-
Vector3 tryHandPoint = Vector3.zero;
90-
Vector3 tryRayTouchPoint = Vector3.zero;
91-
9283
if (currentController != null)
9384
{
9485
if (touchType == TouchType.IndexFinger)
9586
{
96-
if (true == TryGetHandPoint(currentController, out tryHandPoint))
87+
if (true == TryGetHandPoint(currentController, TrackedHandJoint.IndexTip, out Vector3 tryHandPoint))
9788
{
9889
touchingPoint = SnapFingerToQuad(tryHandPoint);
9990
}
@@ -104,10 +95,9 @@ private void Update()
10495
}
10596
else if (touchType == TouchType.HandRay)
10697
{
107-
if (true == TryGetHandRayPoint(currentController, out tryRayTouchPoint))
98+
if (true == TryGetHandPoint(currentController, TrackedHandJoint.Palm, out Vector3 tryHandPoint))
10899
{
109-
110-
touchingPoint = SnapFingerToQuad(tryRayTouchPoint);
100+
touchingPoint = SnapFingerToQuad(tryHandPoint);
111101
}
112102
else
113103
{
@@ -133,15 +123,14 @@ private void Update()
133123
UpdateIdle();
134124
UpdateUVMapping();
135125
}
136-
137126
#endregion MonoBehaviour Handlers
138127

139128

140129
#region Private Methods
141-
private bool TryGetHandPoint(IMixedRealityController controller, out Vector3 handPoint)
130+
private bool TryGetHandPoint(IMixedRealityController controller, TrackedHandJoint joint, out Vector3 handPoint)
142131
{
143132
Vector3 point = Vector3.zero;
144-
if (true == HandJointUtils.TryGetJointPose(TrackedHandJoint.IndexTip, controller.ControllerHandedness, out MixedRealityPose pose))
133+
if (true == HandJointUtils.TryGetJointPose(joint, controller.ControllerHandedness, out MixedRealityPose pose))
145134
{
146135
handPoint = pose.Position;
147136
return true;
@@ -150,35 +139,6 @@ private bool TryGetHandPoint(IMixedRealityController controller, out Vector3 han
150139
handPoint = point;
151140
return false;
152141
}
153-
private bool TryGetHandRayPoint(IMixedRealityController controller, out Vector3 handRayPoint)
154-
{
155-
if (controller != null &&
156-
controller.InputSource != null &&
157-
controller.InputSource.Pointers != null &&
158-
controller.InputSource.Pointers.Length > 0 &&
159-
controller.InputSource.Pointers[0].Result != null )
160-
{
161-
handRayPoint = controller.InputSource.Pointers[0].Position;
162-
return true;
163-
}
164-
165-
handRayPoint = Vector3.zero;
166-
return false;
167-
}
168-
private bool IsControllerInNearMode(IMixedRealityController controller)
169-
{
170-
if (controller != null &&
171-
controller.InputSource != null &&
172-
controller.InputSource.Pointers != null &&
173-
controller.InputSource.Pointers.Length > 0)
174-
{
175-
if (controller.InputSource.Pointers[0].Result.RayStepIndex < 3 || touchType == TouchType.IndexFinger)
176-
{
177-
return true;
178-
}
179-
}
180-
return false;
181-
}
182142
private void ValidityCheck()
183143
{
184144
//check for box collider
@@ -340,51 +300,8 @@ private Vector3 SnapFingerToQuad(Vector3 pointToSnap)
340300

341301
return Vector3.ProjectOnPlane(pointToSnap - planePoint, planeNormal) + planePoint;
342302
}
343-
private bool FindRayCollision(Ray ray, out Vector3 collisionPt)
344-
{
345-
Vector3 point = mesh.vertices[0];
346-
point = this.transform.TransformPoint(point);
347-
Plane plane = new Plane(gameObject.transform.forward, point);
348-
float enter = 0.0f;
349-
if (true == plane.Raycast(ray, out enter))
350-
{
351-
collisionPt = ray.GetPoint(enter);
352-
return true;
353-
}
354-
collisionPt = Vector3.zero;
355-
return false;
356-
}
357-
private bool HasHandRayLeftObject()
358-
{
359-
if (currentController != null && currentController.InputSource != null &&
360-
currentController.InputSource.Pointers != null &&
361-
currentController.InputSource.Pointers.Length > 0 &&
362-
currentController.InputSource.Pointers[0].Result != null &&
363-
currentController.InputSource.Pointers[0].Result.RayStepIndex == 0)
364-
{
365-
//Hand Ray on No Object;
366-
return true;
367-
}
368-
if (currentController != null && currentController.InputSource.Pointers[0].Result.CurrentPointerTarget != null)
369-
{
370-
if (currentController.InputSource.Pointers[0].Result.CurrentPointerTarget != this.gameObject)
371-
{
372-
//Hand Ray on a different object.;
373-
return true;
374-
}
375-
else
376-
{
377-
//Hand Ray on this object.;
378-
return false;
379-
}
380-
}
381-
382-
//Hand Ray invalid;
383-
return false;
384-
}
385303
private void DisconnectTouch()
386304
{
387-
currentPointer = null;
388305
currentController = null;
389306
touchingSource = null;
390307
touchingPoint = Vector3.zero;
@@ -467,11 +384,10 @@ public void OnTouchStarted(HandTrackingInputEventData eventData)
467384
{
468385
if (touchingSource == null)
469386
{
470-
currentPointer = eventData.InputSource.Pointers[0];
471-
currentController = currentPointer.Controller;
472387
touchingSource = eventData.InputSource;
388+
currentController = touchingSource.Pointers[0].Controller;
473389

474-
TryGetHandPoint(eventData.Controller, out Vector3 handPt);
390+
TryGetHandPoint(eventData.Controller, TrackedHandJoint.IndexTip, out Vector3 handPt);
475391

476392
touchingPoint = SnapFingerToQuad(handPt);
477393
touchingInitialPt = touchingPoint;
@@ -516,12 +432,10 @@ public void OnInputDown(InputEventData eventData)
516432
{
517433
if (touchingSource == null)
518434
{
519-
currentPointer = eventData.InputSource.Pointers[0];
520-
currentController = currentPointer.Controller;
521435
touchingSource = eventData.InputSource;
522-
523-
TryGetHandRayPoint(currentController, out touchingPoint);
524-
436+
currentController = touchingSource.Pointers[0].Controller;
437+
TryGetHandPoint(currentController, TrackedHandJoint.Palm, out touchingPoint);
438+
// touchingPoint = currentController.InputSource.Pointers[0].Position;
525439
touchingPoint = SnapFingerToQuad(touchingPoint);
526440
touchingInitialPt = touchingPoint;
527441
touchingUV = GetUVFromPoint(touchingPoint);

0 commit comments

Comments
 (0)