Exemple #1
0
        // Everything inside this method is rendered with transformation resulting from ModifyRenderMatrix.
        protected virtual void OnRenderData(PaintEventArgs e)
        {
            try
            {
                int cells_count      = 0;
                int grid_cells_count = 0;

                if (m_RenderGrids || m_RenderCells)
                {
                    using (m_Navmesh.AcquireReadDataLock())
                    {
                        var grid_cells = m_Navmesh.dbg_GetGridCells();

                        if (m_RenderGrids)
                        {
                            foreach (Nav.GridCell grid_cell in grid_cells)
                            {
                                RenderHelper.Render(grid_cell, m_RenderCenter, e, m_RenderConnections, m_RenderIds);
                            }

                            grid_cells_count = grid_cells.Count;
                        }

                        if (m_RenderCells)
                        {
                            float max_move_cost_mult = 1;

                            foreach (Nav.GridCell grid_cell in grid_cells)
                            {
                                foreach (Nav.Cell cell in grid_cell.Cells)
                                {
                                    RenderHelper.Render(cell, m_RenderCenter, e, m_RenderConnections, m_RenderIds, m_LastMaxMoveCostMult);
                                    max_move_cost_mult = Math.Max(max_move_cost_mult, cell.MovementCostMult);
                                }

                                cells_count += grid_cell.Cells.Count;
                            }

                            m_LastMaxMoveCostMult = max_move_cost_mult;
                        }
                    }
                }

                if (m_RenderExploreCells || m_RenderExploreArea)
                {
                    using (m_Explorer.AquireReadDataLock())
                    {
                        var explore_cells = m_Explorer.dbg_GetExploreCells();

                        foreach (Nav.ExploreCell explore_cell in explore_cells)
                        {
                            RenderHelper.Render(explore_cell, m_Explorer.ExploreDestPrecision, m_RenderCenter, e, m_RenderConnections, m_RenderIds);

                            if (m_RenderExploreArea)
                            {
                                RenderHelper.DrawString(e.Graphics, Brushes.Black, m_RenderCenter, explore_cell.Position, explore_cell.CellsArea().ToString(), 5);
                            }
                        }
                    }
                }

                if (m_RenderRegions)
                {
                    var regions = m_Navmesh.Regions;

                    foreach (var region in regions)
                    {
                        RenderHelper.DrawRectangle(e.Graphics, Pens.Black, m_RenderCenter, region.area.Min, region.area.Max);
                    }

                    //Vec3 safe_point = m_Navigator.GetNearestGridCellOutsideAvoidAreas();

                    //if (!safe_point.IsEmpty)
                    //    RenderHelper.DrawPoint(e.Graphics, Pens.Green, render_center, safe_point);
                }

                if (m_RenderAxis)
                {
                    e.Graphics.DrawString("X", new Font("Arial", 6 / m_RenderScale), Brushes.Black, 25 / m_RenderScale, 0);
                    e.Graphics.DrawLine(RenderHelper.AXIS_PEN, -25 / m_RenderScale, 0, 25 / m_RenderScale, 0);
                    e.Graphics.DrawString("Y", new Font("Arial", 6 / m_RenderScale), Brushes.Black, 0, 25 / m_RenderScale);
                    e.Graphics.DrawLine(RenderHelper.AXIS_PEN, 0, -25 / m_RenderScale, 0, 25 / m_RenderScale);
                }

                if (!m_RenderOriginalPath && m_RenderPath)
                {
                    DestType last_path_dest_type = DestType.None;
                    if (m_Navigator.TryGetPath(ref m_LastPath, ref last_path_dest_type))
                    {
                        m_LastPath.Insert(0, m_Navigator.CurrentPos);
                    }
                    RenderHelper.DrawLines(e.Graphics, RenderHelper.PATH_PEN, m_RenderCenter, m_LastPath, 1);
                }

                if (m_RenderBacktrackPath)
                {
                    if (m_Navigator.TryGetBackTrackPath(ref m_LastBacktrackPath))
                    {
                        m_LastBacktrackPath.Insert(0, m_Navigator.CurrentPos);
                    }
                    RenderHelper.DrawLines(e.Graphics, Pens.Blue, m_RenderCenter, m_LastBacktrackPath, 1);
                }

                if (m_RenderPositionsHistory)
                {
                    m_Navigator.TryGetDebugPositionsHistory(ref m_LastPositionsHistory);
                    RenderHelper.DrawLines(e.Graphics, Pens.Green, m_RenderCenter, m_LastPositionsHistory, 1);
                }

                if (!m_Navigator.CurrentPos.IsEmpty)
                {
                    RenderHelper.DrawPoint(e.Graphics, Pens.Blue, m_RenderCenter, m_Navigator.CurrentPos);
                }
                if (!m_Navigator.Destination.IsEmpty)
                {
                    RenderHelper.DrawPoint(e.Graphics, Pens.LightBlue, m_RenderCenter, m_Navigator.Destination);
                }

                {
                    Vec3 curr = m_Navigator.CurrentPos;
                    Vec3 dest = m_Navigator.Destination;

                    if (!curr.IsEmpty && !dest.IsEmpty)
                    {
                        if (m_RenderOriginalPath)
                        {
                            List <Vec3> path = new List <Vec3>();
                            m_Navigator.FindPath(curr, dest, MovementFlag.Walk, ref path, -1, false, false, 0, false, 0, false);
                            path.Insert(0, curr);
                            RenderHelper.DrawLines(e.Graphics, Pens.Black, m_RenderCenter, path, 1);
                        }

                        if (m_RenderRayCast)
                        {
                            Vec3 intersection = null;
                            RenderHelper.DrawLine(e.Graphics, m_Navmesh.RayCast2D(curr, dest, MovementFlag.Walk, ref intersection) ? Pens.Green : Pens.Red, m_RenderCenter, curr, intersection);
                        }
                    }
                }

                if (m_WaypointsPaths.Count > 0)
                {
                    int waypoint_id = 1;
                    foreach (List <Vec3> p in m_WaypointsPaths)
                    {
                        if (p.Count > 0)
                        {
                            RenderHelper.DrawCircle(e.Graphics, Pens.Black, m_RenderCenter, p[0], 3);
                            RenderHelper.DrawString(e.Graphics, Brushes.Black, m_RenderCenter, p[0], waypoint_id.ToString(), 10);
                        }
                        RenderHelper.DrawLines(e.Graphics, Pens.Red, m_RenderCenter, p, 1);
                        ++waypoint_id;
                    }
                }

                if (m_Bot != null)
                {
                    //if (!m_Bot.Paused && m_CenterOnBot)
                    //    m_RenderCenter = new PointF(m_Bot.Position.X, m_Bot.Position.Y);
                    m_Bot.Render(e.Graphics, m_RenderCenter);
                }
            }
            catch (Exception)
            {
            }
        }