Skip to content

Commit aa1a9df

Browse files
author
David Kline
authored
Merge pull request #3443 from NorbertNemec/feature/MovementConstraintType-FixDistanceFromHead
Introduce MovementConstraintType.FixDistanceFromHead in ManipulationHandler
2 parents edf19fe + 130f96e commit aa1a9df

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

Assets/MixedRealityToolkit.SDK/Features/Input/Handlers/ManipulationHandler.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ private enum TwoHandedManipulation
5757
[Tooltip("Constrain rotation along an axis")]
5858
private RotationConstraintType constraintOnRotation = RotationConstraintType.None;
5959

60+
[SerializeField]
61+
[Tooltip("Constrain movement")]
62+
private MovementConstraintType constraintOnMovement = MovementConstraintType.None;
63+
6064
[SerializeField]
6165
private HandMovementType handMoveType = HandMovementType.OneAndTwoHanded;
6266

@@ -88,7 +92,7 @@ private enum State
8892
private void Awake()
8993
{
9094
gazeHandHelper = new GazeHandHelper();
91-
m_moveLogic = new TwoHandMoveLogic();
95+
m_moveLogic = new TwoHandMoveLogic(constraintOnMovement);
9296
m_rotateLogic = new TwoHandRotateLogic(constraintOnRotation);
9397
m_scaleLogic = new TwoHandScaleLogic();
9498
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
namespace Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities
5+
{
6+
public enum MovementConstraintType
7+
{
8+
None,
9+
FixDistanceFromHead
10+
}
11+
}

Assets/MixedRealityToolkit/Definitions/Utilities/MovementConstraintType.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/MixedRealityToolkit/Utilities/Physics/TwoHandMoveLogic.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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;
45
using UnityEngine;
56

67
namespace 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

Comments
 (0)