예제 #1
0
    private void UpdateCameraTexture()
    {
        if (!util.IsReady())
        {
            util.Init();
            return;
        }

        var pos = util.GetHMDTransform();

        this.transform.position = pos.position;
        this.transform.rotation = pos.rotation;
    }
예제 #2
0
    void Update()
    {
        if (!util.IsReady())
        {
            util.Init();
            return;
        }

        var h = util.GetHMDTransform();

        if (h != null)
        {
            Head.transform.position = h.position;
            Head.transform.rotation = h.rotation;
        }

        //IPD取得してカメラに反映
        float IPD = util.GetPropertyFloatWhenConnected(util.GetHMDIndex(), Valve.VR.ETrackedDeviceProperty.Prop_UserIpdMeters_Float);

        if (!float.IsNaN(IPD))
        {
            LeftEye.transform.localPosition  = new Vector3(-IPD / 2f, 0, 0);
            RightEye.transform.localPosition = new Vector3(IPD / 2f, 0, 0);
        }

        var l = util.GetLeftControllerTransform();

        if (l != null)
        {
            LeftHand.transform.position = l.position;
            LeftHand.transform.rotation = l.rotation;
        }

        var r = util.GetRightControllerTransform();

        if (r != null)
        {
            RightHand.transform.position = r.position;
            RightHand.transform.rotation = r.rotation;
        }
    }
예제 #3
0
    void Update()
    {
        ValueWatcher();
        //System.GC.Collect();

        //FPSモニタ
        if (showing && !busy)
        {
            fps             = fps * 0.99f + (1f / Time.deltaTime) * 0.01f;
            FPSMonitor.text = String.Format("{0:###}", 1f / Time.deltaTime);

            //よほどのことがない限り下がらないfpsが一気に下がったらメニューを強制的に閉じる
            if (fps < 15f) //表示時で15fps以下
            {
                MenuEndFunc(0);
            }
        }
        else
        {
            fps = 90; //閉じてるときは90扱いにする
        }


        //初期化されていないとき初期化する
        if (!util.IsReady())
        {
            util.Init();
            return;
        }

        //チュートリアル中の見失い防止処理
        //初期位置から動いてないときは自動で再配置する
        if (isInTutorial || EOVRO.Position == Vector3.zero)
        {
            TutorialTimer += Time.deltaTime;
            if (TutorialTimer > 10f)
            {
                TutorialTimer = 0;
                setPosition();
            }
        }

        //移動モード
        if (isScreenMoving)
        {
            ulong button = 0;
            EasyOpenVRUtil.Transform pos  = util.GetHMDTransform();
            EasyOpenVRUtil.Transform cpos = null;
            if (screenMoveWithRight)
            {
                if (util.GetControllerButtonPressed(util.GetRightControllerIndex(), out button))
                {
                    cpos = util.GetRightControllerTransform();
                }
            }
            else
            {
                if (util.GetControllerButtonPressed(util.GetLeftControllerIndex(), out button))
                {
                    cpos = util.GetLeftControllerTransform();
                }
            }
            if (button == 0)
            {
                AudioMan.PlayApplySound();
                isScreenMoving = false;
            }

            if (pos != null && cpos != null)
            {
                var     z   = 0;
                Vector3 ang = (cpos.rotation * Quaternion.AngleAxis(45, Vector3.right)).eulerAngles;
                //常にこっちに向き、ゆっくり追従する
                Vector3 BillboardPosition = cpos.position;                      //これが難しい...
                Vector3 BillboardRotation = new Vector3(-ang.x, -ang.y, ang.z); //こっち向く。これでオッケー

                EOVRO.Position = BillboardPosition;
                EOVRO.Rotation = BillboardRotation;
            }
        }
    }
예제 #4
0
    void Update()
    {
        //姿勢取得ライブラリが初期化されていないとき初期化する
        //(OpenVRの初期化はEasyOpenVROverlayの方で行われるはずなので待機)
        if (!util.IsReady())
        {
            util.Init();
            return;
        }

        //HMDの位置情報が使えるようになった & 初期位置が初期化されていないとき
        if (util.GetHMDTransform() != null && PositionInitialize)
        {
            //とりあえずUnityスタート時のHMD位置に設定
            //(サンプル用。より適切なタイミングで呼び直してください。
            // OpenVRが初期化されていない状態では原点になってしまいます)
            setPosition();

            //初期位置初期化処理を停止
            PositionInitialize = false;
        }

        //カーソル位置を更新
        //オーバーレイライブラリが返す座標系をCanvasの座標系に変換している。
        //オーバーレイライブラリの座標サイズ(RenderTexture依存)と
        //Canvasの幅・高さが一致する必要がある。
        LeftCursorTextRectTransform.anchoredPosition  = new Vector2(EasyOpenVROverlay.LeftHandU - CanvasRectTransform.sizeDelta.x / 2f, EasyOpenVROverlay.LeftHandV - CanvasRectTransform.sizeDelta.y / 2f);
        RightCursorTextRectTransform.anchoredPosition = new Vector2(EasyOpenVROverlay.RightHandU - CanvasRectTransform.sizeDelta.x / 2f, EasyOpenVROverlay.RightHandV - CanvasRectTransform.sizeDelta.y / 2f);

        //移動モード処理
        if (isScreenMoving)
        {
            ulong button = 0;
            EasyOpenVRUtil.Transform pos  = util.GetHMDTransform(); //HMDが有効か調べる
            EasyOpenVRUtil.Transform cpos = null;                   //任意の手の姿勢情報
            if (screenMoveWithRight)                                //右手で操作されたなら
            {
                //右手のボタンが押されているか取得しながら、右手が有効か調べる
                if (util.GetControllerButtonPressed(util.GetRightControllerIndex(), out button))
                {
                    //有効なら右手の姿勢情報を取得する(瞬間的に通信が切れnullの可能性もある)
                    cpos = util.GetRightControllerTransform();
                }
            }
            else
            {
                //左手のボタンが押されているか取得しながら、右手が有効か調べる
                if (util.GetControllerButtonPressed(util.GetLeftControllerIndex(), out button))
                {
                    //有効なら左手の姿勢情報を取得する(瞬間的に通信が切れnullの可能性もある)
                    cpos = util.GetLeftControllerTransform();
                }
            }

            //ボタンが一切押されなくなったならば移動モードから抜ける
            if (button == 0)
            {
                isScreenMoving = false;
            }

            //HMDも取得したコントローラ姿勢も有効ならば
            if (pos != null && cpos != null)
            {
                //コントローラの姿勢クォータニオンを45度傾けて、オイラー角に変換(しないと意図しない向きになってしまう)
                Vector3 ang = (cpos.rotation * Quaternion.AngleAxis(45, Vector3.right)).eulerAngles;

                //コントローラの位置をそのままOverlayの位置に反映
                EasyOpenVROverlay.Position = cpos.position;                 //これが難しい...

                //コントローラの回転を適時反転させてOverlayの回転に反映(こちら向きにする)
                EasyOpenVROverlay.Rotation = new Vector3(-ang.x, -ang.y, ang.z);
            }
        }
    }
예제 #5
0
    void Update()
    {
        if (!eou.IsReady())
        {
            eou.StartOpenVR();
        }

        if (HMD_Offset == null || LeftHand_Offset == null || RightHand_Offset == null)
        {
            HMD_Offset       = eou.GetHMDTransform();
            LeftHand_Offset  = eou.GetLeftControllerTransform();
            RightHand_Offset = eou.GetRightControllerTransform();
        }

        eou.AutoExitOnQuit();

        _config = configManager.GetConfig();

        HMDTrans       = eou.GetHMDTransform();
        LeftHandTrans  = eou.GetLeftControllerTransform();
        RightHandTrans = eou.GetRightControllerTransform();

        eou.SetGameObjectTransform(ref HMD, HMDTrans);
        eou.SetGameObjectTransform(ref LeftHand, LeftHandTrans);
        eou.SetGameObjectTransform(ref RightHand, RightHandTrans);

        eou.SetGameObjectTransformWithOffset(ref HMD_withOffset, HMDTrans, HMD_Offset);
        eou.SetGameObjectTransformWithOffset(ref LeftHand_withOffset, LeftHandTrans, LeftHand_Offset);
        eou.SetGameObjectTransformWithOffset(ref RightHand_withOffset, RightHandTrans, RightHand_Offset);

        ulong button;

        if (isFollowRightHand)
        {
            eou.GetControllerButtonPressed(eou.GetRightControllerIndex(), out button);
        }
        else
        {
            eou.GetControllerButtonPressed(eou.GetLeftControllerIndex(), out button);
        }
        if (button != 0)
        {
            V_Chest.SetActive(false);
            V_Foot_L.SetActive(false);
            V_Foot_R.SetActive(false);
            V_Offset.SetActive(false);
        }

        if (_config.isMenuLeftHand && LeftHandTrans != null && LeftHandTrans.velocity.y < -3.5f || _config.isMenuRightHand && RightHandTrans != null && RightHandTrans.velocity.y < -3.5f)
        {
            if (!MenuManager.IsActive() && (!_config.isMenuLock || _config.MenuLockButton == 0 || _config.MenuLockButton == button))
            {
                MenuManager.Open();
            }
        }
        else if (_config.isMenuLeftHand && LeftHandTrans != null && LeftHandTrans.velocity.y > 3.5f || _config.isMenuRightHand && RightHandTrans != null && RightHandTrans.velocity.y > 3.5f)
        {
            if (MenuManager.IsActive() && (!_config.isMenuLock || _config.MenuLockButton == 0 || _config.MenuLockButton == button))
            {
                MenuManager.Close();
            }
        }
    }