Example #1
0
        protected override void Draw(GameTime gameTime)
        {
            //FIX POSTPROCESSING
            spriteBatch.Begin();
            spriteBatch.End();

            BloomComponent.BeginDraw();
            GraphicsDevice.Clear(Color.Black);
            for (int i = 0; i < CelestialBodies.Count; i++)
            {
                if (CelestialBodies[i].RenderWithBloom)
                {
                    CelestialBodies[i].Render();
                }
            }
            base.Draw(gameTime);

            Grid.Render(Observer.Camera.ViewMatrix, Observer.Camera.ProjectionsMatrix, Matrix.CreateTranslation(new Vector3(CelestialBody.GLOBALX - 3500000, CelestialBody.GLOBALY, CelestialBody.GLOBALZ - 3500000)));

            GraphicsDevice.BlendState        = BlendState.Opaque;
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.RasterizerState   = RasterizerState.CullNone;
            GraphicsDevice.SamplerStates[0]  = SamplerState.LinearWrap;

            for (int i = 0; i < CelestialBodies.Count; i++)
            {
                CelestialBodies[i].DrawEllipsoid();
                if (!CelestialBodies[i].RenderWithBloom)
                {
                    spriteBatch.Begin();
                    spriteBatch.End();

                    var v1 = Vector3.Zero;
                    var v2 = new Vector3((float)CelestialBodies[i].XCoord + CelestialBody.GLOBALX, (float)CelestialBodies[i].ZCoord + CelestialBody.GLOBALY, (float)CelestialBodies[i].YCoord + CelestialBody.GLOBALZ);

                    var direction = v2 - v1;
                    direction.Normalize();

                    Ray Ray = new Ray(Vector3.Zero, direction);

                    CelestialBodies[i].IsAllowedToRender = !(Ray.Intersects(CelestialBodies.Find(p => p.Name == "Sun").BoundingBox) > 1) || (v2 - v1).Length() < (new Vector3(CelestialBody.GLOBALX, CelestialBody.GLOBALY, CelestialBody.GLOBALZ) - v1).Length();
                    CelestialBodies[i].Render();
                }
                spriteBatch.Begin();
                CelestialBodies[i].DrawInformation(spriteBatch);
                spriteBatch.End();

                if (ShowDebug)
                {
                    BoundingBoxRenderer.Render(CelestialBodies[i].BoundingBox, GraphicsDevice, Observer.Camera.ViewMatrix, Observer.Camera.ProjectionsMatrix, Color.Red);
                }
            }

            _total_frames++;

            if (ShowDebug)
            {
                spriteBatch.Begin();
                Observer.Camera.RenderDebug(spriteBatch, DebugFont);
                CelestialBody.DrawDebug(spriteBatch, DebugFont);
                spriteBatch.DrawString(DebugFont, fps + " frames per second", new Vector2(GraphicsDevice.PresentationParameters.BackBufferWidth - UI.Width - 150, 15), Color.White);
                spriteBatch.End();
            }
        }