void Start()
    {
        var openVRError  = EVRInitError.None;
        var overlayError = EVROverlayError.None;

        //OpenVRの初期化
        openvr = OpenVR.Init(ref openVRError, EVRApplicationType.VRApplication_Overlay);
        if (openVRError != EVRInitError.None)
        {
            Debug.LogError(Tag + "OpenVRの初期化に失敗." + openVRError.ToString());
            ApplicationQuit();
            return;
        }

        //オーバーレイ機能の初期化
        overlay      = OpenVR.Overlay;
        overlayError = overlay.CreateOverlay(OverlayKey, OverlayFriendlyName, ref overlayHandle);
        if (overlayError != EVROverlayError.None)
        {
            Debug.LogError(Tag + "Overlayの初期化に失敗. " + overlayError.ToString());
            ApplicationQuit();
            return;
        }

        //オーバーレイの大きさ設定(幅のみ。高さはテクスチャの比から自動計算される)
        var width = 2.0f;

        overlay.SetOverlayWidthInMeters(overlayHandle, width);
        //オーバーレイの透明度を設定
        var alpha = 0.5f;

        overlay.SetOverlayAlpha(overlayHandle, alpha);

        //オーバーレイに渡すテクスチャ種類の設定
        var isOpenGL = SystemInfo.graphicsDeviceVersion.Contains("OpenGL");

        if (isOpenGL)
        {
            //pGLuintTexture
            overlayTexture.eType = ETextureType.OpenGL;
            //上下反転しない
            textureYflip = 1;
        }
        else
        {
            //pTexture
            overlayTexture.eType = ETextureType.DirectX;
            //上下反転する
            textureYflip = -1;
        }
        Debug.Log(Tag + "初期化完了しました");
    }
Ejemplo n.º 2
0
    // Token: 0x06005F2D RID: 24365 RVA: 0x00215594 File Offset: 0x00213994
    private ulong GetOverlayHandle(string overlayName, Transform transform, float widthInMeters = 1f)
    {
        ulong      num     = 0UL;
        CVROverlay overlay = OpenVR.Overlay;

        if (overlay == null)
        {
            return(num);
        }
        string          pchOverlayKey   = SteamVR_Overlay.key + "." + overlayName;
        EVROverlayError evroverlayError = overlay.FindOverlay(pchOverlayKey, ref num);

        if (evroverlayError != EVROverlayError.None)
        {
            evroverlayError = overlay.CreateOverlay(pchOverlayKey, overlayName, ref num);
        }
        if (evroverlayError == EVROverlayError.None)
        {
            overlay.ShowOverlay(num);
            overlay.SetOverlayAlpha(num, this.alpha);
            overlay.SetOverlayWidthInMeters(num, widthInMeters);
            if (SteamVR.instance.textureType == ETextureType.DirectX)
            {
                VRTextureBounds_t vrtextureBounds_t = default(VRTextureBounds_t);
                vrtextureBounds_t.uMin = 0f;
                vrtextureBounds_t.vMin = 1f;
                vrtextureBounds_t.uMax = 1f;
                vrtextureBounds_t.vMax = 0f;
                overlay.SetOverlayTextureBounds(num, ref vrtextureBounds_t);
            }
            SteamVR_Camera steamVR_Camera = (this.loadingScreenDistance != 0f) ? null : SteamVR_Render.Top();
            if (steamVR_Camera != null && steamVR_Camera.origin != null)
            {
                SteamVR_Utils.RigidTransform rigidTransform = new SteamVR_Utils.RigidTransform(steamVR_Camera.origin, transform);
                rigidTransform.pos.x = rigidTransform.pos.x / steamVR_Camera.origin.localScale.x;
                rigidTransform.pos.y = rigidTransform.pos.y / steamVR_Camera.origin.localScale.y;
                rigidTransform.pos.z = rigidTransform.pos.z / steamVR_Camera.origin.localScale.z;
                HmdMatrix34_t hmdMatrix34_t = rigidTransform.ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(num, SteamVR_Render.instance.trackingSpace, ref hmdMatrix34_t);
            }
            else
            {
                SteamVR_Utils.RigidTransform rigidTransform2 = new SteamVR_Utils.RigidTransform(transform);
                HmdMatrix34_t hmdMatrix34_t2 = rigidTransform2.ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(num, SteamVR_Render.instance.trackingSpace, ref hmdMatrix34_t2);
            }
        }
        return(num);
    }
Ejemplo n.º 3
0
 public EVROverlayError Create(string key, string friendlyName)
 {
     if (!Created)
     {
         Key          = key;
         FriendlyName = friendlyName;
         var error = FOverlay.CreateOverlay(key, friendlyName, ref FHandle);
         Created = error == EVROverlayError.None;
         FOverlay.SetOverlayWidthInMeters(FHandle, 1.5f);
         return(error);
     }
     else
     {
         return(EVROverlayError.None);
     }
 }
Ejemplo n.º 4
0
        public static bool SetOverlayTransform(string key, ref Matrix posMatrix, uint?controllerId, float width)
        {
            Debug.Assert(m_cvrOverlay != null);
            ulong handle = OpenVR.k_ulOverlayHandleInvalid;
            var   oError = m_cvrOverlay.FindOverlay(key, ref handle);

            if (oError != EVROverlayError.None)
            {
                Debug.Fail("Overlay does not exist " + oError.ToString());
                return(false);
            }
            HmdMatrix34_t hmdMatrix = new HmdMatrix34_t();

            MatrixToHmdMatrix34(ref posMatrix, ref hmdMatrix);

            if (controllerId == null)
            {
                oError = m_cvrOverlay.SetOverlayTransformAbsolute(handle, ETrackingUniverseOrigin.TrackingUniverseStanding, ref hmdMatrix);
            }
            else
            {
                oError = m_cvrOverlay.SetOverlayTransformTrackedDeviceRelative(handle, (uint)controllerId, ref hmdMatrix);
            }
            if (oError != EVROverlayError.None)
            {
                Debug.Fail("Overlay set transform failed " + oError.ToString());
                return(false);
            }

            oError = m_cvrOverlay.SetOverlayWidthInMeters(handle, width);
            if (oError != EVROverlayError.None)
            {
                Debug.Fail("Overlay set width failed " + oError.ToString());
                return(false);
            }
            return(true);
        }
Ejemplo n.º 5
0
        private static EVROverlayError ProcessOverlay2(CVROverlay overlay, ref ulong overlayHandle, ref bool overlayVisible, bool dashboardVisible)
        {
            var err = EVROverlayError.None;

            if (overlayHandle == 0)
            {
                err = overlay.FindOverlay("VRCX2", ref overlayHandle);
                if (err != EVROverlayError.None)
                {
                    if (err != EVROverlayError.UnknownOverlay)
                    {
                        return(err);
                    }
                    overlayVisible = false;
                    err            = overlay.CreateOverlay("VRCX2", "VRCX2", ref overlayHandle);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                    err = overlay.SetOverlayAlpha(overlayHandle, 0.9f);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                    err = overlay.SetOverlayWidthInMeters(overlayHandle, 1f);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                    err = overlay.SetOverlayInputMethod(overlayHandle, VROverlayInputMethod.None);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                    var m = Matrix.Scaling(1f);
                    m *= Matrix.Translation(0, -0.3f, -1.5f);
                    var hm34 = new HmdMatrix34_t
                    {
                        m0  = m.M11,
                        m1  = m.M21,
                        m2  = m.M31,
                        m3  = m.M41,
                        m4  = m.M12,
                        m5  = m.M22,
                        m6  = m.M32,
                        m7  = m.M42,
                        m8  = m.M13,
                        m9  = m.M23,
                        m10 = m.M33,
                        m11 = m.M43,
                    };
                    err = overlay.SetOverlayTransformTrackedDeviceRelative(overlayHandle, OpenVR.k_unTrackedDeviceIndex_Hmd, ref hm34);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                }
            }

            if (!dashboardVisible)
            {
                var texture = new Texture_t
                {
                    handle = m_Texture2.NativePointer
                };
                err = overlay.SetOverlayTexture(overlayHandle, ref texture);
                if (err != EVROverlayError.None)
                {
                    return(err);
                }
                if (!overlayVisible)
                {
                    err = overlay.ShowOverlay(overlayHandle);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                    overlayVisible = true;
                }
            }
            else if (overlayVisible)
            {
                err = overlay.HideOverlay(overlayHandle);
                if (err != EVROverlayError.None)
                {
                    return(err);
                }
                overlayVisible = false;
            }

            return(err);
        }
Ejemplo n.º 6
0
        private static EVROverlayError ProcessOverlay1(CVROverlay overlay, ref ulong overlayHandle, ref bool overlayVisible, bool dashboardVisible, uint overlayIndex, DateTime nextOverlay)
        {
            var err = EVROverlayError.None;

            if (overlayHandle == 0)
            {
                err = overlay.FindOverlay("VRCX1", ref overlayHandle);
                if (err != EVROverlayError.None)
                {
                    if (err != EVROverlayError.UnknownOverlay)
                    {
                        return(err);
                    }
                    overlayVisible = false;
                    err            = overlay.CreateOverlay("VRCX1", "VRCX1", ref overlayHandle);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                    err = overlay.SetOverlayAlpha(overlayHandle, 0.9f);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                    err = overlay.SetOverlayWidthInMeters(overlayHandle, 1f);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                    err = overlay.SetOverlayInputMethod(overlayHandle, VROverlayInputMethod.None);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                }
            }

            if (overlayIndex != OpenVR.k_unTrackedDeviceIndexInvalid)
            {
                // http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices
                // Scaling-Rotation-Translation
                var m = Matrix.Scaling(0.25f);
                m *= Matrix.RotationX(m_Rotation[0]);
                m *= Matrix.RotationY(m_Rotation[1]);
                m *= Matrix.RotationZ(m_Rotation[2]);
                m *= Matrix.Translation(m_Translation[0], m_Translation[1], m_Translation[2]);
                var hm34 = new HmdMatrix34_t
                {
                    m0  = m.M11,
                    m1  = m.M21,
                    m2  = m.M31,
                    m3  = m.M41,
                    m4  = m.M12,
                    m5  = m.M22,
                    m6  = m.M32,
                    m7  = m.M42,
                    m8  = m.M13,
                    m9  = m.M23,
                    m10 = m.M33,
                    m11 = m.M43,
                };
                err = overlay.SetOverlayTransformTrackedDeviceRelative(overlayHandle, overlayIndex, ref hm34);
                if (err != EVROverlayError.None)
                {
                    return(err);
                }
            }

            if (!dashboardVisible &&
                DateTime.UtcNow.CompareTo(nextOverlay) <= 0)
            {
                var texture = new Texture_t
                {
                    handle = m_Texture1.NativePointer
                };
                err = overlay.SetOverlayTexture(overlayHandle, ref texture);
                if (err != EVROverlayError.None)
                {
                    return(err);
                }
                if (!overlayVisible)
                {
                    err = overlay.ShowOverlay(overlayHandle);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                    overlayVisible = true;
                }
            }
            else if (overlayVisible)
            {
                err = overlay.HideOverlay(overlayHandle);
                if (err != EVROverlayError.None)
                {
                    return(err);
                }
                overlayVisible = false;
            }

            return(err);
        }
Ejemplo n.º 7
0
        private static EVROverlayError ProcessDashboard(CVROverlay overlay, ref ulong dashboardHandle, bool dashboardVisible)
        {
            var err = EVROverlayError.None;

            if (dashboardHandle == 0)
            {
                err = overlay.FindOverlay("VRCX", ref dashboardHandle);
                if (err != EVROverlayError.None)
                {
                    if (err != EVROverlayError.UnknownOverlay)
                    {
                        return(err);
                    }
                    ulong handle = 0;
                    err = overlay.CreateDashboardOverlay("VRCX", "VRCX", ref dashboardHandle, ref handle);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                    err = overlay.SetOverlayWidthInMeters(dashboardHandle, 1.5f);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                    err = overlay.SetOverlayInputMethod(dashboardHandle, VROverlayInputMethod.Mouse);
                    if (err != EVROverlayError.None)
                    {
                        return(err);
                    }
                }
            }

            var e = new VREvent_t();

            while (overlay.PollNextOverlayEvent(dashboardHandle, ref e, (uint)Marshal.SizeOf(e)))
            {
                var type = (EVREventType)e.eventType;
                if (type == EVREventType.VREvent_MouseMove)
                {
                    var m = e.data.mouse;
                    var s = m_Browser1.Size;
                    m_Browser1.GetBrowserHost().SendMouseMoveEvent((int)(m.x * s.Width), s.Height - (int)(m.y * s.Height), false, CefEventFlags.None);
                }
                else if (type == EVREventType.VREvent_MouseButtonDown)
                {
                    var m = e.data.mouse;
                    var s = m_Browser1.Size;
                    m_Browser1.GetBrowserHost().SendMouseClickEvent((int)(m.x * s.Width), s.Height - (int)(m.y * s.Height), MouseButtonType.Left, false, 1, CefEventFlags.LeftMouseButton);
                }
                else if (type == EVREventType.VREvent_MouseButtonUp)
                {
                    var m = e.data.mouse;
                    var s = m_Browser1.Size;
                    m_Browser1.GetBrowserHost().SendMouseClickEvent((int)(m.x * s.Width), s.Height - (int)(m.y * s.Height), MouseButtonType.Left, true, 1, CefEventFlags.None);
                }
            }

            if (dashboardVisible)
            {
                var texture = new Texture_t
                {
                    handle = m_Texture1.NativePointer
                };
                err = overlay.SetOverlayTexture(dashboardHandle, ref texture);
                if (err != EVROverlayError.None)
                {
                    return(err);
                }
            }

            return(err);
        }
Ejemplo n.º 8
0
    //位置情報を更新
    private void updatePosition()
    {
#pragma warning disable 0219
        string Tag = "[" + this.GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod(); //クラス名とメソッド名を自動取得
#pragma warning restore 0219

        //RenderTextureが生成されているかチェック
        if (!renderTexture.IsCreated())
        {
            Debug.Log(Tag + "RenderTextureがまだ生成されていない");
            return;
        }

        //回転を生成
        Quaternion quaternion = Quaternion.Euler(Rotation.x, Rotation.y, Rotation.z);
        //座標系を変更(右手系と左手系の入れ替え)
        Vector3 position = Position;
        position.z = -Position.z;
        //HMD視点位置変換行列に書き込む。
        Matrix4x4 m = Matrix4x4.TRS(position, quaternion, Scale);

        //鏡像反転
        Vector3 Mirroring = new Vector3(MirrorX ? -1 : 1, MirrorY ? -1 : 1, 1);

        //4x4行列を3x4行列に変換する。
        p.m0  = Mirroring.x * m.m00;
        p.m1  = Mirroring.y * m.m01;
        p.m2  = Mirroring.z * m.m02;
        p.m3  = m.m03;
        p.m4  = Mirroring.x * m.m10;
        p.m5  = Mirroring.y * m.m11;
        p.m6  = Mirroring.z * m.m12;
        p.m7  = m.m13;
        p.m8  = Mirroring.x * m.m20;
        p.m9  = Mirroring.y * m.m21;
        p.m10 = Mirroring.z * m.m22;
        p.m11 = m.m23;

        //回転行列を元に相対位置で表示
        if (DeviceTracking)
        {
            //deviceindexを処理(コントローラーなどはその時その時で変わるため)
            var idx = OpenVR.k_unTrackedDeviceIndex_Hmd;
            switch (DeviceIndex)
            {
            case TrackingDeviceSelect.LeftController:
                idx = openvr.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand);
                break;

            case TrackingDeviceSelect.RightController:
                idx = openvr.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.RightHand);
                break;

            default:
                idx = (uint)DeviceIndex;
                break;
            }
            //device情報に変化があったらInspectorに反映
            if (DeviceIndexOld != (int)idx)
            {
                Debug.Log(Tag + "Device Updated");
                UpdateDeviceInfo(idx);
                DeviceIndexOld = (int)idx;
            }

            //HMDからの相対的な位置にオーバーレイを表示する。
            overlay.SetOverlayTransformTrackedDeviceRelative(overlayHandle, idx, ref p);
        }
        else
        {
            //空間の絶対位置にオーバーレイを表示する
            if (!Seated)
            {
                overlay.SetOverlayTransformAbsolute(overlayHandle, ETrackingUniverseOrigin.TrackingUniverseStanding, ref p);
            }
            else
            {
                overlay.SetOverlayTransformAbsolute(overlayHandle, ETrackingUniverseOrigin.TrackingUniverseSeated, ref p);
            }
        }

        if (ResetSeatedCamera)
        {
            OpenVR.System.ResetSeatedZeroPose();
            ResetSeatedCamera = false;
        }

        //オーバーレイの大きさ設定(幅のみ。高さはテクスチャの比から自動計算される)
        overlay.SetOverlayWidthInMeters(overlayHandle, width);

        //オーバーレイの透明度を設定
        overlay.SetOverlayAlpha(overlayHandle, alpha);

        //マウスカーソルスケールを設定する(これにより表示領域のサイズも決定される)
        try
        {
            HmdVector2_t vecMouseScale = new HmdVector2_t
            {
                v0 = renderTexture.width,
                v1 = renderTexture.height
            };
            overlay.SetOverlayMouseScale(overlayHandle, ref vecMouseScale);
        }
        catch (UnassignedReferenceException e)
        {
            Debug.LogError(Tag + "RenderTextureがセットされていません " + e.ToString());
            ProcessError();
            return;
        }
    }
Ejemplo n.º 9
0
        private bool StartupOVR()
        {
            EVRInitError error = EVRInitError.Driver_Failed;

            vr = OpenVR.Init(ref error, EVRApplicationType.VRApplication_Overlay);

            if (error != EVRInitError.None)
            {
                Debug.WriteLine("OpenVR Init Error: " + error.ToString());
                return(false);
            }

            overlay = OpenVR.Overlay;

            EVROverlayError overlayError = overlay.CreateOverlay("Jstf_ovr_cards", "OpenVR Cards System Overlay", ref overlayHandle);

            if (overlayError != EVROverlayError.None)
            {
                OpenVR.Shutdown();
                Debug.WriteLine("OpenVR Overlay Error: " + overlayError.ToString());
                return(false);
            }

            /*overlayError = overlay.SetOverlayFromFile(overlayHandle, AssetsPath + "overlay.png");
             * if (overlayError != EVROverlayError.None)
             * {
             *      CleanupOVR();
             *      Debug.WriteLine("OpenVR Overlay Error: " + overlayError.ToString());
             *      return false;
             * }*/

            overlayError = overlay.SetOverlayInputMethod(overlayHandle, VROverlayInputMethod.Mouse);
            if (overlayError != EVROverlayError.None)
            {
                CleanupOVR();
                Debug.WriteLine("OpenVR Overlay Error: " + overlayError.ToString());
                return(false);
            }

            overlayTexture = new Texture_t
            {
                eType       = ETextureType.OpenGL,
                eColorSpace = EColorSpace.Auto,
                handle      = (IntPtr)textureId
            };

            overlayError = overlay.SetOverlayTexture(overlayHandle, ref overlayTexture);
            if (overlayError != EVROverlayError.None)
            {
                CleanupOVR();
                Debug.WriteLine("OpenVR Overlay Error: " + overlayError.ToString());
                return(false);
            }

            HmdId = OpenVR.k_unTrackedDeviceIndex_Hmd;

            for (uint i = HmdId + 1; i < OpenVR.k_unMaxTrackedDeviceCount; i++)
            {
                if (vr.IsTrackedDeviceConnected(i))
                {
                    ETrackedDeviceClass cls = vr.GetTrackedDeviceClass(i);
                    if (cls == ETrackedDeviceClass.Controller)
                    {
                        ETrackedControllerRole rl = vr.GetControllerRoleForTrackedDeviceIndex(i);
                        if (rl == ETrackedControllerRole.LeftHand)
                        {
                            LeftControllerId = i;
                            Debug.WriteLine("Found Left Controller");
                        }
                        else if (rl == ETrackedControllerRole.RightHand)
                        {
                            RightControllerId = i;
                            Debug.WriteLine("Found Right Controller");
                        }
                    }
                }
            }

            mat = new HmdMatrix34_t
            {
                m0  = 1,
                m1  = 0,
                m2  = 0,
                m3  = 0f,
                m4  = 0,
                m5  = 1,
                m6  = 0,
                m7  = 0.1f,
                m8  = 0,
                m9  = 0,
                m10 = 1,
                m11 = 0f
            };



            overlayError = overlay.SetOverlayTransformTrackedDeviceRelative(overlayHandle, RightControllerId, ref mat);
            if (overlayError != EVROverlayError.None)
            {
                Debug.WriteLine("Cannot bind overlay to Tracked device.");
                Debug.WriteLine("Error: " + overlayError.ToString());
                CleanupOVR();
                return(false);
            }
            overlayError = overlay.SetOverlayWidthInMeters(overlayHandle, 0.2f);
            if (overlayError != EVROverlayError.None)
            {
                Debug.WriteLine("Cannot set overlay size.");
                Debug.WriteLine("Error: " + overlayError.ToString());
                CleanupOVR();
                return(false);
            }

            overlayError = overlay.SetOverlayAlpha(overlayHandle, 1);
            if (overlayError != EVROverlayError.None)
            {
                Debug.WriteLine("Cannot set overlay alpha.");
                Debug.WriteLine("Error: " + overlayError.ToString());
                CleanupOVR();
                return(false);
            }

            overlayError = overlay.SetOverlayColor(overlayHandle, 1, 1, 1);
            if (overlayError != EVROverlayError.None)
            {
                Debug.WriteLine("Cannot set overlay color.");
                Debug.WriteLine("Error: " + overlayError.ToString());
                CleanupOVR();
                return(false);
            }
#if DEBUG
            Debug.WriteLine("OpenVR Startup Complete");
#endif
            return(true);
        }
Ejemplo n.º 10
0
 public void SetWidth(float width)
 {
     //オーバーレイの大きさ設定(幅のみ。高さはテクスチャの比から自動計算される)
     overlay.SetOverlayWidthInMeters(overlayHandle, width);
 }
Ejemplo n.º 11
0
    public void UpdateOverlay()
    {
        CVROverlay overlay = OpenVR.Overlay;

        if (overlay == null)
        {
            return;
        }
        if (this.texture != null)
        {
            EVROverlayError evroverlayError = overlay.ShowOverlay(this.handle);
            if ((evroverlayError == EVROverlayError.InvalidHandle || evroverlayError == EVROverlayError.UnknownOverlay) && overlay.FindOverlay(SteamVR_Overlay.key, ref this.handle) != EVROverlayError.None)
            {
                return;
            }
            Texture_t texture_t = default(Texture_t);
            texture_t.handle      = this.texture.GetNativeTexturePtr();
            texture_t.eType       = SteamVR.instance.textureType;
            texture_t.eColorSpace = EColorSpace.Auto;
            overlay.SetOverlayTexture(this.handle, ref texture_t);
            overlay.SetOverlayAlpha(this.handle, this.alpha);
            overlay.SetOverlayWidthInMeters(this.handle, this.scale);
            overlay.SetOverlayAutoCurveDistanceRangeInMeters(this.handle, this.curvedRange.x, this.curvedRange.y);
            VRTextureBounds_t vrtextureBounds_t = default(VRTextureBounds_t);
            vrtextureBounds_t.uMin = this.uvOffset.x * this.uvOffset.z;
            vrtextureBounds_t.vMin = (1f + this.uvOffset.y) * this.uvOffset.w;
            vrtextureBounds_t.uMax = (1f + this.uvOffset.x) * this.uvOffset.z;
            vrtextureBounds_t.vMax = this.uvOffset.y * this.uvOffset.w;
            overlay.SetOverlayTextureBounds(this.handle, ref vrtextureBounds_t);
            HmdVector2_t hmdVector2_t = default(HmdVector2_t);
            hmdVector2_t.v0 = this.mouseScale.x;
            hmdVector2_t.v1 = this.mouseScale.y;
            overlay.SetOverlayMouseScale(this.handle, ref hmdVector2_t);
            SteamVR_Camera steamVR_Camera = SteamVR_Render.Top();
            if (steamVR_Camera != null && steamVR_Camera.origin != null)
            {
                SteamVR_Utils.RigidTransform rigidTransform = new SteamVR_Utils.RigidTransform(steamVR_Camera.origin, base.transform);
                rigidTransform.pos.x = rigidTransform.pos.x / steamVR_Camera.origin.localScale.x;
                rigidTransform.pos.y = rigidTransform.pos.y / steamVR_Camera.origin.localScale.y;
                rigidTransform.pos.z = rigidTransform.pos.z / steamVR_Camera.origin.localScale.z;
                rigidTransform.pos.z = rigidTransform.pos.z + this.distance;
                HmdMatrix34_t hmdMatrix34_t = rigidTransform.ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(this.handle, SteamVR_Render.instance.trackingSpace, ref hmdMatrix34_t);
            }
            overlay.SetOverlayInputMethod(this.handle, this.inputMethod);
            if (this.curved || this.antialias)
            {
                this.highquality = true;
            }
            if (this.highquality)
            {
                overlay.SetHighQualityOverlay(this.handle);
                overlay.SetOverlayFlag(this.handle, VROverlayFlags.Curved, this.curved);
                overlay.SetOverlayFlag(this.handle, VROverlayFlags.RGSS4X, this.antialias);
            }
            else if (overlay.GetHighQualityOverlay() == this.handle)
            {
                overlay.SetHighQualityOverlay(0UL);
            }
        }
        else
        {
            overlay.HideOverlay(this.handle);
        }
    }
Ejemplo n.º 12
0
    void Update()
    {
        //初期化失敗するなどoverlayが無効な場合は実行しない
        if (overlay == null || error)
        {
            return;
        }

        if (show)
        {
            //オーバーレイを表示する
            overlay.ShowOverlay(overlayHandle);
        }
        else
        {
            //オーバーレイを非表示にする
            overlay.HideOverlay(overlayHandle);
        }

        //イベントを処理する
        uint uncbVREvent = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t));

        while (overlay.PollNextOverlayEvent(overlayHandle, ref Event, uncbVREvent))
        {
            if (eventlog)
            {
                Debug.Log(Tag + "Event:" + ((EVREventType)Event.eventType).ToString());
            }
            //Debug.Log(Tag +"Event:"+ (Event.eventType).ToString());
            switch ((EVREventType)Event.eventType)
            {
            case EVREventType.VREvent_MouseMove:
                MouseX = Event.data.mouse.x;
                MouseY = Event.data.mouse.y;
                break;

            case EVREventType.VREvent_MouseButtonDown:
                MouseClick = true;
                break;

            case EVREventType.VREvent_MouseButtonUp:
                MouseClick = false;
                break;

            case EVREventType.VREvent_DashboardActivated:
                break;

            case EVREventType.VREvent_DashboardDeactivated:
                break;

            case EVREventType.VREvent_DashboardRequested:
                break;

            case EVREventType.VREvent_DashboardThumbSelected:
                break;

            case EVREventType.VREvent_EnterStandbyMode:
                break;

            case EVREventType.VREvent_LeaveStandbyMode:
                break;

            case EVREventType.VREvent_KeyboardCharInput:
                break;

            case EVREventType.VREvent_KeyboardClosed:
                break;

            case EVREventType.VREvent_KeyboardDone:
                break;

            case EVREventType.VREvent_ResetDashboard:
                break;

            case EVREventType.VREvent_ScreenshotTriggered:
                break;

            case EVREventType.VREvent_WirelessDisconnect:
                break;

            case EVREventType.VREvent_WirelessReconnect:
                break;

            case EVREventType.VREvent_Quit:
                Debug.Log(Tag + "Quit");
                ApplicationQuit();
                break;

            default:
                break;
            }
        }

        if (overlay.IsDashboardVisible())
        {
            //サムネイルにテクスチャを設定
            if (thumbnailAvailable)
            {
                var overlayError = EVROverlayError.None;
                overlayError = overlay.SetOverlayTexture(thumbnailHandle, ref thumbnailTexture);
                if (overlayError != EVROverlayError.None)
                {
                    Debug.LogError(Tag + "Overlayにサムネイルをセットできませんでした. " + overlayError.ToString());
                    error = true;
                    return;
                }
            }
        }

        //オーバーレイが表示されている時
        if (overlay.IsOverlayVisible(overlayHandle) && overlay.IsActiveDashboardOverlay(overlayHandle))
        {
            //オーバーレイの大きさ設定(幅のみ。高さはSetOverlayMouseScaleの比から自動計算される)
            overlay.SetOverlayWidthInMeters(overlayHandle, width);
            //オーバーレイの透明度を設定
            overlay.SetOverlayAlpha(overlayHandle, alpha);

            //RenderTextureが生成されているかチェック
            if (!renderTexture.IsCreated())
            {
                Debug.Log(Tag + "RenderTextureがまだ生成されていない");
                return;
            }

            try
            {
                //マウスカーソルスケールを設定する(これにより表示領域のサイズも決定される)
                vecMouseScale.v0 = renderTexture.width;
                vecMouseScale.v1 = renderTexture.height;
                overlay.SetOverlayMouseScale(overlayHandle, ref vecMouseScale);
                //RenderTextureからネイティブテクスチャのハンドルを取得
                overlayTexture.handle = renderTexture.GetNativeTexturePtr();
            }
            catch (UnassignedReferenceException e)
            {
                Debug.LogError(Tag + "RenderTextureがセットされていません " + e.ToString());
                error = true;
                return;
            }

            //オーバーレイにテクスチャを設定
            var overlayError = EVROverlayError.None;
            overlayError = overlay.SetOverlayTexture(overlayHandle, ref overlayTexture);
            if (overlayError != EVROverlayError.None)
            {
                Debug.LogError(Tag + "Overlayにテクスチャをセットできませんでした. " + overlayError.ToString());
                error = true;
                return;
            }
        }
    }
Ejemplo n.º 13
0
    private void Update()
    {
#pragma warning disable 0219
        string Tag = "[" + this.GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod(); //クラス名とメソッド名を自動取得
#pragma warning restore 0219

        //エラーが発生した場合や、ハンドルが無効な場合は実行しない
        if (IsError())
        {
            return;
        }


        //イベントを処理する(終了された時true)
        if (ProcessEvent())
        {
            Debug.Log(Tag + "VRシステムが終了されました");
            ApplicationQuit();
        }

        //サイドバイサイド3D
        overlay.SetOverlayFlag(overlayHandle, VROverlayFlags.SideBySide_Parallel, true);
        overlay.ShowOverlay(overlayHandle);


        //オーバーレイが表示されている時
        if (overlay.IsOverlayVisible(overlayHandle))
        {
            if (overlay.IsOverlayVisible(overlayHandle))
            {
                //widthをセット インスペクタからいじれる
                overlay.SetOverlayWidthInMeters(overlayHandle, width);

                //HMD視点位置変換行列に書き込む。
                //ここでは回転なし、平行移動ありのHUD的な状態にしている。
                var wx = -0f;
                var wy = -0f;
                var wz = -overlayScreenDepth;

                p.m0 = 1; p.m1 = 0; p.m2 = 0; p.m3 = wx;
                p.m4 = 0; p.m5 = 1; p.m6 = 0; p.m7 = wy;
                p.m8 = 0; p.m9 = 0; p.m10 = 1; p.m11 = wz;

                //回転行列を元に、HMDからの相対的な位置にオーバーレイを表示する。
                //代わりにSetOverlayTransformAbsoluteを使用すると、ルーム空間に固定することができる
                uint indexunTrackedDevice = 0;//0=HMD(他にControllerやTrackerにすることもできる)
                overlay.SetOverlayTransformTrackedDeviceRelative(overlayHandle, indexunTrackedDevice, ref p);

                //RenderTextureが生成されているかチェック
                if (!renderTexture.IsCreated())
                {
                    Debug.Log(Tag + "RenderTextureがまだ生成されていない");
                    return;
                }

                //RenderTextureからネイティブテクスチャのハンドルを取得
                try
                {
                    overlayTexture.handle = renderTexture.GetNativeTexturePtr();
                }
                catch (UnassignedReferenceException e)
                {
                    Debug.LogError(Tag + "RenderTextureがセットされていません");
                    ApplicationQuit();
                    return;
                }

                //オーバーレイにテクスチャを設定
                var overlayError = EVROverlayError.None;
                overlayError = overlay.SetOverlayTexture(overlayHandle, ref overlayTexture);
                if (overlayError != EVROverlayError.None)
                {
                    Debug.LogError(Tag + "Overlayにテクスチャをセットできませんでした. " + overlayError.ToString());
                    ApplicationQuit();
                    return;
                }
            }
        }
    }
Ejemplo n.º 14
0
 /**
  * Set an overlay's width, in meters
  */
 public void SetWidthInMeters(float width)
 {
     ReportError(overlay.SetOverlayWidthInMeters(handle, width));
 }
Ejemplo n.º 15
0
 //大きくする(操作不能になることもあるので保存しない)
 public void upWidth()
 {
     config.width += 0.1f;
     overlay.SetOverlayWidthInMeters(overlayHandle, config.width);
 }