Beispiel #1
0
        public static void Draw(GameTime gameTime)
        {
            if (ActiveScene != null)
            {
                //if (!Setup.Game.IsActive) //Pause Game when minimized
                //return;

                if (ActiveScene.ShouldSort)
                {
                    ActiveScene.GameObjects = ActiveScene.GameObjects.OrderByDescending(Item => Item.Layer).ToList();
                    ActiveScene.ShouldSort  = false;
                }

                ///
                Light.Init_Light();
                ResolutionIndependentRenderer.BeginDraw();                                                                                                                                                               //Resolution related -> Mandatory

                Setup.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Setup.Camera.GetViewTransformationMatrix()); // -> Mandatory
                SpriteRenderer.LastEffect = null;                                                                                                                                                                        // This should be the same effect as in the begin method above
                ActiveScene.Draw(Setup.spriteBatch);
                Setup.spriteBatch.End();

                //Light (Experimental)
                Light.ApplyLighting();

                ActiveScene.ShowUI(Setup.spriteBatch);

                LoadSceneNow_Serialization();
            }
        }
Beispiel #2
0
        public Matrix GetViewTransformationMatrix()
        {
            if (_isViewTransformationDirty)
            {
                _camTranslationVector.X = -_position.X;
                _camTranslationVector.Y = -_position.Y;

                Matrix.CreateTranslation(ref _camTranslationVector, out _camTranslationMatrix);
                Matrix.CreateRotationZ(_rotation, out _camRotationMatrix);

                _camScaleVector.X = _zoom;
                _camScaleVector.Y = _zoom;
                _camScaleVector.Z = 1;

                Matrix.CreateScale(ref _camScaleVector, out _camScaleMatrix);

                _resTranslationVector.X = ResolutionIndependentRenderer.GetVirtualRes().X * 0.5f;
                _resTranslationVector.Y = ResolutionIndependentRenderer.GetVirtualRes().Y * 0.5f;
                _resTranslationVector.Z = 0;

                Matrix.CreateTranslation(ref _resTranslationVector, out _resTranslationMatrix);

                _transform = _camTranslationMatrix *
                             _camRotationMatrix *
                             _camScaleMatrix *
                             _resTranslationMatrix *
                             ResolutionIndependentRenderer.getTransformationMatrix();

                _isViewTransformationDirty = false;
            }

            return(_transform);
        }
Beispiel #3
0
        private void ScreenSizeChanged(object sender, EventArgs args)
        {
            ResolutionIndependentRenderer.SetResolution(Setup.GameWindow.ClientBounds.Width, Setup.GameWindow.ClientBounds.Height, false);
            ResolutionIndependentRenderer.SetVirtualResolution(Setup.GameWindow.ClientBounds.Width, Setup.GameWindow.ClientBounds.Height);
            //ResolutionIndependentRenderer.Init(ref graphics);

            Scene.ImGUI_RenderTarget = new RenderTarget2D(Setup.GraphicsDevice, Setup.graphics.PreferredBackBufferWidth, Setup.graphics.PreferredBackBufferHeight, false, Setup.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
            Light.RenderTarget2D     = new RenderTarget2D(Setup.GraphicsDevice, Setup.graphics.PreferredBackBufferWidth, Setup.graphics.PreferredBackBufferHeight, false, Setup.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
            Light.ShadowMap          = new RenderTarget2D(Setup.GraphicsDevice, Setup.graphics.PreferredBackBufferWidth, Setup.graphics.PreferredBackBufferHeight, false, Setup.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None); //Depth is not needed
            SceneManager.SceneTexPtr = Scene.GuiRenderer.BindTexture(Light.RenderTarget2D);
        }
Beispiel #4
0
        public override void Update(GameTime gameTime)
        {
            gameObject.Name            = "Camera Controller";
            gameObject.ShouldBeDeleted = false;
            gameObject.ShouldBeRemoved = false;

            Setup.Camera.Position      = gameObject.Transform.Position;
            Setup.Camera.Rotation      = gameObject.Transform.Rotation;
            gameObject.Transform.Scale = Vector2.One;
            Setup.Camera.Zoom          = CameraZoom;

            if (Dirty && !FN_Editor.EditorScene.IsThisTheEditor)
            {
                Dirty = false;
                ResolutionIndependentRenderer.SetVirtualResolution(TargetResolution.X, TargetResolution.Y);
                ResolutionIndependentRenderer.SetResolution(ScreenSize.X, ScreenSize.Y, IsFullScreen);
                ResolutionIndependentRenderer.Init(ref Setup.graphics);
            }
        }
Beispiel #5
0
        public static void DrawGrid_Effect(int RowsCount, int ColumnsCount, Vector2 Position, Point Spacing, int Thickness = 2)
        {
            RowsCount    = Math.Clamp(RowsCount, 1, 100);
            ColumnsCount = Math.Clamp(ColumnsCount, 1, 100);
            Thickness    = Math.Clamp(Thickness, 2, 50);
            Spacing.X    = Math.Clamp(Spacing.X, 1, 100);
            Spacing.Y    = Math.Clamp(Spacing.Y, 1, 100);
            Position    += ResolutionIndependentRenderer.GetVirtualRes() * 0.5f;

            for (int i = 0; i <= RowsCount; i++)
            {
                DrawLine_Effect(new Vector2(Position.X, Position.Y + i * Spacing.Y), new Vector2(Position.X + Spacing.X * ColumnsCount, Position.Y + i * Spacing.Y));
            }

            for (int i = 0; i <= ColumnsCount; i++)
            {
                DrawLine_Effect(new Vector2(Position.X + i * Spacing.X, Position.Y), new Vector2(Position.X + i * Spacing.X, Position.Y + Spacing.Y * RowsCount));
            }
        }
Beispiel #6
0
        private void ImportantIntialization()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            /////////Camera And Resolution Independent Renderer/////// -> Mandatory
            Camera      = new Camera2D();
            Camera.Zoom = 1f;

            Setup.Initialize(graphics, Content, spriteBatch, Window, Camera, this);

            ResolutionIndependentRenderer.Init(ref graphics);
            ResolutionIndependentRenderer.SetVirtualResolution(1366, 768);
            ResolutionIndependentRenderer.SetResolution(1366, 768, false);

            PrevRes = new Vector2(1366, 768);

            Exiting += SerializeBeforeExit;
            AppDomain.CurrentDomain.UnhandledException += CleanUp;
            Window.ClientSizeChanged += ScreenSizeChanged;
        }
Beispiel #7
0
 public void ShowUI(SpriteBatch spriteBatch)
 {
     // Drawing ImGUI Stuff
     Setup.GraphicsDevice.SetRenderTarget(null);
     spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null, null);
     spriteBatch.Draw(ImGUI_RenderTarget, Vector2.Zero, new Rectangle(0, 0, (int)ResolutionIndependentRenderer.GetVirtualRes().X, (int)ResolutionIndependentRenderer.GetVirtualRes().Y), Color.White);
     spriteBatch.End();
 }
Beispiel #8
0
 public static Vector2 GetMousePosition()
 {
     return(ResolutionIndependentRenderer.ScaleMouseToScreenCoordinates(Mouse.GetState().Position.ToVector2()));
 }