Get() public static method

Gets the current state of the given virtual 2-dimensional axis mask on the given controller mask. Returns the vector of the largest masked axis across all masked controllers. Values range from -1 to 1.
public static Get ( Axis2D virtualMask, Controller, controllerMask = Controller.Active ) : Vector2
virtualMask Axis2D
controllerMask Controller,
return Vector2
    private void ManipulateObject_Update()
    {
        if (OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger) || Input.GetKeyDown(KeyCode.C))
        {
            fsm.ChangeState(RaycastStates.Raycast);
        }
        if (OVRInput.GetDown(OVRInput.Button.Two) || Input.GetKeyDown(KeyCode.F))
        {
            fsm.ChangeState(RaycastStates.GrabbedObject);
        }
        // Sets the line
        this.line.SetPosition(0, transform.position);
        this.line.SetPosition(1, this.grabbedObject.position);
        // Position
        if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickUp) || Input.GetKey(KeyCode.UpArrow))
        {
            this.grabbedObject.transform.position += transform.TransformDirection(Vector3.up) * moveSpeed;
        }
        if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickDown) || Input.GetKey(KeyCode.DownArrow))
        {
            if (Vector3.Distance(transform.position, this.grabbedObject.transform.position) > 2)
            {
                this.grabbedObject.transform.position += transform.TransformDirection(Vector3.down) * moveSpeed;
            }
        }
        if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickLeft) || Input.GetKey(KeyCode.LeftArrow))
        {
            this.grabbedObject.transform.position += transform.TransformDirection(Vector3.left) * moveSpeed;
        }
        if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickRight) || Input.GetKey(KeyCode.RightArrow))
        {
            this.grabbedObject.transform.position += transform.TransformDirection(Vector3.right) * moveSpeed;
        }
        if (OVRInput.Get(OVRInput.Button.Four) || Input.GetKey(KeyCode.Q))
        {
            this.grabbedObject.transform.position += transform.TransformDirection(Vector3.forward) * moveSpeed;
        }
        if (OVRInput.Get(OVRInput.Button.Three) || Input.GetKey(KeyCode.E))
        {
            this.grabbedObject.transform.position += transform.TransformDirection(Vector3.back) * moveSpeed;
        }

        // Rotation
        if (OVRInput.GetDown(OVRInput.Button.SecondaryThumbstickUp) || Input.GetKeyDown(KeyCode.I))
        {
            //this.grabbedObject.Rotate(Vector3.right * Time.deltaTime * rotationSpeed);
            this.grabbedObject.Rotate(Vector3.right * 90);
        }
        if (OVRInput.GetDown(OVRInput.Button.SecondaryThumbstickDown) || Input.GetKeyDown(KeyCode.K))
        {
            //this.grabbedObject.Rotate(Vector3.left * Time.deltaTime * rotationSpeed);
            this.grabbedObject.Rotate(Vector3.left * 90);
        }
        if (OVRInput.GetDown(OVRInput.Button.SecondaryThumbstickLeft) || Input.GetKeyDown(KeyCode.J))
        {
            //this.grabbedObject.Rotate(Vector3.up * Time.deltaTime * rotationSpeed);
            this.grabbedObject.Rotate(Vector3.up * 90);
        }
        if (OVRInput.GetDown(OVRInput.Button.SecondaryThumbstickRight) || Input.GetKeyDown(KeyCode.L))
        {
            //this.grabbedObject.Rotate(Vector3.down * Time.deltaTime * rotationSpeed);
            this.grabbedObject.Rotate(Vector3.down * 90);
        }
    }
 public bool ButtonTouched(OVRInput.Touch button)
 {
     return(OVRInput.Get(button, controller));
 }
Esempio n. 3
0
 bool getRightHandTrigger()
 {
     return(OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger) > TRIGGER_THRESHOLD);
 }
Esempio n. 4
0
 protected virtual void Update()
 {
     Receive(OVRInput.Get(axis, controller));
 }
 public Vector2 GetAxis2D(OVRInput.Axis2D axis)
 {
     return(OVRInput.Get(axis, controller));
 }
Esempio n. 6
0
    // Update is called once per frame
    void Update()
    {
        if (this.GetComponent <OVRGrabbable>().isGrabbed)
        {
            InputDevice     leftController   = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand);
            InputDevice     rightController  = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
            OVRInput.Axis1D activeController = OVRInput.Axis1D.SecondaryIndexTrigger;

            OVRGrabber hand = this.gameObject.GetComponent <OVRGrabbable>().grabbedBy;
            if (hand.name == "LeftHandAnchor")
            {
                activeController = OVRInput.Axis1D.PrimaryIndexTrigger;
            }
            else if (hand.name == "RightHandAnchor")
            {
                activeController = OVRInput.Axis1D.SecondaryIndexTrigger;
            }

            //if (OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, activeController))
            if (OVRInput.Get(activeController) == 1)
            {
                if (bucketCounter > 0 && !buttonDown)
                {
                    HapticEvent(0.5f);
                    buttonDown     = true;
                    bucketCounter -= 1;
                    switch (bucketCounter)
                    {
                    case 1:
                        transform.Find("bucket filled2").gameObject.SetActive(false);
                        transform.Find("bucket filled1").gameObject.SetActive(true);
                        break;

                    case 2:
                        transform.Find("bucket filled3").gameObject.SetActive(false);
                        transform.Find("bucket filled2").gameObject.SetActive(true);
                        break;

                    case 3:
                        transform.Find("bucket filled4").gameObject.SetActive(false);
                        transform.Find("bucket filled3").gameObject.SetActive(true);
                        break;

                    case 4:
                        transform.Find("bucket filled5").gameObject.SetActive(false);
                        transform.Find("bucket filled4").gameObject.SetActive(true);
                        break;

                    case 0:
                        transform.Find("bucket filled1").gameObject.SetActive(false);
                        break;

                    default:
                        break;
                    }
                    Transform cube = Instantiate(cubePrefab, this.transform.position, Quaternion.identity);
                    audio.clip = empty;
                    audio.Play();
                    // cube.gameObject.GetComponent<SandCube>().hasNotBeenGrabbed = false;
                }
            }
            if (OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger) == 0)
            {
                buttonDown = false;
            }
        }
    }
Esempio n. 7
0
    void AddData()
    {
        RightP_X = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch).x.ToString();
        RightP_Y = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch).y.ToString();
        RightP_Z = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch).z.ToString();

        RightR_W = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch).w.ToString();
        RightR_X = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch).x.ToString();
        RightR_Y = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch).y.ToString();
        RightR_Z = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch).z.ToString();


        LeftP_X = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch).x.ToString();
        LeftP_Y = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch).y.ToString();
        LeftP_Z = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch).z.ToString();

        LeftR_W = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch).w.ToString();
        LeftR_X = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch).x.ToString();
        LeftR_Y = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch).y.ToString();
        LeftR_Z = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch).z.ToString();


        playerpos_X = Camera.main.gameObject.transform.position.x.ToString();
        playerpos_Y = Camera.main.gameObject.transform.position.y.ToString();
        playerpos_Z = Camera.main.gameObject.transform.position.z.ToString();


        playerrot_W = Camera.main.gameObject.transform.rotation.w.ToString();
        playerrot_X = Camera.main.gameObject.transform.rotation.x.ToString();
        playerrot_Y = Camera.main.gameObject.transform.rotation.y.ToString();
        playerrot_Z = Camera.main.gameObject.transform.rotation.z.ToString();

        Raccel_X = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch).x.ToString();
        Raccel_Y = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch).y.ToString();
        Raccel_Z = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch).z.ToString();

        Laccel_X = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch).x.ToString();
        Laccel_Y = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch).y.ToString();
        Laccel_Z = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch).z.ToString();

        Cam_pos_X = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye).x.ToString();
        Cam_pos_Y = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye).y.ToString();
        Cam_pos_Z = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye).z.ToString();

        Cam_rot_X = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye).x.ToString();
        Cam_rot_Y = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye).y.ToString();
        Cam_rot_Z = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye).z.ToString();
        Cam_rot_W = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye).w.ToString();

        Raaccel_X = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.RTouch).x.ToString();
        Raaccel_Y = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.RTouch).y.ToString();
        Raaccel_Z = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.RTouch).z.ToString();

        Laaccel_X = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.LTouch).x.ToString();
        Laaccel_Y = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.LTouch).y.ToString();
        Laaccel_Z = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.LTouch).z.ToString();

        Rvel_X = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch).x.ToString();
        Rvel_Y = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch).y.ToString();
        Rvel_Z = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch).z.ToString();

        Lvel_X = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch).x.ToString();
        Lvel_Y = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch).y.ToString();
        Lvel_Z = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch).z.ToString();

        Ravel_X = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch).x.ToString();
        Ravel_Y = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch).y.ToString();
        Ravel_Z = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch).z.ToString();

        Lavel_X = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch).x.ToString();
        Lavel_Y = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch).y.ToString();
        Lavel_Z = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch).z.ToString();

        PrimaryHandTrigger   = OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.LTouch).ToString();
        SecondaryHandTrigger = OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.RTouch).ToString();



        string[]        rowDataTemp = new string[55];
        List <string[]> rowData1    = new List <string[]>();

        // You can add up the values in as many cells as you want.

        rowDataTemp    = new string[55];
        rowDataTemp[0] = Time.frameCount.ToString();
        rowDataTemp[1] = RightP_X;
        rowDataTemp[2] = RightP_Y;
        rowDataTemp[3] = RightP_Z;

        rowDataTemp[4] = RightR_W;
        rowDataTemp[5] = RightR_X;
        rowDataTemp[6] = RightR_Y;
        rowDataTemp[7] = RightR_Z;

        rowDataTemp[8]  = LeftP_X;
        rowDataTemp[9]  = LeftP_Y;
        rowDataTemp[10] = LeftP_Z;

        rowDataTemp[11] = LeftR_W;
        rowDataTemp[12] = LeftR_X;
        rowDataTemp[13] = LeftR_Y;
        rowDataTemp[14] = LeftR_X;

        rowDataTemp[15] = playerpos_X;
        rowDataTemp[16] = playerpos_Y;
        rowDataTemp[17] = playerpos_Z;

        rowDataTemp[18] = playerrot_W;
        rowDataTemp[19] = playerrot_X;
        rowDataTemp[20] = playerrot_Y;
        rowDataTemp[21] = playerrot_Z;

        rowDataTemp[22] = Raccel_X;
        rowDataTemp[23] = Raccel_Y;
        rowDataTemp[24] = Raccel_Z;

        rowDataTemp[25] = Laccel_X;
        rowDataTemp[26] = Laccel_Y;
        rowDataTemp[27] = Laccel_Z;

        rowDataTemp[28] = Cam_pos_X;
        rowDataTemp[29] = Cam_pos_Y;
        rowDataTemp[30] = Cam_pos_Z;

        rowDataTemp[31] = Cam_rot_W;
        rowDataTemp[32] = Cam_rot_X;
        rowDataTemp[33] = Cam_rot_Y;
        rowDataTemp[34] = Cam_rot_Z;

        rowDataTemp[35] = Raaccel_X;
        rowDataTemp[36] = Raaccel_X;
        rowDataTemp[37] = Raaccel_X;

        rowDataTemp[38] = Laaccel_X;
        rowDataTemp[39] = Laaccel_Y;
        rowDataTemp[40] = Laaccel_Z;

        rowDataTemp[41] = Rvel_X;
        rowDataTemp[42] = Rvel_X;
        rowDataTemp[43] = Rvel_X;

        rowDataTemp[44] = Lvel_X;
        rowDataTemp[45] = Lvel_Y;
        rowDataTemp[46] = Lvel_Z;

        rowDataTemp[47] = Ravel_X;
        rowDataTemp[48] = Ravel_X;
        rowDataTemp[49] = Ravel_X;

        rowDataTemp[50] = Lavel_X;
        rowDataTemp[51] = Lavel_Y;
        rowDataTemp[52] = Lavel_Z;

        rowDataTemp[53] = PrimaryHandTrigger;
        rowDataTemp[54] = SecondaryHandTrigger;



        rowData1.Add(rowDataTemp);

        string[][] output = new string[rowData.Count][];

        for (int i = 0; i < output.Length; i++)
        {
            output[i] = rowData1[i];
        }

        int    length    = output.GetLength(0);
        string delimiter = ",";

        StringBuilder sb1 = new StringBuilder();

        for (int index = 0; index < length; index++)
        {
            sb1.AppendLine(string.Join(delimiter, output[index]));
        }


        StreamWriter outStream = File.AppendText(filePath + fileName);

        outStream.Write(sb1);
        outStream.Close();
    }
Esempio n. 8
0
    void Update()
    {
        bool controllerConnected = OVRInput.IsControllerConnected(m_controller);

        if ((controllerConnected != m_prevControllerConnected) || !m_prevControllerConnectedCached || (m_hasInputFocus != m_hasInputFocusPrev))
        {
            if (activeControllerType == ControllerType.Rift)
            {
                m_modelOculusTouchQuestAndRiftSLeftController.SetActive(false);
                m_modelOculusTouchQuestAndRiftSRightController.SetActive(false);
                m_modelOculusTouchRiftLeftController.SetActive(controllerConnected && (m_controller == OVRInput.Controller.LTouch));
                m_modelOculusTouchRiftRightController.SetActive(controllerConnected && (m_controller == OVRInput.Controller.RTouch));
                m_modelOculusTouchQuest2LeftController.SetActive(false);
                m_modelOculusTouchQuest2RightController.SetActive(false);

                m_animator = m_controller == OVRInput.Controller.LTouch ? m_modelOculusTouchRiftLeftController.GetComponent <Animator>() :
                             m_modelOculusTouchRiftRightController.GetComponent <Animator>();
                m_activeController = m_controller == OVRInput.Controller.LTouch ? m_modelOculusTouchRiftLeftController : m_modelOculusTouchRiftRightController;
            }
            else if (activeControllerType == ControllerType.Quest2)
            {
                m_modelOculusTouchQuestAndRiftSLeftController.SetActive(false);
                m_modelOculusTouchQuestAndRiftSRightController.SetActive(false);
                m_modelOculusTouchRiftLeftController.SetActive(false);
                m_modelOculusTouchRiftRightController.SetActive(false);
                m_modelOculusTouchQuest2LeftController.SetActive(controllerConnected && (m_controller == OVRInput.Controller.LTouch));
                m_modelOculusTouchQuest2RightController.SetActive(controllerConnected && (m_controller == OVRInput.Controller.RTouch));

                m_animator = m_controller == OVRInput.Controller.LTouch ? m_modelOculusTouchQuest2LeftController.GetComponent <Animator>() :
                             m_modelOculusTouchQuest2RightController.GetComponent <Animator>();
                m_activeController = m_controller == OVRInput.Controller.LTouch ? m_modelOculusTouchQuest2LeftController : m_modelOculusTouchQuest2RightController;
            }
            else             /*if (activeControllerType == ControllerType.QuestAndRiftS)*/
            {
                m_modelOculusTouchQuestAndRiftSLeftController.SetActive(controllerConnected && (m_controller == OVRInput.Controller.LTouch));
                m_modelOculusTouchQuestAndRiftSRightController.SetActive(controllerConnected && (m_controller == OVRInput.Controller.RTouch));
                m_modelOculusTouchRiftLeftController.SetActive(false);
                m_modelOculusTouchRiftRightController.SetActive(false);
                m_modelOculusTouchQuest2LeftController.SetActive(false);
                m_modelOculusTouchQuest2RightController.SetActive(false);

                m_animator = m_controller == OVRInput.Controller.LTouch ? m_modelOculusTouchQuestAndRiftSLeftController.GetComponent <Animator>() :
                             m_modelOculusTouchQuestAndRiftSRightController.GetComponent <Animator>();
                m_activeController = m_controller == OVRInput.Controller.LTouch ? m_modelOculusTouchQuestAndRiftSLeftController : m_modelOculusTouchQuestAndRiftSRightController;
            }

            m_activeController.SetActive(m_hasInputFocus && controllerConnected);

            m_prevControllerConnected       = controllerConnected;
            m_prevControllerConnectedCached = true;
            m_hasInputFocusPrev             = m_hasInputFocus;
        }

        if (m_animator != null)
        {
            m_animator.SetFloat("Button 1", OVRInput.Get(OVRInput.Button.One, m_controller) ? 1.0f : 0.0f);
            m_animator.SetFloat("Button 2", OVRInput.Get(OVRInput.Button.Two, m_controller) ? 1.0f : 0.0f);
            m_animator.SetFloat("Button 3", OVRInput.Get(OVRInput.Button.Start, m_controller) ? 1.0f : 0.0f);

            m_animator.SetFloat("Joy X", OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, m_controller).x);
            m_animator.SetFloat("Joy Y", OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, m_controller).y);

            m_animator.SetFloat("Trigger", OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, m_controller));
            m_animator.SetFloat("Grip", OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, m_controller));
        }
    }
Esempio n. 9
0
    void Update()
    {
        if (!paused)
        {
            time += Time.deltaTime;
        }
        if (OVRInput.GetDown(OVRInput.Button.One))
        {
            paused = !paused;
        }

        Vector3 lh = leftHand.transform.position;
        Vector3 rh = rightHand.transform.position;

        Vector3 lhv = transform.worldToLocalMatrix.MultiplyPoint(lh);
        Vector3 rhv = transform.worldToLocalMatrix.MultiplyPoint(rh);

        Vector3 v1 = lhv - olhv;
        Vector3 v2 = rhv - orhv;

        olhv = lhv;
        orhv = rhv;

        //Vector3 v1 = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTrackedRemote);
        //Vector3 v2 = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTrackedRemote);

        //Matrix4x4 trs = Matrix4x4.TRS(Vector3.zero, Quaternion.Inverse(transform.rotation), transform.localScale);
        //v1 = transform.worldToLocalMatrix.MultiplyVector(v1);//trs.MultiplyVector(v1);
        //v2 = transform.worldToLocalMatrix.MultiplyVector(v2);//trs.MultiplyVector(v2);

        float lf = -OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick).y;
        float rf = -OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick).y;

        float lt = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger);
        float rt = OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger);

        if (OVRInput.GetDown(OVRInput.Button.Two))
        {
            rff = !rff;
        }
        if (OVRInput.GetDown(OVRInput.Button.Four))
        {
            lff = !lff;
        }

        if (lt > 0 && Mathf.Abs(lf) > 0)
        {
            lr = Mathf.Clamp(lr - lt * 0.02f * Mathf.Sign(lf), 0.05f, 0.95f);
        }

        if (rt > 0 && Mathf.Abs(rf) > 0)
        {
            rr = Mathf.Clamp(rr - rt * 0.02f * Mathf.Sign(rf), 0.05f, 0.95f);
        }

        leftHand.transform.GetChild(0).transform.localScale  = handSize * transform.lossyScale;
        rightHand.transform.GetChild(0).transform.localScale = handSize * transform.lossyScale;

        float[] g1 = { lhv.x, lhv.y, lhv.z, lf };
        float[] g2 = { rhv.x, rhv.y, rhv.z, rf };

        computeShader.SetBool("paused", paused);
        computeShader.SetBool("useOpt", useOpt);

        computeShader.SetFloat("time", time);
        computeShader.SetFloat("deltaTime", Time.fixedDeltaTime);

        computeShader.SetFloats("g1", g1);
        computeShader.SetFloats("g2", g2);

        computeShader.SetVector("v1", v1);
        computeShader.SetVector("v2", v2);

        computeShader.SetFloat("speed", speed);
        computeShader.SetFloat("maxForce", maxForce);
        computeShader.SetFloat("radius", radius);
        computeShader.SetFloat("fov", fov);
        computeShader.SetFloat("randomness", randomness);

        computeShader.SetFloat("aSight", aSight);
        computeShader.SetFloat("cSight", cSight);
        computeShader.SetFloat("sSight", sSight);
        computeShader.SetFloat("aWeight", aWeight);
        computeShader.SetFloat("cWeight", cWeight);
        computeShader.SetFloat("sWeight", sWeight);

        computeShader.SetFloat("lr", lr);
        computeShader.SetFloat("rr", rr);
        computeShader.SetBool("rff", rff);
        computeShader.SetBool("lff", lff);

        computeShader.Dispatch(zeroBuffers, bGroups, 1, 1);
        computeShader.Dispatch(countBins, pGroups, 1, 1);
        computeShader.Dispatch(copyCounts, bGroups, 1, 1);

        for (int o = 1; o < numBins; o *= 2)
        {
            computeShader.SetInt("o", o);
            computeShader.Dispatch(scanIter, bGroups, 1, 1);
            computeShader.Dispatch(swapBuffers, bGroups, 1, 1);
        }

        computeShader.Dispatch(sortBins, pGroups, 1, 1);
        computeShader.Dispatch(swarm, pGroups, 1, 1);

        // int[] bleh = new int[numBins];
        // int[] bleh2 = new int[numBins];
        // int[] bleh3 = new int[2 * numBins];
        // binCounts.GetData(bleh);
        // temp.GetData(bleh3);
        // binIds.GetData(bleh2);

        // string str = "cnt: ";
        // string str3 = "tmp: ";
        // string str2 = "ids: ";
        // for (int q = 0; q < 2 * numBins; q++)
        // {
        //     if (q < numBins)
        //     {
        //         str += bleh[q] + ", ";
        //         str2 += bleh2[q] + ", ";
        //     }
        //     str3 += bleh3[q] + ", ";
        // }
        // print(str);
        // print(str3);
        // print(str2);
        // print("");
    }
Esempio n. 10
0
    // FixedUpdate is called once per frame and deals with Physics
    private void FixedUpdate()
    {
        // Updates app with remote inputs
        OVRInput.FixedUpdate();

        // If player presses touch button/spacebar from ground then jump in the air
        if ((OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger) || Input.GetKeyDown(KeyCode.Space)) && rb.position.y < 4.2f)
        {
            rb.AddExplosionForce(jump * Time.deltaTime, rb.position, 7f, 9f, ForceMode.Impulse);
        }
        // If player is in the air, increase gravity
        if (rb.velocity.y > 0)
        {
            rb.AddForce(Vector2.down * Physics2D.gravity.y * fall * Time.deltaTime);
        }
        // If touch position on x/y touchpad is found
        if ((OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad).x != 0) && (OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad).y != 0))
        {
            touch_x = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad).x;
            touch_y = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad).y;

            if (touch_x < 0 && touch_y < 0)
            {
                //If negative x/y then compare values
                if (touch_y <= touch_x)
                {
                    //fbforce
                    rb.AddForce(new Vector3(touch_x * damper, 0, touch_y) * umovement * Time.deltaTime, ForceMode.Impulse);
                    rb.AddTorque(new Vector3(touch_y, 0, touch_x * damper) * umovement * Time.deltaTime, ForceMode.Impulse);
                }
                else
                {
                    //sbs
                    rb.AddForce(new Vector3(touch_x, 0, touch_y * damper) * umovement * Time.deltaTime, ForceMode.Impulse);
                    rb.AddTorque(new Vector3(0, touch_x * damper, touch_y) * umovement * Time.deltaTime, ForceMode.Impulse);
                }
            }
            else
            {
                if (touch_y >= touch_x)
                {
                    //fbforce
                    rb.AddForce(new Vector3(touch_x * damper, 0, touch_y) * umovement * Time.deltaTime, ForceMode.Impulse);
                    rb.AddTorque(new Vector3(touch_y, 0, touch_x * damper) * umovement * Time.deltaTime, ForceMode.Impulse);
                }
                else
                {
                    //sbs
                    rb.AddForce(new Vector3(touch_x, 0, touch_y * damper) * umovement * Time.deltaTime, ForceMode.Impulse);
                    rb.AddTorque(new Vector3(0, touch_x * damper, touch_y) * umovement * Time.deltaTime, ForceMode.Impulse);
                }
            }
        }
        else
        {
            //get speed on x & y axis
            speed_x = Input.GetAxis("Horizontal");
            speed_y = Input.GetAxis("Vertical");

            //If w is pressed move the z axis forward 500 + Rotate Player
            if (Input.GetKey("w") || Input.GetKey(KeyCode.UpArrow))
            {
                //fbforce
                rb.AddForce(Vector3.forward * umovement * Time.deltaTime, ForceMode.Impulse);
                rb.AddTorque(new Vector3(speed_y, 0, speed_x) * umovement * Time.deltaTime, ForceMode.Impulse);
            }
            //If s is pressed move the z axis back 500
            if (Input.GetKey("s") || Input.GetKey(KeyCode.DownArrow))
            {
                //fbforce
                rb.AddForce(Vector3.back * umovement * Time.deltaTime, ForceMode.Impulse);
                rb.AddTorque(new Vector3(speed_y, 0, speed_x) * -umovement * Time.deltaTime, ForceMode.Impulse);
            }

            //If d is pressed move the x axis 500
            if (Input.GetKey("d") || Input.GetKey(KeyCode.RightArrow))
            {
                //sbs
                rb.AddForce(Vector3.right * umovement * Time.deltaTime, ForceMode.Impulse);
                rb.AddTorque(new Vector3(0, speed_x, speed_y) * umovement * Time.deltaTime, ForceMode.Impulse);
            }

            //If a is pressed move the x axis -500
            if (Input.GetKey("a") || Input.GetKey(KeyCode.LeftArrow))
            {
                //sbs
                rb.AddForce(Vector3.left * umovement * Time.deltaTime, ForceMode.Impulse);
                rb.AddTorque(new Vector3(0, speed_x, speed_y) * -umovement * Time.deltaTime, ForceMode.Impulse);
            }
        }
    }
Esempio n. 11
0
 public override bool GetMouseButton(int button)
 {
     return(OVRInput.Get(clickbutton, controller));
 }
Esempio n. 12
0
    /*
     * void OnTriggerEnter(Collider other)
     * {
     *  if (other.tag == "Target1" || other.tag == "Target2" || other.tag == "Target3" || other.tag == "Target4" || other.tag == "Target5")
     *  {
     *      iscrashed = true;
     *  }
     * }
     */
    // Update is called once per frame
    void Update()
    {
        if (OVRInput.GetDown(OVRInput.Button.One))
        //if (Input.GetKeyDown("space"))
        {
            if (num == 0)
            {
                transform.Rotate(0, 180, 0);
                num += 1;
            }
            else if (num == 1)
            {
                text2.SetActive(false);
                text3.SetActive(true);
                num += 1;
            }
            else if (num == 2)
            {
                text3.SetActive(false);
                text4.SetActive(true);
                num += 1;
            }
            else
            {
                text4.SetActive(false);
                speed = 40.0f;
                start = true;
            }
        }
        if (start == true)
        {
            //Here start flight
            leftControl  = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
            rightControl = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
            // acceleration:
            speed += leftControl.y;  // left controller axis moving front/back
                                     //transform.position += new Vector3(1, 1, 1) * Time.deltaTime * speed;
            transform.Translate(0, 0, speed * Time.deltaTime);
            if (speed == 0)
            {
                speed = 0;
            }
            else if (speed < 10)
            {
                speed = 10;
            }
            if (speed > 150)
            {
                speed = 150;
            }
            //Debug.Log(speed);

            // yaw, pitch, roll:

            /*
             * if (OVRInput.GetDown(OVRInput.Button.One))  // Pressed "A" on right controller
             * {
             *  trackSwitch = !trackSwitch;  // turn on position and rotation tracking of touch controllers
             * }*/

            transform.Rotate(rightControl.y * 50 * Time.deltaTime, leftControl.x * 50 * Time.deltaTime, -rightControl.x * 50 * Time.deltaTime); // left/right movement flipped
        }
    }
Esempio n. 13
0
        public override void OnUpdate()
        {
            switch (button)
            {
            case setButton.One:
                switch (buttonType)
                {
                case setButtonType.getButton:
                    if (OVRInput.Get(OVRInput.Button.One, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    else
                    {
                        storeResult.Value = false;
                    }
                    break;

                case setButtonType.getButtonDown:
                    if (OVRInput.GetDown(OVRInput.Button.One, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    break;

                case setButtonType.getButtonUp:
                    if (OVRInput.GetUp(OVRInput.Button.One, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    break;
                }
                break;

            case setButton.Two:
                switch (buttonType)
                {
                case setButtonType.getButton:
                    if (OVRInput.Get(OVRInput.Button.Two, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    else
                    {
                        storeResult.Value = false;
                    }
                    break;

                case setButtonType.getButtonDown:
                    if (OVRInput.GetDown(OVRInput.Button.Two, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    break;

                case setButtonType.getButtonUp:
                    if (OVRInput.GetUp(OVRInput.Button.Two, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    break;
                }
                break;

            case setButton.Start:
                switch (buttonType)
                {
                case setButtonType.getButton:
                    if (OVRInput.Get(OVRInput.Button.Start, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    else
                    {
                        storeResult.Value = false;
                    }
                    break;

                case setButtonType.getButtonDown:
                    if (OVRInput.GetDown(OVRInput.Button.Start, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    break;

                case setButtonType.getButtonUp:
                    if (OVRInput.GetUp(OVRInput.Button.Start, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    break;
                }
                break;

            case setButton.PrimaryThumbstick:
                switch (buttonType)
                {
                case setButtonType.getButton:
                    if (OVRInput.Get(OVRInput.Button.PrimaryThumbstick, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    else
                    {
                        storeResult.Value = false;
                    }
                    break;

                case setButtonType.getButtonDown:
                    if (OVRInput.GetDown(OVRInput.Button.PrimaryThumbstick, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    break;

                case setButtonType.getButtonUp:
                    if (OVRInput.GetUp(OVRInput.Button.PrimaryThumbstick, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    break;
                }
                break;

            case setButton.PrimaryHandTrigger:
                switch (buttonType)
                {
                case setButtonType.getButton:
                    if (OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    else
                    {
                        storeResult.Value = false;
                    }
                    break;

                case setButtonType.getButtonDown:
                    if (OVRInput.GetDown(OVRInput.Button.PrimaryHandTrigger, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    break;

                case setButtonType.getButtonUp:
                    if (OVRInput.GetUp(OVRInput.Button.PrimaryHandTrigger, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    break;
                }
                break;

            case setButton.PrimaryIndexTrigger:
                switch (buttonType)
                {
                case setButtonType.getButton:
                    if (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    else
                    {
                        storeResult.Value = false;
                    }
                    break;

                case setButtonType.getButtonDown:
                    if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    break;

                case setButtonType.getButtonUp:
                    if (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger, controllerInput))
                    {
                        storeResult.Value = true;
                        Fsm.Event(sendEvent);
                    }
                    break;
                }
                break;
            }
        }
    public virtual void UpdateMovement()
    {
        if (HaltUpdateMovement)
        {
            return;
        }

        if (EnableLinearMovement)
        {
            bool moveForward = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow);
            bool moveLeft    = Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow);
            bool moveRight   = Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow);
            bool moveBack    = Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow);

            bool dpad_move = false;

            if (OVRInput.Get(OVRInput.Button.DpadUp))
            {
                moveForward = true;
                dpad_move   = true;
            }

            if (OVRInput.Get(OVRInput.Button.DpadDown))
            {
                moveBack  = true;
                dpad_move = true;
            }

            MoveScale = 1.0f;

            if ((moveForward && moveLeft) || (moveForward && moveRight) ||
                (moveBack && moveLeft) || (moveBack && moveRight))
            {
                MoveScale = 0.70710678f;
            }

            // No positional movement if we are in the air
            if (!Controller.isGrounded)
            {
                MoveScale = 0.0f;
            }

            MoveScale *= SimulationRate * Time.deltaTime;

            // Compute this for key movement
            float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

            // Run!
            if (dpad_move || Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
            {
                moveInfluence *= 2.0f;
            }

            Quaternion ort      = transform.rotation;
            Vector3    ortEuler = ort.eulerAngles;
            ortEuler.z = ortEuler.x = 0f;
            ort        = Quaternion.Euler(ortEuler);

            if (moveForward)
            {
                MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * Vector3.forward);
            }
            if (moveBack)
            {
                MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * BackAndSideDampen * Vector3.back);
            }
            if (moveLeft)
            {
                MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.left);
            }
            if (moveRight)
            {
                MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.right);
            }



            moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

#if !UNITY_ANDROID // LeftTrigger not avail on Android game pad
            moveInfluence *= 1.0f + OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger);
#endif

            Vector2 primaryAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
            if (RightMove == 1)
            {
                primaryAxis = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
            }

            // If speed quantization is enabled, adjust the input to the number of fixed speed steps.
            if (FixedSpeedSteps > 0)
            {
                primaryAxis.y = Mathf.Round(primaryAxis.y * FixedSpeedSteps) / FixedSpeedSteps;
                primaryAxis.x = Mathf.Round(primaryAxis.x * FixedSpeedSteps) / FixedSpeedSteps;
            }

            if (primaryAxis.y > 0.0f)
            {
                MoveThrottle += ort * (primaryAxis.y * transform.lossyScale.z * moveInfluence * Vector3.forward);
            }

            if (primaryAxis.y < 0.0f)
            {
                MoveThrottle += ort * (Mathf.Abs(primaryAxis.y) * transform.lossyScale.z * moveInfluence *
                                       BackAndSideDampen * Vector3.back);
            }

            if (primaryAxis.x < 0.0f)
            {
                MoveThrottle += ort * (Mathf.Abs(primaryAxis.x) * transform.lossyScale.x * moveInfluence *
                                       BackAndSideDampen * Vector3.left);
            }

            if (primaryAxis.x > 0.0f)
            {
                MoveThrottle += ort * (primaryAxis.x * transform.lossyScale.x * moveInfluence * BackAndSideDampen *
                                       Vector3.right);
            }
        }

        if (EnableRotation)
        {
            Vector3 euler           = transform.rotation.eulerAngles;
            float   rotateInfluence = SimulationRate * Time.deltaTime * RotationAmount * RotationScaleMultiplier;

            bool curHatLeft = OVRInput.Get(OVRInput.Button.PrimaryShoulder);

            if (curHatLeft && !prevHatLeft)
            {
                euler.y -= RotationRatchet;
            }

            prevHatLeft = curHatLeft;

            bool curHatRight = OVRInput.Get(OVRInput.Button.SecondaryShoulder);

            if (curHatRight && !prevHatRight)
            {
                euler.y += RotationRatchet;
            }

            prevHatRight = curHatRight;

            euler.y       += buttonRotation;
            buttonRotation = 0f;


#if !UNITY_ANDROID || UNITY_EDITOR
            if (!SkipMouseRotation)
            {
                euler.y += Input.GetAxis("Mouse X") * rotateInfluence * 3.25f;
            }
#endif

            if (SnapRotation)
            {
                if (OVRInput.Get(OVRInput.Button.SecondaryThumbstickLeft) ||
                    (RotationEitherThumbstick && OVRInput.Get(OVRInput.Button.PrimaryThumbstickLeft)))
                {
                    if (ReadyToSnapTurn)
                    {
                        euler.y        -= RotationRatchet;
                        ReadyToSnapTurn = false;
                    }
                }
                else if (OVRInput.Get(OVRInput.Button.SecondaryThumbstickRight) ||
                         (RotationEitherThumbstick && OVRInput.Get(OVRInput.Button.PrimaryThumbstickRight)))
                {
                    if (ReadyToSnapTurn)
                    {
                        euler.y        += RotationRatchet;
                        ReadyToSnapTurn = false;
                    }
                }
                else
                {
                    ReadyToSnapTurn = true;
                }
            }
            else
            {
                Vector2 secondaryAxis = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
                if (RightMove == 1)
                {
                    secondaryAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
                }
                if (RotationEitherThumbstick)
                {
                    Vector2 altSecondaryAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
                    if (RightMove == 1)
                    {
                        altSecondaryAxis = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
                    }
                    if (secondaryAxis.sqrMagnitude < altSecondaryAxis.sqrMagnitude)
                    {
                        secondaryAxis = altSecondaryAxis;
                    }
                }
                euler.y += secondaryAxis.x * rotateInfluence;
            }

            transform.rotation = Quaternion.Euler(euler);
        }
    }
Esempio n. 15
0
    public virtual void UpdateMovement()
    {
        if (HaltUpdateMovement)
        {
            return;
        }

        bool moveForward = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow);
        bool moveLeft    = Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow);
        bool moveRight   = Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow);
        bool moveBack    = Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow);

        bool dpad_move = false;

        if (OVRInput.Get(OVRInput.Button.DpadUp))
        {
            moveForward = true;
            dpad_move   = true;
        }

        if (OVRInput.Get(OVRInput.Button.DpadDown))
        {
            moveBack  = true;
            dpad_move = true;
        }

        MoveScale = 1.0f;

        if ((moveForward && moveLeft) || (moveForward && moveRight) ||
            (moveBack && moveLeft) || (moveBack && moveRight))
        {
            MoveScale = 0.70710678f;
        }

        // No positional movement if we are in the air
        if (!Controller.isGrounded)
        {
            MoveScale = 0.0f;
        }

        MoveScale *= SimulationRate * Time.deltaTime;

        // Compute this for key movement
        float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        if (dpad_move || Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            moveInfluence *= 2.0f;
        }

        Quaternion ort      = transform.rotation;
        Vector3    ortEuler = ort.eulerAngles;

        ortEuler.z = ortEuler.x = 0f;
        ort        = Quaternion.Euler(ortEuler);

        if (moveForward)
        {
            MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * Vector3.forward);
        }
        if (moveBack)
        {
            MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * BackAndSideDampen * Vector3.back);
        }
        if (moveLeft)
        {
            MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.left);
        }
        if (moveRight)
        {
            MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.right);
        }

        Vector3 euler = transform.rotation.eulerAngles;

        bool curHatLeft = OVRInput.Get(OVRInput.Button.PrimaryShoulder);

        if (curHatLeft && !prevHatLeft)
        {
            euler.y -= RotationRatchet;
        }

        prevHatLeft = curHatLeft;

        bool curHatRight = OVRInput.Get(OVRInput.Button.SecondaryShoulder);

        if (curHatRight && !prevHatRight)
        {
            euler.y += RotationRatchet;
        }

        prevHatRight = curHatRight;

        euler.y       += buttonRotation;
        buttonRotation = 0f;

        float rotateInfluence = SimulationRate * Time.deltaTime * RotationAmount * RotationScaleMultiplier;

#if !UNITY_ANDROID || UNITY_EDITOR
        if (!SkipMouseRotation)
        {
            euler.y += Input.GetAxis("Mouse X") * rotateInfluence * 3.25f;
        }
#endif

        moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

#if !UNITY_ANDROID // LeftTrigger not avail on Android game pad
        moveInfluence *= 1.0f + OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger);
#endif

        Vector2 primaryAxis = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);

        if (primaryAxis.y > 0.0f)
        {
            MoveThrottle += ort * (primaryAxis.y * transform.lossyScale.z * moveInfluence * Vector3.forward);
        }

        if (primaryAxis.y < 0.0f)
        {
            MoveThrottle += ort * (Mathf.Abs(primaryAxis.y) * transform.lossyScale.z * moveInfluence * BackAndSideDampen * Vector3.back);
        }

        if (primaryAxis.x < 0.0f)
        {
            MoveThrottle += ort * (Mathf.Abs(primaryAxis.x) * transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.left);
        }

        if (primaryAxis.x > 0.0f)
        {
            MoveThrottle += ort * (primaryAxis.x * transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.right);
        }

        Vector2 secondaryAxis = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);

        euler.y += secondaryAxis.x * rotateInfluence;

        transform.rotation = Quaternion.Euler(euler);
    }
Esempio n. 16
0
    void OnCollisionEnter(Collision col)
    {
        ///TODO: Left Hand not doing it correctly all of the times
        if (col.collider.tag == "Enemy" || col.collider.tag == "Mole")
        {
            //Left Hand
            if (gameObject.name == "hand_left" && OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger) >= 0.1 && OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger) >= 0.1 /*&& hand.velocity.magnitude >= speed*/)
            {
                if (col.collider.tag == "Mole")
                {
                    Debug.Log("Destroy");
                    Moles mole = col.gameObject.GetComponent <Moles> ();
                    mole.state = Moles.State.GOING_DOWN;
                    if (col.gameObject != temp)
                    {
                        temp = null;
                    }
                    if (temp == null)
                    {
                        molesScript.molesHit += 1;
                    }
                    temp = col.gameObject;
                    haptics.vibrate(true);
                }
                else
                {
                    Destroy(col.gameObject);
                    haptics.vibrate(true);
                }
                //Destroy the enemy
                //Destroy (col.gameObject);
            }
            //Right Hand
            else if (gameObject.name == "hand_right" && OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger) >= 0.1 && OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger) >= 0.1 /*&& hand.velocity.magnitude >= speed*/)
            {
                if (col.collider.tag == "Mole")
                {
                    Moles mole = col.gameObject.GetComponent <Moles>();
                    mole.state = Moles.State.GOING_DOWN;
                    if (col.gameObject != temp)
                    {
                        temp = null;
                    }
                    if (temp == null)
                    {
                        molesScript.molesHit += 1;
                    }
                    temp = col.gameObject;
                    haptics.vibrate(false);
                }
                else
                {
                    Destroy(col.gameObject);
                    haptics.vibrate(false);
                }
                //Destroy the enemy
                //Destroy (col.gameObject);
            }
        }

        if (col.collider.tag == "Player")
        {
            Physics.IgnoreCollision(col.gameObject.GetComponent <Collider>(), GetComponent <Collider>());
        }
    }
Esempio n. 17
0
 void Update()
 {
     if (!OVRInput.Get(OVRInput.NearTouch.PrimaryIndexTrigger, OVRInput.Controller.RTouch) && OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.RTouch))
     {
         RaycastHit hit;
         if (Physics.Raycast(lineRenderer.transform.position, lineRenderer.transform.forward, out hit, 10f, rayLayer) && hit.transform.gameObject.layer == LayerMask.NameToLayer("Walkable"))
         {
             lineRenderer.SetPosition(0, lineRenderer.transform.position);
             lineRenderer.SetPosition(1, hit.point);
             placeHolder.SetActive(true);
             placeHolder.transform.position = hit.point;
             if (OVRInput.GetUp(OVRInput.Button.Two, OVRInput.Controller.RTouch))
             {
                 transform.position = placeHolder.transform.position + Vector3.up;
             }
         }
     }
     else
     {
         lineRenderer.SetPosition(0, lineRenderer.transform.position);
         lineRenderer.SetPosition(1, lineRenderer.transform.position);
         placeHolder.SetActive(false);
     }
 }
 // Get the touch controller input
 void GetInput()
 {
     // Get the left and right controller input
     inputL = (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger) != 0f);
     inputR = (OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger) != 0f);
 }
Esempio n. 19
0
            public static bool Prefix(bool useKeyboard, bool useController, GameInput ___instance)
            {
                XRInputManager xrInput = GetXRInputManager();

                for (int i = 0; i < GameInput.axisValues.Length; i++)
                {
                    GameInput.axisValues[i] = 0f;
                }

                if (useController)
                {
                    if (GameInput.GetUseOculusInputManager() && XRSettings.loadedDeviceName != "Oculus")
                    {
                        Vector2 vector = OVRInput.Get(OVRInput.RawAxis2D.LThumbstick, OVRInput.Controller.Active);
                        GameInput.axisValues[2] = vector.x;
                        GameInput.axisValues[3] = -vector.y;
                        Vector2 vector2 = OVRInput.Get(OVRInput.RawAxis2D.RThumbstick, OVRInput.Controller.Active);
                        GameInput.axisValues[0] = vector2.x;
                        GameInput.axisValues[1] = -vector2.y;
                        GameInput.axisValues[4] = OVRInput.Get(OVRInput.RawAxis1D.LIndexTrigger, OVRInput.Controller.Active);
                        GameInput.axisValues[5] = OVRInput.Get(OVRInput.RawAxis1D.RIndexTrigger, OVRInput.Controller.Active);
                        GameInput.axisValues[6] = 0f;
                        if (OVRInput.Get(OVRInput.RawButton.DpadLeft, OVRInput.Controller.Active))
                        {
                            GameInput.axisValues[6] -= 1f;
                        }
                        if (OVRInput.Get(OVRInput.RawButton.DpadRight, OVRInput.Controller.Active))
                        {
                            GameInput.axisValues[6] += 1f;
                        }
                        GameInput.axisValues[7] = 0f;
                        if (OVRInput.Get(OVRInput.RawButton.DpadUp, OVRInput.Controller.Active))
                        {
                            GameInput.axisValues[7] += 1f;
                        }
                        if (OVRInput.Get(OVRInput.RawButton.DpadDown, OVRInput.Controller.Active))
                        {
                            GameInput.axisValues[7] -= 1f;
                        }
                    }
                    else
                    {
                        GameInput.ControllerLayout controllerLayout = GameInput.GetControllerLayout();
                        if (controllerLayout == GameInput.ControllerLayout.Xbox360 || controllerLayout == GameInput.ControllerLayout.XboxOne || Application.platform == RuntimePlatform.PS4)
                        {
                            GameInput.axisValues[2] = Input.GetAxis("ControllerAxis1");
                            GameInput.axisValues[3] = Input.GetAxis("ControllerAxis2");
                            GameInput.axisValues[0] = Input.GetAxis("ControllerAxis4");
                            GameInput.axisValues[1] = Input.GetAxis("ControllerAxis5");
                            if (Application.platform == RuntimePlatform.PS4)
                            {
                                GameInput.axisValues[4] = Mathf.Max(Input.GetAxis("ControllerAxis8"), 0f);
                                GameInput.axisValues[5] = Mathf.Max(-Input.GetAxis("ControllerAxis3"), 0f);
                            }
                            else if (Application.platform == RuntimePlatform.XboxOne)
                            {
                                GameInput.axisValues[4] = Mathf.Max(Input.GetAxis("ControllerAxis3"), 0f);
                                GameInput.axisValues[5] = Mathf.Max(-Input.GetAxis("ControllerAxis3"), 0f);
                            }
                            else
                            {
                                GameInput.axisValues[4] = Mathf.Max(-Input.GetAxis("ControllerAxis3"), 0f);
                                GameInput.axisValues[5] = Mathf.Max(Input.GetAxis("ControllerAxis3"), 0f);
                            }
                            GameInput.axisValues[6] = Input.GetAxis("ControllerAxis6");
                            GameInput.axisValues[7] = Input.GetAxis("ControllerAxis7");
                        }
                        else if (controllerLayout == GameInput.ControllerLayout.Switch)
                        {
                            GameInput.axisValues[2] = InputUtils.GetAxis("ControllerAxis1");
                            GameInput.axisValues[3] = InputUtils.GetAxis("ControllerAxis2");
                            GameInput.axisValues[0] = InputUtils.GetAxis("ControllerAxis4");
                            GameInput.axisValues[1] = InputUtils.GetAxis("ControllerAxis5");
                            GameInput.axisValues[4] = Mathf.Max(InputUtils.GetAxis("ControllerAxis3"), 0f);
                            GameInput.axisValues[5] = Mathf.Max(-InputUtils.GetAxis("ControllerAxis3"), 0f);
                            GameInput.axisValues[6] = InputUtils.GetAxis("ControllerAxis6");
                            GameInput.axisValues[7] = InputUtils.GetAxis("ControllerAxis7");
                        }
                        else if (controllerLayout == GameInput.ControllerLayout.PS4)
                        {
                            GameInput.axisValues[2] = Input.GetAxis("ControllerAxis1");
                            GameInput.axisValues[3] = Input.GetAxis("ControllerAxis2");
                            GameInput.axisValues[0] = Input.GetAxis("ControllerAxis3");
                            GameInput.axisValues[1] = Input.GetAxis("ControllerAxis6");
                            GameInput.axisValues[4] = (Input.GetAxis("ControllerAxis4") + 1f) * 0.5f;
                            GameInput.axisValues[5] = (Input.GetAxis("ControllerAxis5") + 1f) * 0.5f;
                            GameInput.axisValues[6] = Input.GetAxis("ControllerAxis7");
                            GameInput.axisValues[7] = Input.GetAxis("ControllerAxis8");
                        }
                    }

                    if (xrInput.hasControllers())
                    {
                        if (XRSettings.loadedDeviceName == "Oculus")
                        {
                            Vector2 vector = OVRInput.Get(OVRInput.RawAxis2D.LThumbstick, OVRInput.Controller.Active);
                            GameInput.axisValues[2] = vector.x;
                            GameInput.axisValues[3] = -vector.y;
                            Vector2 vector2 = OVRInput.Get(OVRInput.RawAxis2D.RThumbstick, OVRInput.Controller.Active);
                            GameInput.axisValues[0] = vector2.x;
                            GameInput.axisValues[1] = -vector2.y;
                            // TODO: Use deadzone?
                            GameInput.axisValues[4] = OVRInput.Get(OVRInput.RawAxis1D.LIndexTrigger, OVRInput.Controller.Active);
                            GameInput.axisValues[5] = OVRInput.Get(OVRInput.RawAxis1D.RIndexTrigger, OVRInput.Controller.Active);
                            if (OVRInput.Get(OVRInput.RawButton.DpadLeft, OVRInput.Controller.Active))
                            {
                                GameInput.axisValues[6] -= 1f;
                            }
                            if (OVRInput.Get(OVRInput.RawButton.DpadRight, OVRInput.Controller.Active))
                            {
                                GameInput.axisValues[6] += 1f;
                            }
                            GameInput.axisValues[7] = 0f;
                            if (OVRInput.Get(OVRInput.RawButton.DpadUp, OVRInput.Controller.Active))
                            {
                                GameInput.axisValues[7] += 1f;
                            }
                            if (OVRInput.Get(OVRInput.RawButton.DpadDown, OVRInput.Controller.Active))
                            {
                                GameInput.axisValues[7] -= 1f;
                            }
                        }
                        bool test = false;
                        //OpenVR Asix values
                        if (XRSettings.loadedDeviceName == "OpenVR" && test)
                        {
                            Vector2 vector = xrInput.Get(Controller.Left, CommonUsages.primary2DAxis);
                            GameInput.axisValues[2] = vector.x;
                            GameInput.axisValues[3] = -vector.y;
                            Vector2 vector2 = xrInput.Get(Controller.Right, CommonUsages.primary2DAxis);
                            GameInput.axisValues[0] = vector2.x;
                            GameInput.axisValues[1] = -vector2.y;
                            // TODO: Use deadzone?
                            GameInput.axisValues[4] = xrInput.Get(Controller.Left, CommonUsages.trigger).CompareTo(0.3f);
                            GameInput.axisValues[5] = xrInput.Get(Controller.Right, CommonUsages.trigger).CompareTo(0.3f);

                            //These axis I'm sure are used for something on other headsets
                            //axisValues[6] = xrInput.Get(Controller.Left, CommonUsages.secondary2DAxisTouch).CompareTo(0.1f);
                            //axisValues[7] = xrInput.Get(Controller.Right, CommonUsages.secondaryTouch).CompareTo(0.1f);
                        }
                    }
                }

                if (useKeyboard)
                {
                    GameInput.axisValues[10] = Input.GetAxis("Mouse ScrollWheel");
                    GameInput.axisValues[8]  = Input.GetAxisRaw("Mouse X");
                    GameInput.axisValues[9]  = Input.GetAxisRaw("Mouse Y");
                }
                for (int j = 0; j < GameInput.axisValues.Length; j++)
                {
                    GameInput.AnalogAxis axis          = (GameInput.AnalogAxis)j;
                    GameInput.Device     deviceForAxis = ___instance.GetDeviceForAxis(axis);
                    float f = GameInput.lastAxisValues[j] - GameInput.axisValues[j];
                    GameInput.lastAxisValues[j] = GameInput.axisValues[j];
                    if (deviceForAxis != GameInput.lastDevice)
                    {
                        float num = 0.1f;
                        if (Mathf.Abs(f) > num)
                        {
                            if (!PlatformUtils.isConsolePlatform)
                            {
                                GameInput.lastDevice = deviceForAxis;
                            }
                        }
                        else
                        {
                            GameInput.axisValues[j] = 0f;
                        }
                    }
                }
                return(false);
            }
Esempio n. 20
0
 void updateMoveTime()
 {
     // Considered recently moved if just moved using CharacterController
     // We don't have access to a snap turn variable in OVRPlayerController, so we have to check the input ourself
     if (pControl && pControl.EnableRotation && pControl.SnapRotation)
     {
         if (OVRInput.Get(OVRInput.Button.SecondaryThumbstickLeft) || (pControl.RotationEitherThumbstick && OVRInput.Get(OVRInput.Button.PrimaryThumbstickLeft)))
         {
             LastPlayerMoveTime = Time.time;
         }
         else if (OVRInput.Get(OVRInput.Button.SecondaryThumbstickRight) || (pControl.RotationEitherThumbstick && OVRInput.Get(OVRInput.Button.PrimaryThumbstickRight)))
         {
             LastPlayerMoveTime = Time.time;
         }
     }
 }
Esempio n. 21
0
 // Just checking the state of the index and thumb cap touch sensors, but with a little bit of
 // debouncing.
 private void UpdateCapTouchStates()
 {
     m_isPointing       = !OVRInput.Get(OVRInput.NearTouch.PrimaryIndexTrigger, m_controller);
     m_isGivingThumbsUp = !OVRInput.Get(OVRInput.NearTouch.PrimaryThumbButtons, m_controller);
 }
Esempio n. 22
0
        /// <summary>
        /// Update the controller data from the provided platform state
        /// </summary>
        /// <param name="interactionSourceState">The InteractionSourceState retrieved from the platform</param>
        public void UpdateController(OVRCameraRig ovrRigRoot, OVRInput.Controller ovrController)
        {
            if (!Enabled || ovrRigRoot == null)
            {
                return;
            }

            IsPositionAvailable = OVRInput.GetControllerPositionValid(ovrController);
            IsRotationAvailable = OVRInput.GetControllerOrientationValid(ovrController);

            Transform playSpaceTransform = ovrRigRoot.transform;

            // Update transform
            Vector3 localPosition = OVRInput.GetLocalControllerPosition(ovrController);
            Vector3 worldPosition = playSpaceTransform.TransformPoint(localPosition);
            // Debug.Log("Controller " + Handedness + " - local: " + localPosition + " - world: " + worldPosition);

            Quaternion localRotation = OVRInput.GetLocalControllerRotation(ovrController);
            Quaternion worldRotation = playSpaceTransform.rotation * localRotation;

            // Update velocity
            Vector3 localVelocity = OVRInput.GetLocalControllerVelocity(ovrController);

            Velocity = playSpaceTransform.TransformDirection(localVelocity);

            Vector3 localAngularVelocity = OVRInput.GetLocalControllerAngularVelocity(ovrController);

            AngularVelocity = playSpaceTransform.TransformDirection(localAngularVelocity);

            if (IsPositionAvailable)
            {
                currentPointerPose.Position = currentGripPose.Position = worldPosition;
            }

            if (IsRotationAvailable)
            {
                currentPointerPose.Rotation = currentGripPose.Rotation = worldRotation;
            }

            // Todo: Complete touch controller mapping

            bool isTriggerPressed = false;

            if (ControllerHandedness == Handedness.Left)
            {
                isTriggerPressed = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger) > cTriggerDeadZone;
            }
            else
            {
                isTriggerPressed = OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger) > cTriggerDeadZone;
            }

            UpdateJointPoses();

            for (int i = 0; i < Interactions?.Length; i++)
            {
                switch (Interactions[i].InputType)
                {
                case DeviceInputType.SpatialPointer:
                    Interactions[i].PoseData = currentPointerPose;
                    if (Interactions[i].Changed)
                    {
                        CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, currentPointerPose);
                    }
                    break;

                case DeviceInputType.SpatialGrip:
                    Interactions[i].PoseData = currentGripPose;
                    if (Interactions[i].Changed)
                    {
                        CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, currentGripPose);
                    }
                    break;

                case DeviceInputType.Select:
                    Interactions[i].BoolData = isTriggerPressed;

                    if (Interactions[i].Changed)
                    {
                        if (Interactions[i].BoolData)
                        {
                            CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                        else
                        {
                            CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                    }
                    break;

                case DeviceInputType.TriggerPress:
                    Interactions[i].BoolData = isTriggerPressed;

                    if (Interactions[i].Changed)
                    {
                        if (Interactions[i].BoolData)
                        {
                            CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                        else
                        {
                            CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                    }
                    break;

                case DeviceInputType.IndexFinger:
                    UpdateIndexFingerData(Interactions[i]);
                    break;
                }
            }
        }
Esempio n. 23
0
 public float GetAxis(OVRInput.Axis1D axis)
 {
     return(OVRInput.Get(axis, controller));
 }
    // Update is called once per frame
    void Update()
    {
        String color = button.name;

        if (OVRInput.Get(OVRInput.RawButton.X))
        {
            Application.Quit();
        }
        Debug.Log(banana.activeSelf);
        if (apple.activeSelf)
        {
            if (color == "Red" && OVRInput.Get(OVRInput.RawButton.A))
            {
                rend.material = mat;
                GameObject c1 = GameObject.Find("Apple_LOD1");
                GameObject c2 = GameObject.Find("Apple_LOD0");
                c1.GetComponent <Renderer> ().material = mat;
                c2.GetComponent <Renderer> ().material = mat;
                Debug.Log("here1");
                //rend.materials[0].SetColor("_Color", Color.red);
                end = DateTime.Now;
                int    timeDiff   = (int)end.Subtract(start).TotalSeconds;
                string wrongGuess = String.Join(" ,", wrongGuesses.ToArray());
                //Debug.Log ("red and apple");

                //do db stuff
                //Query q =
                //GqlQuery query = "INSERT INTO USER_DATA (USER_NAME,DEVICE,RESPONSE_TIME, FRUIT_NAME, COLOR_REP, INCORRECT_CHOICES) VALUES ('JANE DOE','M','3','BANANA','RED','RED');";
                //db.RunQuery(query);
                wrongGuesses = new List <string> ();
                wrongCount   = 0;
                bChange      = true;
            }
            else if (bChange)
            {
                System.Threading.Thread.Sleep(2000);                  //sleep for 2 secs
                apple.SetActive(false);
                banana.SetActive(true);
                bChange       = false;
                rend.material = plain;
                GameObject c1 = GameObject.Find("Apple_LOD1");
                GameObject c2 = GameObject.Find("Apple_LOD0");
                c1.GetComponent <Renderer> ().material = plain;
                c2.GetComponent <Renderer> ().material = plain;
            }
            else
            {
                wrongCount++;
                wrongGuesses.Add(button.name);
            }
        }
        else if (banana.activeSelf)
        {
            if (color == "Yellow" && OVRInput.Get(OVRInput.RawButton.A))
            {
                rend.material = mat;
                GameObject c1 = GameObject.Find("Banana_LOD1");
                GameObject c2 = GameObject.Find("Banana_LOD0");
                c1.GetComponent <Renderer> ().material = mat;
                c2.GetComponent <Renderer> ().material = mat;
                Debug.Log("in banana");
                //rend.materials[0].SetColor("_Color", Color.red);
                end = DateTime.Now;
                int    timeDiff   = (int)end.Subtract(start).TotalSeconds;
                string wrongGuess = String.Join(" ,", wrongGuesses.ToArray());
                Debug.Log(banana.activeSelf);

                //do db stuff
                wrongGuesses = new List <string> ();
                wrongCount   = 0;
                bChange      = true;
            }
            else if (bChange)
            {
                System.Threading.Thread.Sleep(2000);                  //sleep for 2 secs
                banana.SetActive(false);
                orange.SetActive(true);
                rend.material = plain;
                GameObject c1 = GameObject.Find("Banana_LOD1");
                GameObject c2 = GameObject.Find("Banana_LOD0");
                c1.GetComponent <Renderer> ().material = plain;
                c2.GetComponent <Renderer> ().material = plain;

                bChange = false;
            }
            else
            {
                wrongCount++;
                wrongGuesses.Add(button.name);
            }
        }
        else if (orange.activeSelf)
        {
            if (color == "Orange" && OVRInput.Get(OVRInput.RawButton.A))
            {
                rend.materials [1] = mat;
                end = DateTime.Now;
                int    timeDiff   = (int)end.Subtract(start).TotalSeconds;
                string wrongGuess = String.Join(" ,", wrongGuesses.ToArray());
                Debug.Log("orange");

                //do db stuff
                wrongGuesses = new List <string> ();
                wrongCount   = 0;
                bChange      = true;
            }
            else if (bChange)
            {
                System.Threading.Thread.Sleep(2000);                  //sleep for 2 secs
                orange.SetActive(false);
                watermelon.SetActive(true);
                rend.materials [1] = plain;
                bChange            = false;
            }
            else
            {
                wrongCount++;
                wrongGuesses.Add(button.name);
            }
        }
        else if (watermelon.activeSelf)
        {
            if (color == "Green" && OVRInput.Get(OVRInput.RawButton.A))
            {
                rend.material = mat;
                int        numOfChildren = transform.childCount;
                GameObject c1            = GameObject.Find("default");
                c1.GetComponent <Renderer> ().material = mat;
                end = DateTime.Now;
                int    timeDiff   = (int)end.Subtract(start).TotalSeconds;
                string wrongGuess = String.Join(" ,", wrongGuesses.ToArray());
                Debug.Log("watermelon");

                //do db stuff
                wrongGuesses = new List <string> ();
                wrongCount   = 0;
                bChange      = true;
            }
            else if (bChange)
            {
                System.Threading.Thread.Sleep(2000);                  //sleep for 2 secs
                watermelon.SetActive(false);
                apple.SetActive(true);
                rend.material = plain;
                GameObject c1 = GameObject.Find("default");
                c1.GetComponent <Renderer> ().material = plain;
                bChange = false;
            }
            else
            {
                wrongCount++;
                wrongGuesses.Add(button.name);
            }
        }
        else
        {
        }
    }
Esempio n. 25
0
 public bool ButtonPressed(OVRInput.Button button)
 {
     return(OVRInput.Get(button, controller));
 }
    IEnumerator RotateFourD()
    {
        while (true)
        {
            for (int i = 0; i < mesh.vertexCount; i++)
            {
                if (Raycast.hitDetect.collider == GetComponent <Collider>() && toggle == false)
                {
                    //3D Rotations
                    if (Input.GetKey(KeyCode.Z) || OVRInput.Get(OVRInput.Button.DpadUp))
                    {
                        fourDmanip[i] = MeshRotFourYZ(fourDmanip[i], rotRate);
                    }
                    else if (Input.GetKey(KeyCode.X) || OVRInput.Get(OVRInput.Button.DpadDown))
                    {
                        fourDmanip[i] = MeshRotFourYZ(fourDmanip[i], -rotRate);
                    }

                    if (Input.GetKey(KeyCode.C) || OVRInput.Get(OVRInput.Button.DpadLeft))
                    {
                        fourDmanip[i] = MeshRotFourXZ(fourDmanip[i], rotRate);
                    }
                    else if (Input.GetKey(KeyCode.V) || OVRInput.Get(OVRInput.Button.DpadRight))
                    {
                        fourDmanip[i] = MeshRotFourXZ(fourDmanip[i], -rotRate);
                    }

                    if (Input.GetKey(KeyCode.F) || OVRInput.Get(OVRInput.Button.Four, OVRInput.Controller.Gamepad))
                    {
                        fourDmanip[i] = MeshRotFourXY(fourDmanip[i], rotRate);
                    }
                    else if (Input.GetKey(KeyCode.G) || OVRInput.Get(OVRInput.Button.One, OVRInput.Controller.Gamepad))
                    {
                        fourDmanip[i] = MeshRotFourXY(fourDmanip[i], -rotRate);
                    }

                    //4D Rotations
                    if (Input.GetKey(KeyCode.N))
                    {
                        fourDmanip[i] = MeshRotFourZW(fourDmanip[i], rotRate);
                    }
                    else if (Input.GetKey(KeyCode.M))
                    {
                        fourDmanip[i] = MeshRotFourZW(fourDmanip[i], -rotRate);
                    }

                    if (ControllerInput.joystickPos.x != 0.0f)
                    {
                        fourDmanip[i] = MeshRotFourXW(fourDmanip[i], rotRate * ControllerInput.joystickPos.x);
                    }

                    if (ControllerInput.joystickPos.y != 0.0f)
                    {
                        fourDmanip[i] = MeshRotFourYW(fourDmanip[i], rotRate * ControllerInput.joystickPos.y);
                    }

                    if (Input.GetKey(KeyCode.H))
                    {
                        fourDmanip[i] = MeshRotFourYW(fourDmanip[i], rotRate);
                    }
                    else if (Input.GetKey(KeyCode.J))
                    {
                        fourDmanip[i] = MeshRotFourYW(fourDmanip[i], -rotRate);
                    }

                    if (Input.GetKey(KeyCode.Y) || OVRInput.Get(OVRInput.Button.Two, OVRInput.Controller.Gamepad))
                    {
                        fourDmanip[i] = MeshRotFourZW(fourDmanip[i], rotRate);
                    }
                    else if (Input.GetKey(KeyCode.U) || OVRInput.Get(OVRInput.Button.Three, OVRInput.Controller.Gamepad))
                    {
                        fourDmanip[i] = MeshRotFourZW(fourDmanip[i], -rotRate);
                    }
                }

                threeDmanip[i] = 2 * fourDmanip[i] / (ControllerInput.lightDist - fourDmanip[i].w);
            }


            GetComponent <MeshFilter>().mesh.vertices = threeDmanip;
            GetComponent <MeshFilter>().mesh.RecalculateNormals();
            if (GetComponent <MeshCollider>() != null)
            {
                GetComponent <MeshCollider>().sharedMesh = GetComponent <MeshFilter>().mesh;
            }

            yield return(new WaitForSeconds(.03f));
        }
    }
Esempio n. 27
0
 bool getLeftHandTrigger()
 {
     return(OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger) > TRIGGER_THRESHOLD);
 }
Esempio n. 28
0
        protected void Update()
        {
            bool didSomething = false;
            // SuperController doesn't give a great API for dealing with Oculus and Vive,
            // but we'll try to use headset-agnostic methods...
            SuperController sc = SuperController.singleton;

            OVRInput.Controller activeController = OVRInput.Controller.None;

            // Find the active controller
            foreach (var controller in _controllers)
            {
                if (OVRInput.IsControllerConnected(controller))
                {
                    activeController = controller;
                    break;
                }
            }

            // Couldn't find a controller!
            if (activeController == OVRInput.Controller.None)
            {
                return;
            }

            bool  btn1          = OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, activeController);
            bool  btn2          = OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, activeController);
            bool  btn3          = OVRInput.Get(OVRInput.Button.One, activeController);
            bool  btn4          = OVRInput.Get(OVRInput.Button.Two, activeController);
            bool  bothPressed   = btn1 && btn2;
            bool  thumbPressed  = OVRInput.Get(OVRInput.Button.PrimaryThumbstick, activeController);
            float pitchVal      = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, activeController).y;
            float rollVal       = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, activeController).x;
            bool  doubleClicked = false;

            // Check for double clicking
            // Both were pressed last update, but not this update
            if (!bothPressed && _bothPressed)
            {
                _doubleClickTimer = DOUBLE_CLICK_TIME;
                _bothPressed      = false;
            }
            else if (_bothPressed) // Both pressed last update, still pressed
            {
            }
            else if (bothPressed)  // Both pressed, but weren't last update
            {
                if (_doubleClickTimer > 0.0f)
                {
                    doubleClicked     = true;
                    _doubleClickTimer = 0.0f;
                }
                else
                {
                    _bothPressed = true;
                }
            }
            if (_doubleClickTimer > 0.0f)
            {
                _doubleClickTimer -= Time.unscaledDeltaTime;
            }



            Transform rotateTarget = sc.navigationRigParent;

            if (!bothPressed)
            {
                if (btn1)
                {
                    // Rotate

                    if (pitchVal > DEADZONE || pitchVal < -DEADZONE)
                    {
                        Vector3 axis = sc.OVRCenterCamera.transform.right;
                        rotateTarget.Rotate(axis, pitchVal, Space.World);
                        didSomething = true;
                    }
                    if (rollVal > DEADZONE || rollVal < -DEADZONE)
                    {
                        Vector3 axis = sc.OVRCenterCamera.transform.forward;
                        rotateTarget.Rotate(axis, -rollVal, Space.World);
                        didSomething = true;
                    }
                }


                if (btn2)
                {
                    // Fly
                    if (pitchVal > DEADZONE || pitchVal < -DEADZONE)
                    {
                        Vector3 dir = sc.OVRCenterCamera.transform.forward;
                        dir *= (pitchVal * Time.deltaTime / Time.timeScale);
                        sc.navigationRig.position += dir;
                        didSomething = true;
                    }
                    if (rollVal > DEADZONE || rollVal < -DEADZONE)
                    {
                        Vector3 dir = sc.OVRCenterCamera.transform.right;
                        dir *= (rollVal * Time.deltaTime / Time.timeScale);
                        sc.navigationRig.position += dir;
                        didSomething = true;
                    }
                }
            }
            else if (!doubleClicked)  // Both pressed, no double click
            {
                // Fly up/down
                if (pitchVal > DEADZONE || pitchVal < -DEADZONE)
                {
                    Vector3 dir = sc.OVRCenterCamera.transform.up;
                    dir *= (pitchVal * Time.deltaTime / Time.timeScale);
                    sc.navigationRig.position += dir;
                    didSomething = true;
                }
                if (rollVal > DEADZONE || rollVal < -DEADZONE)
                {
                    // Rotate left/right

                    Vector3 axis = sc.OVRCenterCamera.transform.up;
                    rotateTarget.Rotate(axis, rollVal, Space.World);
                    didSomething = true;
                }
            }
            else // Double clicked
            {
                if (btn3)
                {
                    if (SuperController.singleton.gameMode == SuperController.GameMode.Play)
                    {
                        SuperController.singleton.gameMode = SuperController.GameMode.Edit;
                    }
                    else
                    {
                        SuperController.singleton.gameMode = SuperController.GameMode.Play;
                    }
                }
                else
                {
                    Vector3 rotation = SuperController.singleton.navigationRig.rotation.eulerAngles;
                    rotation.x = 0;
                    rotation.z = 0;
                    SuperController.singleton.navigationRig.rotation = Quaternion.Euler(rotation);
                }
                didSomething = true;
            }


            // If any action was performed then temporarily disable standard navigation
            if (didSomething)
            {
                sc.disableNavigation       = true;
                _enableNavigationCountdown = NAVIGATION_DISABLE_TIMER;
            }
            else if (_enableNavigationCountdown > 0)
            {
                _enableNavigationCountdown -= Time.deltaTime;
                if (_enableNavigationCountdown <= 0.0f)
                {
                    _enableNavigationCountdown = 0;
                    sc.disableNavigation       = false;
                }
            }
        }
Esempio n. 29
0
 bool getRightIndexTrigger()
 {
     return(OVRInput.Get(OVRInput.Button.SecondaryIndexTrigger));
 }
Esempio n. 30
0
    ControllerPose GetControllerPose(OVRInput.Controller controller)
    {
        ovrAvatarButton buttons = 0;

        if (OVRInput.Get(OVRInput.Button.One, controller))
        {
            buttons |= ovrAvatarButton.One;
        }
        if (OVRInput.Get(OVRInput.Button.Two, controller))
        {
            buttons |= ovrAvatarButton.Two;
        }
        if (OVRInput.Get(OVRInput.Button.Start, controller))
        {
            buttons |= ovrAvatarButton.Three;
        }
        if (OVRInput.Get(OVRInput.Button.PrimaryThumbstick, controller))
        {
            buttons |= ovrAvatarButton.Joystick;
        }

        ovrAvatarTouch touches = 0;

        if (OVRInput.Get(OVRInput.Touch.One, controller))
        {
            touches |= ovrAvatarTouch.One;
        }
        if (OVRInput.Get(OVRInput.Touch.Two, controller))
        {
            touches |= ovrAvatarTouch.Two;
        }
        if (OVRInput.Get(OVRInput.Touch.PrimaryThumbstick, controller))
        {
            touches |= ovrAvatarTouch.Joystick;
        }
        if (OVRInput.Get(OVRInput.Touch.PrimaryThumbRest, controller))
        {
            touches |= ovrAvatarTouch.ThumbRest;
        }
        if (OVRInput.Get(OVRInput.Touch.PrimaryIndexTrigger, controller))
        {
            touches |= ovrAvatarTouch.Index;
        }
        if (!OVRInput.Get(OVRInput.NearTouch.PrimaryIndexTrigger, controller))
        {
            touches |= ovrAvatarTouch.Pointing;
        }
        if (!OVRInput.Get(OVRInput.NearTouch.PrimaryThumbButtons, controller))
        {
            touches |= ovrAvatarTouch.ThumbUp;
        }

        return(new ControllerPose
        {
            buttons = buttons,
            touches = touches,
            joystickPosition = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, controller),
            indexTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, controller),
            handTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, controller),
            isActive = (OVRInput.GetActiveController() & controller) != 0,
        });
    }