Пример #1
0
        public void EndFrameRendering()
        {
            var bepuPhysicsManager = _sceneInterface.GetManager <BEPUPhysicsManager>(false);

            if (bepuPhysicsManager == null)
            {
                return;
            }

            if (!Visible || _sceneState == null)
            {
                return;
            }

            ModelDrawer.Draw(_sceneState.View, _sceneState.Projection);

            LineDrawer.LightingEnabled    = false;
            LineDrawer.VertexColorEnabled = true;
            LineDrawer.World      = Matrix.Identity;
            LineDrawer.View       = _sceneState.View;
            LineDrawer.Projection = _sceneState.Projection;

            ContactDrawer.Draw(LineDrawer, bepuPhysicsManager.Space);

            BoundingBoxDrawer.Draw(LineDrawer, bepuPhysicsManager.Space);

            SimulationIslandDrawer.Draw(LineDrawer, bepuPhysicsManager.Space);

            Application.Graphics.GraphicsDevice.SamplerStates.Reset();
        }
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            modelDrawer.Draw(camera.ViewMatrix, camera.ProjectionMatrix);

            base.Draw(gameTime);
        }
Пример #3
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            drawingContext.DrawRectangle(Brushes.Black, new Pen(), new Rect(new Point(0, 0), new Size(ActualWidth, ActualHeight)));

            var drawer = new ModelDrawer(_model, drawingContext, ActualWidth, ActualHeight);

            drawer.Draw();
        }
Пример #4
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            _chunkManager.ChunkSystem.Renderer.RenderAll();

            lock (_physicsMutex)
            {
                if (drawPhysics)
                {
                    modelDrawer.Draw(MathConverter.Convert(cam.View), MathConverter.Convert(cam.Projection));
                }
            }

            if (pickedPos != Vector3I.One * -1)
            {
                BoundingBox picked = new BoundingBox(pickedPos.ToVector3() - 0.55f * Vector3.One, pickedPos.ToVector3() + 0.55f * Vector3.One);
                BoundingBoxRenderer.Render(GraphicsDevice, picked, camManager.MainCamera);

                BoundingBox sidePicked = new BoundingBox(sidePickedPos.ToVector3() - 0.55f * Vector3.One, sidePickedPos.ToVector3() + 0.55f * Vector3.One);
                BoundingBoxRenderer.Render(GraphicsDevice, sidePicked, Color.Blue, camManager.MainCamera);

                BoundingBox b1 = new BoundingBox(pickedPos.ToVector3(), pickedPos.ToVector3() + Vector3.One);
                BoundingBox b2 = new BoundingBox(pickedPos.ToVector3() + Vector3.Left, pickedPos.ToVector3() + Vector3.Up + Vector3.Backward);
                BoundingBox b3 = new BoundingBox(pickedPos.ToVector3() + Vector3.Forward, pickedPos.ToVector3() + Vector3.Up + Vector3.Right);
                BoundingBox b4 = new BoundingBox(pickedPos.ToVector3() + Vector3.Left + Vector3.Forward, pickedPos.ToVector3() + Vector3.Up);

                BoundingBox b5 = new BoundingBox(pickedPos.ToVector3() + Vector3.Down, pickedPos.ToVector3() + Vector3.Right + Vector3.Backward);
                BoundingBox b6 = new BoundingBox(pickedPos.ToVector3() + Vector3.Left + Vector3.Down, pickedPos.ToVector3() + Vector3.Backward);
                BoundingBox b7 = new BoundingBox(pickedPos.ToVector3() + Vector3.Forward + Vector3.Down, pickedPos.ToVector3() + Vector3.Right);
                BoundingBox b8 = new BoundingBox(pickedPos.ToVector3() + Vector3.Left + Vector3.Forward + Vector3.Down, pickedPos.ToVector3());
            }

            spriteBatch.Begin();

            spriteBatch.DrawString(font, "Target: " + cam.Target, Vector2.One * 2f, Color.White);
            spriteBatch.DrawString(font, "Position: " + cam.Position, new Vector2(2, 2 + font.LineSpacing + 2), Color.White);
            spriteBatch.DrawString(font, "Selected: " + ((pickedPos == Vector3I.One * -1) ? "None" : pickedPos.ToString()), new Vector2(2, 2 + 2 * font.LineSpacing + 2), Color.White);

            if (_paused)
            {
                Vector2 dim = font.MeasureString("Paused");

                spriteBatch.DrawString(font, "Paused", new Vector2(GraphicsDevice.Viewport.Width - dim.X - 2, 2), Color.White);
            }

            spriteBatch.Draw(contentLibrary.DummyPixel, new Rectangle(GraphicsDevice.Viewport.Width / 2 - 1, GraphicsDevice.Viewport.Height / 2 - 1, 2, 2), Color.White);

            spriteBatch.End();

            _fpsCounter.Draw();

            base.Draw(gameTime);
        }
Пример #5
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(new Color(.41f, .41f, .45f, 1));

            var viewMatrix       = Camera.ViewMatrix;
            var projectionMatrix = Camera.ProjectionMatrix;

            if (displayEntities)
            {
                ModelDrawer.Draw(viewMatrix, projectionMatrix);
            }

            if (displayConstraints)
            {
                ConstraintDrawer.Draw(viewMatrix, projectionMatrix);
            }

            LineDrawer.LightingEnabled    = false;
            LineDrawer.VertexColorEnabled = true;
            LineDrawer.World      = Matrix.Identity;
            LineDrawer.View       = MathConverter.Convert(viewMatrix);
            LineDrawer.Projection = MathConverter.Convert(projectionMatrix);

            if (displayContacts)
            {
                ContactDrawer.Draw(LineDrawer, currentSimulation.Space);
            }

            if (displayBoundingBoxes)
            {
                BoundingBoxDrawer.Draw(LineDrawer, currentSimulation.Space);
            }

            if (displaySimulationIslands)
            {
                SimulationIslandDrawer.Draw(LineDrawer, currentSimulation.Space);
            }


            //This doesn't actually draw the elements in the demo (that's the modeldrawer's job),
            //but some demos can specify their own extra stuff to draw.
            currentSimulation.Draw();

            base.Draw(gameTime);

            #region UI Drawing

            UIDrawer.Begin();
            int bottom = GraphicsDevice.Viewport.Bounds.Height;
            int right  = GraphicsDevice.Viewport.Bounds.Width;
            if (displayUI)
            {
                FPStotalSinceLast += gameTime.ElapsedGameTime.TotalSeconds;
                FPStotalFramesSinceLast++;
                if (gameTime.TotalGameTime.TotalSeconds - FPSlastTime > .25 && gameTime.ElapsedGameTime.TotalSeconds > 0)
                {
                    double avg = FPStotalSinceLast / FPStotalFramesSinceLast;
                    FPSlastTime             = gameTime.TotalGameTime.TotalSeconds;
                    FPStoDisplay            = Math.Round(1 / avg, 1);
                    averagePhysicsTime      = Math.Round(1000 * currentSimulation.PhysicsTime, 1);
                    FPStotalSinceLast       = 0;
                    FPStotalFramesSinceLast = 0;
                }

                DataTextDrawer.Draw("FPS: ", FPStoDisplay, new Vector2(50, bottom - 150));
                DataTextDrawer.Draw("Physics Time (ms): ", averagePhysicsTime, new Vector2(50, bottom - 133));
                DataTextDrawer.Draw("Collision Pairs: ", currentSimulation.Space.NarrowPhase.Pairs.Count, new Vector2(50, bottom - 116));
                if (displayActiveEntityCount)
                {
                    int countActive = 0;
                    for (int i = 0; i < currentSimulation.Space.Entities.Count; i++)
                    {
                        if (currentSimulation.Space.Entities[i].ActivityInformation.IsActive)
                        {
                            countActive++;
                        }
                    }
                    DataTextDrawer.Draw("Active Objects: ", countActive, new Vector2(50, bottom - 99));
                }
#if !WINDOWS
                DataTextDrawer.Draw("Press Start for Controls", new Vector2(50, bottom - 82));
#else
                DataTextDrawer.Draw("Press F1 for Controls", new Vector2(50, bottom - 82));
#endif

                TinyTextDrawer.Draw("Current Simulation: ", currentSimulationIndex, new Vector2(right - 200, bottom - 100));
                TinyTextDrawer.Draw(currentSimulation.Name, new Vector2(right - 180, bottom - 86));

                currentSimulation.DrawUI();
            }
            if (displayMenu)
            {
                UIDrawer.Draw(controlsMenu, new Rectangle(right / 2 - 400, bottom / 2 - 300, 800, 600), Color.White);
            }
            UIDrawer.End();

            #endregion
        }