Exemplo n.º 1
0
    //終了イベントをキャッチした時に戻す
    private bool ProcessEvent()
    {
#pragma warning disable 0219
        string Tag = "[" + this.GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod(); //クラス名とメソッド名を自動取得
#pragma warning restore 0219

        //イベント構造体のサイズを取得
        uint uncbVREvent = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t));

        //イベント情報格納構造体
        VREvent_t Event = new VREvent_t();
        //イベントを取り出す
        while (overlay.PollNextOverlayEvent(overlayHandle, ref Event, uncbVREvent))
        {
            //イベントのログを表示
            if (eventLog)
            {
                Debug.Log(Tag + "Event:" + ((EVREventType)Event.eventType).ToString());
            }

            //イベント情報で分岐
            switch ((EVREventType)Event.eventType)
            {
            case EVREventType.VREvent_Quit:
                Debug.Log(Tag + "Quit");
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 2
0
        public bool ProcessEvent(bool debug)
        {
            //イベント構造体のサイズを取得
            uint uncbVREvent = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t));

            //イベント情報格納構造体
            VREvent_t Event = new VREvent_t();

            //イベントを取り出す
            while (overlay.PollNextOverlayEvent(overlayHandle, ref Event, uncbVREvent))
            {
                //イベントのログを表示
                if (debug)
                {
                    Console.WriteLine("Event:" + ((EVREventType)Event.eventType).ToString());
                }

                //イベント情報で分岐
                switch ((EVREventType)Event.eventType)
                {
                case EVREventType.VREvent_Quit:
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
    public bool PollNextEvent(ref VREvent_t pEvent)
    {
        CVROverlay overlay = OpenVR.Overlay;

        if (overlay == null)
        {
            return(false);
        }
        uint uncbVREvent = (uint)Marshal.SizeOf(typeof(VREvent_t));

        return(overlay.PollNextOverlayEvent(this.handle, ref pEvent, uncbVREvent));
    }
Exemplo n.º 4
0
 static void PollOverlayEvents(ulong handle)
 {
     if (m_cvrOverlay.HandleControllerOverlayInteractionAsMouse(handle, m_controller2ID))
     {
         //controller points to the overlay and event was generated. Unsure if the call above must be called every tick to generate event
         VREvent_t oEvent     = new VREvent_t();
         uint      oEventSize = (uint)Marshal.SizeOf(oEvent);
         while (m_cvrOverlay.PollNextOverlayEvent(handle, ref oEvent, oEventSize))
         {
             Log.WriteLineAndConsole("OVERLAY event (#" + oEvent.trackedDeviceIndex + "): " + oEvent.eventType.ToString() + " " + Enum.GetName(typeof(EVREventType), oEvent.eventType));
             switch (oEvent.eventType)
             {
             case (uint)EVREventType.VREvent_MouseMove:
                 if (oEvent.trackedDeviceIndex == m_controller2ID)
                 {
                     Log.WriteLineAndConsole("  " + oEvent.data.mouse.x + "," + oEvent.data.mouse.y);
                 }
                 break;
             }
         }
     }
     ;
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        private void RenderRoutine()
        {
            StartupGL();
            if (!StartupOVR())
            {
                CleanupGL();
                return;
            }

            EVROverlayError overlayError = overlay.ShowOverlay(overlayHandle);

            if (overlayError != EVROverlayError.None)
            {
                Debug.WriteLine("Cannot show overlay.");
                Debug.WriteLine("Error: " + overlayError.ToString());
                CleanupOVR();
                CleanupGL();
                return;
            }

            while (RenderAlive)
            {
                DateTime begin = DateTime.Now;
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                if (CurrentCard == null)
                {
                    if (CardQueue.TryDequeue(out Card c))
                    {
                        if (c != null)
                        {
                            CurrentCard = c;
                            continue;
                        }
                    }
                    Thread.Sleep(500);
                }
                else
                {
                    DrawCard(CurrentCard);

                    GL.Clear(ClearBufferMask.DepthBufferBit);

                    if (CurrentCard.Status == CardStatus.Hidden)
                    {
                        CurrentCard = null;
                        Debug.WriteLine("Dropping card.");
                    }


                    overlayError = overlay.SetOverlayTexture(overlayHandle, ref overlayTexture);
                    if (overlayError != EVROverlayError.None)
                    {
                        Debug.WriteLine("Cannot set texture.");
                        Debug.WriteLine("Error: " + overlayError.ToString());
                        CleanupOVR();
                        CleanupGL();
                        return;
                    }
                }


                if (EchoWindow)
                {
                    GL.ClearColor(1, 1, 1, 0);

                    GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
                    GL.DrawBuffer(DrawBufferMode.Back);
                    GL.Viewport(0, 0, render_window.Width, render_window.Height);
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                    GL.Disable(EnableCap.Blend);
                    EchoScene.Instance.Draw();

                    render_window.SwapBuffers();

                    GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBufferId);
                    GL.Enable(EnableCap.Blend);
                    GL.DrawBuffer(DrawBufferMode.ColorAttachment0);
                    GL.Viewport(0, 0, textureSizeX, textureSizeY);
                    GL.ClearColor(0, 0, 0, 0);
                }

                VREvent_t ev = new VREvent_t();
                if (overlay.PollNextOverlayEvent(overlayHandle, ref ev, (uint)Marshal.SizeOf(ev.GetType())))
                {
                    switch ((EVREventType)ev.eventType)
                    {
                    case EVREventType.VREvent_OverlayShown:
                        Debug.WriteLine("Overlay shown.");
                        break;

                    case EVREventType.VREvent_OverlayHidden:
                        Debug.WriteLine("Overlay Hidden.");
                        break;
                    }
                }

                if (vr.PollNextEvent(ref ev, (uint)Marshal.SizeOf(ev.GetType())))
                {
                    switch ((EVREventType)ev.eventType)
                    {
                    case EVREventType.VREvent_Quit:
                        StopRender();
                        break;

                    case EVREventType.VREvent_DriverRequestedQuit:
                        StopRender();
                        break;
                    }
                }
                DateTime end = DateTime.Now;
                double   ms  = (end - begin).TotalMilliseconds;
                Thread.Sleep((int)(Math.Max(12.0 - ms, 0)));
            }

            CleanupOVR();
            CleanupGL();
        }
Exemplo n.º 7
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;
            }
        }
    }