/// <summary> /// Updates the controller state information. /// </summary> /// <param name="source">Input source to use to update the position.</param> private void UpdateControllerState(DebugInteractionSourceState source) { float time; if (manualController.UseUnscaledTime) { time = Time.unscaledTime; } else { time = Time.time; } CurrentButtonStates.SelectButtonStateChanged = (CurrentButtonStates.IsSelectButtonDown != source.SelectPressed); CurrentButtonStates.IsSelectButtonDown = source.SelectPressed; if (CurrentButtonStates.SelectButtonStateChanged && source.SelectPressed) { CurrentButtonStates.SelectDownStartTime = time; CurrentButtonStates.CumulativeDelta = Vector3.zero; } if (SupportsPosition) { Vector3 controllerPosition; if (source.SourcePose.TryGetPosition(out controllerPosition)) { CurrentButtonStates.CumulativeDelta += controllerPosition - ControllerPosition; ControllerPosition = controllerPosition; } } if (SupportsRotation) { Quaternion controllerRotation; if (source.SourcePose.TryGetRotation(out controllerRotation)) { ControllerRotation = controllerRotation; } } if (SupportsRay) { PointingRay = source.SourcePose.PointerRay; } if (SupportsMenuButton) { CurrentButtonStates.MenuButtonStateChanged = (CurrentButtonStates.IsMenuButtonDown != source.MenuPressed); CurrentButtonStates.IsMenuButtonDown = source.MenuPressed; } if (SupportsGrasp) { CurrentButtonStates.GraspStateChanged = (CurrentButtonStates.IsGrasped != source.Grasped); CurrentButtonStates.IsGrasped = source.Grasped; } SendControllerStateEvents(time); }
/// <summary> /// Updates the controller positional information. /// </summary> /// <param name="controllerSource">Controller source to use to update the position.</param> /// <param name="editorControllerData">EditorControllerData structure to update.</param> private void UpdateControllerState(DebugInteractionSourceState controllerSource, Editor3DoFData editorControllerData) { // Check for button presses if (controllerSource.IsSelectPressed != editorControllerData.IsSelectButtonDownPending) { editorControllerData.IsSelectButtonDownPending = controllerSource.IsSelectPressed; editorControllerData.SelectButtonStateUpdateTimer = ButtonPressDelay; } if (controllerSource.IsMenuPressed != editorControllerData.IsMenuButtonDownPending) { editorControllerData.IsMenuButtonDownPending = controllerSource.IsMenuPressed; editorControllerData.MenuButtonStateUpdateTimer = ButtonPressDelay; } if (controllerSource.IsGrasped != editorControllerData.IsGraspedPending) { editorControllerData.IsGraspedPending = controllerSource.IsGrasped; editorControllerData.GraspStateUpdateTimer = ButtonPressDelay; } // Not sure if we really need to do this? // Button presses are delayed to mitigate issue with hand position shifting during air tap editorControllerData.SelectButtonStateChanged = false; if (editorControllerData.SelectButtonStateUpdateTimer > 0) { editorControllerData.SelectButtonStateUpdateTimer -= Time.deltaTime; if (editorControllerData.SelectButtonStateUpdateTimer <= 0) { editorControllerData.IsSelectButtonDown = editorControllerData.IsSelectButtonDownPending; editorControllerData.SelectButtonStateChanged = true; if (editorControllerData.IsSelectButtonDown) { editorControllerData.SelectButtonDownStartTime = Time.time; } } } // TODO: update other button states (menu, grasp) SendControllerStateEvents(editorControllerData); }
/// <summary> /// Updates the hand positional information. /// </summary> /// <param name="handSource">Hand source to use to update the position.</param> /// <param name="editorHandData">EditorHandData structure to update.</param> private void UpdateHandState(DebugInteractionSourceState handSource, EditorHandData editorHandData, float deltaTime, float time) { // Update hand position Vector3 handPosition; if (handSource.Properties.Location.TryGetPosition(out handPosition)) { editorHandData.HandDelta = handPosition - editorHandData.HandPosition; editorHandData.HandPosition = handPosition; } // Check for finger presses if (handSource.Pressed != editorHandData.IsFingerDownPending) { editorHandData.IsFingerDownPending = handSource.Pressed; editorHandData.FingerStateUpdateTimer = FingerPressDelay; } // Finger presses are delayed to mitigate issue with hand position shifting during air tap editorHandData.FingerStateChanged = false; if (editorHandData.FingerStateUpdateTimer > 0) { editorHandData.FingerStateUpdateTimer -= deltaTime; if (editorHandData.FingerStateUpdateTimer <= 0) { editorHandData.IsFingerDown = editorHandData.IsFingerDownPending; editorHandData.FingerStateChanged = true; if (editorHandData.IsFingerDown) { editorHandData.FingerDownStartTime = time; } } } SendHandStateEvents(editorHandData, time); }
/// <summary> /// Updates the hand positional information. /// </summary> /// <param name="handSource">Hand source to use to update the position.</param> /// <param name="editorHandData">EditorHandData structure to update.</param> private void UpdateHandState(DebugInteractionSourceState handSource, EditorHandData editorHandData) { // Update hand position Vector3 handPosition; if (handSource.Properties.Location.TryGetPosition(out handPosition)) { editorHandData.HandDelta = handPosition - editorHandData.HandPosition; editorHandData.HandPosition = handPosition; } // Check for finger presses if (handSource.Pressed != editorHandData.IsFingerDownPending) { editorHandData.IsFingerDownPending = handSource.Pressed; editorHandData.FingerStateUpdateTimer = FingerPressDelay; } // Finger presses are delayed to mitigate issue with hand position shifting during air tap editorHandData.FingerStateChanged = false; if (editorHandData.FingerStateUpdateTimer > 0) { editorHandData.FingerStateUpdateTimer -= Time.deltaTime; if (editorHandData.FingerStateUpdateTimer <= 0) { editorHandData.IsFingerDown = editorHandData.IsFingerDownPending; editorHandData.FingerStateChanged = true; if (editorHandData.IsFingerDown) { editorHandData.FingerDownStartTime = Time.time; } } } SendHandStateEvents(editorHandData); }