コード例 #1
0
    // Correct the yaw drift component of the FOVE headset
    private void CorrectHeadsetYawDrift()
    {
        long currentTimeMs         = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
        long timeSinceLastUpdateMs = currentTimeMs - lastDriftCorrectionTimeMs;

        if (timeSinceLastUpdateMs < (long)millisecondsBetweenDriftCorrection)
        {
            return;
        }

        Quaternion foveToFlatSurface     = Quaternion.Euler(FoveHeadsetTareOrientation.eulerAngles.x, 0.0f, FoveHeadsetTareOrientation.eulerAngles.z);
        Quaternion viveToFlatSurface     = Quaternion.Euler(ViveTrackerTareOrientation.eulerAngles.x, 0.0f, ViveTrackerTareOrientation.eulerAngles.z);
        Quaternion tareFoveOnFlatSurface = (FoveHeadsetTareOrientation * Quaternion.Inverse(foveToFlatSurface));
        Quaternion tareViveOnFlatSurface = (ViveTrackerTareOrientation * Quaternion.Inverse(viveToFlatSurface));

        Quaternion currentFoveRotation  = FoveInterface.GetHMDRotation();
        Quaternion curFoveOnFlatSurface = (currentFoveRotation * Quaternion.Inverse(foveToFlatSurface));
        Quaternion curViveOnFlatSurface = (currentViveTrackerPose.rot * Quaternion.Inverse(viveToFlatSurface));

        Quaternion desiredYawDiff = tareFoveOnFlatSurface * Quaternion.Inverse(tareViveOnFlatSurface);
        Quaternion currentYawDiff = curFoveOnFlatSurface * Quaternion.Inverse(curViveOnFlatSurface);

        yawDriftCorrectionOffset = (desiredYawDiff * Quaternion.Inverse(currentYawDiff)).eulerAngles.y;

        lastDriftCorrectionTimeMs = currentTimeMs;
    }
コード例 #2
0
    // Update is called once per frame
    private void Update()
    {
        Ray ray = new Ray(this.transform.position, FoveInterface.GetHMDRotation() * Vector3.forward * distance);

        //Rayを画面に表示
        Debug.DrawRay(ray.origin, ray.direction * distance, Color.green);

        /*
         * Debug.LogFormat("Rotation x : {0}, y: {1} z: {2} ",
         *          ray.direction.x, ray.direction.y, ray.direction.z);
         */

        Debug.LogFormat("{0}", Mathf.Round(FoveInterface.GetHMDPosition().z));
        // まばたきでボールを飛ばすように
        countTime += Time.deltaTime;

        if (FoveInterface.CheckEyesClosed() == EFVR_Eye.Both &&
            countTime > blinkThreshold)
        {
            GameObject tempBall = MakeBall();
            tempBall.GetComponent <BaketBall>().Shot(ray.direction * power);
            tempBall  = null;
            countTime = 0;
        }
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        //時間関連データの取得
        nt = DateTime.Now;     //ここに到達したときの時刻を取得する
        TimeSpan ts = nt - st; //実行からどれくらい経過しているのかを計算

        //fpsの計算
        ++frameCount;
        float time = Time.realtimeSinceStartup - prevTime;

        if (time >= 0.5f)
        {
            fpstime = frameCount / time;
            //Debug.LogFormat("{0}fps", fpstime);
            frameCount = 0;
            prevTime   = Time.realtimeSinceStartup;
        }

        //目のデータの取得
        FoveInterface.EyeRays eyes = FoveInterface.GetEyeRays();

        //HMD関連のデータの取得
        hmdpos = FoveInterface.GetHMDPosition(); //HMDの位置座標
        hmdrot = FoveInterface.GetHMDRotation(); //HMDの方向座標
        //Debug.Log(hmdpos.x + "," + hmdpos.y + "," + hmdpos.z + "," + hmdrot.x + "," + hmdrot.y + "," + hmdrot.z + "," + hmdrot.w);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            tf = 1;
        }

        if (tf == 1)//csvへの書き込み
        {
            //CSVに記録する情報
            //現在時刻,現在時刻のミリ秒,経過時間,経過時間のミリ秒,fps,チェッカールームの回転速度,眼球の座標(左),眼球の座標(右),視線のベクトル(左),視線のベクトル(右),HMDの座標,HMDの向き
            streamWriter.Write(nt.ToString() + ',' + nt.Millisecond.ToString() + ',' + ts.ToString() + ',' + nt.Millisecond.ToString() + ','
                               + eyes.right.origin.x.ToString() + ',' + eyes.right.origin.y.ToString() + ',' + eyes.right.origin.z.ToString() + ','
                               + eyes.left.origin.x.ToString() + ',' + eyes.left.origin.y.ToString() + ',' + eyes.left.origin.z.ToString() + ','
                               + hmdpos.x.ToString() + ',' + hmdpos.y.ToString() + ',' + hmdpos.z.ToString() + ','
                               + hmdrot.x.ToString() + ',' + hmdrot.y.ToString() + ',' + hmdrot.z.ToString() + ',' + hmdrot.w.ToString()); //csvに書き込むデータのリスト
            streamWriter.WriteLine();                                                                                                      //データの取得
            Debug.Log("書き込み中");
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            streamWriter.Close();//csvに書き込む
            Debug.Log("書き込み終了");
        }
    }
コード例 #4
0
        private void Update()
        {
            //move the weapon in function of Type of Inputs
            if (m_camInputManager.CurrentInputName == "Mouse")
            {
                transform.position = m_cameraTransform.position;
                transform.rotation = m_cameraTransform.rotation;
            }
            else if (m_camInputManager.CurrentInputName == "Gamepad")
            {
                transform.position = m_cameraTransform.position;

                if (m_camInputManager.CurrentCamera.name == "VRCamera")
                {
                    transform.rotation = Quaternion.Slerp(transform.rotation, InputTracking.GetLocalRotation(VRNode.Head),
                                                          m_Damping * (1 - Mathf.Exp(k_DampingCoef * Time.deltaTime)));

                    Quaternion lookAtRotation = Quaternion.LookRotation(m_VRReticle.ReticleTransform.position - m_gunContainer.position);
                    m_gunContainer.rotation = Quaternion.Slerp(m_gunContainer.rotation, lookAtRotation, m_GunContainerSmoothing * Time.deltaTime);
                }
                else if (m_camInputManager.CurrentCamera.name == "FoveInterface")
                {
                    Quaternion quat = FoveInterface.GetHMDRotation();
                    transform.rotation = Quaternion.Slerp(transform.rotation, quat,
                                                          m_Damping * (1 - Mathf.Exp(k_DampingCoef * Time.deltaTime)));

                    Quaternion lookAtRotation = Quaternion.LookRotation(m_VRReticle.ReticleTransform.position - m_gunContainer.position);
                    m_gunContainer.rotation = Quaternion.Slerp(m_gunContainer.rotation, lookAtRotation, m_GunContainerSmoothing * Time.deltaTime);
                }
            }

            else if (m_camInputManager.CurrentInputName == "Touch")
            {
                //Update anchors of touch weapon
                OVRInput.Update();
                if (tag == "LTouch")
                {
                    transform.localRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch);
                    transform.localPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch);
                }
                else if (tag == "RTouch")
                {
                    transform.localRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch);
                    transform.localPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch);
                }
            }
        }
コード例 #5
0
    void Awake()
    {
        foveInterface = SceneLoader.instance.foveInterface.GetComponentInChildren <FoveInterface>().gameObject;

        float forwardAmount = 0.55f;

        transform.position = FoveInterface.GetHMDRotation() * Vector3.forward * forwardAmount;
        transform.position = new Vector3(transform.position.x + foveInterface.transform.position.x,
                                         foveInterface.transform.position.y,
                                         transform.position.z + foveInterface.transform.position.z);
        transform.LookAt(foveInterface.transform.position);

        // Light configuration
        globalDirectionalLight.transform.position = transform.position;
        globalDirectionalLight.transform.rotation = transform.rotation;
        globalDirectionalLight.transform.Rotate(new Vector3(30, 30, 0));
    }
コード例 #6
0
    void FixedUpdate()
    {
        if (!recordingTrackingData)
        {
            return;
        }

        var vp = videoSphere.GetComponent <VideoPlayer>();

        if (vp.isPlaying)
        {
            nextRecord = Time.time + recordRate;

            var quaternion = FoveInterface.GetHMDRotation();
            var euler      = quaternion.eulerAngles;

            //var leftEyeVector = FoveInterface.GetLeftEyeVector();
            //var rightEyeVector = FoveInterface.GetRightEyeVector();

            //var leftRay = new Ray(foveInterface.GetEyeCamera(Fove.EFVR_Eye.Left).transform.position, leftEyeVector);
            //var rightRay = new Ray(foveInterface.GetEyeCamera(Fove.EFVR_Eye.Right).transform.position, rightEyeVector);

            FoveInterface.EyeRays rays = FoveInterface.GetEyeRays();
            var leftRay  = rays.left;
            var rightRay = rays.right;


            //Debug.DrawRay(leftRay.origin, leftRay.direction, Color.green, 2, false);
            //Debug.DrawRay(rightRay.origin, rightRay.direction, Color.blue, 2, false);

            Vector2 pixeluvLeft  = GetPixelTextureCoords(leftRay);
            Vector2 pixeluvRight = GetPixelTextureCoords(rightRay);

            string[] data = new string[] { vp.time.ToString(), euler.x.ToString(), euler.y.ToString(), euler.z.ToString(), quaternion.x.ToString(), quaternion.y.ToString(), quaternion.z.ToString(), quaternion.w.ToString(),
                     leftRay.direction.x.ToString(), leftRay.direction.y.ToString(), leftRay.direction.z.ToString(), rightRay.direction.x.ToString(), rightRay.direction.y.ToString(), rightRay.direction.z.ToString(),
                     pixeluvLeft.x.ToString(), pixeluvLeft.y.ToString(), pixeluvRight.x.ToString(), pixeluvRight.y.ToString(), insideTargetAreaChecker.InsideTargetArea().ToString() };

            orientationStringWriter.Write(string.Join(delimiter, data) + "\n");
        }
    }
コード例 #7
0
    private void Update()
    {
        /**
         * Press H to localize FOVE space -> Vive Space -> World Space
         *   The user's current head orientation will now be used as a reference for 0 degree yaw in world space
         *   The position of the user will now be shifted to the origin of world space
         */
        if (Input.GetKeyDown(KeyCode.H))
        {
            // Check that headset vive tracker and controllers are both active
            if ((IsHeadsetPositionTracked() && IsControllersConnected()) == false)
            {
                return;
            }

            // Check that fove is set up correctly
            if ((FoveInterface.IsHardwareConnected() && FoveInterface.IsHardwareReady()) == false)
            {
                return;
            }

            // See how much we should rotate FOVE to get it to its proper Vive space
            Vector3    leftControllerRotation      = leftController.transform.localRotation.eulerAngles;
            Vector3    rightControllerRotation     = rightController.transform.localRotation.eulerAngles;
            Vector3    averageControllerRotation   = (leftControllerRotation + rightControllerRotation) / 2.0f;
            Vector3    foveHmdRotation             = FoveInterface.GetHMDRotation().eulerAngles;
            Quaternion foveToViveRotationTransform = Quaternion.Euler(0.0f, (averageControllerRotation - foveHmdRotation).y, 0.0f);
            Debug.Log("FoveToViveRotationTransform: " + foveToViveRotationTransform + averageControllerRotation);
            yawOrientationOffset = foveToViveRotationTransform.eulerAngles.y;

            // Shift everything back to center
            personSetup.transform.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            personSetup.transform.position = new Vector3(0.0f, 0.0f, 0.0f);

            // See how much we should rotate the Vive to get it into its proper world space
            FoveViveToWorldSpace           = Quaternion.Euler(0.0f, averageControllerRotation.y * -1.0f, 0.0f);
            personSetup.transform.rotation = FoveViveToWorldSpace;
            Vector3 scenePositionShiftAmount = transform.position * -1.0f;
            personSetup.transform.position = new Vector3(
                scenePositionShiftAmount.x,
                personSetup.transform.position.y,
                scenePositionShiftAmount.z);

            // Log the current FOVE headset and Vive Tracker orientation
            FoveHeadsetTareOrientation = FoveInterface.GetHMDRotation();
            ViveTrackerTareOrientation = currentViveTrackerPose.rot;

            // Everything is done
            isHeadsetCalibrated = true;
            Debug.Log("Finished setting up FOVE localization");
        }

        /**
         * Press P to shift the user's current position to the center of world space
         */
        if (Input.GetKeyDown(KeyCode.P))
        {
            ReCenterUser();
        }

        // Attempt to mitigate FOVE headset's yaw drift
        if (driftCorrection)
        {
            CorrectHeadsetYawDrift();
        }
        else
        {
            yawDriftCorrectionOffset = 0.0f;
        }

        // Update the position and orientation of the headset
        transform.localRotation = Quaternion.Euler(0.0f, yawOrientationOffset + yawDriftCorrectionOffset, 0.0f);
        var eyePositionOffset = transform.localRotation * FoveInterface.GetHMDRotation() * trackerToEyePositionOffset;

        transform.localPosition = currentViveTrackerPose.pos + eyePositionOffset;

        // Rotate person setup to world space + any additional rotate offset specified by user
        Vector3 currentPersonPosition = transform.position;

        personSetup.transform.rotation = Quaternion.Euler(FoveViveToWorldSpace.eulerAngles + new Vector3(0.0f, rotateSetupDegree, 0.0f));
        TeleportUser(currentPersonPosition);
    }
コード例 #8
0
ファイル: SpinRoom.cs プロジェクト: Yoshiya1113/Fove
    // Update is called once per frame
    void Update()
    {
        //fpsの計算
        ++frameCount;
        float time = Time.realtimeSinceStartup - prevTime;

        if (time >= 0.5f)
        {
            fpstime = frameCount / time;
            //Debug.LogFormat("{0}fps", fpstime);
            frameCount = 0;
            prevTime   = Time.realtimeSinceStartup;
        }

        //目のデータの取得
        FoveInterface.EyeRays eyes = FoveInterface.GetEyeRays();
        //視点の計算
        RaycastHit hitLeft, hitRight;

        Physics.Raycast(eyes.left, out hitLeft, Mathf.Infinity);
        Physics.Raycast(eyes.right, out hitRight, Mathf.Infinity);
        originhit = hitLeft.point + ((hitRight.point - hitLeft.point) / 2);//視点座標を代入

        //HMD関連のデータの取得
        hmdpos = FoveInterface.GetHMDPosition(); //HMDの位置座標
        hmdrot = FoveInterface.GetHMDRotation(); //HMDの方向座標
        //Debug.Log(hmdpos.x + "," + hmdpos.y + "," + hmdpos.z + "," + hmdrot.x + "," + hmdrot.y + "," + hmdrot.z + "," + hmdrot.w);


        if (Input.GetKeyDown(KeyCode.Space))
        {
            spintim   = 1;
            n         = 90.0f;
            spinstart = DateTime.Now;//実行を始めた時刻
        }

        if (Input.GetKeyDown(KeyCode.N))
        {
            vectionfeel = 1;
            //n = 90.0f;
        }

        if (spintim == 1)                 //checkerroomの回転、csvへの書き込み
        {
            nt = DateTime.Now;            //ここに到達したときの時刻を取得する
            TimeSpan ts = nt - spinstart; //実行からどれくらい経過しているのかを計算

            //経過時刻と角速度に合わせてチェッカールームを傾ける
            //フレーム当たりの角速度を
            spinangle  = ts.Milliseconds * n / 1000.0f;
            spinangle += ts.Seconds * n;
            spinangle += ts.Minutes * n;
            //spinangle += 0.9f;//Unityは60fpsというのを前提
            transform.localRotation = Quaternion.Euler(0.0f, spinangle, 0.0f);

            //CSVに記録する情報
            //現在時刻,現在時刻のミリ秒,経過時間,経過時間のミリ秒,fps,チェッカールームの回転速度,眼球の座標(左),眼球の座標(右),視線のベクトル(左),視線のベクトル(右),視点の座標,HMDの座標,HMDの向き,ベクション
            streamWriter.Write(nt.ToString() + ',' + nt.Millisecond.ToString() + ',' + ts.ToString() + ',' + nt.Millisecond.ToString() + ','
                               + fpstime.ToString() + ','                                                                                                                                           //fps
                               + n.ToString() + ','                                                                                                                                                 //チェッカールームの回転速度
                               + eyes.left.origin.x.ToString() + ',' + eyes.left.origin.y.ToString() + ',' + eyes.left.origin.z.ToString() + ','                                                    //左目の座標
                               + eyes.right.origin.x.ToString() + ',' + eyes.right.origin.y.ToString() + ',' + eyes.right.origin.z.ToString() + ','                                                 //右目の座標
                               + FoveInterface.GetLeftEyeVector().x.ToString() + ',' + FoveInterface.GetLeftEyeVector().y.ToString() + ',' + FoveInterface.GetLeftEyeVector().z.ToString() + ','    //左目ベクトル
                               + FoveInterface.GetRightEyeVector().x.ToString() + ',' + FoveInterface.GetRightEyeVector().y.ToString() + ',' + FoveInterface.GetRightEyeVector().z.ToString() + ',' //右目ベクトル
                               + originhit.x.ToString() + ',' + originhit.y.ToString() + ',' + originhit.z.ToString() + ','                                                                         //視点の座標
                               + hmdpos.x.ToString() + ',' + hmdpos.y.ToString() + ',' + hmdpos.z.ToString() + ','                                                                                  //HMDの座標
                               + hmdrot.x.ToString() + ',' + hmdrot.y.ToString() + ',' + hmdrot.z.ToString() + ',' + hmdrot.w.ToString() + ','                                                      //HMDの向き
                               + vectionfeel.ToString());                                                                                                                                           //ベクション
            //csvに書き込むデータのリスト
            streamWriter.WriteLine();                                                                                                                                                               //改行
            Debug.Log("書き込み中");

            //データ確認用
            //Debug.Log(spinstart);//回転開始時
            //Debug.Log(nt);//現在時刻
            //Debug.Log(ts);//経過時間
            //Debug.Log(ts.Milliseconds);//経過時間(ミリ秒)
            //Debug.Log(spinangle);//移動角
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            spintim = 0;
            streamWriter.Close();//csvに書き込む
            //Debug.Log("書き込み終了");
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            n = 180.0f;
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            n = 60.0f;
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            n = 90.0f;
        }
    }
コード例 #9
0
 // Update is called once per frame
 void Update()
 {
     Debug.DrawLine(transform.position, FoveInterface.GetHMDRotation() * Vector3.forward + transform.position, Color.red, 1.0f);
     //Debug.Log(FoveInterface.GetHMDRotation() * Vector3.forward + transform.position);
 }
 // Update is called once per frame
 void Update()
 {
     transform.rotation = FoveInterface.GetHMDRotation();
 }