예제 #1
0
        void Init()
        {
            ViveInput.AddPressUp(HandRole.RightHand, ControllerButton.Pad, () => {
                float x = ViveInput.GetAxis(HandRole.RightHand, ControllerAxis.PadX);
                float y = ViveInput.GetAxis(HandRole.RightHand, ControllerAxis.PadY);

                float angle = Mathf.Atan2(y, x) * Mathf.Rad2Deg;

                if (Mathf.Abs(angle) < 45f)
                {
                    //right
                    //+ inner
                    Ratio      += m_ratioDeltaAmount;
                    InnerRadius = OuterRadius * Ratio;
                }
                else if (Mathf.Abs(angle) > 135f)
                {
                    //left
                    //- inner
                    Ratio      -= m_ratioDeltaAmount;
                    InnerRadius = OuterRadius * Ratio;
                }
                else if (angle > 45f && angle < 135f)
                {
                    //up
                    //+ outer
                    OuterRadius += m_radiusDeltaAmount;
                    InnerRadius  = OuterRadius * Ratio;
                }
                else if (angle > -135f && angle < -45f)
                {
                    //down
                    //- outer
                    OuterRadius -= m_radiusDeltaAmount;
                    InnerRadius  = OuterRadius * Ratio;
                }
                HapticManager.Instance.TriggerHaptic(HandRole.RightHand, 1000);
            });

            ViveInput.AddPressUp(HandRole.LeftHand, ControllerButton.Pad, () => {
                float x = ViveInput.GetAxis(HandRole.LeftHand, ControllerAxis.PadX);
                float y = ViveInput.GetAxis(HandRole.LeftHand, ControllerAxis.PadY);

                float angle = Mathf.Atan2(y, x) * Mathf.Rad2Deg;

                if (Mathf.Abs(angle) < 45f)
                {
                    //right
                    PerformRedo();
                }
                else if (Mathf.Abs(angle) > 135f)
                {
                    //left
                    //undo
                    PerformUndo();
                }
                else if (angle > 45f && angle < 135f)
                {
                    //up
                    //MeshGenerator.Instance.CreateMesh();
                }
                else if (angle > -135f && angle < -45f)
                {
                    //down
                    //MeshIOManager.Instance.ExportMesh();
                }
                HapticManager.Instance.TriggerHaptic(HandRole.LeftHand, 1000);
            });

            ViveInput.AddPressUp(HandRole.RightHand, ControllerButton.Menu, () => {
                //ToolState = (DeformTools.ToolState)(((int)ToolState + 1) % 5);
            });
        }
        private void Update()
        {
            if (m_updateDynamically)
            {
#if (VIU_OCULUSVR_1_32_0_OR_NEWER || VIU_OCULUSVR_1_36_0_OR_NEWER || VIU_OCULUSVR_1_37_0_OR_NEWER) && VIU_OCULUSVR_AVATAR
                if (sdkAvatar == IntPtr.Zero)
                {
                    return;
                }

                if (m_deviceIndex == LEFT_INDEX)
                {
                    inputStateLeft.transform.position    = transform.position;
                    inputStateLeft.transform.orientation = transform.rotation;
                    inputStateLeft.transform.scale       = transform.localScale;

                    inputStateLeft.buttonMask = 0;
                    inputStateLeft.touchMask  = ovrAvatarTouch.Pointing | ovrAvatarTouch.ThumbUp;

                    if (ViveInput.GetPress(HandRole.LeftHand, ControllerButton.AKey))
                    {
                        inputStateLeft.buttonMask |= ovrAvatarButton.One;
                    }

                    if (ViveInput.GetPress(HandRole.LeftHand, ControllerButton.BKey))
                    {
                        inputStateLeft.buttonMask |= ovrAvatarButton.Two;
                    }

                    if (ViveInput.GetPress(HandRole.LeftHand, ControllerButton.System))
                    {
                        inputStateLeft.buttonMask |= ovrAvatarButton.Three;
                    }

                    if (ViveInput.GetPress(HandRole.LeftHand, ControllerButton.Pad))
                    {
                        inputStateLeft.buttonMask |= ovrAvatarButton.Joystick;
                    }

                    if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.AKeyTouch))
                    {
                        inputStateLeft.touchMask &= ~ovrAvatarTouch.ThumbUp;
                        inputStateLeft.touchMask |= ovrAvatarTouch.One;
                    }
                    if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.BkeyTouch))
                    {
                        inputStateLeft.touchMask &= ~ovrAvatarTouch.ThumbUp;
                        inputStateLeft.touchMask |= ovrAvatarTouch.Two;
                    }
                    if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.PadTouch))
                    {
                        inputStateLeft.touchMask &= ~ovrAvatarTouch.ThumbUp;
                        inputStateLeft.touchMask |= ovrAvatarTouch.Joystick;
                    }
                    if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.TriggerTouch))
                    {
                        inputStateLeft.touchMask &= ~ovrAvatarTouch.Pointing;
                        inputStateLeft.touchMask |= ovrAvatarTouch.Index;
                    }

                    inputStateLeft.joystickX    = ViveInput.GetAxis(HandRole.LeftHand, ControllerAxis.JoystickX);
                    inputStateLeft.joystickY    = ViveInput.GetAxis(HandRole.LeftHand, ControllerAxis.JoystickY);
                    inputStateLeft.indexTrigger = ViveInput.GetAxis(HandRole.LeftHand, ControllerAxis.Trigger);
                    inputStateLeft.handTrigger  = ViveInput.GetAxis(HandRole.LeftHand, ControllerAxis.CapSenseGrip);
                    inputStateLeft.isActive     = true;
                }
                else if (m_deviceIndex == RIGHT_INDEX)
                {
                    inputStateRight.transform.position    = transform.position;
                    inputStateRight.transform.orientation = transform.rotation;
                    inputStateRight.transform.scale       = transform.localScale;

                    inputStateRight.buttonMask = 0;
                    inputStateRight.touchMask  = ovrAvatarTouch.Pointing | ovrAvatarTouch.ThumbUp;

                    if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.AKey))
                    {
                        inputStateRight.buttonMask |= ovrAvatarButton.One;
                    }

                    if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.BKey))
                    {
                        inputStateRight.buttonMask |= ovrAvatarButton.Two;
                    }

                    if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.Pad))
                    {
                        inputStateRight.buttonMask |= ovrAvatarButton.Joystick;
                    }

                    if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.AKeyTouch))
                    {
                        inputStateRight.touchMask &= ~ovrAvatarTouch.ThumbUp;
                        inputStateRight.touchMask |= ovrAvatarTouch.One;
                    }
                    if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.BkeyTouch))
                    {
                        inputStateRight.touchMask &= ~ovrAvatarTouch.ThumbUp;
                        inputStateRight.touchMask |= ovrAvatarTouch.Two;
                    }
                    if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.PadTouch))
                    {
                        inputStateRight.touchMask &= ~ovrAvatarTouch.ThumbUp;
                        inputStateRight.touchMask |= ovrAvatarTouch.Joystick;
                    }
                    if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.TriggerTouch))
                    {
                        inputStateRight.touchMask &= ~ovrAvatarTouch.Pointing;
                        inputStateRight.touchMask |= ovrAvatarTouch.Index;
                    }

                    inputStateRight.joystickX    = ViveInput.GetAxis(HandRole.RightHand, ControllerAxis.JoystickX);
                    inputStateRight.joystickY    = ViveInput.GetAxis(HandRole.RightHand, ControllerAxis.JoystickY);
                    inputStateRight.indexTrigger = ViveInput.GetAxis(HandRole.RightHand, ControllerAxis.Trigger);
                    inputStateRight.handTrigger  = ViveInput.GetAxis(HandRole.RightHand, ControllerAxis.CapSenseGrip);
                    inputStateRight.isActive     = true;
                }

                CAPI.ovrAvatarPose_UpdateHandsWithType(sdkAvatar, inputStateLeft, inputStateRight, m_controllerType);
                CAPI.ovrAvatarPose_Finalize(sdkAvatar, Time.deltaTime);
#endif

                UpdateComponents();

#if VIU_OCULUSVR_1_37_0_OR_NEWER && VIU_OCULUSVR_AVATAR
                if (m_deviceIndex == LEFT_INDEX)
                {
                    ovrAvatarControllerComponent component = new ovrAvatarControllerComponent();
                    if (CAPI.ovrAvatarPose_GetLeftControllerComponent(sdkAvatar, ref component))
                    {
                        UpdateAvatarComponent(component.renderComponent);
                    }
                }
                else if (m_deviceIndex == RIGHT_INDEX)
                {
                    ovrAvatarControllerComponent component = new ovrAvatarControllerComponent();
                    if (CAPI.ovrAvatarPose_GetRightControllerComponent(sdkAvatar, ref component))
                    {
                        UpdateAvatarComponent(component.renderComponent);
                    }
                }
#endif
            }
        }
예제 #3
0
파일: Main.cs 프로젝트: daaqing452/HMD-Tap
    void Update()
    {
        text_fps.text     = "fps: " + fps;
        text_network.text = server.info;

        float   posX = ViveInput.GetAxis(handRole, ControllerAxis.PadX);
        float   posY = ViveInput.GetAxis(handRole, ControllerAxis.PadY);
        Vector2 pos  = new Vector2(posX, posY);

        text [0].text = posX + " " + posY;

        if (mode == "auto log")
        {
            text_cnt.text     = logCnt.ToString();
            text_autoLog.text = "Auto Log: " + logging.ToString();
            if (ViveInput.GetPressDown(handRole, ControllerButton.Trigger))
            {
                logging = !logging;
            }
            if (ViveInput.GetPressDown(handRole, ControllerButton.Pad))
            {
                if (pos.y <= -0.85)
                {
                    homeStuff.SetActive(!homeStuff.activeSelf);
                }
            }
        }

        if (mode == "predict")
        {
            predictShowFrame = Mathf.Max(predictShowFrame - 1, 0);
            if (predictShowFrame == 0)
            {
                text_predict.text = "";
            }
            List <string> recvs = server.Recv();
            foreach (string s in recvs)
            {
                string[] arr = s.Split(' ');
                string   tag = arr[0];
                if (tag == "result")
                {
                    string show = "";
                    switch (int.Parse(arr[1]))
                    {
                    case 0: show = "left"; break;

                    case 1: show = "right"; break;

                    case 2: show = "upper-left"; break;

                    case 3: show = "upper-right"; break;

                    case 4: show = "lower-left"; break;

                    case 5: show = "lower-right"; break;

                    case 6: show = "front-left"; break;

                    case 7: show = "front-right"; break;
                    }
                    predictShowFrame  = 30;
                    text_predict.text = show;
                }
            }
        }

        if (ViveInput.GetPressDown(handRole, ControllerButton.Pad))
        {
            if (pos.x <= -0.85)
            {
                ModeChange(-1);
            }
            if (pos.x >= 0.85)
            {
                ModeChange(1);
            }
        }
    }