예제 #1
0
    // Update is called once per frame
    void Update()
    {
        var grabbingObject = grab.GetGrabbedObject();

        VRTK_ControllerReference reference = VRTK_ControllerReference.GetControllerReference(gameObject);

        IsOnSwipeHorizontal = false;
        IsOnSwipeVertical   = false;
        diffTouchPadX       = 0f;
        diffTouchPadY       = 0f;

        //タッチパッドのスワイプを取得
        if (VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Touchpad, SDK_BaseController.ButtonPressTypes.TouchDown, reference))
        {
            touchMarginSumX = 0f;
            touchMarginSumY = 0f;
            var prevTouchAxis = VRTK_SDK_Bridge.GetControllerAxis(SDK_BaseController.ButtonTypes.Touchpad, reference);
            prevTouchPadX = prevTouchAxis.x;
            prevTouchPadY = prevTouchAxis.y;
        }

        if (grabbingObject != null && !Node.scaleConstraint)
        {
            if (VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Touchpad, SDK_BaseController.ButtonPressTypes.Touch, reference))
            {
                var   nowTouchAxis = VRTK_SDK_Bridge.GetControllerAxis(SDK_BaseController.ButtonTypes.Touchpad, reference);
                float nowTouchPadX = nowTouchAxis.x;
                diffTouchPadX = nowTouchPadX - prevTouchPadX;
                if (touchMarginSumX > TOUCH_MARGIN) //タッチ移動量がマージンを超えたら
                {
                    IsOnSwipeHorizontal = true;
                }
                prevTouchPadX    = nowTouchPadX;
                touchMarginSumX += Mathf.Abs(diffTouchPadX);

                float nowTouchPadY = nowTouchAxis.y;
                diffTouchPadY = nowTouchPadY - prevTouchPadY;
                if (touchMarginSumY > TOUCH_MARGIN) //タッチ移動量がマージンを超えたら
                {
                    IsOnSwipeVertical = true;
                }
                prevTouchPadY    = nowTouchPadY;
                touchMarginSumY += Mathf.Abs(diffTouchPadY);
            }

            //左右スワイプでスケール変更
            if (IsOnSwipeHorizontal)
            {
                Vector3 newScale = (1f + diffTouchPadX) * grabbingObject.transform.localScale;
                grabbingObject.transform.localScale = newScale;
            }
        }
    }
예제 #2
0
        void Update()
        {
            VRTK_ControllerReference controllerReference = VRTK_ControllerReference.GetControllerReference(gameObject);

            //Only continue if the controller reference is valid
            if (!VRTK_ControllerReference.IsValid(controllerReference))
            {
                return;
            }

            Vector2 currentTriggerAxis  = VRTK_SDK_Bridge.GetControllerAxis(SDK_BaseController.ButtonTypes.Trigger, controllerReference);
            Vector2 currentGripAxis     = VRTK_SDK_Bridge.GetControllerAxis(SDK_BaseController.ButtonTypes.Grip, controllerReference);
            Vector2 currentTouchpadAxis = VRTK_SDK_Bridge.GetControllerAxis(SDK_BaseController.ButtonTypes.Touchpad, controllerReference);

            // Trigger Pressed end
            if (VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Trigger, SDK_BaseController.ButtonPressTypes.PressUp, controllerReference))
            {
            }
        }
    // Update is called once per frame
    void Update()
    {
        //スワイプ値リセット
        IsOnSwipeHorizontal = false;
        IsOnSwipeVertical   = false;
        diffTouchPadX       = 0f;
        diffTouchPadY       = 0f;

        VRTK_ControllerReference reference = VRTK_ControllerReference.GetControllerReference(gameObject);

        if (headsetType == SDK_BaseHeadset.HeadsetType.Undefined)
        {
            headsetType = VRTK_DeviceFinder.GetHeadsetType();
        }

        if (headsetType == SDK_BaseHeadset.HeadsetType.OculusRift)
        {
            //Riftでのタッチパッドの移動量取得
            var axis = VRTK_SDK_Bridge.GetControllerAxis(SDK_BaseController.ButtonTypes.Touchpad, reference);

            var absX = Mathf.Abs(axis.x);
            var absY = Mathf.Abs(axis.y);
            if (absX > absY) //X軸スワイプ
            {
                if (absX > TOUCH_MARGIN)
                {
                    IsOnSwipeHorizontal = true;
                    diffTouchPadX       = (axis.x - TOUCH_MARGIN) * 0.05f * Time.deltaTime * 30f;
                }
            }
            else //Y軸スワイプ
            {
                if (absY > TOUCH_MARGIN)
                {
                    IsOnSwipeVertical = true;
                    diffTouchPadY     = (axis.y - TOUCH_MARGIN) * 0.05f * Time.deltaTime * 30f;
                }
            }
        }
        else //Rift以外の場合
        {
            //Viveでのタッチパッドの移動量取得
            if (VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Touchpad, SDK_BaseController.ButtonPressTypes.TouchDown, reference))
            {
                touchMarginSumX = 0f;
                touchMarginSumY = 0f;
                prevTouchPadX   = VRTK_SDK_Bridge.GetControllerAxis(SDK_BaseController.ButtonTypes.Touchpad, reference).x;
                prevTouchPadY   = VRTK_SDK_Bridge.GetControllerAxis(SDK_BaseController.ButtonTypes.Touchpad, reference).y;
            }
            else if (VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Touchpad, SDK_BaseController.ButtonPressTypes.Touch, reference))
            {
                float nowTouchPadX = VRTK_SDK_Bridge.GetControllerAxis(SDK_BaseController.ButtonTypes.Touchpad, reference).x;
                diffTouchPadX = nowTouchPadX - prevTouchPadX;
                if (touchMarginSumX > TOUCH_MARGIN) //タッチ移動量がマージンを超えたら
                {
                    IsOnSwipeHorizontal = true;
                }
                prevTouchPadX    = nowTouchPadX;
                touchMarginSumX += Mathf.Abs(diffTouchPadX);

                float nowTouchPadY = VRTK_SDK_Bridge.GetControllerAxis(SDK_BaseController.ButtonTypes.Touchpad, reference).y;
                diffTouchPadY = nowTouchPadY - prevTouchPadY;
                if (touchMarginSumY > TOUCH_MARGIN) //タッチ移動量がマージンを超えたら
                {
                    IsOnSwipeVertical = true;
                }
                prevTouchPadY    = nowTouchPadY;
                touchMarginSumY += Mathf.Abs(diffTouchPadY);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        VRTK_ControllerReference reference = VRTK_ControllerReference.GetControllerReference(gameObject);

        IsOnSwipeHorizontal = false;
        IsOnSwipeVertical   = false;
        diffTouchPadX       = 0f;
        diffTouchPadY       = 0f;

        //グリップ押してる
        if (VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Grip, SDK_BaseController.ButtonPressTypes.Press, reference))
        {
            //タッチパッドのスワイプを取得
            if (VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Touchpad, SDK_BaseController.ButtonPressTypes.TouchDown, reference))
            {
                touchMarginSumX = 0f;
                touchMarginSumY = 0f;
                var prevTouchAxis = VRTK_SDK_Bridge.GetControllerAxis(SDK_BaseController.ButtonTypes.Touchpad, reference);
                prevTouchPadX = prevTouchAxis.x;
                prevTouchPadY = prevTouchAxis.y;
            }
            else if (VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Touchpad, SDK_BaseController.ButtonPressTypes.Touch, reference))
            {
                var   nowTouchAxis = VRTK_SDK_Bridge.GetControllerAxis(SDK_BaseController.ButtonTypes.Touchpad, reference);
                float nowTouchPadX = nowTouchAxis.x;
                diffTouchPadX = nowTouchPadX - prevTouchPadX;
                if (touchMarginSumX > TOUCH_MARGIN) //タッチ移動量がマージンを超えたら
                {
                    IsOnSwipeHorizontal = true;
                }
                prevTouchPadX    = nowTouchPadX;
                touchMarginSumX += Mathf.Abs(diffTouchPadX);

                float nowTouchPadY = nowTouchAxis.y;
                diffTouchPadY = nowTouchPadY - prevTouchPadY;
                if (touchMarginSumY > TOUCH_MARGIN) //タッチ移動量がマージンを超えたら
                {
                    IsOnSwipeVertical = true;
                }
                prevTouchPadY    = nowTouchPadY;
                touchMarginSumY += Mathf.Abs(diffTouchPadY);
            }
            else if (VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Touchpad, SDK_BaseController.ButtonPressTypes.TouchUp, reference))
            {
                targetPosition = rootObject.transform.position;
                targetRotation = rootObject.transform.rotation;
                prevPosition   = rootObject.transform.InverseTransformPoint(transform.parent.position);
                prevRotation   = Quaternion.Inverse(rootObject.transform.rotation) * transform.parent.rotation;
            }
        }


        if (VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Grip, SDK_BaseController.ButtonPressTypes.PressDown, reference))
        {
            targetPosition = rootObject.transform.position;
            targetRotation = rootObject.transform.rotation;
            prevPosition   = rootObject.transform.InverseTransformPoint(transform.parent.position);
            prevRotation   = Quaternion.Inverse(rootObject.transform.rotation) * transform.parent.rotation;
        }
        //グリップ押してる
        else if (VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Grip, SDK_BaseController.ButtonPressTypes.Press, reference))
        {
            //移動
            var diffPosition = rootObject.transform.InverseTransformPoint(transform.parent.position) - prevPosition;
            targetPosition = targetPosition - rootObject.transform.TransformVector(diffPosition) * moveFactor;
            if (!VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Touchpad, SDK_BaseController.ButtonPressTypes.Touch, reference))
            {
                rootObject.transform.position = Vector3.Lerp(rootObject.transform.position, targetPosition, Time.deltaTime * lerpFactor);
            }

            prevPosition = rootObject.transform.InverseTransformPoint(transform.parent.position);

            /*
             * //回転
             * var diffRotation = Quaternion.Inverse(rootObject.transform.rotation) * transform.parent.rotation * Quaternion.Inverse(prevRotation);
             * var euler = diffRotation.eulerAngles;
             * diffRotation = Quaternion.Euler(0f, diffRotation.eulerAngles.y * rotateFactor, 0f);
             * targetRotation = targetRotation * diffRotation;
             * if (!VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Touchpad, SDK_BaseController.ButtonPressTypes.Touch, reference))
             * {
             *  //var lerpQ = Quaternion.Lerp(rootObject.transform.rotation, targetRotation, Time.deltaTime * lerpFactor);
             *  float angle;
             *  Vector3 axis;
             *  diffRotation.ToAngleAxis(out angle, out axis);
             *  rootObject.transform.RotateAround(transform.parent.position, axis, angle);
             * }
             *
             * prevRotation = Quaternion.Inverse(rootObject.transform.rotation) * transform.parent.rotation;
             */
        }

        //左右スワイプでスケール変更
        if (IsOnSwipeHorizontal)
        {
            Vector3 newScale = (1f - diffTouchPadX) * rootObject.transform.localScale;
            ScaleAround(rootObject, transform.position, newScale);
        }
    }