internal static void SetDeviceViewport(Viewport viewport)
        {
            GetRenderProfiler().StartProfilingBlock("MySandboxGame::SetDeviceViewport");

            if (m_renderTargetsCount == 0)
            {
                if ((DefaultSurface.Description.Height >= (viewport.Height + viewport.Y))
                    && (DefaultSurface.Description.Width >= (viewport.Width + viewport.X))
                    ||
                    m_screenshot != null)
                {
                    GetRenderProfiler().StartProfilingBlock("set viewport");
                    GraphicsDevice.Viewport = viewport;
                    GetRenderProfiler().EndProfilingBlock();
                }
                else
                {
                    GetRenderProfiler().StartProfilingBlock("change screen size");
                    UpdateScreenSize();
                    GetRenderProfiler().EndProfilingBlock();
                }
            }
            else
            {
                GetRenderProfiler().StartProfilingBlock("set viewport");
                GraphicsDevice.Viewport = viewport;
                GetRenderProfiler().EndProfilingBlock();
            }
            GetRenderProfiler().EndProfilingBlock();

        }
        private static void SetupCustomViewProjection(MyEffectTransparentGeometry effect, ref Viewport originalViewport, MyBillboard lastBillboard, ref bool ignoreDepth, ref Matrix projectionMatrix)
        {
            if (lastBillboard.CustomViewProjection != -1 && MyRenderProxy.BillboardsViewProjectionRead.ContainsKey(lastBillboard.CustomViewProjection))
            {
                var billboardViewProjection = MyRenderProxy.BillboardsViewProjectionRead[lastBillboard.CustomViewProjection];
                effect.SetViewMatrix(ref billboardViewProjection.ViewAtZero);
                effect.SetProjectionMatrix(ref billboardViewProjection.Projection);


                Matrix invProjectionMatrix = Matrix.Invert((MyRenderCamera.m_backupMatrix.HasValue ? MyRenderCamera.m_backupMatrix.Value : MyRenderCamera.ProjectionMatrix));
                effect.SetInverseDefaultProjectionMatrix(ref invProjectionMatrix);

                Viewport viewport = new Viewport((int)billboardViewProjection.Viewport.OffsetX, (int)billboardViewProjection.Viewport.OffsetY,
                    (int)billboardViewProjection.Viewport.Width, (int)billboardViewProjection.Viewport.Height);
                if (MyRender.GetScreenshot() != null)
                    viewport = new Viewport((int)(billboardViewProjection.Viewport.OffsetX * MyRender.GetScreenshot().SizeMultiplier.X),
                                            (int)(billboardViewProjection.Viewport.OffsetY * MyRender.GetScreenshot().SizeMultiplier.Y),
                                            (int)(billboardViewProjection.Viewport.Width * MyRender.GetScreenshot().SizeMultiplier.X),
                                            (int)(billboardViewProjection.Viewport.Height * MyRender.GetScreenshot().SizeMultiplier.Y));
                MyRender.SetDeviceViewport(viewport);
                ignoreDepth = !billboardViewProjection.DepthRead;
                projectionMatrix = billboardViewProjection.Projection;
            }
            else
            {
                var viewMatrix = MyRenderCamera.ViewMatrixAtZero;
                effect.SetViewMatrix(ref viewMatrix);
                effect.SetProjectionMatrix(ref MyRenderCamera.ProjectionMatrix);
                MyRender.SetDeviceViewport(originalViewport);
                ignoreDepth = false;
                projectionMatrix = MyRenderCamera.ProjectionMatrix;
            }
        }
        public static BoundingFrustum UnprojectRectangle(VRageMath.Rectangle source, Viewport viewport, Matrix viewMatrix, Matrix projectionMatrix)
        {
            // Point in screen space of the center of the region selected
            Vector2 regionCenterScreen = new Vector2(source.Center.X, source.Center.Y);
            // Generate the projection matrix for the screen region
            Matrix regionProjMatrix = projectionMatrix;
            // Calculate the region dimensions in the projection matrix. M11 is inverse of width, M22 is inverse of height.
            regionProjMatrix.M11 /= ((float)source.Width / (float)viewport.Width);
            regionProjMatrix.M22 /= ((float)source.Height / (float)viewport.Height);
            // Calculate the region center in the projection matrix. M31 is horizonatal center.
            regionProjMatrix.M31 = (regionCenterScreen.X - (viewport.Width / 2f)) / ((float)source.Width / 2f);

            // M32 is vertical center. Notice that the screen has low Y on top, projection has low Y on bottom.
            regionProjMatrix.M32 = -(regionCenterScreen.Y - (viewport.Height / 2f)) / ((float)source.Height / 2f);

            return new BoundingFrustum(viewMatrix * regionProjMatrix);
        }
 void PrepareViewportForCascade(int splitIndex)
 {
     // Set the viewport for the current split   
     Viewport splitViewport = new Viewport();
     splitViewport.MinDepth = 0;
     splitViewport.MaxDepth = 1;
     splitViewport.Width = ShadowMapCascadeSize;
     splitViewport.Height = ShadowMapCascadeSize;
     splitViewport.X = splitIndex * ShadowMapCascadeSize;
     splitViewport.Y = 0;
     //Must be here because otherwise it crasher after resolution change
     MyRender.SetDeviceViewport(splitViewport);
 }
示例#5
0
        /// <summary>
        /// Attempts to begin drawing the control. Returns false if this was not possible.
        /// </summary>
        private bool BeginDraw()
        {
            // Make sure the graphics device is big enough, and is not lost.
            if (HandleDeviceResetAndSizeChanged() != ResizeResetResult.OK) return false;

            // Multiple DirectImage instances can share the same device. The viewport is adjusted
            // for when a smaller DirectImage is rendering.
            if (surfaceType == SurfaceType.DirectX9)
            {
                Viewport viewport = new Viewport();
                viewport.X = 0;
                viewport.Y = 0;
                viewport.Width = viewportWidth;
                viewport.Height = viewportHeight;
//                viewport.MinZ = 0;
                //viewport.MaxZ = 1;
                GraphicsDevice.Viewport = viewport;
            }

            if (surfaceType == SurfaceType.Direct2D)
            {
                var viewport2D = new Viewport();
                viewport2D.Height = viewportHeight;
                viewport2D.MaxDepth = 1;
                viewport2D.MinDepth = 0;
                //viewport2D.TopLeftX = 0;
                //viewport2D.TopLeftY = 0;
                viewport2D.Width = viewportWidth;
                graphicsDeviceService10.SetViewport(viewport2D);
            }
            return true;
        }
示例#6
0
        public static void DrawText(Vector3D worldCoord, StringBuilder text, Color color, float scale, bool depthRead, MyGuiDrawAlignEnum align = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, int customViewProjection = -1)
        {
            System.Diagnostics.Debug.Assert(customViewProjection == -1 || MyRenderProxy.BillboardsViewProjectionRead.ContainsKey(customViewProjection));

            if (customViewProjection != -1 && !MyRenderProxy.BillboardsViewProjectionRead.ContainsKey(customViewProjection))
                return;

            //customViewProjection
            Vector4D screenCoord = Vector4D.Transform(worldCoord, customViewProjection == -1 ? MyRenderCamera.ViewProjectionMatrix : MyRenderProxy.BillboardsViewProjectionRead[customViewProjection].View * MyRenderProxy.BillboardsViewProjectionRead[customViewProjection].Projection);

            if (screenCoord.Z > 0)
            {
                Vector2 projectedPoint2D = new Vector2((float)(screenCoord.X / screenCoord.W) / 2.0f + 0.5f, (float)(-screenCoord.Y / screenCoord.W) / 2.0f + 0.5f);

                if (customViewProjection == -1)
                    projectedPoint2D = MyRender.GetHudPixelCoordFromNormalizedCoord(projectedPoint2D);
                else
                {
                    var myviewport = MyRenderProxy.BillboardsViewProjectionRead[customViewProjection].Viewport;
                    SharpDX.Viewport viewport = new Viewport((int)myviewport.OffsetX, (int)myviewport.OffsetY, (int)myviewport.Width, (int)myviewport.Height);

                    projectedPoint2D = new Vector2(
                        projectedPoint2D.X * viewport.Width + viewport.X,
                        projectedPoint2D.Y * viewport.Height + viewport.Y);
                }

                DrawText(projectedPoint2D, text, color, scale, depthRead, align);
            }
        }
示例#7
0
        public bool ProjectToTarget(ref Vector3 position, out Vector2 coordinate, Viewport viewport)
        {
            Vector2 size = new Vector2(viewport.Width, viewport.Height);

            bool result = ProjectToCoordinate(this, ref position, out coordinate, ref size);

            coordinate.X = size.X * (coordinate.X * 0.5f + 0.5f);
            coordinate.Y = size.Y * (coordinate.Y * 0.5f + 0.5f);

            return result;
        }
示例#8
0
 public void ProjectFromTarget(ref Vector2 coordinate, float projectDepth, out Vector3 position, Viewport viewport)
 {
     Vector2 size = new Vector2(viewport.Width, viewport.Height);
     ProjectFromCoordinate(this, false, ref coordinate, projectDepth, out position, ref size);
 }
示例#9
0
 public void SetDeviceViewport(Viewport viewport)
 {
     MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyMinerGame::SetDeviceViewport");
     if (m_renderTargetsCount == 0)
     {
         if ((MyMinerGame.Static.GraphicsManager.PreferredBackBufferHeight >= (viewport.Height + viewport.Y))
             && (MyMinerGame.Static.GraphicsManager.PreferredBackBufferWidth >= (viewport.Width + viewport.X)))
         {
             MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("set viewport");
             MyMinerGame.Static.GraphicsDevice.Viewport = viewport;
             MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
         }
         else
         {
             MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("change screen size");
             MyVideoModeManager.UpdateScreenSize();
             MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
         }
     }
     else  
     {
         MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("set viewport");
         MyMinerGame.Static.GraphicsDevice.Viewport = viewport;
         MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
     }
     MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
         
 }