Ejemplo n.º 1
0
    void Update()
    {
        eou.Init();
        eou.AutoExitOnQuit();

        var l = eou.GetLeftControllerTransform();
        var r = eou.GetRightControllerTransform();

        eou.SetGameObjectLocalTransform(ref LeftController, eou.GetLeftControllerTransform());
        eou.SetGameObjectLocalTransform(ref RightController, r);
    }
Ejemplo n.º 2
0
    private void UpdatePos()
    {
        if (!util.IsReady())
        {
            util.Init();
            return;
        }

        EasyOpenVRUtil.Transform pos;
        if (controller == LR.Left)
        {
            pos = util.GetLeftControllerTransform();
        }
        else
        {
            pos = util.GetRightControllerTransform();
        }
        this.transform.position = pos.position;
        this.transform.rotation = pos.rotation;
    }
Ejemplo n.º 3
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;
        }
    }
Ejemplo n.º 4
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;
            }
        }
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //初期化されていないとき初期化する
        if (!util.IsReady())
        {
            util.Init();
            return;
        }

        //fpsに依存しない更新にする
        util.SetAutoUpdate(false);
        util.ClearPredictedTime();
        util.Update();

        //フレームタイミングを表示
        FrameTiming = FrameTiming * 0.99 + util.GetCompositorFrameTime() * 0.01f;

        FPSMonitor2.text = String.Format("{0:###.#}", FrameTiming + 0.05f);
        //30fpsを切ったら自動でセーフモードへ
        if (FrameTiming > 33.3)
        {
            ResoMan.LowResolution(false);
        }

        //秒に一回Battery残量を反映
        if (BatteryUpdateTimer > 1.0f)
        {
            //コントローラ
            batteryWorker.PercentL = util.GetDeviceBatteryPercentage(util.GetLeftControllerIndex()) / 100.0f;
            batteryWorker.PercentR = util.GetDeviceBatteryPercentage(util.GetRightControllerIndex()) / 100.0f;

            //トラッカー
            List <uint> list = util.GetViveTrackerIndexList();
            if (list.Count > 0)
            {
                batteryWorker.PercentT1 = util.GetDeviceBatteryPercentage(list[0]) / 100.0f;
            }
            else
            {
                batteryWorker.PercentT1 = float.NaN;
            }
            if (list.Count > 1)
            {
                batteryWorker.PercentT2 = util.GetDeviceBatteryPercentage(list[1]) / 100.0f;
            }
            else
            {
                batteryWorker.PercentT2 = float.NaN;
            }
            if (list.Count > 2)
            {
                batteryWorker.PercentT3 = util.GetDeviceBatteryPercentage(list[2]) / 100.0f;
            }
            else
            {
                batteryWorker.PercentT3 = float.NaN;
            }

            BatteryUpdateTimer = 0f;
        }
        else
        {
            BatteryUpdateTimer += Time.deltaTime;
        }


        //コントローラのボタン入力と取得可能かをチェック
        ulong Leftbutton = 0, Rightbutton = 0, HMDbutton = 0;
        bool  leftok  = util.GetControllerButtonPressed(util.GetLeftControllerIndex(), out Leftbutton);
        bool  rightok = util.GetControllerButtonPressed(util.GetRightControllerIndex(), out Rightbutton);
        //bool hmdok = util.GetControllerButtonPressed(util.GetHMDIndex(), out HMDbutton);

        /*
         * if (hmdok) {
         *  if ((HMDbutton & 0x80000000) != 0)
         *  {
         *      //かぶってる
         *  }
         *  else {
         *      //かぶってない
         *  }
         * }*/

        //左手の加速度を取得(左手が有効な場合)
        Vector3 leftHandVelocity = Vector3.zero;

        if (leftok && config.detectLeftHand)
        {
            var trans = util.GetLeftControllerTransform();
            if (trans != null)
            {
                leftHandVelocity = trans.velocity;
            }
        }

        //右手の加速度を取得(右手が有効な場合)
        Vector3 rightHandVelocity = Vector3.zero;

        if (rightok && config.detectRightHand)
        {
            var trans = util.GetRightControllerTransform();
            if (trans != null)
            {
                rightHandVelocity = trans.velocity;
            }
        }

        //タップロック反映
        if (config.taplockmode)
        {
            if ((Leftbutton == config.unlockkey) || (Rightbutton == config.unlockkey))
            {
                //ボタンが押されているとき
                eovro.tapEnable = true;

                CursorL.locked = false;
                CursorR.locked = false;
            }
            else
            {
                //ボタンが押されていないとき
                eovro.tapEnable = false;

                CursorL.locked = true;
                CursorR.locked = true;
            }
        }
        else
        {
            //ロック関係なし
            eovro.tapEnable = true;

            CursorL.locked = false;
            CursorR.locked = false;
        }

        //ピーク検出
        if (AccelerationPeak < Math.Abs(leftHandVelocity.y))
        {
            AccelerationPeak = Math.Abs(leftHandVelocity.y);
            PeakText.text    = string.Format("Acceleration\nSet: {0:#.#}", AccelerationPeak);
        }
        if (AccelerationPeak < Math.Abs(rightHandVelocity.y))
        {
            AccelerationPeak = Math.Abs(rightHandVelocity.y);
            PeakText.text    = string.Format("Acceleration\nSet: {0:#.#}", AccelerationPeak);
        }

        //腕振り下ろしを判定
        if (leftHandVelocity.y < -config.speeddown)
        {
            //ロックモードではない or グリップボタンだけが押されている(&ロックモード)
            if (!config.lockmode || (Leftbutton == config.unlockkey))
            {
                menu.IsRightHand = false;
                if (menu.showing == false)
                {
                    menu.MenuStart = true;
                    MissSwingTime  = Time.time; //現在時刻を記録
                }
                else
                {
                    //空振り

                    //メニューを出してから十分時間経ってるのに振った
                    if (Time.time > MissSwingTime + 1)
                    {
                        AudioMan.PlayCancelSound(); //振りミス音を鳴らす
                        MissSwingTime = Time.time;  //現在時刻を記録
                    }
                }
            }
        }
        if (rightHandVelocity.y < -config.speeddown)
        {
            //ロックモードではない or グリップボタンだけが押されている(&ロックモード)
            if (!config.lockmode || (Rightbutton == config.unlockkey))
            {
                menu.IsRightHand = true;
                if (menu.showing == false)
                {
                    menu.MenuStart = true;
                    MissSwingTime  = Time.time; //現在時刻を記録
                }
                else
                {
                    //空振り

                    //メニューを出してから十分時間経ってるのに振った
                    if (Time.time > MissSwingTime + 1)
                    {
                        AudioMan.PlayCancelSound(); //振りミス音を鳴らす
                        MissSwingTime = Time.time;  //現在時刻を記録
                    }
                }
            }
        }

        //腕振り上げ判定
        if (leftHandVelocity.y > config.speedup || rightHandVelocity.y > config.speedup)
        {
            //ロックモードではない or グリップボタンだけが押されている(&ロックモード)
            if (!config.lockmode || (Rightbutton == config.unlockkey) || (Leftbutton == config.unlockkey))
            {
                menu.MenuEndFunc(0);
            }
        }

        //腕横振り判定
        if (Math.Abs(leftHandVelocity.z) > config.speedup && config.slideClose)
        {
            //ロックモードではない or グリップボタンだけが押されている(&ロックモード)
            if (!config.lockmode || Leftbutton == config.unlockkey)
            {
                //方向判定
                if (leftHandVelocity.z < 0)
                {
                    menu.MenuEndFunc(1);
                }
                else
                {
                    menu.MenuEndFunc(2);
                }
            }
        }
        if (Math.Abs(rightHandVelocity.z) > config.speedup && config.slideClose)
        {
            //ロックモードではない or グリップボタンだけが押されている(&ロックモード)
            if (!config.lockmode || Rightbutton == config.unlockkey)
            {
                //方向判定
                if (rightHandVelocity.z < 0)
                {
                    menu.MenuEndFunc(1);
                }
                else
                {
                    menu.MenuEndFunc(2);
                }
            }
        }


        //Debug.Log(util.GetRightControllerTransform().velocity.x);
    }
Ejemplo n.º 6
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);
            }
        }
    }
Ejemplo n.º 7
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!util.IsReady())
        {
            util.Init();
            return;
        }

        button = 0;

        Vector3 nowPos;

        if (controller == LR.Left)
        {
            util.GetControllerButtonPressed(util.GetLeftControllerIndex(), out button);
            nowPos = util.GetLeftControllerTransform().position;
        }
        else
        {
            util.GetControllerButtonPressed(util.GetRightControllerIndex(), out button);
            nowPos = util.GetRightControllerTransform().position;
        }

        /**
         * 加速度
         */
        float   deltaTime = 1; //1フレーム
        Vector3 v         = (nowPos - prePos) / deltaTime;
        Vector3 a         = (v - preV) / deltaTime;

        accele    = a * 10000;
        acceleAvg = Mathf.Sqrt(
            (a.x * a.x) +
            (a.y * a.y) +
            (a.z * a.z)
            );

        prePos = nowPos;
        preV   = v;

        /**
         * コードショット部分
         */
        if (isTriggerPressed)
        {
            //トリガー押されてる状態から離されるとコードを放つ
            if (button != ViveConstants.TRIGGER)
            {
                //ChordPadManager.instance.Ring(nowPos.y - 0.5f);
                Debug.Log(nowPos.y - 0.5f);
                isTriggerPressed = false;
            }
        }
        else
        {
            //トリガーが離されてる状態から押されるとコードを止める
            if (button == ViveConstants.TRIGGER)
            {
                //ChordPadManager.instance.Mute();
                isTriggerPressed = true;
            }
        }
    }
Ejemplo n.º 8
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();
            }
        }
    }