11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
4+ using Microsoft . MixedReality . Toolkit . Core . Definitions . Utilities ;
45using UnityEngine ;
56
67namespace Microsoft . MixedReality . Toolkit . Core . Utilities . Physics
@@ -17,9 +18,20 @@ namespace Microsoft.MixedReality.Toolkit.Core.Utilities.Physics
1718 public class TwoHandMoveLogic
1819 {
1920 private static readonly Vector3 offsetPosition = new Vector3 ( 0 , - 0.2f , 0 ) ;
21+ private readonly MovementConstraintType movementConstraint ;
22+
2023 private float handRefDistance ;
2124 private float objRefDistance ;
2225
26+ /// <summary>
27+ /// Constructor.
28+ /// </summary>
29+ /// <param name="rotationConstraint"></param>
30+ public TwoHandMoveLogic ( MovementConstraintType _movementConstraint )
31+ {
32+ movementConstraint = _movementConstraint ;
33+ }
34+
2335 /// <summary>
2436 /// The initial angle between the hand and the object
2537 /// </summary>
@@ -61,11 +73,17 @@ public Vector3 Update(Vector3 centroid, Vector3 manipulationObjectPosition)
6173 var targetDirection = Vector3 . Normalize ( gazeAngularOffset * newHandDirection ) ;
6274 targetDirection = CameraCache . Main . transform . TransformDirection ( targetDirection ) ;
6375
64- // Compute how far away the object should be based on the ratio of the current to original hand distance
65- var currentHandDistance = Vector3 . Magnitude ( newHandPosition - pivotPosition ) ;
66- var distanceRatio = currentHandDistance / handRefDistance ;
67- var distanceOffset = distanceRatio > 0 ? ( distanceRatio - 1f ) * DistanceScale : 0 ;
68- var targetDistance = objRefDistance + distanceOffset ;
76+ var targetDistance = objRefDistance ;
77+
78+ if ( movementConstraint != MovementConstraintType . FixDistanceFromHead )
79+ {
80+ // Compute how far away the object should be based on the ratio of the current to original hand distance
81+ var currentHandDistance = Vector3 . Magnitude ( newHandPosition - pivotPosition ) ;
82+ var distanceRatio = currentHandDistance / handRefDistance ;
83+ var distanceOffset = distanceRatio > 0 ? ( distanceRatio - 1f ) * DistanceScale : 0 ;
84+ targetDistance += distanceOffset ;
85+ }
86+
6987 var newPosition = pivotPosition + ( targetDirection * targetDistance ) ;
7088 var newDistance = Vector3 . Distance ( newPosition , pivotPosition ) ;
7189
0 commit comments