Example #1
0
 private void ToggleTool(HandGestureState currentState, HandGestureState previousState, bool right)
 {
     if (currentState == HandGestureState.DragSelection)
     {
         if (right)
         {
             DragToggleHelper(true, ref rightCurrentPositionMarker, ref rightStartingPoint, _rightHandSkeleton, ref rightStickActive);
             //rightCurrentPositionMarker.position = rightStartingPoint.position = _rightHandSkeleton.Bones[(int)BoneId.Hand_ThumbTip].Transform.position;
             //rightCurrentPositionMarker.rotation = rightStartingPoint.rotation = _rightControllerMarker.transform.rotation;
             //rightStickActive = true;
             //AtomicSelection.Instance.BeginTransformation(true);
         }
         else
         {
             DragToggleHelper(true, ref leftCurrentPositionMarker, ref leftStartingPoint, _leftHandSkeleton, ref leftStickActive);
             //leftCurrentPositionMarker.position = leftStartingPoint.position = _leftHandSkeleton.Bones[(int)BoneId.Hand_ThumbTip].Transform.position;
             //leftCurrentPositionMarker.rotation = leftStartingPoint.rotation = _leftControllerMarker.transform.rotation;
             //leftStickActive = true;
             //AtomicSelection.Instance.BeginTransformation(false);
         }
         ToggleTranslateToolVisibility(true, right);
         ToggleTranslateToolColliders(true, right);
         BeginTranslationDrag?.Invoke((right) ? Hand.Right : Hand.Left);
         ADM.QLog("begin drag");
     }
     else if (previousState == HandGestureState.DragSelection && currentState != HandGestureState.DragSelection)
     {
         DisengageTranslationTool(right);
     }
 }
        private void ToggleTool(HandGestureState currentState, HandGestureState previousState, bool right)
        {
            if (currentState == HandGestureState.DragSelection &&
                (previousState == HandGestureState.Selection || previousState == HandGestureState.Neutral))
            {
                if (right && !rightStickActive)
                {
                    rightCurrentPositionMarker.position = rightStartingPoint.position = rightStartingPoint.position = _rightHandSkeleton.Bones[(int)BoneId.Hand_ThumbTip].Transform.position;
                    rightStartingPoint.rotation         = _rightControllerMarker.transform.rotation;
                    currentRightUpAxis = rightStartingPoint.up;
                    rightCurrentPositionMarker.rotation = currentPivot.rotation;
                    rightStickActive = true;
                    AtomicSelection.Instance.BeginTransformation(true);
                    BeginRotationGearToggler(true);
                    ToggleVisibility(true, true);
                    ToggleColliders(true, true);
                    BeginRotationDrag?.Invoke(Hand.Right);
                    //ADM.QLog("begin drag");
                }
                else if (!right && !leftStickActive)
                {
                    leftCurrentPositionMarker.position = leftStartingPoint.position = _leftHandSkeleton.Bones[(int)BoneId.Hand_ThumbTip].Transform.position;
                    leftStartingPoint.rotation         = _leftControllerMarker.transform.rotation;
                    currentLeftUpAxis = leftStartingPoint.up;
                    leftCurrentPositionMarker.rotation = currentPivot.rotation;
                    leftStickActive = true;
                    AtomicSelection.Instance.BeginTransformation(false);
                    BeginRotationGearToggler(false);
                    ToggleVisibility(true, false);
                    ToggleColliders(true, false);
                    BeginRotationDrag?.Invoke(Hand.Left);
                    //ADM.QLog("begin drag");
                }
            }
            else if (currentState == HandGestureState.Stop)
            {
                if (right)
                {
                    DisengageRotationTool(true, ref rightStickActive, ref rightLineRenderer);
                }
                else
                {
                    DisengageRotationTool(false, ref leftStickActive, ref leftLineRenderer);
                }

                EndRotationDrag?.Invoke((right) ? Hand.Right : Hand.Left);
                ADM.QLog("end drag");
            }
        }
Example #3
0
 /// <summary>
 /// handler for all console output for hand input
 /// </summary>
 private void ILog(string text, bool right)
 {
     if (_debuggingEnabled)
     {
         if (right)
         {
             rightDebugOutput.text = text;
         }
         else
         {
             leftDebugOutput.text = text;
         }
         ADM.QLog(text);
         Debug.Log(text);
     }
 }
Example #4
0
 private void DisengageTranslationTool(bool right)
 {
     ToggleTranslateToolVisibility(false, right);
     ToggleTranslateToolColliders(false, right);
     if (right)
     {
         rightLineRenderer.SetPositions(new Vector3[] { Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero });
         rightStickActive = false;
         AtomicSelection.Instance.CompleteTransformation(true);
     }
     else
     {
         leftLineRenderer.SetPositions(new Vector3[] { Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero });
         leftStickActive = false;
         AtomicSelection.Instance.CompleteTransformation(false);
     }
     EndTranslationDrag?.Invoke((right) ? Hand.Right : Hand.Left);
     ADM.QLog("end drag");
 }
    void Update()
    {
        //ADM.QLog("current right hand state: " + currentRightHandGestureState);
        //ADM.QLog("current left hand state: " + currentLeftHandGestureState);
        #region thumb
        if (OVRInput.GetDown(OVRInput.Touch.One, Controller.RTouch))
        {
            ADM.QLog("Got right thumb touch.");
            rightHandState |= TouchStates.thumb;
            UpdateHandState(true);
            StartCoroutine(HoldThresholdTrigger(true, TouchStates.thumb, TouchStateIndex.thumb, Time.time));
        }

        if (OVRInput.GetUp(OVRInput.Touch.One, Controller.RTouch))
        {
            ADM.QLog("Got right thumb touch release.");
            rightHandState &= ~TouchStates.thumb;
            UpdateHandState(true);
            rightHeldLong[(int)TouchStateIndex.thumb] = false;
            RefreshHeldLongState?.Invoke(true, rightHeldLong);
        }

        if (OVRInput.GetDown(OVRInput.Touch.One, Controller.LTouch))
        {
            ADM.QLog("Got left thumb touch.");
            leftHandState |= TouchStates.thumb;
            UpdateHandState(false);
            StartCoroutine(HoldThresholdTrigger(false, TouchStates.thumb, TouchStateIndex.thumb, Time.time));
        }

        if (OVRInput.GetUp(OVRInput.Touch.One, Controller.LTouch))
        {
            ADM.QLog("Got left thumb touch release.");
            leftHandState &= ~TouchStates.thumb;
            UpdateHandState(false);
            leftHeldLong[(int)TouchStateIndex.thumb] = false;
            RefreshHeldLongState?.Invoke(true, rightHeldLong);
        }
        #endregion thumb

        #region pointer
        if (OVRInput.GetDown(OVRInput.Touch.PrimaryIndexTrigger, Controller.LTouch))
        {
            ADM.QLog("Got left index finger touch.");
            leftHandState |= TouchStates.pointer;
            UpdateHandState(false);
            StartCoroutine(HoldThresholdTrigger(false, TouchStates.pointer, TouchStateIndex.pointer, Time.time));
        }

        if (OVRInput.GetUp(OVRInput.Touch.PrimaryIndexTrigger, Controller.LTouch))
        {
            ADM.QLog("Got left index finger touch release.");
            leftHandState &= ~TouchStates.pointer;
            UpdateHandState(false);
            leftHeldLong[(int)TouchStateIndex.pointer] = false;
            RefreshHeldLongState?.Invoke(true, rightHeldLong);
        }

        if (OVRInput.GetDown(OVRInput.Touch.PrimaryIndexTrigger, Controller.RTouch))
        {
            ADM.QLog("Got right index finger touch.");
            rightHandState |= TouchStates.pointer;
            UpdateHandState(true);
            StartCoroutine(HoldThresholdTrigger(true, TouchStates.pointer, TouchStateIndex.pointer, Time.time));
        }

        if (OVRInput.GetUp(OVRInput.Touch.PrimaryIndexTrigger, Controller.RTouch))
        {
            ADM.QLog("Got right index finger touch release.");
            rightHandState &= ~TouchStates.pointer;
            UpdateHandState(true);
            rightHeldLong[(int)TouchStateIndex.pointer] = false;
            RefreshHeldLongState?.Invoke(true, rightHeldLong);
        }
        #endregion pointer

        #region grip
        if (OVRInput.GetDown(OVRInput.Button.PrimaryHandTrigger, Controller.LTouch))
        {
            ADM.QLog("Got left grip touch.");
            leftHandState |= TouchStates.middle;
            UpdateHandState(false);
            StartCoroutine(HoldThresholdTrigger(false, TouchStates.middle, TouchStateIndex.middle, Time.time));
        }

        if (OVRInput.GetUp(OVRInput.Button.PrimaryHandTrigger, Controller.LTouch))
        {
            ADM.QLog("Got left grip touch release.");
            leftHandState &= ~TouchStates.middle;
            UpdateHandState(false);
            leftHeldLong[(int)TouchStateIndex.middle] = false;
            RefreshHeldLongState?.Invoke(true, rightHeldLong);
        }

        if (OVRInput.GetDown(OVRInput.Button.PrimaryHandTrigger, Controller.RTouch))
        {
            ADM.QLog("Got right grip touch.");
            rightHandState |= TouchStates.middle;
            UpdateHandState(true);
            StartCoroutine(HoldThresholdTrigger(true, TouchStates.middle, TouchStateIndex.middle, Time.time));
        }

        if (OVRInput.GetUp(OVRInput.Button.PrimaryHandTrigger, Controller.RTouch))
        {
            ADM.QLog("Got right grip touch release.");
            rightHandState &= ~TouchStates.middle;
            UpdateHandState(true);
            rightHeldLong[(int)TouchStateIndex.middle] = false;
            RefreshHeldLongState?.Invoke(true, rightHeldLong);
        }
        #endregion grip

        #region rotation
        if (currentRightHandGestureState == HandGestureState.DragSelection &&
            ((Vector3.Dot(Vector3.up, RightMarker.Instance.transform.up) < 0.75f && currentRightRotationState == RotationState.lowerCase) ||
             (Vector3.Dot(Vector3.up, RightMarker.Instance.transform.right) < 0.75f && currentRightRotationState == RotationState.upperCase) ||
             (Vector3.Dot(Vector3.up, -1 * RightMarker.Instance.transform.right) < 0.75f && currentRightRotationState == RotationState.specialCharacters) ||
             (Vector3.Dot(_selectionRightStartingMarker.transform.forward, RightMarker.Instance.transform.right) < 0.75f && currentRightRotationState == RotationState.numbers))
            )
        {
            // ADM.QLog("Right rotation state just changed.");
            UpdateRotationState(true);
        }

        if (currentLeftHandGestureState == HandGestureState.DragSelection &&
            ((Vector3.Dot(Vector3.up, LeftMarker.Instance.transform.up) < 0.75f && currentLeftRotationState == RotationState.lowerCase) ||
             (Vector3.Dot(Vector3.up, -1 * LeftMarker.Instance.transform.right) < 0.75f && currentLeftRotationState == RotationState.upperCase) ||
             (Vector3.Dot(Vector3.up, LeftMarker.Instance.transform.right) < 0.75f && currentLeftRotationState == RotationState.specialCharacters) ||
             (Vector3.Dot(_selectionLeftStartingMarker.transform.forward, -1 * LeftMarker.Instance.transform.right) < 0.75f && currentLeftRotationState == RotationState.numbers))
            )
        {
            // ADM.QLog("Left rotation state just changed.");
            UpdateRotationState(false);
        }
        #endregion rotation
    }
    void UpdateRotationState(bool right)
    {
        RotationState previousRotationState = (right) ? currentRightRotationState : currentLeftRotationState;

        if (right)
        {
            if (Vector3.Dot(Vector3.up, RightMarker.Instance.transform.up) >= 0.75f)
            {
                currentRightRotationState = RotationState.lowerCase;
            }

            if (Vector3.Dot(Vector3.up, RightMarker.Instance.transform.right) >= 0.75f)
            {
                currentRightRotationState = RotationState.upperCase;
            }

            if (Vector3.Dot(Vector3.up, -1 * RightMarker.Instance.transform.right) >= 0.75f)
            {
                currentRightRotationState = RotationState.specialCharacters;
            }

            if ((rightHandState & TouchStates.middle) != 0 &&
                Vector3.Dot(
                    RightMarker.Instance.transform.right,
                    _selectionRightStartingMarker.transform.forward
                    ) > 0.75
                )
            {
                currentRightRotationState = RotationState.numbers;
            }

            RightRotationStateChanged?.Invoke(currentRightRotationState, previousRotationState);
        }
        else
        {
            //ADM.QLog(string.Format("Input Left Rotation Results - " +
            //    "lowercase condition: {0} " +
            //    "uppercase condition: {1} " +
            //    "special char condition: {2} " +
            //    "numbers condition: {3}",
            //    Vector3.Dot(Vector3.up, LeftMarker.Instance.transform.up),
            //    Vector3.Dot(Vector3.up, -1 * LeftMarker.Instance.transform.right),
            //    Vector3.Dot(Vector3.up, LeftMarker.Instance.transform.right),
            //    Vector3.Dot(-1 * LeftMarker.Instance.transform.right, _selectionLeftStartingMarker.transform.forward)
            //    ));
            if (Vector3.Dot(Vector3.up, LeftMarker.Instance.transform.up) >= 0.75f)
            {
                currentLeftRotationState = RotationState.lowerCase;
            }

            if (Vector3.Dot(Vector3.up, -1 * LeftMarker.Instance.transform.right) >= 0.75f)
            {
                currentLeftRotationState = RotationState.upperCase;
            }

            if (Vector3.Dot(Vector3.up, LeftMarker.Instance.transform.right) >= 0.75f)
            {
                currentLeftRotationState = RotationState.specialCharacters;
            }

            if ((leftHandState & TouchStates.middle) != 0 &&
                Vector3.Dot(-1 * LeftMarker.Instance.transform.right, _selectionLeftStartingMarker.transform.forward) > 0.75f)
            {
                currentLeftRotationState = RotationState.numbers;
            }

            ADM.QLog("Left new rotation state: " + currentLeftRotationState);
            LeftRotationStateChanged?.Invoke(currentLeftRotationState, previousRotationState);
        }
    }
        /// <summary>
        /// Ratchet loop that handles state when the hand snaps on/off the root position of the gizmo during drag
        /// </summary>
        private IEnumerator ToggleRotationGear(bool right)
        {
            bool firstTimeOnly = true;

            if (right)
            {
                if (!AtomicModeController.Instance.HasFlag(AtomicModeController.Instance.currentRightMode, TransformMode.Rotate))
                {
                    yield break;
                }
                while (rightStickActive)
                {
                    yield return(new WaitUntil(() => (_rightMarkerDistanceMagnitude > _gearThreshold || !rightStickActive)));

                    if (!rightStickActive ||
                        !AtomicModeController.Instance.HasFlag(AtomicModeController.Instance.currentRightMode, TransformMode.Rotate))
                    {
                        yield break;
                    }
                    _rightSurfaceLockMarker.position = GetStartingArrowPoint(true);
                    rightRotationGearEngaged         = true;

                    if (firstTimeOnly)
                    {
                        CalculateRotationOffset(true);
                        firstTimeOnly = false;
                    }

                    rightStartingLocalRoll = RightMarker.Instance.transform.parent.localEulerAngles.z;

                    ADM.QLog("right gear on");

                    yield return(new WaitUntil(() => (_rightMarkerDistanceMagnitude < _gearThreshold || !rightStickActive)));


                    rightStartingLocalRoll           = 0;
                    rightRotationGearEngaged         = false;
                    _rightSurfaceLockMarker.position = rightStartingPoint.position;
                    _rightSurfaceLockMarker.rotation = rightStartingPoint.rotation;
                    ADM.QLog("right gear off");
                }
                _rightSurfaceLockMarker.position = rightStartingPoint.position;
                _rightSurfaceLockMarker.rotation = rightStartingPoint.rotation;
            }
            else
            {
                if (!AtomicModeController.Instance.HasFlag(AtomicModeController.Instance.currentLeftMode, TransformMode.Rotate))
                {
                    yield break;
                }

                while (leftStickActive)
                {
                    yield return(new WaitUntil(() => (_leftMarkerDistanceMagnitude > _gearThreshold || !leftStickActive)));

                    if (!leftStickActive ||
                        !AtomicModeController.Instance.HasFlag(AtomicModeController.Instance.currentLeftMode, TransformMode.Rotate))
                    {
                        yield break;
                    }
                    _leftSurfaceLockMarker.position = GetStartingArrowPoint(false);
                    leftRotationGearEngaged         = true;

                    if (firstTimeOnly)
                    {
                        CalculateRotationOffset(false);
                        firstTimeOnly = false;
                    }

                    leftStartingLocalRoll = LeftMarker.Instance.transform.parent.localEulerAngles.z;

                    ADM.QLog("left gear on");

                    yield return(new WaitUntil(() => (_leftMarkerDistanceMagnitude < _gearThreshold || !leftStickActive)));


                    leftStartingLocalRoll           = 0;
                    leftRotationGearEngaged         = false;
                    _leftSurfaceLockMarker.position = leftStartingPoint.position;
                    _leftSurfaceLockMarker.rotation = leftStartingPoint.rotation;
                    ADM.QLog("left gear off");
                }
                _leftSurfaceLockMarker.position = leftStartingPoint.position;
                _leftSurfaceLockMarker.rotation = leftStartingPoint.rotation;
            }
        }