void handleStateChanges()
    {
        bool stateIsValid = vrSystem.GetControllerState((uint)index, ref state,
                                                        (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VRControllerState_t)));


        if (!stateIsValid)
        {
            Debug.Log("Invalid State for Idx: " + index);
        }

        if (stateIsValid && state.GetHashCode() != prevState.GetHashCode())
        {
            if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Trigger) != 0 &&
                (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.Trigger) == 0)
            {
                if (activeBeamInterceptObj == null)
                {
                    return;
                }
                activeBeamInterceptObj.grab(this);
            }
            else if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Trigger) == 0 &&
                     (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.Trigger) != 0)
            {
                if (activeBeamInterceptObj == null)
                {
                    return;
                }
                activeBeamInterceptObj.release(this);
                activeBeamInterceptObj = null;
            }

            prevState = state;
        }
    }
    void handleStateChanges()
    {
        bool stateIsValid = vrSystem.GetControllerState((uint)index, ref state);

        if (!stateIsValid)
        {
            Debug.Log("Invalid State for Idx: " + index);
        }

        if (stateIsValid && state.GetHashCode() != prevState.GetHashCode())
        {
            if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.ApplicationMenu) != 0 &&
                (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.ApplicationMenu) == 0)
            {
                toggleMenu();
            }


            if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Trigger) != 0 &&
                (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.Trigger) == 0)
            {
                // just pulled the trigger
                castBeamAnyway = true;
                triggerPulled  = true;

                if (currNodeCollided != null)
                {
                    updateNodeCollidedPosition = true;
                    currNodeCollided.GetComponentInChildren <Collider>().enabled = false;
                    NodeInfo info = fDirScript.getNodeInfo(currNodeCollided.name);
                    info.positionIsStationary = true;
                }
            }
            else if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Trigger) == 0 &&
                     (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.Trigger) != 0)
            {
                // just released the trigger
                castBeamAnyway             = false;
                updateSlider               = false;
                updateNodeSelectedPosition = false;
                triggerPulled              = false;

                if (currNodeSelected != null)
                {
                    NodeInfo info = fDirScript.getNodeInfo(currNodeSelected.name);
                    if (info != null)
                    {
                        info.positionIsStationary = false;
                        info.interState           = NodeInteractionState.NONE;
                        fDirScript.numHighlighed--;
                    }

                    currNodeSelected = null;
                }

                if (currNodeCollided != null)
                {
                    updateNodeCollidedPosition = false;
                    currNodeCollided.GetComponentInChildren <Collider>().enabled = true;
                    NodeInfo info = fDirScript.getNodeInfo(currNodeCollided.name);
                    info.positionIsStationary = false;
                }
            }

            if (prevState.rAxis1.x < 1.0f && state.rAxis1.x == 1.0f)
            {
                // just pulled the trigger in all the way
                if (currNodeCollided != null)
                {
                    NodeInfo info = fDirScript.getNodeInfo(currNodeCollided.name);
                    if (info.prevInterState == NodeInteractionState.SELECTED)
                    {
                        info.prevInterState = NodeInteractionState.NONE;
                    }
                    else
                    {
                        info.prevInterState = NodeInteractionState.SELECTED;
                    }
                }
                else if (currMenuSubObject != null)
                {
                    if (currMenuSubObject.name.Equals("ForceBox"))
                    {
                        menuManager.toggleForce();
                    }
                    else if (currMenuSubObject.name.Equals("ShowLinesBox"))
                    {
                        menuManager.toggleShowLines();
                    }
                    else if (currMenuSubObject.name.Equals("NodePointerBox"))
                    {
                        menuManager.toggleNodePointers();
                    }
                }
            }


            if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) != 0 &&
                (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) == 0)
            {
                fDirScript.grabSphereWithObject(gameObject);
            }
            else if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) == 0 &&
                     (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) != 0)
            {
                fDirScript.releaseSphereWithObject(gameObject);
            }



            prevState = state;
        }


        if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Touchpad) != 0)
        {
            float h = state.rAxis0.x;
            float v = state.rAxis0.y;

            if (Mathf.Abs(h) > Mathf.Abs(v))
            {
                fDirScript.rotateGraphHorizontal(h);
            }
            else
            {
                fDirScript.rotateGraphVertical(v);
            }
        }
    }
Exemple #3
0
    void updateControllerStates()
    {
        bool stateIsValid = vrSystem.GetControllerState((uint)index, ref state);

        if (stateIsValid && state.GetHashCode() != prevState.GetHashCode())
        {
            if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.ApplicationMenu) != 0 &&
                (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.ApplicationMenu) == 0)
            {
                // hit the menu button
                if (hasController)
                {
                    releaseController();
                }
                else
                {
                    hasController = true;
                    otherControllerScript.releaseController();
                    timelineGameObject.SetActive(true);
                    timelineGameObject.transform.SetParent(gameObject.transform);
                    timelineGameObject.transform.localPosition = new Vector3(0.0f, 0.0f, 0.1f);
                    timelineGameObject.transform.localRotation = Quaternion.Euler(90.0f, 0.0f, 0.0f);
                }
            }


            if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) != 0 &&
                (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) == 0)
            {
                // hit the grip button
                gripPressed = true;

                if (otherControllerScript.isGripPressed())
                {
                    accordianManager.deactivate();
                    scaleTimeline = true;
                    currSliderScript.startScale(transform.position, otherController.transform.position);
                }
                else
                {
                    Vector3 dir = transform.forward - transform.up;
                    dir.y = 0.0f;
                    dir.Normalize();
                    Vector3 pos = transform.position;

                    // shoot a ray and see if the controller is pointed at the timeline

                    RaycastHit hitInfo;

                    // try for timeline slider
                    if (Physics.Raycast(deviceRay.origin, deviceRay.direction, out hitInfo, 30.0f, sliderMask))
                    {
                        accordianManager.setAccordianType(AccordianActionType.TIMELINE);
                    }
                    else
                    {
                        accordianManager.setAccordianType(AccordianActionType.SUBNETS);
                    }

                    accordianManager.activate(pos, dir);
                }
            }

            else if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) == 0 &&
                     (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) != 0)
            {
                gripPressed = false;
                currSliderScript.endScale();
                scaleTimeline = false;
                accordianManager.deactivate();
            }



            // trigger is being pressed
            if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Trigger) != 0)
            {
                // trigger completely pressed
                if (prevState.rAxis1.x < 1.0f && state.rAxis1.x >= 1.0f)
                {
                    handleTriggerClick();
                }
                // trigger released from completely pressed
                else if (state.rAxis1.x < 1.0f && prevState.rAxis1.x >= 1.0f)
                {
                    handleTriggerUnclick();
                }
            }

            if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Touchpad) != 0 &&
                (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.Touchpad) == 0)
            {
                if (Mathf.Abs(state.rAxis0.y) >= Mathf.Abs(state.rAxis0.x) && state.rAxis0.y < 0.0f)
                {
                    togglePlayAnimation();
                    otherControllerScript.togglePlayAnimation();
                }
                else
                {
                    int currTime = sqlConnClass.getTimeSliceIdx();
                    if (state.rAxis0.x < 0.0f)
                    {
                        sqlConnClass.setTimeSlice(currTime - 1);
                    }
                    else if (state.rAxis0.x > 0.0f)
                    {
                        sqlConnClass.setTimeSlice(currTime + 1);
                    }

                    float currPos = sqlConnClass.getTimeSliceFloat();
                    currSliderScript.updateSliderPosition(currPos);
                }
            }


            prevState = state;
        }


        if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) != 0)
        {
            accordianManager.tryToAdjustDistance(transform.position);
        }
    }