Esempio n. 1
0
        private void SETUP_eyeRender(int eyeIndex)
        {
            GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.Default);
            EyeType       eye            = hmd.EyeRenderOrder[eyeIndex];
            EyeRenderDesc renderDesc     = eyeRenderDesc[(int)eye];
            Rect          renderViewport = eyeRenderViewport[(int)eye];

            UpdateFromHmd(eye);

            renderPose[(int)eye] = config.player.hmd.PoseF;

            // Calculate view matrix
            var finalRollPitchYaw = config.player.Rotation;

            var finalUp = finalRollPitchYaw.Transform(Vector3.UnitY);
            //var finalUp = Vector3.UnitY
            var finalForward = finalRollPitchYaw.Transform(-Vector3.UnitZ);

            var shiftedEyePos = config.player.Position;

            eyeView = Matrix.Translation(renderDesc.HmdToEyeViewOffset) * config.player.LookAtRH;

            // Calculate projection matrix
            eyeProjection = OVR.MatrixProjection(renderDesc.Fov, 0.001f, -1000.0f, true);
            eyeProjection.Transpose();

            eyeWorld = Matrix.Identity;

            // Set Viewport for our eye
            GraphicsDevice.SetViewport(renderViewport.ToViewportF());
        }
Esempio n. 2
0
        public Matrix GetEyeProjection(int eyeIndex, float zNear, float zFar)
        {
            var projection = OVR.MatrixProjection(EyeRenderDesc[eyeIndex].Fov, zNear, zFar, true);

            projection.Transpose();
            return(projection);
        }
Esempio n. 3
0
        protected sealed override void Draw(GameTime gameTime)
        {
            var rollPitchYaw = Matrix.RotationY(bodyYaw);

            // Get eye poses
            hmd.GetEyePoses(0, hmdToEyeViewOffset, eyeRenderPose);
            layerEyeFov.RenderPoseLeft  = eyeRenderPose[0];
            layerEyeFov.RenderPoseRight = eyeRenderPose[1];

#if RUNVR
            for (int eyeIndex = 0; eyeIndex < 2; eyeIndex++)
            {
                var eye        = hmd.EyeRenderOrder[eyeIndex];
                var renderDesc = eyeRenderDesc[(int)eye];
                var renderPose = eyeRenderPose[(int)eye];

                // Calculate view matrix
                Matrix finalRollPitchYaw = rollPitchYaw * renderPose.Orientation.GetMatrix();
                var    finalUp           = finalRollPitchYaw.Transform(Vector3.UnitY);
                var    finalForward      = finalRollPitchYaw.Transform(-Vector3.UnitZ);
                var    shiftedEyePos     = rollPitchYaw.Transform(headPos + renderPose.Position);
                view = Matrix.LookAtRH(shiftedEyePos, shiftedEyePos + finalForward, finalUp);

                // Calculate projection matrix
                projection = OVR.MatrixProjection(renderDesc.Fov, 0.01f, 10000.0f, Projection.RightHanded);
                projection.Transpose();

                // Get render target
                var swapTexture = eyeTexture[(int)eye];
                swapTexture.AdvanceToNextView();

                // Clear the screen
                GraphicsDevice.SetRenderTargets(swapTexture.DepthStencilView, swapTexture.CurrentView);
                GraphicsDevice.SetViewport(swapTexture.Viewport);
                ((SharpDX.Direct3D11.Device)GraphicsDevice).ImmediateContext.ClearDepthStencilView(
                    swapTexture.DepthStencilView,
                    DepthStencilClearFlags.Depth |
                    DepthStencilClearFlags
                    .Stencil, 1, 0);
                ((SharpDX.Direct3D11.Device)GraphicsDevice).ImmediateContext.ClearRenderTargetView(swapTexture.CurrentView,
                                                                                                   Color.CornflowerBlue);
                DrawScene(gameTime);
                if (UsePsMove)
                {
                    PsMoveController.Draw(GraphicsDevice, view, projection);
                }
            }
#else
            GraphicsDevice.Clear(Color.CornflowerBlue);

            var eye        = hmd.EyeRenderOrder[0];
            var renderDesc = eyeRenderDesc[(int)eye];
            var renderPose = eyeRenderPose[(int)eye];
            // Calculate view matrix
            Matrix finalRollPitchYaw = rollPitchYaw * renderPose.Orientation.GetMatrix();
            var    finalUp           = finalRollPitchYaw.Transform(Vector3.UnitY);
            var    finalForward      = finalRollPitchYaw.Transform(-Vector3.UnitZ);
            var    shiftedEyePos     = rollPitchYaw.Transform(headPos + renderPose.Position);
            view = Matrix.LookAtRH(shiftedEyePos, shiftedEyePos + finalForward, finalUp);

            // Calculate projection matrix
            projection = OVR.MatrixProjection(renderDesc.Fov, 0.01f, 10000.0f, Projection.RightHanded);
            projection.Transpose();
            DrawScene(gameTime);
            base.Draw(gameTime);
#endif
        }