public override void OnRender(GameTime gameTime)
        {
            if (!_levelLoaded)
            {
                return;
            }

            base.OnRender(gameTime);

            if (_debugViewState)
            {
                float scale = (SceneManager.Instance.GetCurrentCamera().Parent.GetPosition().Z / 1024.0f);

                float left = UnitsConverter.ToSimUnits(SceneManager.Instance.GetCurrentCamera().Parent.GetPosition().X - Platform.Instance.Device.Viewport.Width / 2f * scale);

                float right = UnitsConverter.ToSimUnits(SceneManager.Instance.GetCurrentCamera().Parent.GetPosition().X + Platform.Instance.Device.Viewport.Width / 2f * scale);

                float top = UnitsConverter.ToSimUnits(-SceneManager.Instance.GetCurrentCamera().Parent.GetPosition().Y + Platform.Instance.Device.Viewport.Height / 2f * scale);

                float bottom = UnitsConverter.ToSimUnits(-SceneManager.Instance.GetCurrentCamera().Parent.GetPosition().Y - Platform.Instance.Device.Viewport.Height / 2f * scale);

                _projection = Matrix.CreateOrthographicOffCenter(
                    left,
                    right,
                    top,
                    bottom,
                    0f,
                    1f
                    );

                if (_debugViewGrid)
                {
                    _debugView.BeginCustomDraw(ref _projection, ref _view);
                    for (float i = left - left % _debugViewGridstep; i < right; i += _debugViewGridstep)
                    {
                        _debugView.DrawSegment(new Vector2(i, top), new Vector2(i, bottom), _gridColor);
                    }
                    for (float i = bottom - bottom % _debugViewGridstep; i < top; i += _debugViewGridstep)
                    {
                        _debugView.DrawSegment(new Vector2(left, i), new Vector2(right, i), _gridColor);
                    }
                    _debugView.EndCustomDraw();
                }

                _debugView.RenderDebugData(ref _projection, ref _view);
            }
        }
Example #2
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.White);//new Color(0x22, 0x22, 0x22));

            Matrix p = camera.Projection;
            Matrix v = camera.View;

            debug.BeginCustomDraw(ref p, ref v);

            if (drawGrid || true)
            {
                for (int x = -cells / 2; x <= cells / 2 + 1; x++)
                {
                    float pos = x * cellSize - cellSize / 2f;
                    debug.DrawSegment(new Vector2(pos, -square / 2f - cellSize / 2f), new Vector2(pos, square / 2f + cellSize / 2f), Color.Gray);
                }

                for (int y = -cells / 2; y <= cells / 2 + 1; y++)
                {
                    float pos = y * cellSize - cellSize / 2f;
                    debug.DrawSegment(new Vector2(-square / 2f - cellSize / 2f, pos), new Vector2(square / 2f + cellSize / 2f, pos), Color.Gray);
                }
            }

            for (int n = 0; n < paths.Count; n++)
            {
                if (n >= count)
                {
                    break;
                }
                float            val   = actions[n].Length / maxLength;
                Color            c     = Color.Lerp(Color.Green, Color.Red, val);
                ArrayList <Pose> poses = paths[n];
                for (int i = 0; i < poses.Count - 1; i++)
                {
                    debug.DrawSegment(poses[i].Position, poses[i + 1].Position, c, 0.01f);
                }
            }

            debug.DrawSolidCircle(goal.Position, 2f, Color.Blue);
            debug.DrawSegment(goal.Position, Vector2.Transform(goal.Position + 5f * Vector2.UnitX, Matrix.CreateRotationZ(goal.Orientation)), Color.Blue, 0.2f);

            debug.EndCustomDraw();
            base.Draw(gameTime);
        }
Example #3
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            batch.Begin(SpriteSortMode.Deferred, null, null, null, rasterizerState, basicEffect, null);
            map.Draw(batch);
            batch.End();

            Matrix debugProjection = Matrix.CreateOrthographic(ConvertUnits.ToSimUnits(graphics.GraphicsDevice.Viewport.Width),
                                                               ConvertUnits.ToSimUnits(-graphics.GraphicsDevice.Viewport.Height), ConvertUnits.ToSimUnits(0.1f), ConvertUnits.ToSimUnits(1000f));
            Matrix _debugView = Matrix.CreateTranslation(ConvertUnits.ToSimUnits(new Vector3(cameraPosition - screenCenter, -1f)));

            debugView.RenderDebugData(debugProjection, _debugView);

            debugView.BeginCustomDraw(debugProjection, _debugView);
            debugView.DrawPoint(playerBody.Position, 0.05f, Color.Blue);
            debugView.EndCustomDraw();

            base.Draw(gameTime);
        }
        /// <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);

            // Draw background physics map.
            ServerConsole.PhysicsWorld.DrawDebugOverlay(Camera);


            // Draw overlayed map components.
            DebugTools.BeginCustomDraw(DebugViewProjection, DebugViewTranslation);
            {
                foreach (var player in Player.AllPlayers)
                {
                    DebugDrawer.DrawDebugPlayer(DebugTools, player);
                }
            }
            DebugTools.EndCustomDraw();


            // Draw Text to debug pannel.
            DebugDrawer.BeginPanelText();
            {
                DebugDrawer.DrawPanelText("--------- Players ---------");
                foreach (var player in Player.AllPlayers)
                {
                    DebugDrawer.DrawPanelText(" ");
                    DebugDrawer.DrawPanelText(string.Format("Name:{0}", player.Name));
                    DebugDrawer.DrawPanelText(string.Format("Id:{0}", player.UniqueID));
                    DebugDrawer.DrawPanelText(string.Format("Position:{0}", player.Position));
                }
            }
            DebugDrawer.EndPanelText(DebugTools);



            // Outputs map text.
            DebugTools.RenderDebugData(DebugViewProjection, DebugViewTranslation);

            // Draw Xna base game.
            base.Draw(gameTime);
        }
Example #5
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(backgroundLight ? LIGHT : DARK);

            Matrix p = camera.Projection;
            Matrix v = camera.View;

            if (cameraView == 2)
            {
                float   orientation   = controller != null && controller.InReverse ? car.Pose.Orientation + MathHelper.Pi : car.Pose.Orientation;
                Vector2 position      = Car.GetCenterPosition(car.Pose);
                Vector2 headingVector = new Vector2((float)Math.Cos(orientation), (float)Math.Sin(orientation));
                float   offset        = 14f;
                float   height        = 10f;
                v = Matrix.CreateLookAt(new Vector3(position + -offset * headingVector, height), new Vector3(position + offset * headingVector, 0f), Vector3.UnitZ);
            }
            else if (cameraView == 3)
            {
                float   or            = car.Pose.Orientation + MathHelper.ToRadians(120f);
                Vector2 headingVector = new Vector2((float)Math.Cos(or), (float)Math.Sin(or));
                v = Matrix.CreateLookAt(new Vector3(car.Pose.Position + -10f * headingVector, 5f), new Vector3(Car.GetCenterPosition(car.Pose), 0f), Vector3.UnitZ);
            }
            else if (cameraView == 4)
            {
                float   or            = goalPose.Orientation;
                Vector2 headingVector = new Vector2((float)Math.Cos(or), (float)Math.Sin(or));
                v = Matrix.CreateLookAt(new Vector3(goalPose.Position + 10f * headingVector, 20f), new Vector3(Car.GetCenterPosition(car.Pose), 0f), Vector3.UnitZ);
            }
            else if (cameraView == 5)
            {
                v = Matrix.CreateLookAt(new Vector3(Car.GetCenterPosition(car.Pose), 20f), new Vector3(Car.GetCenterPosition(car.Pose), 0f), Vector3.UnitY);
                if (rotateCar)
                {
                    v *= Matrix.CreateRotationZ(-car.Body.Rotation + MathHelper.PiOver2);
                }
            }

            if (gridDone && (drawGrid || drawVoro || drawHeur))
            {
                basicEffect.World      = Matrix.Identity;
                basicEffect.View       = v;
                basicEffect.Projection = p;
                spriteBatch.Begin(0, null, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone, basicEffect);

                if (drawHeur)
                {
                    HybridAStar.Draw(spriteBatch);
                }
                else
                {
                    grid.Draw(spriteBatch, drawVoro);
                }

                spriteBatch.End();
            }

            debug.BeginCustomDraw(ref p, ref v);

            debug.DrawSolidCircle(Car.GetFrontAxlePosition(car.Pose), 0.2f, Color.Green);

            if ((pathSearching && watchSearch || pathSearchingDone && drawSearch) && HybridAStar.Expanded != null && HybridAStar.Expanded.Count > 0)
            {
                LinkedList <HybridAStar.Node> expanded = new LinkedList <HybridAStar.Node>();
                lock (HybridAStar.Expanded)
                {
                    expanded.AddAll(HybridAStar.Expanded);
                }

                float pathLength = expanded.Last.f;
                foreach (HybridAStar.Node n in expanded)
                {
                    if (pathDone && n.rsIndex >= 0)
                    {
                        for (int i = n.rsIndex; i < poses.Count - 1; i++)
                        {
                            debug.DrawSegment(poses[i].Position, poses[i + 1].Position, Color.Purple, 0.02f);
                        }
                    }
                    else if (n.from != null)
                    {
                        Color color;
                        if (n.cell.rev == 0)
                        {
                            color = Color.Lerp(Color.Orange, Color.Green, n.g / pathLength);
                        }
                        else
                        {
                            color = Color.Lerp(Color.Blue, Color.Cyan, n.g / pathLength);
                        }

                        debug.DrawSegment(n.from.pose.Position, n.pose.Position, color, 0.02f);
                    }
                }
            }

            if (pathDone)
            {
                if (drawPath)
                {
                    for (int i = 0; i < poses.Count - 1; i++)
                    {
                        Color c = poses[i].Gear == Gear.Forward ? Color.Blue : Color.Red;
                        debug.DrawSegment(poses[i].Position, poses[i + 1].Position, c, 0.04f);
                        debug.DrawPoint(poses[i].Position, 0.1f, c * 0.5f);
                    }
                }
            }

            if (pathSearchingDone && !pathSmoothDone && (drawSmoothedPath || drawController))
            {
                Smoother.Draw(debug);
            }

            if (pathSmoothDone)
            {
                if (drawFrontPath && controller.FrontPath != null)
                {
                    int num = controller.FrontPath.Count;
                    for (int i = 0; i < num - 1; i++)
                    {
                        if (controller.FrontPath[i].Gear == Gear.Forward)
                        {
                            debug.DrawSegment(controller.FrontPath[i].Position, controller.FrontPath[i + 1].Position, Color.DarkOrange);
                        }
                        else
                        {
                            debug.DrawSegment(controller.ReverseFrontPath[i].Position, controller.ReverseFrontPath[i + 1].Position, Color.Cyan);
                        }
                    }
                }

                if (drawSmoothedPath)
                {
                    for (int i = 0; i < smoothedPath.Count - 1; i++)
                    {
                        debug.DrawSegment(smoothedPath[i].Position, smoothedPath[i + 1].Position, smoothedPath[i].Gear == Gear.Forward ? Color.DarkGreen : Color.Red, 0.04f);
                        //if (Smoother.UnsafeIndices != null && Smoother.UnsafeIndices.Contains(i))
                        //debug.DrawCircle(smoothedPath[i].Position, 0.2f, Color.Orange);
                    }
                }

                if (drawController)
                {
                    controller.Draw(debug);
                }
            }

            if (drawStart)
            {
                startPose.DrawPose(debug, new Color(0f, 1f, 0f, 0.9f), 1.1f);
            }
            if (drawGoal)
            {
                goalPose.DrawPose(debug, new Color(1f, 0f, 0f, 0.9f), 1.1f);
            }

            if (drawCurrent)
            {
                if (pathSmoothDone && controller.State != StanleyFSMController.ControllerState.MissionComplete)
                {
                    debug.DrawCircle(controller.ClosestPoint, 0.1f, controller.InReverse ? Color.Aqua : Color.Orange);
                    if (controller.InReverse)
                    {
                        debug.DrawCircle(controller.FakeFrontAxle, 0.2f, Color.Aqua);
                    }
                }

                car.Pose.DrawPose(debug, 0.2f, Color.Red);
            }

            debug.EndCustomDraw();

            if (drawDebugData)
            {
                debug.RenderDebugData(ref p, ref v);
            }

            if (drawCar)
            {
                car.Draw(v, p);
            }

            if (showDebugInfo)
            {
                string info = String.Format("Speed: {0:0.0}", Math.Round(car.SpeedMPH, 1));
                if (pathSmoothDone)
                {
                    info += String.Format("\nGas: {0:0.00}", Math.Round(currentControls.Gas * 100f, 2));
                    info += String.Format("\nBrake: {0:0.00}", Math.Round(currentControls.Brake * 100f, 2));
                    info += String.Format("\nCTE: {0:0.0000}", Math.Round(controller.CrossTrackError, 4));
                    info += "\n" + controller.State.ToString();
                    info += "\n" + controller.DebugInfo;
                }
                spriteBatch.Begin();
                spriteBatch.DrawString(font, info, new Vector2(8, 4), !backgroundLight ? LIGHT : DARK);
                spriteBatch.End();
            }

            if (showDashboard)
            {
                dashboard.Draw(gameTime);
            }

            base.Draw(gameTime);
        }
Example #6
0
        public void DrawDebug(SpriteBatch sb)
        {
            var view       = Camera.GetFarseerViewMatrix();
            var projection = Matrix.CreateOrthographicOffCenter(0,
                                                                ConvertUnits.ToSimUnits(GraphicsDevice.Viewport.Width),
                                                                ConvertUnits.ToSimUnits(GraphicsDevice.Viewport.Height),
                                                                0, 0, 1);

            DebugView.BeginCustomDraw(ref projection, ref view);
            foreach (var b in World.BodyList)
            {
                Transform f;
                b.GetTransform(out f);
                for (var i = 0; i <= b.FixtureList.Count() - 1; i++)
                {
                    var color = Color.Blue;
                    if (b.Awake)
                    {
                        color = Color.Red;
                    }
                    if (b.FixtureList[i].Shape == null)
                    {
                        continue;
                    }
                    if (b.UserData != null)
                    {
                        if (((GameObject)b.UserData).IgnoreDebug)
                        {
                            continue;
                        }
                    }
                    DebugView.DrawShape(b.FixtureList[i], f, color);
                }
            }
            DebugView.EndCustomDraw();
            sb.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null, null,
                     Camera.GetViewMatrix());
            foreach (var obj in GameObjects.Objects)
            {
                sb.Draw(Vector, new Rectangle((int)obj.Value.Position.X - 32, (int)obj.Value.Position.Y - 32, 64, 64),
                        Color.White);
                var obj1 = obj;
                foreach (var pos in from i in obj.Value.Body.FixtureList
                         where i.UserData != null
                         where !((GameObject)i.UserData).IgnoreDebug
                         select Utils.PositionOfFixture(obj1.Value.Body, i))
                {
                    sb.Draw(Vector, new Rectangle((int)pos.X - 16, (int)pos.Y - 16, 32, 32), Color.White);
                }
            }
            if (Raycast.Casts != null)
            {
                foreach (var cast in Raycast.Casts)
                {
                    if (cast.HitPoint != Vector2.Zero)
                    {
                        DrawLine(SpriteBatch, cast.StartPoint, cast.HitPoint, Color.Red);
                        DrawLine(SpriteBatch, cast.HitPoint, cast.EndPoint, Color.Blue);
                    }
                    else
                    {
                        DrawLine(SpriteBatch, cast.StartPoint, cast.EndPoint, Color.Blue);
                    }
                }
                Raycast.Casts.Clear();
            }
            sb.End();
        }