2
2
// Licensed under the MIT License.
3
3
4
4
using Microsoft . MixedReality . Toolkit . Utilities ;
5
+ using System ;
5
6
using UnityEngine ;
6
7
7
8
namespace Microsoft . MixedReality . Toolkit . Physics
@@ -25,6 +26,9 @@ internal class ManipulationMoveLogic
25
26
private Vector3 objectLocalGrabPoint ;
26
27
private Vector3 grabToObject ;
27
28
29
+ private Vector3 objectLocalAttachPoint ;
30
+ private Vector3 attachToObject ;
31
+
28
32
/// <summary>
29
33
/// Setup function
30
34
/// </summary>
@@ -37,17 +41,57 @@ public void Setup(MixedRealityPose pointerCentroidPose, Vector3 grabCentroid, Mi
37
41
Quaternion worldToPointerRotation = Quaternion . Inverse ( pointerCentroidPose . Rotation ) ;
38
42
pointerLocalGrabPoint = worldToPointerRotation * ( grabCentroid - pointerCentroidPose . Position ) ;
39
43
40
- objectLocalGrabPoint = Quaternion . Inverse ( objectPose . Rotation ) * ( grabCentroid - objectPose . Position ) ;
41
- objectLocalGrabPoint = objectLocalGrabPoint . Div ( objectScale ) ;
44
+ attachToObject = objectPose . Position - pointerCentroidPose . Position ;
45
+ objectLocalAttachPoint = Quaternion . Inverse ( objectPose . Rotation ) * ( pointerCentroidPose . Position - objectPose . Position ) ;
46
+ objectLocalAttachPoint = objectLocalAttachPoint . Div ( objectScale ) ;
42
47
43
48
grabToObject = objectPose . Position - grabCentroid ;
49
+ objectLocalGrabPoint = Quaternion . Inverse ( objectPose . Rotation ) * ( grabCentroid - objectPose . Position ) ;
50
+ objectLocalGrabPoint = objectLocalGrabPoint . Div ( objectScale ) ;
44
51
}
45
52
46
53
/// <summary>
47
54
/// Update the position based on input.
48
55
/// </summary>
49
56
/// <returns>A Vector3 describing the desired position</returns>
57
+ [ Obsolete ( "This update function is out of date and does not properly support Near Manipulation. Use UpdateTransform instead" ) ]
50
58
public Vector3 Update ( MixedRealityPose pointerCentroidPose , Quaternion objectRotation , Vector3 objectScale , bool usePointerRotation )
59
+ {
60
+ return FarManipulationUpdate ( pointerCentroidPose , objectRotation , objectScale , usePointerRotation ) ;
61
+ }
62
+
63
+ /// <summary>
64
+ /// Update the position based on input.
65
+ /// </summary>
66
+ /// <returns>A Vector3 describing the desired position</returns>
67
+ public Vector3 UpdateTransform ( MixedRealityPose pointerCentroidPose , MixedRealityTransform currentTarget , bool isPointerAnchor , bool isNearManipulation )
68
+ {
69
+ if ( isNearManipulation )
70
+ {
71
+ return NearManipulationUpdate ( pointerCentroidPose , currentTarget ) ;
72
+ }
73
+ else
74
+ {
75
+ return FarManipulationUpdate ( pointerCentroidPose , currentTarget . Rotation , currentTarget . Scale , isPointerAnchor ) ;
76
+ }
77
+ }
78
+
79
+ /// <summary>
80
+ /// Updates the position during near manipulation
81
+ /// </summary>
82
+ /// <returns>A Vector3 describing the desired position during near manipulation</returns>
83
+ private Vector3 NearManipulationUpdate ( MixedRealityPose pointerCentroidPose , MixedRealityTransform currentTarget )
84
+ {
85
+ Vector3 scaledLocalAttach = Vector3 . Scale ( objectLocalAttachPoint , currentTarget . Scale ) ;
86
+ Vector3 worldAttachPoint = currentTarget . Rotation * scaledLocalAttach + currentTarget . Position ;
87
+ return currentTarget . Position + ( pointerCentroidPose . Position - worldAttachPoint ) ;
88
+ }
89
+
90
+ /// <summary>
91
+ /// Updates the position during far manipulation
92
+ /// </summary>
93
+ /// <returns>A Vector3 describing the desired position during far manipulation</returns>
94
+ private Vector3 FarManipulationUpdate ( MixedRealityPose pointerCentroidPose , Quaternion objectRotation , Vector3 objectScale , bool isPointerAnchor )
51
95
{
52
96
float distanceRatio = 1.0f ;
53
97
@@ -58,7 +102,7 @@ public Vector3 Update(MixedRealityPose pointerCentroidPose, Quaternion objectRot
58
102
distanceRatio = currentHandDistance / pointerRefDistance ;
59
103
}
60
104
61
- if ( usePointerRotation )
105
+ if ( isPointerAnchor )
62
106
{
63
107
Vector3 scaledGrabToObject = Vector3 . Scale ( objectLocalGrabPoint , objectScale ) ;
64
108
Vector3 adjustedPointerToGrab = ( pointerLocalGrabPoint * distanceRatio ) ;
0 commit comments