GetAxis() public method

public GetAxis ( EVRButtonId buttonId = EVRButtonId.k_EButton_SteamVR_Touchpad ) : Vector2
buttonId EVRButtonId
return Vector2
示例#1
0
    void Update()
    {
        //Set device equal to the tracked controller
        device = SteamVR_Controller.Input((int)trackedObject.index);
        //Store touchpad y axis in local variable
        touchpadY = device.GetAxis().y;
        touchpadX = device.GetAxis().x;

        if (isNoCollison)
        {
            //If touchpad is touched in top half
            movePlayer();
        }
        else
        {
            if (touchpadY < 0)               //Player can only move backwards
            {
                movePlayer();
            }
            else
            {
                Debug.Log("STILL STUCK");
            }
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        device = SteamVR_Controller.Input((int)controller.index);

        trigger = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger);

        Debug.Log(trigger);

        RF.AddRelativeForce(0, trigger.x * throttleMult, 0);
        LF.AddRelativeForce(0, trigger.x * throttleMult, 0);
        RB.AddRelativeForce(0, trigger.x * throttleMult, 0);
        LB.AddRelativeForce(0, trigger.x * throttleMult, 0);

        if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad) && device.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
        {
            //Read the touchpad values
            touchpad = device.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);

            QC.AddRelativeTorque(0, touchpad.x * yawMult, 0);
        }

        //if(device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) {
        //Application.LoadLevel(lvl);
        //}
    }
 void Update()
 {
     device = SteamVR_Controller.Input((int)trackedObject.index);
     if (device.GetAxis().x != 0)
     {
         if (device.GetAxis().x < -0.33f)
         {
             if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
             {
                 TrackpadPressed((int)trackedObject.index, "left");
             }
         }
         else if (device.GetAxis().x > -0.33f && device.GetAxis().x < 0.33f)
         {
             if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
             {
                 TrackpadPressed((int)trackedObject.index, "center");
             }
         }
         else if (device.GetAxis().x > 0.33f)
         {
             if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
             {
                 TrackpadPressed((int)trackedObject.index, "right");
             }
         }
     }
     if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
     {
         TriggerPressed();
     }
 }
    // Update is called once per frame
    void Update()
    {
        device = SteamVR_Controller.Input((int)trackedObject.index);

        if (controller.padPressed)
        {
            float x = device.GetAxis().x;
            float y = device.GetAxis().y;

            Vector3 forward;

            if (x != 0 || y != 0)
            {
                int areaTag = area(x, y);

                if (areaTag == 1 || areaTag == 3)
                {
                    forward = controller.transform.TransformDirection(Vector3.forward);
                    float curSpeed = m_Speed * y;
                    player.SimpleMove(forward * curSpeed);
                }
                else if (areaTag == 2 || areaTag == 4)
                {
                    player.transform.Rotate(0, x * m_TurnSpeed, 0);
                }
            }
        }
    }
    void Update()
    {
        device1 = SteamVR_Controller.Input((int)controller1.index);
        device2 = SteamVR_Controller.Input((int)controller2.index);

        if (device2.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Vector3 move = controller2.transform.forward;
            move = new Vector3(move.x * device2.GetAxis().y, 0f, move.z * device2.GetAxis().y);
            Vector3 move2 = controller2.transform.right;
            move2 = new Vector3(move2.x * device2.GetAxis().x, 0f, move2.z * device2.GetAxis().x);

            _rb.MovePosition(transform.position + ((move + move2) / 2) * speed * Time.deltaTime);
        }

        if (device1.GetTouchDown(SteamVR_Controller.ButtonMask.Grip))
        {
            if (!_OnHand)
            {
                _OnHand = Instantiate(pistol, controller1.transform.position, controller1.transform.rotation) as GameObject;
                _OnHand.transform.SetParent(controller1.transform);
            }
        }

        if (device1.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            if (_OnHand)
            {
                _OnHand.GetComponent <PistolScript>().Shoot();
            }
        }
    }
示例#6
0
        /// <summary>
        /// Get extra scroll delta from gamepad
        /// </summary>
        protected Vector2 GetExtraScrollDelta()
        {
            Vector2 scrollDelta = new Vector2();

            if (useLeftStickScroll)
            {
#if HTCVIVE
                _RightDevice = SteamVR_Controller.Input((int)rightTracked.index);
                float x = _RightDevice.GetAxis().x;
                float y = _RightDevice.GetAxis().y;
#else
                float x = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick).x;
                float y = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick).y;
#endif
                if (Mathf.Abs(x) < leftStickDeadZone)
                {
                    x = 0;
                }
                if (Mathf.Abs(y) < leftStickDeadZone)
                {
                    y = 0;
                }
                scrollDelta = new Vector2(x, y);
            }
            return(scrollDelta);
        }
示例#7
0
    // Update is called once per frame
    void Update()
    {
        AttachArrow();
        //Gets SteamVR Controller and gets trigger press depth
        SteamVR_Controller.Device deviceRight = SteamVR_Controller.Input((int)rightController.index);
        triggerAxis = deviceRight.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x; //get trigger depth


        //Trigger
        boneTrigger.transform.localPosition = Vector3.Lerp(boneTrigger.transform.localPosition, boneTriggerTargetPosition * triggerAxis, Time.deltaTime * 10);
        boneTriggerTargetRotation           = Quaternion.Euler(new Vector3(90f + (-9.6f * triggerAxis), 0f, -90f));
        boneTrigger.transform.localRotation = Quaternion.Slerp(boneTrigger.transform.localRotation, boneTriggerTargetRotation, Time.deltaTime * 10);

        if (triggerAxis == 1) //trigger is pulled all the way
        {
            if (isAttached)
            {
                Fire();
            }
        }

        //String Pull back as touchpad down button is pressed
        if (deviceRight.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Vector2 touchpad;
            touchpad = deviceRight.GetAxis();

            if (touchpad.y < 0f)
            {
                StringPull();
            }
        }
    }
示例#8
0
    void UpdateFreeRotation()
    {
        Vector2 sticks = new Vector2();

        SteamVR_Controller.Device device = SteamVR_Controller.Input((int)rightController.GetComponent <SteamVR_TrackedController>().controllerIndex);
        if (UnityEngine.XR.XRDevice.model == "Vive MV")
        {
            bool    pressTouchpad = device.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad);
            Vector2 touch         = device.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);
            sticks = pressTouchpad ? touch : new Vector2(0, 0); // to emulate joystick press hard the touchpad
        }
        else if (UnityEngine.XR.XRDevice.model == "Lenovo Explorer")
        {
            sticks = device.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);
        }
        else if (UnityEngine.XR.XRDevice.model == "Vive MV")
        {
            sticks = device.GetAxis(EVRButtonId.k_EButton_Axis2);
        }

        //print(sticks);
        GameObject pivot = new GameObject();

        pivot.transform.position = player.transform.Find("[CameraRig]").Find("Camera (eye)").transform.position;

        player.transform.SetParent(pivot.transform);

        pivot.transform.Rotate(Vector3.up, sticks[0]);
        player.transform.SetParent(null);
        Destroy(pivot);
    }
    void Update()
    {
        controller = SteamVR_Controller.Input((int)trackedObj.index);

        // right hand functions
        if (controller.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Debug.Log("right touched!");
        }

        // setting initial touch position for swiping
        if (controller.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            touchLast = controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x;
        }

        // activate/deactivate objectMenu on touchpad press
        if (controller.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Debug.Log("right tp pressed down!");
            objectMenu.SetActive(!objectMenu.activeSelf);
        }

        // if objectMenu is active and player is touching touchpad,
        // rotate the objectMenu based on swiping left/right on touchpad.
        if (objectMenu.activeSelf && controller.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
        {
            touchCurrent = controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x;
            distance     = touchCurrent - touchLast;
            touchLast    = touchCurrent;

            objectMenu.transform.Rotate(Vector3.forward * distance * swipeSpeed);
        }
    }
示例#10
0
        /*--------------------------------------------------------------------------------------------*/
        private ControlState GetControllerState(GameObject pControlGo)
        {
            SteamVR_TrackedObject control = pControlGo.GetComponent <SteamVR_TrackedObject>();

            SteamVR_Controller.Device input = null;

            var state = new ControlState();

            state.Controller = control;
            state.Tx         = control.transform;
            state.IsValid    = control.isValid;

            if (control.index < 0)
            {
                state.IsValid = false;
            }
            else
            {
                input         = SteamVR_Controller.Input((int)control.index);
                state.IsValid = (state.IsValid && input.valid);
            }

            if (state.IsValid)
            {
                state.TouchpadAxis  = input.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);
                state.TriggerAxis   = input.GetAxis(EVRButtonId.k_EButton_SteamVR_Trigger);
                state.TouchpadTouch = input.GetTouch(EVRButtonId.k_EButton_SteamVR_Touchpad);
                state.TouchpadPress = input.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad);
                state.GripPress     = input.GetPress(EVRButtonId.k_EButton_Grip);
                state.MenuPress     = input.GetPress(EVRButtonId.k_EButton_ApplicationMenu);
            }

            return(state);
        }
示例#11
0
    // Update is called once per frame
    void Update()
    {
        Controller = SteamVR_Controller.Input((int)trackedObj.index);


        // Getting the Touchpad Axis
        if (Controller.GetAxis() != Vector2.zero)
        {
            Debug.Log(gameObject.name + Controller.GetAxis());
        }

        // Getting the Trigger press
        if (Controller.GetHairTriggerDown())
        {
            Debug.Log(gameObject.name + " Trigger Press");
        }

        // Getting the Trigger Release
        if (Controller.GetHairTriggerUp())
        {
            Debug.Log(gameObject.name + " Trigger Release");
        }

        // Getting the Grip Press
        if (Controller.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
        {
            Debug.Log(gameObject.name + " Grip Press");
        }

        // Getting the Grip Release
        if (Controller.GetPressUp(SteamVR_Controller.ButtonMask.Grip))
        {
            Debug.Log(gameObject.name + " Grip Release");
        }
    }
示例#12
0
    void Update()
    {
        SteamVR_Controller.Device leftHandDevice  = SteamVR_Controller.Input((int)LeftHand.index);
        SteamVR_Controller.Device rightHandDevice = SteamVR_Controller.Input((int)RightHand.index);

        bool  leftScroll      = leftHandDevice.GetTouch(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad);
        float leftScrollPos   = leftHandDevice.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).y;
        float leftScrollDelta = (leftScroll && !_leftWasScrolling) || !leftScroll ? 0 : leftScrollPos - _lastLeftScrollPos;

        _leftWasScrolling  = leftScroll;
        _lastLeftScrollPos = leftScrollPos;

        bool  rightScroll      = rightHandDevice.GetTouch(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad);
        float rightScrollPos   = rightHandDevice.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).y;
        float rightScrollDelta = (rightScroll && !_rightWasScrolling) || !rightScroll ? 0 : rightScrollPos - _lastRightScrollPos;

        _rightWasScrolling  = rightScroll;
        _lastRightScrollPos = rightScrollPos;

        SixDofControl.StrokeWeightMaxModifier  = leftScrollDelta * 20;
        SixDofControl.StrokeWeightAlpha        = leftHandDevice.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x;
        SixDofControl.UndoRequested            = leftHandDevice.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad);
        SixDofControl.RedoRequested            = rightHandDevice.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad);
        SixDofControl.PickerSphereSizeModifier = rightScrollDelta * 20;
        SixDofControl.ColorPicking             = rightHandDevice.GetPress(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger);
        SixDofControl.LeftHandPressed          = leftHandDevice.GetPress(Valve.VR.EVRButtonId.k_EButton_Grip);
        SixDofControl.RightHandPressed         = rightHandDevice.GetPress(Valve.VR.EVRButtonId.k_EButton_Grip);
    }
示例#13
0
 // Processes the input and calls the ProcessSquadSelection with the X, Y values of the click
 private void Controller_PadClicked(object sender, ClickedEventArgs e)
 {
     if (device.GetAxis().x != 0 || device.GetAxis().y != 0)
     {
         ProcessSquadSelection(device.GetAxis().x, device.GetAxis().y);
     }
 }
示例#14
0
    void Update()
    {
        //------------------------using the pad------------------------\\

        if (selectorHand != null)
        {
            if (_selectedObjectIsActive || _rotationGizmoIsSelected)
            {
                return;
            }
            else
            {
                //TODO: move to menu handler
                if (selectorHand.GetAxis().x != 0 || selectorHand.GetAxis().y != 0)
                {
                    if (selectorHand.GetAxis().x < 0 && selectorHand.GetAxis().y > 0)
                    {
                        _stateManagerMutatorRef.SET_EDITOR_MODE_UNIVERSAL();
                    }
                    if (selectorHand.GetAxis().x > 0 && selectorHand.GetAxis().y > 0)
                    {
                        _stateManagerMutatorRef.SET_EDITOR_MODE_CLONE_DELETE();
                    }
                    if (selectorHand.GetAxis().x < 0 && selectorHand.GetAxis().y < 0)
                    {
                        _stateManagerMutatorRef.SET_EDITOR_MODE_OPEN_MENU();
                    }
                    if (selectorHand.GetAxis().x > 0 && selectorHand.GetAxis().y < 0)
                    {
                        _stateManagerMutatorRef.SET_EDITOR_MODE_OPEN_MENU();
                    }
                }
            }
        }
    }
示例#15
0
        /*--------------------------------------------------------------------------------------------*/
        private void UpdateCursorWithDevice(Transform pDeviceTx, SteamVR_Controller.Device pDevice,
                                            Info pInfo, CursorType pCursorType)
        {
            if (!CursorDataProvider.HasCursorData(pCursorType))
            {
                return;
            }

            ICursorDataForInput data = CursorDataProvider.GetCursorDataForInput(pCursorType);

            data.SetUsedByInput(pDevice.valid);

            if (!pDevice.valid)
            {
                return;
            }

            Vector2 touchAxis   = pDevice.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);
            Vector2 triggerAxis = pDevice.GetAxis(EVRButtonId.k_EButton_SteamVR_Trigger);
            bool    isTouch     = pDevice.GetTouch(EVRButtonId.k_EButton_SteamVR_Touchpad);
            float   sizeProg    = (isTouch ? touchAxis.x * 2 + 1 : 0.5f);
            Vector3 worldOffset = pDeviceTx.TransformVector(pInfo.LocalPosition);

            data.SetWorldPosition(pDeviceTx.position + worldOffset);
            data.SetWorldRotation(pDeviceTx.rotation * Quaternion.Euler(pInfo.LocalRotation));
            data.SetSize(Mathf.Lerp(pInfo.MinSize, pInfo.MaxSize, sizeProg));
            data.SetTriggerStrength(triggerAxis.x);
        }
    // Update is called once per frame
    void Update()
    {
        device = SteamVR_Controller.Input((int)trackedObj.index);

        if (Lconrtollerflag == false)
        {
            if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
            {
                touchLast = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x;
            }

            if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
            {
                touchCurrent = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x;
                distance     = touchCurrent - touchLast;
                touchLast    = touchCurrent;
                swipeSum    += distance;

                if (!hasSwipedRight)
                {
                    if (swipeSum > 0.5f)
                    {
                        swipeSum = 0;
                        SwipeRight();
                        hasSwipedRight = true;
                        hasSwipedLeft  = false;
                    }
                }

                if (!hasSwipedLeft)
                {
                    if (swipeSum < -0.5f)
                    {
                        swipeSum = 0;
                        SwipeLeft();
                        hasSwipedLeft  = true;
                        hasSwipedRight = false;
                    }
                }
            }

            if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad))
            {
                //Reset Swipe
                SwipeReset();
            }

            if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
            {
                //Spawn object currently selected by menu
                SpawnObject();
            }

            if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
            {
                objectMenuManager.EnableDisableMenu();
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        device = SteamVR_Controller.Input((int)trackedObj.index);
        if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            touchLast = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);
            //SteamVR_Touchpad);
            //.x;
        }
        if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
        {
            touchCurrent = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0);
            //SteamVR_Touchpad);
            //.x;
            distance  = touchCurrent - touchLast;
            touchLast = touchCurrent;
            swipeSum += distance;

            objectMenu.SetActive(true);

            if (!hasSwipedRight)
            {
                if (swipeSum.x > 0.5f)
                {
                    swipeSum.x = 0;
                    SwipeRight();
                    hasSwipedRight = true;
                    hasSwipedLeft  = false;
                }
            }

            if (!hasSwipedLeft)
            {
                if (swipeSum.x < -0.5f)
                {
                    swipeSum.x = 0;
                    SwipeLeft();
                    hasSwipedLeft  = true;
                    hasSwipedRight = false;
                }
            }
        }

        if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad))
        {
            swipeSum.x     = 0;
            touchCurrent.x = 0;
            touchLast.x    = 0;
            hasSwipedLeft  = false;
            hasSwipedRight = false;

            objectMenu.SetActive(false);
        }

        if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            SpawnObject();
        }
    }
示例#18
0
    // Update is called once per frame
    void Update()
    {
        device = SteamVR_Controller.Input((int)trackedObj.index);
        if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            touchLast = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x;
        }
        if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
        {
            // This code does not play well with Oculus. User must release the stick, not return it to center. Ugh
            touchCurrent = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x;
            distance     = touchCurrent - touchLast;
            touchLast    = touchCurrent;
            swipeSum    += distance;

            if (!hasSwipedRight)
            {
                if (swipeSum > 0.49f)
                {
                    swipeSum = 0f;
                    SwipeRight();
                    hasSwipedRight = true;
                    hasSwipedLeft  = false;
                }
            }
            if (!hasSwipedLeft)
            {
                if (swipeSum < -0.49f)
                {
                    swipeSum = 0f;
                    SwipeLeft();
                    hasSwipedRight = false;
                    hasSwipedLeft  = true;
                }
            }
            if (!objectMenuManager.isMenuShown)
            {
                ShowMenu();
            }
        }
        if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad))
        {
            if (objectMenuManager.isMenuShown)
            {
                HideMenu();
            }
            swipeSum       = 0f;
            touchCurrent   = 0;
            touchLast      = 0;
            hasSwipedLeft  = false;
            hasSwipedRight = false;
            Debug.Log("TouchUp");
        }
        if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            //Spawn object currently selected by menu
            SpawnObject();
        }
    }
    // Update is called once per frame
    void Update()
    {
        device = SteamVR_Controller.Input((int)trackedObj.index);

        if (device.GetPressUp(SteamVR_Controller.ButtonMask.ApplicationMenu))
        {
            MenuSwitch();
        }

        if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            touchLast = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x;
        }

        if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
        {
            touchCurrent = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x;
            distance     = touchCurrent - touchLast;
            touchLast    = touchCurrent;
            swipeSum    += distance;

            if (!hasSwipedRight)
            {
                if (swipeSum > 0.5f)
                {
                    swipeSum = 0;
                    SwipeRight();
                    hasSwipedRight = true;
                    hasSwipedLeft  = false;
                }
            }

            if (!hasSwipedLeft)
            {
                if (swipeSum < -0.5f)
                {
                    swipeSum = 0;
                    SwipeLeft();
                    hasSwipedLeft  = true;
                    hasSwipedRight = false;
                }
            }
        }

        if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad))
        {
            swipeSum       = 0;
            touchCurrent   = 0;
            touchLast      = 0;
            hasSwipedLeft  = false;
            hasSwipedRight = false;
        }
        if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            //Spawn object currently selected by menu
            SpawnObject();
        }
        //Debug.Log("Found device");
    }
示例#20
0
 void Update()
 {
     device = SteamVR_Controller.Input((int)trackedObject.index);
     if (device.GetAxis().x != 0 || device.GetAxis().y != 0)
     {
         Debug.Log(device.GetAxis().x + " " + device.GetAxis().y);
     }
 }
示例#21
0
 // Update is called once per frame
 void Update()
 {
     print(cont.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0));
     print(cont.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis1));
     print(cont.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis2));
     print(cont.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis3));
     print(cont.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis4));
 }
示例#22
0
    // Update is called once per frame
    void Update()
    {
        device = SteamVR_Controller.Input((int)trackedObj.index);

        //set initial touch to 0
        if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            touchLast = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x;
        }

        //detect touch
        if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
        {
            touchCurrent = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x;
            //how much did finger move this frame?
            distance  = touchCurrent - touchLast;
            touchLast = touchCurrent;
            //total movement
            swipeSum += distance;

            if (!hasSwipedRight)
            {
                if (swipeSum > 0.5f)
                {
                    swipeSum = 0;
                    SwipeRight();
                    hasSwipedLeft = true;
                    hasSwipedLeft = false;
                }
            }
            if (!hasSwipedLeft)
            {
                if (swipeSum < -0.5f)
                {
                    swipeSum = 0;
                    SwipeLeft();
                }
                hasSwipedLeft  = true;
                hasSwipedRight = false;
            }
        }

        //reset variable if finger up
        if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad))
        {
            swipeSum       = 0;
            touchCurrent   = 0;
            touchLast      = 0;
            hasSwipedLeft  = false;
            hasSwipedRight = false;
        }

        //Spawn object currently selected by menu
        if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            SpawnObject();
        }
    }
示例#23
0
    public void Update()
    {
        SteamVR_Controller.Device ctrl = SteamVR_Controller.Input((int)controller.index);

        // Handle trigger input
        if (ctrl.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            VRTriggerInteraction interaction = new VRTriggerInteraction(ctrl, gameObject);
            Service.EventManager.SendEvent(EventId.VRControllerTriggerPress, interaction);
            CallListeners(triggerListeners, true);
        }

        if (ctrl.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
        {
            VRTriggerInteraction interaction = new VRTriggerInteraction(ctrl, gameObject);
            Service.EventManager.SendEvent(EventId.VRControllerTriggerRelease, interaction);
            CallListeners(triggerListeners, false);
        }

        // Handle trigger input
        if (ctrl.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
        {
            VRTriggerInteraction interaction = new VRTriggerInteraction(ctrl, gameObject);
            Service.EventManager.SendEvent(EventId.VRControllerGripPress, interaction);
            CallListeners(gripListeners, true);
        }

        if (ctrl.GetPressUp(SteamVR_Controller.ButtonMask.Grip))
        {
            VRTriggerInteraction interaction = new VRTriggerInteraction(ctrl, gameObject);
            Service.EventManager.SendEvent(EventId.VRControllerGripRelease, interaction);
            CallListeners(gripListeners, false);
        }

        // Handle touchpad input
        VRTouchpadInteraction touch;

        if (ctrl.GetTouch(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad))
        {
            if (!isTouchDown)
            {
                touch = new VRTouchpadInteraction(gameObject, ctrl.GetAxis());
                Service.EventManager.SendEvent(EventId.VRControllerTouchpadPress, touch);
                isTouchDown = true;
            }
            else
            {
                touch = new VRTouchpadInteraction(gameObject, ctrl.GetAxis());
                Service.EventManager.SendEvent(EventId.VRControllerTouchpadDrag, touch);
            }
        }
        else if (isTouchDown)
        {
            touch = new VRTouchpadInteraction(gameObject, ctrl.GetAxis());
            Service.EventManager.SendEvent(EventId.VRControllerTouchpadRelease, touch);
            isTouchDown = false;
        }
    }
示例#24
0
        //
        public override int GetInputState(ref XDevicePlugin.ControllerState state)
        {
            if (m_Device.connected)
            {
                Vector2 v2;
                //
                v2 = m_Device.GetAxis(EVRButtonId.k_EButton_Axis1);
                state.axes[(int)ControllerAxis.PrimaryTrigger] = v2.x;
                v2 = m_Device.GetAxis(EVRButtonId.k_EButton_Axis0);
                state.axes[(int)ControllerAxis.PrimaryThumbX] = v2.x;
                state.axes[(int)ControllerAxis.PrimaryThumbY] = v2.y;
                //
                state.buttons = 0;
                if (m_Device.GetHairTrigger())
                {
                    state.buttons |= (uint)XimmerseButton.Trigger;
                }
                if (m_Device.GetPress(SteamVR_Controller.ButtonMask.Grip))
                {
                    state.buttons |= (uint)XimmerseButton.Grip;
                }

                if (m_Device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
                {
                    state.buttons |= (uint)XimmerseButton.Touch;
                }
                if (m_Device.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
                {
                    state.buttons |= (uint)XimmerseButton.Click;
                }

                if (m_Device.GetPress(SteamVR_Controller.ButtonMask.ApplicationMenu))
                {
                    state.buttons |= (uint)XimmerseButton.App;
                }
                if (m_Device.GetPress(SteamVR_Controller.ButtonMask.System))
                {
                    state.buttons |= (uint)XimmerseButton.Home;
                }

                //
                TrackedDevicePose_t pose = m_UseOnNewPoses?m_Pose:m_Device.GetPose();
                XDevicePlugin.SetInt(handle, XDevicePlugin.kField_TrackingResultInt, (int)(pose.bPoseIsValid?TrackingResult.PoseTracked:TrackingResult.NotTracked));
                SteamVR_Utils.RigidTransform rt = new SteamVR_Utils.RigidTransform(pose.mDeviceToAbsoluteTracking);
                Vector3 v3 = rt.pos;
                state.position[0] = v3.x;
                state.position[1] = v3.y;
                state.position[2] = -v3.z;
                Quaternion q = rt.rot;
                state.rotation[0] = -q.x;
                state.rotation[1] = -q.y;
                state.rotation[2] = q.z;
                state.rotation[3] = q.w;
                //
            }
            return(0);
        }
 // only when the trackpad is pressed
 void Controller_PadClicked(object sender, ClickedEventArgs e)
 {
     if (device.GetAxis().x != 0 || device.GetAxis().y != 0)
     {
         //Debug.Log (device.GetAxis ().x + " " + device.GetAxis ().y);
         fingerOnPressCoordenateX = device.GetAxis().x;
         fingerOnPressCoordenateY = device.GetAxis().y;
     }
 }
示例#26
0
        public override float GetAxis1D(NVRButtons button)
        {
            if (Controller != null)
            {
                return(Controller.GetAxis(GetButton(button)).x);
            }

            return(0);
        }
示例#27
0
    // Update is called once per frame
    void Update()
    {
        Controller = SteamVR_Controller.Input((int)trackedObj.index);

        // Getting the Touchpad Axis
        if (Controller.GetAxis() != Vector2.zero)
        {
            Debug.Log(gameObject.name + Controller.GetAxis());
        }

        // Getting the Trigger press
        if (Controller.GetHairTriggerDown())
        {
            triggerPress = true;
//			Debug.Log(gameObject.name + " Trigger Press");
//			if (gameObject.name == "Controller (right)") {
//				InteractionManager.right_trigger_press = true;
//			} else if (gameObject.name == "Controller (left)") {
//				InteractionManager.left_trigger_press = true;
//			}
//
            //InteractionManager.ActiveHairlineTrigger(gameObject.name);

            //if we're on controller right
//			if(gameObject.name == "Controller (right)"){
//				Debug.Log ("both at the same time!!!");
//
//				//find the interaction manager and call the function we wrote
//
//				//GameObject.Find ("InteractionManager").GetComponent<Interactions> ().HandleRightTriggerPressed ();
//			}
        }

        // Getting the Trigger Release
        if (Controller.GetHairTriggerUp())
        {
            triggerPress = false;
//			if (gameObject.name == "Controller (right)") {
//				InteractionManager.right_trigger_press = false;
//			} else if (gameObject.name == "Controller (left)") {
//				InteractionManager.left_trigger_press = false;
//			}
//			Debug.Log(gameObject.name + " Trigger Release");
        }

        // Getting the Grip Press
        if (Controller.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
        {
            Debug.Log(gameObject.name + " Grip Press");
        }

        // Getting the Grip Release
        if (Controller.GetPressUp(SteamVR_Controller.ButtonMask.Grip))
        {
            Debug.Log(gameObject.name + " Grip Release");
        }
    }
示例#28
0
    void ProcessController(SteamVR_Controller.Device controller, GameObject controllerGO, bool left)
    {
        if (controller == null)
        {
            //Debug.LogError("Controller not found " + left);
            return;
        }

        // 1
        if (controller.GetAxis() != Vector2.zero)
        {
            Debug.Log(left + " " + controller.GetAxis());
        }

        // 2
        if (controller.GetHairTriggerDown())
        {
            Debug.LogError(left + " Trigger Press");
            TriggerPull(controllerGO);
        }

        // 3
        if (controller.GetHairTriggerUp())
        {
            Debug.Log(left + " Trigger Release");
        }

        // 4
        if (controller.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
        {
            Debug.Log(left + " Grip Press");
        }

        // 5
        if (controller.GetPressUp(SteamVR_Controller.ButtonMask.Grip))
        {
            Debug.Log(left + " Grip Release");
        }

        if (controller.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Debug.Log("STOP TOUCHING ME!");
        }

        if (controller.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            TriggerSwitch(controllerGO);
        }

        if (controller.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
        {
            movementScript.Respawn();
        }

        //Debug.Log("Controller " + left + " has something " + controller.index + " // " + controller.transform.pos);
    }
    /* -------------------------------------------------------------------------------------------------------------------------------------------------------- //
    *
    *                                                                              Object Menu
    *  // -------------------------------------------------------------------------------------------------------------------------------------------------------- */

    void ObjectMenu()
    {
        if (ControllerRight)
        {
            if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
            {
                touchLast = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x;
            }
            if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
            {
                touchCurrent = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x;
                distance     = touchCurrent - touchLast;
                touchLast    = touchCurrent;
                swipeSum    += distance;

                if (!hasSwipedRight)
                {
                    if (swipeSum > 0.3f)
                    {
                        swipeSum = 0;
                        SwipeRight();
                        hasSwipedRight = true;
                    }
                }

                if (!hasSwipedLeft)
                {
                    if (swipeSum < -0.3f)
                    {
                        swipeSum = 0;
                        SwipeLeft();
                        hasSwipedLeft  = true;
                        Active.enabled = true;
                    }
                }
            }

            if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad))
            {
                Active.enabled = false;
                int currentObject = objectMenuManager.currentObject;
                objectMenuManager.objectList[currentObject].SetActive(false);

                swipeSum       = 0;
                touchCurrent   = 0;
                touchLast      = 0;
                hasSwipedLeft  = false;
                hasSwipedRight = false;
            }

            if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger) && device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
            {
                SpawnObject();
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        device = SteamVR_Controller.Input((int)trackedObject.index);


        // ------------------------------------------------------------------------------------------ //
        // track users' finger when hovering the trackpad and store in array
        fingerCoordenatesX = device.GetAxis().x;
        fingerCoordenatesY = device.GetAxis().y;
    }
        private void Update()
        {
            controllerIndex = (uint)trackedController.index;
            device = SteamVR_Controller.Input((int)controllerIndex);

            Vector2 currentTriggerAxis = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger);
            Vector2 currentTouchpadAxis = device.GetAxis();

            //Trigger
            if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
            {
                OnTriggerPressed(SetButtonEvent(ref triggerPressed, true, currentTriggerAxis.x));
                EmitAlias(ButtonAlias.Trigger, true, currentTriggerAxis.x, ref triggerPressed);
            }
            else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
            {
                OnTriggerReleased(SetButtonEvent(ref triggerPressed, false, 0f));
                EmitAlias(ButtonAlias.Trigger, false, 0f, ref triggerPressed);
            }
            else
            {
                if (Vector2ShallowEquals(triggerAxis, currentTriggerAxis))
                {
                    triggerAxisChanged = false;
                }
                else
                {
                    OnTriggerAxisChanged(SetButtonEvent(ref triggerAxisChanged, true, currentTriggerAxis.x));
                }
            }

            //ApplicationMenu
            if (device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
            {
                OnApplicationMenuPressed(SetButtonEvent(ref applicationMenuPressed, true, 1f));
                EmitAlias(ButtonAlias.Application_Menu, true, 1f, ref applicationMenuPressed);
            }
            else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.ApplicationMenu))
            {

                OnApplicationMenuReleased(SetButtonEvent(ref applicationMenuPressed, false, 0f));
                EmitAlias(ButtonAlias.Application_Menu, false, 0f, ref applicationMenuPressed);
            }

            //Grip
            if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Grip))
            {
                OnGripPressed(SetButtonEvent(ref gripPressed, true, 1f));
                EmitAlias(ButtonAlias.Grip, true, 1f, ref gripPressed);
            }
            else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Grip))
            {
                OnGripReleased(SetButtonEvent(ref gripPressed, false, 0f));
                EmitAlias(ButtonAlias.Grip, false, 0f, ref gripPressed);
            }

            //Touchpad Pressed
            if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
            {
                OnTouchpadPressed(SetButtonEvent(ref touchpadPressed, true, 1f));
                EmitAlias(ButtonAlias.Touchpad_Press, true, 1f, ref touchpadPressed);
            }
            else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad))
            {
                OnTouchpadReleased(SetButtonEvent(ref touchpadPressed, false, 0f));
                EmitAlias(ButtonAlias.Touchpad_Press, false, 0f, ref touchpadPressed);
            }

            //Touchpad Touched
            if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
            {
                OnTouchpadTouchStart(SetButtonEvent(ref touchpadTouched, true, 1f));
                EmitAlias(ButtonAlias.Touchpad_Touch, true, 1f, ref touchpadTouched);
            }
            else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad))
            {
                OnTouchpadTouchEnd(SetButtonEvent(ref touchpadTouched, false, 0f));
                EmitAlias(ButtonAlias.Touchpad_Touch, false, 0f, ref touchpadTouched);
            }
            else
            {
                if (Vector2ShallowEquals(touchpadAxis, currentTouchpadAxis))
                {
                    touchpadAxisChanged = false;
                }
                else {
                    OnTouchpadAxisChanged(SetButtonEvent(ref touchpadTouched, true, 1f));
                    touchpadAxisChanged = true;
                }
            }

            // Save current touch and trigger settings to detect next change.
            touchpadAxis = new Vector2(currentTouchpadAxis.x, currentTouchpadAxis.y);
            triggerAxis = new Vector2(currentTriggerAxis.x, currentTriggerAxis.y);
        }
示例#32
0
    // Use this for initialization
    void Start()
    {
        GameObject controller = this.transform.parent.gameObject;
        SteamVR_TrackedObject trackedObject = controller.GetComponent<SteamVR_TrackedObject>();
        device = SteamVR_Controller.Input((int)trackedObject.index);

        this.UpdateAsObservable()
            .Subscribe(v => {
                var currentPosition = this.transform.position;
                speed = (currentPosition - oldPosition) / Time.deltaTime;
                oldPosition = currentPosition;

                var currenRotaion = this.transform.forward;
                angularVelocity = Quaternion.FromToRotation(oldRotation,currenRotaion);
                oldRotation = currenRotaion;
            });

        /*
        this.OnCollisionEnterAsObservable()
            .Where(v => speed.magnitude > 0.5f)
            .Subscribe(v =>
                {
                    v.gameObject.GetComponent<Rigidbody>().AddForce(speed / 0.5f, ForceMode.Impulse);
                }
            );*/

        //つかむ動作をしたとき
        this.OnTriggerStayAsObservable()
            .Where(v => v.GetComponent<GrabbableObject>() != null)
            .Where(v => grabbingObject == null)
            .Where(v => device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
            .Select(v => v.gameObject)
            .Where(v => v.GetComponent<IGrabbable>().Grabbed == false)
            .Subscribe(v => GrabAction(v));

        //手を放したとき
        this.UpdateAsObservable()
            .Where(_ => device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
            .Where(_ => grabbingObject != null)
            .Where(_ => grabbingObject.GetComponent<IGrabbable>() != null)
            .Subscribe(_ => UnGrabAction(grabbingObject,true));

        //道具をつかんだとき
        this.OnTriggerStayAsObservable()
            .Where(v => v.GetComponent<IGrippable>() != null)
            .Where(v => grabbingObject == null)
            .Where(v => device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
            .Select(v => v.gameObject)
            .Where(v => v.GetComponent<IGrippable>().Grabbed == false)
            .Subscribe(v => GripAction(v));

        //道具を放したとき
        this.UpdateAsObservable()
            .Where(_ => device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
            .Where(_ => grabbingObject != null)
            .Where(_ => grabbingObject.GetComponent<IGrippable>() != null)
            .Select(_ => grabbingObject)
            .Subscribe(v => UnGripAction(v,true));

        //道具を切り替えたとき
        this.OnTriggerStayAsObservable()
            .Where(v => v.GetComponent<IGrippable>() != null)
            .Where(v => grabbingObject == null)
            .Where(v => device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
            .Select(v => v.gameObject)
            .Where(v => v.GetComponent<IGrippable>().Grabbed == true)
            .Subscribe(v => SwichGripAction(v,v.transform.parent.gameObject));

        //道具のトリガーを引いたとき
        this.UpdateAsObservable()
            .Where(_ => grabbingObject != null)
            .Where(_ => grabbingObject.GetComponent<IShootable>() != null)
            .Where(_ => Mathf.Abs(device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x) > 0.0f)
            .Select(_ => grabbingObject)
            .Subscribe(v =>
                {
                    grabbingObject.GetComponent<IShootable>().Shot(device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x);
                }
            );
    }
    void Update()
    {
        if (!isServer || !isLocalPlayer)
            return;
        float xLeftInput = 0;
        float zLeftInput = 0;
        float xRightInput = 0;
        float zRightInput = 0;
        bool leftActive = true;
        // Setting up the Vive controllers
        bool leftGripPressed = false;
        try {
            leftController = SteamVR_Controller.Input((int)leftTrackedObject.index);
            leftGripPressed = leftController.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip);
            if (leftController.GetPress(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad)) {
                // Get the left inputs
                xLeftInput = leftController.GetAxis().x;
                zLeftInput = leftController.GetAxis ().y;
            }

        } catch (System.Exception) {
            //Just roll with it
            leftActive = false;
        }
        bool rightGripPressed = false;
        try {
            rightController = SteamVR_Controller.Input((int)rightTrackedObject.index);
            rightGripPressed = rightController.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip);
            if (rightController.GetPress(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad)) {
                // Get the left inputs
                xRightInput = rightController.GetAxis().x;
                zRightInput = rightController.GetAxis ().y;
            }
        } catch (System.Exception) {
            if (!leftActive) {
                Debug.Log ("No controllers Connected");
            }
        }

        //Calculate movement velocity  as a 3D vector
        // Strafe
        float _xMov = xLeftInput + xRightInput;
        // Forward
        float _zMov = zLeftInput + zRightInput;

        Vector3 _movHorizontal;
        Vector3 _movVertical;

        // Move relative to the first person camera
        if (isServer) {
            _movHorizontal = firstPersonCam.transform.right * _xMov;
            _movVertical = firstPersonCam.transform.forward * _zMov;
        }

        finalSpeed = speed;

        // Final movement vector
        Vector3 _velocity = (_movHorizontal + _movVertical).normalized * finalSpeed;
        bool gripsPressed = (leftGripPressed || rightGripPressed);
        //if the player is jumping
        if (gripsPressed && !isFalling)
        {
            isFalling = true;
            playerAudio.PlayOneShot(jumpSound, 0.6f);
            motor.Jump();
        }

        // Apply movement
        motor.Move(_velocity);

        // Calculate rotation as a 3D vector (turning around)
        float _yRot = Input.GetAxisRaw("Mouse X");

        Vector3 _rotation = new Vector3(0f, _yRot, 0f) * lookSensitivity;

        // Apply rotation
        motor.Rotate(_rotation);

        // Calculate camera rotation as a 3D vector (turning around)
        float _xRot = Input.GetAxisRaw("Mouse Y");

        // REVERT: Change yRot to 0f
        Vector3 _cameraRotation = new Vector3(_xRot, _yRot, 0f) * lookSensitivity;

        // Apply rotation
        motor.RotateCamera(_cameraRotation);
    }