4 using System.Collections.Generic;
8 namespace HoloToolkit.Unity.InputModule.Utilities.Interactions
24 private const float MinHandDistanceForPitchM = 0.1f;
29 private const float RotationMultiplier = 2f;
41 private Vector3 previousHandlebarRotation;
57 private Vector3 ProjectHandlebarGivenConstraint(
AxisConstraint constraint, Vector3 handlebarRotation, Transform manipulationRoot)
59 Vector3 result = handlebarRotation;
81 private Vector3 GetHandlebarDirection(Dictionary<uint, Vector3> handsPressedMap, Transform manipulationRoot)
83 var handsEnumerator = handsPressedMap.Values.GetEnumerator();
84 handsEnumerator.MoveNext();
85 var hand1 = handsEnumerator.Current;
86 handsEnumerator.MoveNext();
87 var hand2 = handsEnumerator.Current;
103 rotationConstraint = constrainRotation;
113 public void Setup(Dictionary<uint, Vector3> handsPressedMap, Transform manipulationRoot)
115 currentRotationConstraint = rotationConstraint;
116 previousHandlebarRotation = GetHandlebarDirection(handsPressedMap, manipulationRoot);
126 public Quaternion
Update(Dictionary<uint, Vector3> handsPressedMap, Transform manipulationRoot, Quaternion currentRotation)
128 var handlebarDirection = GetHandlebarDirection(handsPressedMap, manipulationRoot);
129 var handlebarDirectionProjected = ProjectHandlebarGivenConstraint(currentRotationConstraint, handlebarDirection, manipulationRoot);
130 var prevHandlebarDirectionProjected = ProjectHandlebarGivenConstraint(currentRotationConstraint, previousHandlebarRotation, manipulationRoot);
131 previousHandlebarRotation = handlebarDirection;
133 var rotationDelta = Quaternion.FromToRotation(prevHandlebarDirectionProjected, handlebarDirectionProjected);
136 var axis = Vector3.zero;
137 rotationDelta.ToAngleAxis(out angle, out axis);
138 angle *= RotationMultiplier;
145 axis = Vector3.up * Vector3.Dot(axis, Vector3.up);
147 return Quaternion.AngleAxis(angle, axis) * currentRotation;