Beispiel #1
0
        void inputUpdate()
        {
#if DOWNLOADED_ARFOUNDATION
            int id = handVRMain_.GetIdFromHandednesses(ThisEitherHand);
            if (!IsTrackingHand || id < 0)
            {
                if (!KEEP_TRACKING_GRABED || !inputState_.isGrab)
                {
                    inputState_.isTracked = false;
                }
                InputSystem.QueueStateEvent(ThisEitherHand == EitherHand.Left ? XRController.leftHand : XRController.rightHand, inputState_);
                return;
            }

            inputState_.isTracked = true;

            var gestures = handVRMain_.GetGestures(id);
            inputState_.isGrab = gestures[(int)HandVRMain.GestureType.Open] < gestures[(int)HandVRMain.GestureType.Close] ||
                                 gestures[(int)HandVRMain.GestureType.Open] < gestures[(int)HandVRMain.GestureType.Grab];

            int   gesturesMaxId = 0;
            float maxValue      = 0f;
            for (int gestureId = 0; gestureId < gestures.Length; gestureId++)
            {
                if (maxValue < gestures[gestureId])
                {
                    gesturesMaxId = gestureId;
                    maxValue      = gestures[gestureId];
                }
            }
            inputState_.gestures = (uint)1 << gesturesMaxId;

            if (handMRManager_.CenterTransform != null)
            {
                inputState_.position = HandCenterPosition - handMRManager_.CenterTransform.position;
                inputState_.gesturePointerPosition = fingers_[8].position - handMRManager_.CenterTransform.position;
            }
            else
            {
                inputState_.position = HandCenterPosition;
                inputState_.gesturePointerPosition = fingers_[8].position;
            }
            inputState_.position = Quaternion.Inverse(DefaultRotation) * inputState_.position;

            if (!handMRManager_.IsLockHandRotation)
            {
                if (inputState_.gestures == 1)
                {
                    if (ThisEitherHand == EitherHand.Left)
                    {
                        inputState_.rotation  = transform.parent.rotation * handVRMain_.GetHandRotation(id);
                        inputState_.rotation  = Quaternion.Inverse(DefaultRotation) * inputState_.rotation;
                        inputState_.rotation *= Quaternion.Euler(0f, BASE_ANGLE, 0f);
                    }
                    else
                    {
                        inputState_.rotation  = transform.parent.rotation * handVRMain_.GetHandRotation(id);
                        inputState_.rotation  = Quaternion.Inverse(DefaultRotation) * inputState_.rotation;
                        inputState_.rotation *= Quaternion.Euler(0f, -BASE_ANGLE, 0f);
                    }
                }
            }
            else
            {
                inputState_.rotation = transform.parent.rotation;
                inputState_.rotation = Quaternion.Inverse(DefaultRotation) * inputState_.rotation;
            }

            inputState_.trackingState = (int)(InputTrackingState.Position | InputTrackingState.Rotation);

            InputSystem.QueueStateEvent(ThisEitherHand == EitherHand.Left ? XRController.leftHand : XRController.rightHand, inputState_);
#endif
        }