コード例 #1
0
 //Convert OSVR.ClientKit.Viewport to Rect
 public static Rect ConvertViewport(OSVR.ClientKit.Viewport viewport, OSVR.ClientKit.DisplayDimensions surfaceDisplayDimensions, int numDisplayInputs, int eyeIndex, int totalDisplayWidth)
 {
     //Unity expects normalized coordinates, not pixel coordinates
     if (numDisplayInputs == 1)
     {
         return(new Rect((float)viewport.Left / (float)surfaceDisplayDimensions.Width,
                         (float)viewport.Bottom / (float)surfaceDisplayDimensions.Height,
                         (float)viewport.Width / (float)surfaceDisplayDimensions.Width,
                         (float)viewport.Height / (float)surfaceDisplayDimensions.Height));
     }
     else if (numDisplayInputs == 2)
     {
         //with two inputs in fullscreen mode, viewports expect to fill the screen
         //Unity can only output to one window, so we offset the right eye by half the total width of the displays
         return(new Rect(eyeIndex == 0 ? 0 : 0.5f + (float)viewport.Left / (float)totalDisplayWidth,
                         (float)viewport.Bottom / (float)surfaceDisplayDimensions.Height,
                         (float)viewport.Width / (float)totalDisplayWidth,
                         (float)viewport.Height / (float)surfaceDisplayDimensions.Height));
     }
     else
     {
         Debug.LogError("[OSVR-Unity] More than two video inputs is not supported. Using default viewport.");
         return(new Rect(0, 0, 0.5f, 1f));
     }
 }
コード例 #2
0
            //Set Resolution of the Unity game window based on total surface width
            private void SetResolution()
            {
                TotalDisplayWidth  = 0; //add up the width of each eye
                TotalDisplayHeight = 0; //don't add up heights

                int numDisplayInputs = DisplayConfig.GetNumDisplayInputs();

                //for each display
                for (int i = 0; i < numDisplayInputs; i++)
                {
                    OSVR.ClientKit.DisplayDimensions surfaceDisplayDimensions = DisplayConfig.GetDisplayDimensions((byte)i);

                    TotalDisplayWidth += (uint)surfaceDisplayDimensions.Width;  //add up the width of each eye
                    TotalDisplayHeight = (uint)surfaceDisplayDimensions.Height; //store the height -- this shouldn't change
                }

                //Set the resolution. Don't force fullscreen if we have multiple display inputs
                //We only need to do this if we aren't using RenderManager, because it adjusts the window size for us
                //@todo figure out why this causes problems with direct mode, perhaps overfill factor?
                if (numDisplayInputs > 1 && !_renderManagerConfigFound)
                {
                    Screen.SetResolution((int)TotalDisplayWidth, (int)TotalDisplayHeight, false);
                }
            }