diff --git a/Assets/HoloToolkit-Examples/SpatialUnderstanding/Scripts/AppState.cs b/Assets/HoloToolkit-Examples/SpatialUnderstanding/Scripts/AppState.cs index e921f50d0aa..c938bb2ebf8 100644 --- a/Assets/HoloToolkit-Examples/SpatialUnderstanding/Scripts/AppState.cs +++ b/Assets/HoloToolkit-Examples/SpatialUnderstanding/Scripts/AppState.cs @@ -275,7 +275,7 @@ private void Update() public void OnSourceDetected(SourceStateEventData eventData) { // If the source has positional info and there is currently no visible source - if (eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.Position)) + if (eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.GripPosition)) { trackedHandsCount++; } @@ -283,7 +283,7 @@ public void OnSourceDetected(SourceStateEventData eventData) public void OnSourceLost(SourceStateEventData eventData) { - if (eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.Position)) + if (eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.GripPosition)) { trackedHandsCount--; } diff --git a/Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs b/Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs index 1e0d2d468db..43b7b6fbe72 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs @@ -46,23 +46,33 @@ public ButtonStates() public bool ManipulationInProgress; public bool HoldInProgress; public Vector3 CumulativeDelta; + public Vector3 CumulativeGripDelta; } + [Tooltip("This property now represents Pointer position (contrast with Grip position)")] public bool SupportsPosition; + [Tooltip("This property now represents Pointer rotation (contrast with Grip rotation)")] public bool SupportsRotation; + public bool SupportsGripPosition; + public bool SupportsGripRotation; public bool SupportsRay; public bool SupportsMenuButton; public bool SupportsGrasp; public bool RaiseEventsBasedOnVisibility; public InteractionSourceInfo SourceKind; + [Tooltip("This property now represents controller's Pointer position (contrast with controller Grip position)")] + public Vector3 ControllerPosition; + [Tooltip("This property now represents controller's Pointer rotation (contrast with controller Grip rotation)")] + public Quaternion ControllerRotation; + //Navigation Gesture Emulation vars Vector3 NavigatorValues = Vector3.zero; //holds the navigation gesture values [-1,1] Vector2 railUsedCurrently = Vector2.one; bool isNavigatorUsingRails = false; - public Vector3 ControllerPosition; - public Quaternion ControllerRotation; + public Vector3 ControllerGripPosition; + public Quaternion ControllerGripRotation; public Ray? PointingRay; @@ -106,6 +116,16 @@ public override SupportedInputInfo GetSupportedInputInfo(uint sourceId) supportedInputInfo |= SupportedInputInfo.Pointing; } + if (SupportsGripPosition) + { + supportedInputInfo |= SupportedInputInfo.GripPosition; + } + + if (SupportsGripRotation) + { + supportedInputInfo |= SupportedInputInfo.GripRotation; + } + if (SupportsMenuButton) { supportedInputInfo |= SupportedInputInfo.Menu; @@ -173,9 +193,9 @@ public override bool TryGetGripPosition(uint sourceId, out Vector3 position) { Debug.Assert(sourceId == controllerId, "Controller data requested for a mismatched source ID."); - if (SupportsPosition) + if (SupportsGripPosition) { - position = ControllerPosition; + position = ControllerGripPosition; return true; } @@ -187,9 +207,9 @@ public override bool TryGetGripRotation(uint sourceId, out Quaternion rotation) { Debug.Assert(sourceId == controllerId, "Controller data requested for a mismatched source ID."); - if (SupportsRotation) + if (SupportsGripRotation) { - rotation = ControllerRotation; + rotation = ControllerGripRotation; return true; } @@ -387,6 +407,25 @@ private void UpdateControllerState(DebugInteractionSourceState source) PointingRay = source.SourcePose.PointerRay; } + if (SupportsGripPosition) + { + Vector3 controllerGripPosition; + if (source.SourcePose.TryGetGripPosition(out controllerGripPosition)) + { + currentButtonStates.CumulativeGripDelta += controllerGripPosition - ControllerGripPosition; + ControllerGripPosition = controllerGripPosition; + } + } + + if (SupportsGripRotation) + { + Quaternion controllerGripRotation; + if (source.SourcePose.TryGetGripRotation(out controllerGripRotation)) + { + ControllerGripRotation = controllerGripRotation; + } + } + if (SupportsMenuButton) { currentButtonStates.MenuButtonStateChanged = (currentButtonStates.IsMenuButtonDown != source.MenuPressed); diff --git a/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionInputSource.cs b/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionInputSource.cs index 1a9d2a8d400..26b25b94f97 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionInputSource.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionInputSource.cs @@ -460,8 +460,10 @@ public override SupportedInputInfo GetSupportedInputInfo(uint sourceId) SourceData sourceData; if (sourceIdToData.TryGetValue(sourceId, out sourceData)) { - retVal |= GetSupportFlag(sourceData.PointerPosition, SupportedInputInfo.Position); - retVal |= GetSupportFlag(sourceData.PointerRotation, SupportedInputInfo.Rotation); + retVal |= GetSupportFlag(sourceData.PointerPosition, SupportedInputInfo.PointerPosition); + retVal |= GetSupportFlag(sourceData.PointerRotation, SupportedInputInfo.PointerRotation); + retVal |= GetSupportFlag(sourceData.GripPosition, SupportedInputInfo.GripPosition); + retVal |= GetSupportFlag(sourceData.GripRotation, SupportedInputInfo.GripRotation); retVal |= GetSupportFlag(sourceData.PointingRay, SupportedInputInfo.Pointing); retVal |= GetSupportFlag(sourceData.Thumbstick, SupportedInputInfo.Thumbstick); retVal |= GetSupportFlag(sourceData.Touchpad, SupportedInputInfo.Touchpad); diff --git a/Assets/HoloToolkit/Input/Scripts/InputSources/SupportedInputInfo.cs b/Assets/HoloToolkit/Input/Scripts/InputSources/SupportedInputInfo.cs index 33c795fdd04..e58fa9142bf 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputSources/SupportedInputInfo.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputSources/SupportedInputInfo.cs @@ -12,13 +12,19 @@ namespace HoloToolkit.Unity.InputModule public enum SupportedInputInfo { None = 0, + [Obsolete("use PointerPosition")] Position = (1 << 0), + PointerPosition = (1 << 0), + [Obsolete("use PointerRotation")] Rotation = (1 << 1), + PointerRotation = (1 << 1), Pointing = (1 << 2), Thumbstick = (1 << 3), Touchpad = (1 << 4), Select = (1 << 5), Menu = (1 << 6), Grasp = (1 << 7), + GripPosition = (1 << 8), + GripRotation = (1 << 9) } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Input/Scripts/InputSources/TouchscreenInputSource.cs b/Assets/HoloToolkit/Input/Scripts/InputSources/TouchscreenInputSource.cs index 6c91bf7fd5e..695d31f654d 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputSources/TouchscreenInputSource.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputSources/TouchscreenInputSource.cs @@ -215,7 +215,7 @@ public override bool TryGetGripRotation(uint sourceId, out Quaternion rotation) public override SupportedInputInfo GetSupportedInputInfo(uint sourceId) { - return SupportedInputInfo.Position | SupportedInputInfo.Pointing; + return SupportedInputInfo.PointerPosition | SupportedInputInfo.Pointing; } public override bool TryGetThumbstick(uint sourceId, out bool isPressed, out Vector2 position) diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/Interactions/DebugInteractionSourcePose.cs b/Assets/HoloToolkit/Input/Scripts/Utilities/Interactions/DebugInteractionSourcePose.cs index e370c788fab..8f1086061db 100644 --- a/Assets/HoloToolkit/Input/Scripts/Utilities/Interactions/DebugInteractionSourcePose.cs +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/Interactions/DebugInteractionSourcePose.cs @@ -19,17 +19,23 @@ public class DebugInteractionSourcePose public bool TryGetFunctionsReturnTrue; public bool IsPositionAvailable; public bool IsRotationAvailable; + public bool IsGripPositionAvailable; + public bool IsGripRotationAvailable; public Vector3 Position; public Vector3 Velocity; public Quaternion Rotation; public Ray? PointerRay; + public Vector3 GripPosition; + public Quaternion GripRotation; public DebugInteractionSourcePose() { TryGetFunctionsReturnTrue = false; IsPositionAvailable = false; IsRotationAvailable = false; + IsGripPositionAvailable = false; + IsGripRotationAvailable = false; Position = new Vector3(0, 0, 0); Velocity = new Vector3(0, 0, 0); Rotation = Quaternion.identity; @@ -38,7 +44,7 @@ public DebugInteractionSourcePose() public bool TryGetPosition(out Vector3 position) { position = Position; - if (!TryGetFunctionsReturnTrue) + if (!TryGetFunctionsReturnTrue) // TODO: bug? does not test IsPositionAvailable (see TryGetRotation) { return false; } @@ -74,5 +80,25 @@ public bool TryGetPointerRay(out Ray pointerRay) } return true; } + + public bool TryGetGripPosition(out Vector3 position) + { + position = GripPosition; + if (!TryGetFunctionsReturnTrue) // TODO: should test IsGripPositionAvailable? (see TryGetPosition) + { + return false; + } + return true; + } + + public bool TryGetGripRotation(out Quaternion rotation) + { + rotation = GripRotation; + if (!TryGetFunctionsReturnTrue || !IsGripRotationAvailable) + { + return false; + } + return true; + } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/Interactions/HandDraggable.cs b/Assets/HoloToolkit/Input/Scripts/Utilities/Interactions/HandDraggable.cs index 1a6bfb3a064..a5bc244c507 100644 --- a/Assets/HoloToolkit/Input/Scripts/Utilities/Interactions/HandDraggable.cs +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/Interactions/HandDraggable.cs @@ -360,9 +360,9 @@ public void OnInputDown(InputEventData eventData) eventData.InputSource.TryGetSourceKind(eventData.SourceId, out sourceKind); if (sourceKind != InteractionSourceInfo.Hand) { - if (!eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.Position)) + if (!eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.GripPosition)) { - // The input source must provide positional data for this script to be usable + // The input source must provide grip positional data for this script to be usable return; } }