protected virtual void OnKey(KeyEventArgs e) { if (e.Control) { if (e.KeyCode == System.Windows.Forms.Keys.D1) { m_RenderPath = !m_RenderPath; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D2) { m_Navmesh.RegionsEnabled = !m_Navmesh.RegionsEnabled; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D4) { m_RenderPositionsHistory = !m_RenderPositionsHistory; e.Handled = true; } } else { if (e.KeyCode == System.Windows.Forms.Keys.S) { Vec3 result = default(Vec3); if (!m_Navmesh.RayTrace(new Vec3(m_RenderCenter.X, m_RenderCenter.Y, 1000), new Vec3(m_RenderCenter.X, m_RenderCenter.Y, -1000), MovementFlag.Walk, ref result)) { result = new Vec3(m_RenderCenter.X, m_RenderCenter.Y, 0); } m_Navigator.CurrentPos = result; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.E) { Vec3 result = default(Vec3); if (!m_Navmesh.RayTrace(new Vec3(m_RenderCenter.X, m_RenderCenter.Y, 1000), new Vec3(m_RenderCenter.X, m_RenderCenter.Y, -1000), MovementFlag.Walk, ref result)) { result = new Vec3(m_RenderCenter.X, m_RenderCenter.Y, 0); } m_Navigator.Destination = result; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.L) { m_RenderLegend = !m_RenderLegend; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D1) { m_RenderGrids = !m_RenderGrids; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D2) { m_RenderCells = !m_RenderCells; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D3) { m_RenderExploreCells = !m_RenderExploreCells; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D4) { m_RenderConnections = !m_RenderConnections; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D5) { m_RenderIds = !m_RenderIds; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D6) { m_RenderAxis = !m_RenderAxis; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D7) { //render_explore_dist = !render_explore_dist; m_RenderRegions = !m_RenderRegions; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D8) { m_RenderOriginalPath = !m_RenderOriginalPath; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D9) { m_RenderRayCast = !m_RenderRayCast; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D0) { m_RenderBacktrackPath = !m_RenderBacktrackPath; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F1) { LoadWaypoints(m_LastWaypointsFile); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F2) { LoadData(m_LastDataFile); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F3) { m_Navmesh.Dump("nav_dump.txt"); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F4) { m_Navmesh.Clear(); m_Navigator.Clear(); m_Explorer.Clear(); LoadDebugConfig(); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F5) { m_Navmesh.Serialize("nav_save"); m_Navigator.Serialize("nav_save"); m_Explorer.Serialize("nav_save"); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F6) { m_Navmesh.Deserialize("nav_save"); m_Navigator.Deserialize("nav_save"); m_Explorer.Deserialize("nav_save"); Vec3 initial_pos = m_Navigator.CurrentPos; if (initial_pos.IsZero()) { initial_pos = m_Navmesh.GetCenter(); } m_RenderCenter.X = initial_pos.X; m_RenderCenter.Y = initial_pos.Y; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F7) { LoadDebugConfig(); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F10) { //Thread t = new Thread(dbg_ContiniousSerialize); //t.Start(); //Thread t = new Thread(dbg_MoveRegions); //t.Start(); m_Navmesh.dbg_GenerateRandomAvoidAreas(2); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.B) { Vec3 result = default(Vec3); m_Navmesh.RayTrace(new Vec3(m_RenderCenter.X, m_RenderCenter.Y, 1000), new Vec3(m_RenderCenter.X, m_RenderCenter.Y, -1000), MovementFlag.Walk, ref result); if (m_Bot != null) { m_Bot.Dispose(); } m_Bot = new TestBot(m_Navmesh, m_Navigator, m_Explorer, result, m_Navigator.Destination, true, false); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.C) { m_CenterOnBot = !m_CenterOnBot; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D) { if (m_Bot != null) { m_Bot.Destination = new Vec3(m_RenderCenter.X, m_RenderCenter.Y, 0); } e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.H) { if (m_Explorer != null) { m_Explorer.HintPos = new Vec3(m_RenderCenter.X, m_RenderCenter.Y, 0); } e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.X) { m_Navigator.CurrentPos = new Vec3(m_RenderCenter.X, m_RenderCenter.Y, 0); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.Space) { if (m_Bot != null) { m_Bot.Paused = !m_Bot.Paused; } e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.V) { if (m_Bot != null) { m_Bot.BackTrace = !m_Bot.BackTrace; } e.Handled = true; } } }
private void NavMeshViewer_KeyPress(object sender, KeyEventArgs e) { if (e.Control) { if (e.KeyCode == System.Windows.Forms.Keys.D1) { render_path = !render_path; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D2) { m_Navmesh.RegionsEnabled = !m_Navmesh.RegionsEnabled; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D3) { m_Navmesh.DangerRegionsEnabled = !m_Navmesh.DangerRegionsEnabled; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D4) { render_positions_history = !render_positions_history; e.Handled = true; } } else { if (e.KeyCode == System.Windows.Forms.Keys.A) { auto_clear_navmesh = !auto_clear_navmesh; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.S) { Vec3 result = null; m_Navmesh.RayTrace(new Vec3(render_center.X, render_center.Y, 1000), new Vec3(render_center.X, render_center.Y, -1000), MovementFlag.Walk, out result); if (result.IsEmpty) result = new Vec3(render_center.X, render_center.Y, 0); m_Navmesh.Navigator.CurrentPos = result; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.E) { Vec3 result = null; m_Navmesh.RayTrace(new Vec3(render_center.X, render_center.Y, 1000), new Vec3(render_center.X, render_center.Y, -1000), MovementFlag.Walk, out result); if (result.IsEmpty) result = new Vec3(render_center.X, render_center.Y, 0); m_Navmesh.Navigator.Destination = result; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.L) { render_legend = !render_legend; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D1) { render_grids = !render_grids; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D2) { render_cells = !render_cells; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D3) { render_explore_cells = !render_explore_cells; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D4) { render_connections = !render_connections; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D5) { render_id = !render_id; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D6) { render_axis = !render_axis; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D7) { //render_explore_dist = !render_explore_dist; render_regions = !render_regions; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D8) { render_original_path = !render_original_path; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D9) { render_ray_cast = !render_ray_cast; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D0) { render_backtrack_path = !render_backtrack_path; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F1) { LoadWaypoints(last_waypoints_file); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F2) { LoadData(last_data_file); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F3) { m_Navmesh.Dump("nav_dump.txt"); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F4) { m_Navmesh.Clear(); LoadDebugConfig(); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F5) { m_Navmesh.Serialize("nav_save.dat"); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F6) { m_Navmesh.Deserialize("nav_save.dat"); Vec3 initial_pos = m_Navmesh.Navigator.CurrentPos; if (initial_pos.IsEmpty) initial_pos = m_Navmesh.GetCenter(); render_center.X = initial_pos.X; render_center.Y = initial_pos.Y; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F7) { LoadDebugConfig(); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F10) { //Thread t = new Thread(dbg_ContiniousSerialize); //t.Start(); Thread t = new Thread(dbg_MoveRegions); t.Start(); //m_Navmesh.dbg_GenerateRandomAvoidAreas(); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.B) { Vec3 result = null; m_Navmesh.RayTrace(new Vec3(render_center.X, render_center.Y, 1000), new Vec3(render_center.X, render_center.Y, -1000), MovementFlag.Walk, out result); bot = new TestBot(m_Navmesh, result, m_Navmesh.Navigator.Destination, true, false); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.C) { center_on_bot = !center_on_bot; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D) { if (bot != null) bot.Destination = new Vec3(render_center.X, render_center.Y, 0); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.H) { if (m_Navmesh.Explorator != null) m_Navmesh.Explorator.HintPos = new Vec3(render_center.X, render_center.Y, 0); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.X) { m_Navmesh.Navigator.CurrentPos = new Vec3(render_center.X, render_center.Y, 0); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.Space) { if (bot != null) bot.Paused = !bot.Paused; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.V) { if (bot != null) bot.BackTrace = !bot.BackTrace; e.Handled = true; } } }
private void NavMeshViewer_KeyPress(object sender, KeyEventArgs e) { if (e.Control) { if (e.KeyCode == System.Windows.Forms.Keys.D1) { render_path = !render_path; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D2) { m_Navmesh.RegionsEnabled = !m_Navmesh.RegionsEnabled; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D3) { m_Navmesh.DangerRegionsEnabled = !m_Navmesh.DangerRegionsEnabled; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D4) { render_positions_history = !render_positions_history; e.Handled = true; } } else { if (e.KeyCode == System.Windows.Forms.Keys.A) { auto_clear_navmesh = !auto_clear_navmesh; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.S) { Vec3 result = null; m_Navmesh.RayTrace(new Vec3(render_center.X, render_center.Y, 1000), new Vec3(render_center.X, render_center.Y, -1000), MovementFlag.Walk, out result); if (result.IsEmpty) { result = new Vec3(render_center.X, render_center.Y, 0); } m_Navmesh.Navigator.CurrentPos = result; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.E) { Vec3 result = null; m_Navmesh.RayTrace(new Vec3(render_center.X, render_center.Y, 1000), new Vec3(render_center.X, render_center.Y, -1000), MovementFlag.Walk, out result); if (result.IsEmpty) { result = new Vec3(render_center.X, render_center.Y, 0); } m_Navmesh.Navigator.Destination = result; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.L) { render_legend = !render_legend; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D1) { render_grids = !render_grids; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D2) { render_cells = !render_cells; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D3) { render_explore_cells = !render_explore_cells; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D4) { render_connections = !render_connections; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D5) { render_id = !render_id; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D6) { render_axis = !render_axis; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D7) { //render_explore_dist = !render_explore_dist; render_regions = !render_regions; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D8) { render_original_path = !render_original_path; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D9) { render_ray_cast = !render_ray_cast; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D0) { render_backtrack_path = !render_backtrack_path; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F1) { LoadWaypoints(last_waypoints_file); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F2) { LoadData(last_data_file); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F3) { m_Navmesh.Dump("nav_dump.txt"); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F4) { m_Navmesh.Clear(); LoadDebugConfig(); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F5) { m_Navmesh.Serialize("nav_save.dat"); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F6) { m_Navmesh.Deserialize("nav_save.dat"); Vec3 initial_pos = m_Navmesh.Navigator.CurrentPos; if (initial_pos.IsEmpty) { initial_pos = m_Navmesh.GetCenter(); } render_center.X = initial_pos.X; render_center.Y = initial_pos.Y; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F7) { LoadDebugConfig(); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.F10) { //Thread t = new Thread(dbg_ContiniousSerialize); //t.Start(); Thread t = new Thread(dbg_MoveRegions); t.Start(); //m_Navmesh.dbg_GenerateRandomAvoidAreas(); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.B) { Vec3 result = null; m_Navmesh.RayTrace(new Vec3(render_center.X, render_center.Y, 1000), new Vec3(render_center.X, render_center.Y, -1000), MovementFlag.Walk, out result); bot = new TestBot(m_Navmesh, result, m_Navmesh.Navigator.Destination, true, false); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.C) { center_on_bot = !center_on_bot; e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.D) { if (bot != null) { bot.Destination = new Vec3(render_center.X, render_center.Y, 0); } e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.H) { if (m_Navmesh.Explorator != null) { m_Navmesh.Explorator.HintPos = new Vec3(render_center.X, render_center.Y, 0); } e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.X) { m_Navmesh.Navigator.CurrentPos = new Vec3(render_center.X, render_center.Y, 0); e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.Space) { if (bot != null) { bot.Paused = !bot.Paused; } e.Handled = true; } else if (e.KeyCode == System.Windows.Forms.Keys.V) { if (bot != null) { bot.BackTrace = !bot.BackTrace; } e.Handled = true; } } }