2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2014-02-10 09:26:13 +00:00
|
|
|
using System.Windows.Forms;
|
2009-04-19 18:07:22 +00:00
|
|
|
using CodeImp.DoomBuilder.Windows;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
|
|
using CodeImp.DoomBuilder.Actions;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using CodeImp.DoomBuilder.Editing;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.VisualModes
|
|
|
|
{
|
2020-02-19 20:59:42 +00:00
|
|
|
public enum PickingMode
|
|
|
|
{
|
|
|
|
Default,
|
2021-01-30 21:01:55 +00:00
|
|
|
SidedefSlopeHandles,
|
|
|
|
VertexSlopeHandles
|
2020-02-19 20:59:42 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Provides specialized functionality for a visual (3D) Doom Builder editing mode.
|
|
|
|
/// </summary>
|
|
|
|
public abstract class VisualMode : EditMode
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
2020-05-23 08:37:42 +00:00
|
|
|
private const double MOVE_SPEED_MULTIPLIER = 0.001;
|
2022-01-03 14:46:00 +00:00
|
|
|
protected const float PICK_RANGE = 0.98f;
|
|
|
|
private const float MOVE_CAMERA_DISTANCE = 64.0f;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Graphics
|
|
|
|
protected IRenderer3D renderer;
|
|
|
|
|
|
|
|
// Options
|
|
|
|
private bool processgeometry;
|
|
|
|
private bool processthings;
|
|
|
|
|
|
|
|
// Input
|
|
|
|
private bool keyforward;
|
|
|
|
private bool keybackward;
|
|
|
|
private bool keyleft;
|
|
|
|
private bool keyright;
|
2013-09-11 09:47:53 +00:00
|
|
|
private bool keyup;
|
|
|
|
private bool keydown;
|
2022-01-03 14:46:00 +00:00
|
|
|
private bool orbit;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
|
|
|
private List<VisualThing> selectedVisualThings;
|
|
|
|
private List<VisualSector> selectedVisualSectors;
|
2013-03-18 13:52:27 +00:00
|
|
|
protected Dictionary<Vertex, VisualVertexPair> vertices;
|
2014-08-25 11:15:19 +00:00
|
|
|
private static Vector2D initialcameraposition;
|
2013-09-11 09:47:53 +00:00
|
|
|
//used in "Play From Here" Action
|
|
|
|
private Thing playerStart;
|
|
|
|
private Vector3D playerStartPosition;
|
2020-05-21 12:20:02 +00:00
|
|
|
private double playerStartAngle;
|
2012-05-11 12:28:20 +00:00
|
|
|
|
2022-01-03 14:46:00 +00:00
|
|
|
private Vector3D orbitPoint;
|
|
|
|
private double orbitXY;
|
|
|
|
private double orbitZ;
|
|
|
|
private double orbitRadius;
|
|
|
|
private bool orbitPointPicked;
|
|
|
|
|
2020-02-19 20:59:42 +00:00
|
|
|
// For picking
|
|
|
|
protected PickingMode pickingmode;
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Map
|
|
|
|
protected VisualBlockMap blockmap;
|
2019-12-26 08:08:11 +00:00
|
|
|
protected Dictionary<Thing, VisualThing> allthings;
|
|
|
|
protected Dictionary<Sector, VisualSector> allsectors;
|
2019-12-30 23:08:17 +00:00
|
|
|
protected Dictionary<Sector, List<VisualSlope>> allslopehandles;
|
2021-01-30 21:01:55 +00:00
|
|
|
protected Dictionary<Sector, List<VisualSlope>> sidedefslopehandles;
|
|
|
|
protected Dictionary<Sector, List<VisualSlope>> vertexslopehandles;
|
2009-04-19 18:07:22 +00:00
|
|
|
protected List<VisualBlockEntry> visibleblocks;
|
2019-12-21 04:43:16 +00:00
|
|
|
protected List<VisualThing> visiblethings;
|
|
|
|
protected List<VisualSector> visiblesectors;
|
2009-04-19 18:07:22 +00:00
|
|
|
protected List<VisualGeometry> visiblegeometry;
|
2021-02-07 15:44:12 +00:00
|
|
|
protected HashSet<VisualSlope> usedslopehandles;
|
2022-01-03 14:46:00 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public bool ProcessGeometry { get { return processgeometry; } set { processgeometry = value; } }
|
|
|
|
public bool ProcessThings { get { return processthings; } set { processthings = value; } }
|
|
|
|
public VisualBlockMap BlockMap { get { return blockmap; } }
|
2014-10-29 13:11:35 +00:00
|
|
|
public Dictionary<Vertex, VisualVertexPair> VisualVertices { get { return vertices; } } //mxd
|
2019-12-30 23:08:17 +00:00
|
|
|
public Dictionary<Sector, List<VisualSlope>> AllSlopeHandles { get { return allslopehandles; } }
|
2021-01-30 21:01:55 +00:00
|
|
|
public Dictionary<Sector, List<VisualSlope>> SidedefSlopeHandles { get { return sidedefslopehandles; } }
|
|
|
|
public Dictionary<Sector, List<VisualSlope>> VertexSlopeHandles { get { return vertexslopehandles; } }
|
2021-02-07 15:44:12 +00:00
|
|
|
public HashSet<VisualSlope> UsedSlopeHandles { get { return usedslopehandles; } }
|
2010-08-22 12:09:32 +00:00
|
|
|
|
|
|
|
// Rendering
|
|
|
|
public IRenderer3D Renderer { get { return renderer; } }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Provides specialized functionality for a visual (3D) Doom Builder editing mode.
|
|
|
|
/// </summary>
|
2015-05-27 12:38:03 +00:00
|
|
|
protected VisualMode()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
this.renderer = General.Map.Renderer3D;
|
|
|
|
this.blockmap = new VisualBlockMap();
|
2019-12-26 08:08:11 +00:00
|
|
|
this.allsectors = new Dictionary<Sector, VisualSector>(General.Map.Map.Sectors.Count);
|
|
|
|
this.allthings = new Dictionary<Thing, VisualThing>(General.Map.Map.Things.Count);
|
2019-12-30 23:08:17 +00:00
|
|
|
this.allslopehandles = new Dictionary<Sector, List<VisualSlope>>(General.Map.Map.Sectors.Count);
|
2021-01-30 21:01:55 +00:00
|
|
|
this.sidedefslopehandles = new Dictionary<Sector, List<VisualSlope>>(General.Map.Map.Sectors.Count);
|
|
|
|
this.vertexslopehandles = new Dictionary<Sector, List<VisualSlope>>(General.Map.Map.Sectors.Count);
|
2009-04-19 18:07:22 +00:00
|
|
|
this.visibleblocks = new List<VisualBlockEntry>();
|
2019-12-21 04:43:16 +00:00
|
|
|
this.visiblesectors = new List<VisualSector>(50);
|
2009-04-19 18:07:22 +00:00
|
|
|
this.visiblegeometry = new List<VisualGeometry>(200);
|
2019-12-21 04:43:16 +00:00
|
|
|
this.visiblethings = new List<VisualThing>(100);
|
2021-02-07 15:44:12 +00:00
|
|
|
this.usedslopehandles = new HashSet<VisualSlope>();
|
2009-04-19 18:07:22 +00:00
|
|
|
this.processgeometry = true;
|
|
|
|
this.processthings = true;
|
2014-10-29 13:11:35 +00:00
|
|
|
this.vertices = new Dictionary<Vertex, VisualVertexPair>(); //mxd
|
2020-02-19 20:59:42 +00:00
|
|
|
this.pickingmode = PickingMode.Default;
|
2013-03-18 13:52:27 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd. Synch camera position to cursor position or center of the screen in 2d-mode
|
2015-12-28 15:01:53 +00:00
|
|
|
if(General.Settings.GZSynchCameras && General.Editing.Mode is ClassicMode)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2016-03-18 12:52:12 +00:00
|
|
|
ClassicMode oldmode = (ClassicMode)General.Editing.Mode;
|
2012-06-07 01:06:37 +00:00
|
|
|
|
2014-08-25 11:15:19 +00:00
|
|
|
if(oldmode.IsMouseInside)
|
|
|
|
initialcameraposition = new Vector2D(oldmode.MouseMapPos.x, oldmode.MouseMapPos.y);
|
|
|
|
else
|
|
|
|
initialcameraposition = new Vector2D(General.Map.CRenderer2D.Viewport.Left + General.Map.CRenderer2D.Viewport.Width / 2.0f, General.Map.CRenderer2D.Viewport.Top + General.Map.CRenderer2D.Viewport.Height / 2.0f);
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
public override void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
2019-12-26 08:08:11 +00:00
|
|
|
// Clean up
|
|
|
|
foreach(KeyValuePair<Sector, VisualSector> s in allsectors) s.Value.Dispose();
|
2009-04-19 18:07:22 +00:00
|
|
|
blockmap.Dispose();
|
|
|
|
visiblesectors = null;
|
|
|
|
visiblegeometry = null;
|
|
|
|
visibleblocks = null;
|
|
|
|
visiblethings = null;
|
2019-12-26 08:08:11 +00:00
|
|
|
allsectors = null;
|
|
|
|
allthings = null;
|
2009-04-19 18:07:22 +00:00
|
|
|
blockmap = null;
|
2012-05-20 00:56:59 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
|
|
|
selectedVisualSectors = null;
|
|
|
|
selectedVisualThings = null;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Done
|
|
|
|
base.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Start / Stop
|
|
|
|
|
|
|
|
// Mode is engaged
|
|
|
|
public override void OnEngage()
|
|
|
|
{
|
|
|
|
base.OnEngage();
|
2014-09-09 12:16:26 +00:00
|
|
|
|
2014-09-20 22:05:23 +00:00
|
|
|
// Update projection (mxd)
|
2014-09-09 12:16:26 +00:00
|
|
|
General.Map.CRenderer3D.CreateProjection();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Update the used textures
|
|
|
|
General.Map.Data.UpdateUsedTextures();
|
|
|
|
|
|
|
|
// Fill the blockmap
|
|
|
|
FillBlockMap();
|
2014-08-25 11:15:19 +00:00
|
|
|
|
|
|
|
//mxd. Synch camera position to cursor position or center of the screen in 2d-mode
|
|
|
|
if(General.Settings.GZSynchCameras)
|
|
|
|
{
|
2016-04-29 21:38:43 +00:00
|
|
|
// Keep previous camera position if Control is held and camera was previously moved in Visual mode
|
|
|
|
if(!General.Interface.CtrlState || General.Map.VisualCamera.Position.GetLengthSq() == 0)
|
2015-02-12 22:04:49 +00:00
|
|
|
{
|
2016-04-29 21:38:43 +00:00
|
|
|
//If initial position is inside or nearby a sector - adjust camera.z accordingly
|
2020-05-21 12:20:02 +00:00
|
|
|
double posz = General.Map.VisualCamera.Position.z;
|
2016-04-29 21:38:43 +00:00
|
|
|
Sector nearestsector = General.Map.Map.GetSectorByCoordinates(initialcameraposition, blockmap);
|
|
|
|
|
|
|
|
if(nearestsector == null)
|
2015-02-12 22:04:49 +00:00
|
|
|
{
|
2016-04-29 21:38:43 +00:00
|
|
|
Linedef nearestline = MapSet.NearestLinedef(General.Map.Map.Linedefs, initialcameraposition);
|
|
|
|
if(nearestline != null)
|
|
|
|
{
|
2020-05-21 12:20:02 +00:00
|
|
|
double side = nearestline.SideOfLine(initialcameraposition);
|
2016-04-29 21:38:43 +00:00
|
|
|
Sidedef nearestside = (side < 0.0f ? nearestline.Front : nearestline.Back) ?? (side < 0.0f ? nearestline.Back : nearestline.Front);
|
|
|
|
if(nearestside != null) nearestsector = nearestside.Sector;
|
|
|
|
}
|
2015-02-12 22:04:49 +00:00
|
|
|
}
|
|
|
|
|
2016-04-29 21:38:43 +00:00
|
|
|
if(nearestsector != null)
|
|
|
|
{
|
|
|
|
int sectorheight = nearestsector.CeilHeight - nearestsector.FloorHeight;
|
|
|
|
if(sectorheight < 41)
|
|
|
|
posz = nearestsector.FloorHeight + Math.Max(16, sectorheight / 2);
|
|
|
|
else if(General.Map.VisualCamera.Position.z < nearestsector.FloorHeight + 41)
|
|
|
|
posz = nearestsector.FloorHeight + 41; // same as in doom
|
|
|
|
else if(General.Map.VisualCamera.Position.z > nearestsector.CeilHeight)
|
|
|
|
posz = nearestsector.CeilHeight - 4;
|
|
|
|
}
|
2015-02-12 22:04:49 +00:00
|
|
|
|
2016-04-29 21:38:43 +00:00
|
|
|
General.Map.VisualCamera.Position = new Vector3D(initialcameraposition.x, initialcameraposition.y, posz);
|
|
|
|
}
|
2014-08-25 11:15:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
General.Map.VisualCamera.PositionAtThing();
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Start special input mode
|
|
|
|
General.Interface.EnableProcessing();
|
|
|
|
General.Interface.StartExclusiveMouseInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mode is disengaged
|
|
|
|
public override void OnDisengage()
|
|
|
|
{
|
|
|
|
base.OnDisengage();
|
2019-12-26 08:08:11 +00:00
|
|
|
|
|
|
|
// Dispose
|
|
|
|
foreach(KeyValuePair<Sector, VisualSector> vs in allsectors)
|
|
|
|
if(vs.Value != null) vs.Value.Dispose();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2019-12-26 08:08:11 +00:00
|
|
|
// Dispose
|
|
|
|
foreach(KeyValuePair<Thing, VisualThing> vt in allthings)
|
2019-12-30 23:08:17 +00:00
|
|
|
if(vt.Value != null) vt.Value.Dispose();
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Apply camera position to thing
|
|
|
|
General.Map.VisualCamera.ApplyToThing();
|
|
|
|
|
|
|
|
// Do not leave the sector on the camera
|
|
|
|
General.Map.VisualCamera.Sector = null;
|
2012-06-26 08:54:25 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
|
|
|
selectedVisualSectors = null;
|
|
|
|
selectedVisualThings = null;
|
2016-11-26 00:02:56 +00:00
|
|
|
|
|
|
|
//mxd. Extra floors may've been edited
|
|
|
|
General.Map.Renderer2D.UpdateExtraFloorFlag();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Stop special input mode
|
|
|
|
General.Interface.DisableProcessing();
|
|
|
|
General.Interface.StopExclusiveMouseInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
public override bool OnUndoBegin()
|
|
|
|
{
|
|
|
|
renderer.SetCrosshairBusy(true);
|
|
|
|
General.Interface.RedrawDisplay();
|
|
|
|
return base.OnUndoBegin();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnUndoEnd()
|
|
|
|
{
|
|
|
|
base.OnUndoEnd();
|
2009-06-11 21:21:20 +00:00
|
|
|
ResourcesReloadedPartial();
|
2009-04-19 18:07:22 +00:00
|
|
|
renderer.SetCrosshairBusy(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool OnRedoBegin()
|
|
|
|
{
|
|
|
|
renderer.SetCrosshairBusy(true);
|
|
|
|
General.Interface.RedrawDisplay();
|
|
|
|
return base.OnRedoBegin();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnRedoEnd()
|
|
|
|
{
|
|
|
|
base.OnRedoEnd();
|
2009-06-11 21:21:20 +00:00
|
|
|
ResourcesReloadedPartial();
|
2009-04-19 18:07:22 +00:00
|
|
|
renderer.SetCrosshairBusy(false);
|
|
|
|
}
|
|
|
|
|
2021-11-28 13:00:24 +00:00
|
|
|
public override bool OnScriptRunBegin()
|
|
|
|
{
|
|
|
|
renderer.SetCrosshairBusy(true);
|
|
|
|
return base.OnScriptRunBegin();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnScriptRunEnd()
|
|
|
|
{
|
|
|
|
base.OnScriptRunEnd();
|
|
|
|
ResourcesReloadedPartial();
|
|
|
|
renderer.SetCrosshairBusy(false);
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
public override void OnReloadResources()
|
|
|
|
{
|
|
|
|
base.OnReloadResources();
|
|
|
|
ResourcesReloaded();
|
|
|
|
}
|
2012-06-07 01:06:37 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2014-12-03 23:15:26 +00:00
|
|
|
public override bool OnMapTestBegin(bool testFromCurrentPosition)
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
if(testFromCurrentPosition)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
//find Single Player Start. Should have Type 1 in all games
|
|
|
|
Thing start = null;
|
2015-12-28 15:01:53 +00:00
|
|
|
foreach(Thing t in General.Map.Map.Things)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
if(t.Type == 1)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
//store thing and position
|
|
|
|
start = t;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
if(start == null)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
General.MainWindow.DisplayStatus(StatusType.Warning, "Can't test from current position: no Player 1 start found!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//now check if camera is located inside a sector
|
|
|
|
Vector3D camPos = General.Map.VisualCamera.Position;
|
2014-08-25 11:15:19 +00:00
|
|
|
Sector s = General.Map.Map.GetSectorByCoordinates(new Vector2D(camPos.x, camPos.y), blockmap);
|
2013-09-11 09:47:53 +00:00
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
if(s == null)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
General.MainWindow.DisplayStatus(StatusType.Warning, "Can't test from current position: cursor is not inside sector!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//41 = player's height in Doom. Is that so in all other games as well?
|
2015-12-28 15:01:53 +00:00
|
|
|
if(s.CeilHeight - s.FloorHeight < 41)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
General.MainWindow.DisplayStatus(StatusType.Warning, "Can't test from current position: sector is too low!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//check camera Z
|
2020-05-21 12:20:02 +00:00
|
|
|
double pz = camPos.z - s.FloorHeight;
|
2012-11-02 23:11:38 +00:00
|
|
|
int ceilRel = s.CeilHeight - s.FloorHeight - 41; //relative ceiling height
|
|
|
|
if(pz > ceilRel) pz = ceilRel; //above ceiling?
|
|
|
|
else if(pz < 0) pz = 0; //below floor?
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//store initial position
|
|
|
|
playerStart = start;
|
|
|
|
playerStartPosition = start.Position;
|
|
|
|
playerStartAngle = start.Angle;
|
|
|
|
|
|
|
|
//everything should be valid, let's move player start here
|
|
|
|
start.Move(new Vector3D(camPos.x, camPos.y, pz));
|
|
|
|
start.Rotate(General.Map.VisualCamera.AngleXY - Angle2D.PI);// (float)Math.PI);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd
|
2014-12-03 23:15:26 +00:00
|
|
|
public override void OnMapTestEnd(bool testFromCurrentPosition)
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
if(testFromCurrentPosition)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
//restore position
|
|
|
|
playerStart.Move(playerStartPosition);
|
|
|
|
playerStart.Rotate(playerStartAngle);
|
|
|
|
playerStart = null;
|
|
|
|
}
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Input
|
|
|
|
|
|
|
|
// Mouse input
|
|
|
|
public override void OnMouseInput(Vector2D delta)
|
|
|
|
{
|
|
|
|
base.OnMouseInput(delta);
|
2022-01-03 14:46:00 +00:00
|
|
|
|
|
|
|
if (orbit)
|
|
|
|
{
|
|
|
|
Vector3D start = General.Map.VisualCamera.Position;
|
|
|
|
|
|
|
|
if (!orbitPointPicked)
|
|
|
|
{
|
|
|
|
Vector3D hitPosition = GetHitPosition();
|
|
|
|
orbitPoint = hitPosition;
|
|
|
|
|
|
|
|
if (!hitPosition.IsFinite())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
orbitPointPicked = true;
|
|
|
|
|
|
|
|
Vector3D pickDelta = start - orbitPoint;
|
|
|
|
orbitRadius = pickDelta.GetLength();
|
|
|
|
orbitXY = pickDelta.GetNormal().GetAngleXY();
|
|
|
|
orbitZ = -pickDelta.GetNormal().GetAngleZ();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change camera angles with the mouse changes
|
|
|
|
orbitXY -= delta.x * VisualCamera.ANGLE_FROM_MOUSE;
|
|
|
|
if(General.Settings.InvertYAxis)
|
|
|
|
orbitZ -= delta.y * VisualCamera.ANGLE_FROM_MOUSE;
|
|
|
|
else
|
|
|
|
orbitZ += delta.y * VisualCamera.ANGLE_FROM_MOUSE;
|
|
|
|
|
|
|
|
orbitXY = Angle2D.Normalized(orbitXY);
|
|
|
|
orbitZ = Angle2D.Normalized(orbitZ);
|
|
|
|
|
|
|
|
if (orbitZ < VisualCamera.MAX_ANGLEZ_LOW) orbitZ = VisualCamera.MAX_ANGLEZ_LOW;
|
|
|
|
if (orbitZ > VisualCamera.MAX_ANGLEZ_HIGH) orbitZ = VisualCamera.MAX_ANGLEZ_HIGH;
|
|
|
|
|
|
|
|
Vector3D orbitDelta = Vector3D.FromAngleXYZ(orbitXY, orbitZ);
|
|
|
|
|
|
|
|
Vector3D newPosition = orbitPoint - orbitDelta * orbitRadius;
|
|
|
|
Vector3D positionUpdate = newPosition - General.Map.VisualCamera.Position;
|
|
|
|
|
|
|
|
General.Map.VisualCamera.Position += positionUpdate * General.Map.VisualCamera.MoveMultiplier;
|
|
|
|
start = General.Map.VisualCamera.Position;
|
|
|
|
|
|
|
|
// Recalculate angles to ensure we're always looking at the orbit point
|
|
|
|
Vector3D updatedDelta = start - orbitPoint;
|
|
|
|
orbitXY = updatedDelta.GetNormal().GetAngleXY();
|
|
|
|
orbitZ = -updatedDelta.GetNormal().GetAngleZ();
|
|
|
|
|
|
|
|
General.Map.VisualCamera.AngleZ = orbitZ;
|
|
|
|
General.Map.VisualCamera.AngleXY = orbitXY;
|
|
|
|
|
|
|
|
General.Map.VisualCamera.ProcessMouseInput(new Vector2D());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
General.Map.VisualCamera.ProcessMouseInput(delta);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BeginAction("moveforward", BaseAction = true)]
|
|
|
|
public virtual void BeginMoveForward()
|
|
|
|
{
|
|
|
|
keyforward = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[EndAction("moveforward", BaseAction = true)]
|
|
|
|
public virtual void EndMoveForward()
|
|
|
|
{
|
|
|
|
keyforward = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BeginAction("movebackward", BaseAction = true)]
|
|
|
|
public virtual void BeginMoveBackward()
|
|
|
|
{
|
|
|
|
keybackward = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[EndAction("movebackward", BaseAction = true)]
|
|
|
|
public virtual void EndMoveBackward()
|
|
|
|
{
|
|
|
|
keybackward = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BeginAction("moveleft", BaseAction = true)]
|
|
|
|
public virtual void BeginMoveLeft()
|
|
|
|
{
|
|
|
|
keyleft = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[EndAction("moveleft", BaseAction = true)]
|
|
|
|
public virtual void EndMoveLeft()
|
|
|
|
{
|
|
|
|
keyleft = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BeginAction("moveright", BaseAction = true)]
|
|
|
|
public virtual void BeginMoveRight()
|
|
|
|
{
|
|
|
|
keyright = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[EndAction("moveright", BaseAction = true)]
|
|
|
|
public virtual void EndMoveRight()
|
|
|
|
{
|
|
|
|
keyright = false;
|
|
|
|
}
|
2022-01-03 14:46:00 +00:00
|
|
|
|
|
|
|
[BeginAction("orbit", BaseAction = true)]
|
|
|
|
public virtual void BeginOrbit()
|
|
|
|
{
|
|
|
|
orbit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[EndAction("orbit", BaseAction = true)]
|
|
|
|
public virtual void EndOrbit()
|
|
|
|
{
|
|
|
|
orbit = false;
|
|
|
|
orbitPointPicked = false;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
[BeginAction("moveup", BaseAction = true)]
|
|
|
|
public virtual void BeginMoveUp()
|
|
|
|
{
|
|
|
|
keyup = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[EndAction("moveup", BaseAction = true)]
|
|
|
|
public virtual void EndMoveUp()
|
|
|
|
{
|
|
|
|
keyup = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BeginAction("movedown", BaseAction = true)]
|
|
|
|
public virtual void BeginMoveDown()
|
|
|
|
{
|
|
|
|
keydown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[EndAction("movedown", BaseAction = true)]
|
|
|
|
public virtual void EndMoveDown()
|
|
|
|
{
|
|
|
|
keydown = false;
|
|
|
|
}
|
2022-01-03 14:46:00 +00:00
|
|
|
|
|
|
|
[BeginAction("movecameratocursor", BaseAction = true)]
|
|
|
|
protected virtual void MoveCameraToCursor()
|
|
|
|
{
|
|
|
|
if (orbit)
|
|
|
|
{
|
|
|
|
orbitRadius = MOVE_CAMERA_DISTANCE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Vector3D hitPosition = GetHitPosition();
|
|
|
|
if (!hitPosition.IsFinite())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3D start = General.Map.VisualCamera.Position;
|
|
|
|
Vector3D delta = start - hitPosition;
|
|
|
|
General.Map.VisualCamera.Position = hitPosition + delta.GetFixedLength(MOVE_CAMERA_DISTANCE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
[BeginAction("movethingleft", BaseAction = true)]
|
2014-11-13 09:43:39 +00:00
|
|
|
protected void MoveSelectedThingsLeft()
|
|
|
|
{
|
2017-01-06 10:01:59 +00:00
|
|
|
MoveSelectedThings(new Vector2D(0f, -General.Map.Grid.GridSizeF), false);
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
|
|
|
//mxd
|
|
|
|
[BeginAction("movethingright", BaseAction = true)]
|
2014-11-13 09:43:39 +00:00
|
|
|
protected void MoveSelectedThingsRight()
|
|
|
|
{
|
2017-01-06 10:01:59 +00:00
|
|
|
MoveSelectedThings(new Vector2D(0f, General.Map.Grid.GridSizeF), false);
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
|
|
|
//mxd
|
|
|
|
[BeginAction("movethingfwd", BaseAction = true)]
|
2014-11-13 09:43:39 +00:00
|
|
|
protected void MoveSelectedThingsForward()
|
|
|
|
{
|
2017-01-06 10:01:59 +00:00
|
|
|
MoveSelectedThings(new Vector2D(-General.Map.Grid.GridSizeF, 0f), false);
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
|
|
|
//mxd
|
|
|
|
[BeginAction("movethingback", BaseAction = true)]
|
2014-11-13 09:43:39 +00:00
|
|
|
protected void MoveSelectedThingsBackward()
|
|
|
|
{
|
2017-01-06 10:01:59 +00:00
|
|
|
MoveSelectedThings(new Vector2D(General.Map.Grid.GridSizeF, 0f), false);
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
2014-11-13 09:43:39 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
|
|
|
[BeginAction("placethingatcursor", BaseAction = true)]
|
2014-11-13 09:43:39 +00:00
|
|
|
protected void PlaceThingAtCursor()
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
Vector2D hitpos = GetHitPosition();
|
2015-12-28 15:01:53 +00:00
|
|
|
if(!hitpos.IsFinite())
|
2014-11-13 09:43:39 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
General.Interface.DisplayStatus(StatusType.Warning, "Cannot place Thing here");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-22 20:30:32 +00:00
|
|
|
MoveSelectedThings(new Vector2D(Math.Round(hitpos.x), Math.Round(hitpos.y)), true);
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//mxd.
|
2022-01-03 14:46:00 +00:00
|
|
|
public Vector3D GetHitPosition()
|
2014-11-13 09:43:39 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
Vector3D start = General.Map.VisualCamera.Position;
|
|
|
|
Vector3D delta = General.Map.VisualCamera.Target - General.Map.VisualCamera.Position;
|
|
|
|
delta = delta.GetFixedLength(General.Settings.ViewDistance * 0.98f);
|
|
|
|
VisualPickResult target = PickObject(start, start + delta);
|
|
|
|
|
2022-01-03 14:46:00 +00:00
|
|
|
if(target.picked == null) return new Vector3D(double.NaN, double.NaN, double.NaN);
|
2013-09-11 09:47:53 +00:00
|
|
|
|
2016-03-18 12:52:12 +00:00
|
|
|
// Now find where exactly did we hit
|
|
|
|
VisualGeometry vg = target.picked as VisualGeometry;
|
|
|
|
if(vg != null) return GetIntersection(start, start + delta, vg.BoundingBox[0], new Vector3D(vg.Vertices[0].nx, vg.Vertices[0].ny, vg.Vertices[0].nz));
|
|
|
|
|
|
|
|
|
|
|
|
VisualThing vt = target.picked as VisualThing;
|
2022-01-03 14:46:00 +00:00
|
|
|
if (vt != null)
|
|
|
|
{
|
|
|
|
Vector3D normal = start - vt.CenterV3D;
|
|
|
|
normal.z = 0;
|
|
|
|
normal = normal.GetNormal();
|
|
|
|
return GetIntersection(start, start + delta, vt.CenterV3D, normal);
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
|
2022-01-03 14:46:00 +00:00
|
|
|
return new Vector3D(double.NaN, double.NaN, double.NaN);
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//mxd. This checks intersection between line and plane
|
2022-01-03 14:46:00 +00:00
|
|
|
private static Vector3D GetIntersection(Vector3D start, Vector3D end, Vector3D planeCenter, Vector3D planeNormal)
|
2014-05-20 09:09:28 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
Vector3D delta = new Vector3D(planeCenter.x - start.x, planeCenter.y - start.y, planeCenter.z - start.z);
|
|
|
|
return start + Vector3D.DotProduct(planeNormal, delta) / Vector3D.DotProduct(planeNormal, end - start) * (end - start);
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd. Should move selected things in specified direction
|
2014-11-13 09:43:39 +00:00
|
|
|
protected virtual void MoveSelectedThings(Vector2D direction, bool absolutePosition) { }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2019-12-20 04:12:39 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Visibility Culling
|
|
|
|
|
|
|
|
int lastProcessed = 0;
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This preforms visibility culling
|
2009-06-16 08:49:14 +00:00
|
|
|
protected void DoCulling()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2019-12-20 04:12:39 +00:00
|
|
|
lastProcessed++;
|
|
|
|
List<Linedef> visiblelines = new List<Linedef>();
|
2013-07-19 15:30:58 +00:00
|
|
|
Vector2D campos2d = General.Map.VisualCamera.Position;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Make collections
|
2019-12-21 04:43:16 +00:00
|
|
|
visiblesectors = new List<VisualSector>(visiblesectors.Count * 2);
|
|
|
|
visiblegeometry = new List<VisualGeometry>(visiblegeometry.Count * 2);
|
|
|
|
visiblethings = new List<VisualThing>(visiblethings.Count * 2);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Get the blocks within view range
|
|
|
|
visibleblocks = blockmap.GetFrustumRange(renderer.Frustum2D);
|
|
|
|
|
|
|
|
// Fill collections with geometry and things
|
|
|
|
foreach(VisualBlockEntry block in visibleblocks)
|
|
|
|
{
|
|
|
|
if(processgeometry)
|
|
|
|
{
|
|
|
|
// Lines
|
|
|
|
foreach(Linedef ld in block.Lines)
|
|
|
|
{
|
|
|
|
// Line not already processed?
|
2019-12-21 04:43:16 +00:00
|
|
|
if (ld.LastProcessed != lastProcessed)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2019-12-20 04:12:39 +00:00
|
|
|
// Add line if not added yet
|
|
|
|
ld.LastProcessed = lastProcessed;
|
|
|
|
visiblelines.Add(ld);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Which side of the line is the camera on?
|
|
|
|
if(ld.SideOfLine(campos2d) < 0)
|
|
|
|
{
|
|
|
|
// Do front of line
|
|
|
|
if(ld.Front != null) ProcessSidedefCulling(ld.Front);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Do back of line
|
|
|
|
if(ld.Back != null) ProcessSidedefCulling(ld.Back);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(processthings)
|
|
|
|
{
|
|
|
|
// Things
|
|
|
|
foreach(Thing t in block.Things)
|
|
|
|
{
|
2019-12-21 04:43:16 +00:00
|
|
|
if (t.LastProcessed == lastProcessed) continue;
|
|
|
|
|
|
|
|
t.LastProcessed = lastProcessed;
|
|
|
|
|
2009-06-17 16:52:28 +00:00
|
|
|
// Not filtered out?
|
2015-10-02 14:47:34 +00:00
|
|
|
if(!General.Map.ThingsFilter.IsThingVisible(t)) continue;
|
|
|
|
|
2019-12-26 08:08:11 +00:00
|
|
|
VisualThing vt;
|
|
|
|
if(allthings.ContainsKey(t))
|
|
|
|
{
|
|
|
|
vt = allthings[t];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Create new visual thing
|
|
|
|
vt = CreateVisualThing(t);
|
|
|
|
allthings[t] = vt;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2019-12-26 08:08:11 +00:00
|
|
|
if(vt != null)
|
|
|
|
{
|
|
|
|
visiblethings.Add(vt);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(processgeometry)
|
|
|
|
{
|
2019-12-26 00:10:00 +00:00
|
|
|
// Find camera sector
|
|
|
|
Sector camsector = blockmap.GetSectorAt(campos2d);
|
|
|
|
if (camsector != null)
|
|
|
|
{
|
|
|
|
General.Map.VisualCamera.Sector = camsector;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// To do: fix this code. It is retarded. Walking over all visible lines is extremely expensive.
|
|
|
|
|
|
|
|
Linedef nld = MapSet.NearestLinedef(visiblelines, campos2d);
|
|
|
|
if (nld != null)
|
|
|
|
{
|
|
|
|
General.Map.VisualCamera.Sector = GetCameraSectorFromLinedef(nld);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Exceptional case: no lines found in any nearby blocks!
|
|
|
|
// This could happen in the middle of an extremely large sector and in this case
|
|
|
|
// the above code will not have found any sectors/sidedefs for rendering.
|
|
|
|
// Here we handle this special case with brute-force. Let's find the sector
|
|
|
|
// the camera is in by searching the entire map and render that sector only.
|
|
|
|
nld = General.Map.Map.NearestLinedef(campos2d);
|
|
|
|
if (nld != null)
|
|
|
|
{
|
|
|
|
General.Map.VisualCamera.Sector = GetCameraSectorFromLinedef(nld);
|
|
|
|
if (General.Map.VisualCamera.Sector != null)
|
|
|
|
{
|
|
|
|
foreach (Sidedef sd in General.Map.VisualCamera.Sector.Sidedefs)
|
|
|
|
{
|
2020-05-21 12:20:02 +00:00
|
|
|
double side = sd.Line.SideOfLine(campos2d);
|
2019-12-26 00:10:00 +00:00
|
|
|
if (((side < 0) && sd.IsFront) ||
|
|
|
|
((side > 0) && !sd.IsFront))
|
|
|
|
ProcessSidedefCulling(sd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Too far away from the map to see anything
|
|
|
|
General.Map.VisualCamera.Sector = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Map is empty
|
|
|
|
General.Map.VisualCamera.Sector = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This finds and adds visible sectors
|
|
|
|
private void ProcessSidedefCulling(Sidedef sd)
|
|
|
|
{
|
2019-12-21 04:43:16 +00:00
|
|
|
// Do nothing if we already added it.
|
|
|
|
if (sd.LastProcessed == lastProcessed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sd.LastProcessed = lastProcessed;
|
|
|
|
|
2019-12-26 08:08:11 +00:00
|
|
|
VisualSector vs;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2019-12-26 08:08:11 +00:00
|
|
|
// Find the visualsector and make it if needed
|
|
|
|
if(allsectors.ContainsKey(sd.Sector))
|
|
|
|
{
|
|
|
|
// Take existing visualsector
|
|
|
|
vs = allsectors[sd.Sector];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Make new visualsector
|
|
|
|
vs = CreateVisualSector(sd.Sector);
|
|
|
|
//if(vs != null) allsectors.Add(sd.Sector, vs); //mxd
|
|
|
|
}
|
|
|
|
|
|
|
|
if(vs != null)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2019-12-21 04:43:16 +00:00
|
|
|
if (sd.Sector.LastProcessed != lastProcessed)
|
|
|
|
{
|
|
|
|
sd.Sector.LastProcessed = lastProcessed;
|
2019-12-26 08:08:11 +00:00
|
|
|
visiblesectors.Add(vs);
|
|
|
|
visiblegeometry.AddRange(vs.FixedGeometry);
|
2019-12-21 04:43:16 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Add sidedef geometry
|
2019-12-26 08:08:11 +00:00
|
|
|
visiblegeometry.AddRange(vs.GetSidedefGeometry(sd));
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This returns the camera sector from linedef
|
2014-05-20 09:09:28 +00:00
|
|
|
private static Sector GetCameraSectorFromLinedef(Linedef ld)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
if(ld.SideOfLine(General.Map.VisualCamera.Position) < 0)
|
|
|
|
{
|
2014-05-20 09:09:28 +00:00
|
|
|
return (ld.Front != null ? ld.Front.Sector : null);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2014-05-20 09:09:28 +00:00
|
|
|
|
|
|
|
return (ld.Back != null ? ld.Back.Sector : null);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Object Picking
|
|
|
|
|
|
|
|
// This picks an object from the scene
|
2012-08-10 12:08:08 +00:00
|
|
|
public VisualPickResult PickObject(Vector3D from, Vector3D to)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
VisualPickResult result = new VisualPickResult();
|
2009-04-19 18:07:22 +00:00
|
|
|
Line2D ray2d = new Line2D(from, to);
|
|
|
|
Vector3D delta = to - from;
|
|
|
|
|
|
|
|
// Setup no result
|
|
|
|
result.picked = null;
|
|
|
|
result.hitpos = new Vector3D();
|
|
|
|
result.u_ray = 1.0f;
|
|
|
|
|
|
|
|
// Find all blocks we are intersecting
|
|
|
|
List<VisualBlockEntry> blocks = blockmap.GetLineBlocks(from, to);
|
|
|
|
|
|
|
|
// Make collections
|
|
|
|
Dictionary<Linedef, Linedef> lines = new Dictionary<Linedef, Linedef>(blocks.Count * 10);
|
|
|
|
Dictionary<Sector, VisualSector> sectors = new Dictionary<Sector, VisualSector>(blocks.Count * 10);
|
|
|
|
List<IVisualPickable> pickables = new List<IVisualPickable>(blocks.Count * 10);
|
|
|
|
|
|
|
|
// Add geometry from the camera sector
|
2019-12-26 08:08:11 +00:00
|
|
|
if((General.Map.VisualCamera.Sector != null) && allsectors.ContainsKey(General.Map.VisualCamera.Sector))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2019-12-26 08:08:11 +00:00
|
|
|
VisualSector vs = allsectors[General.Map.VisualCamera.Sector];
|
2009-04-19 18:07:22 +00:00
|
|
|
sectors.Add(General.Map.VisualCamera.Sector, vs);
|
2020-02-23 00:07:40 +00:00
|
|
|
foreach(VisualGeometry g in vs.FixedGeometry) pickables.Add(g);
|
2019-12-30 23:08:17 +00:00
|
|
|
|
|
|
|
// Add slope handles
|
2021-01-30 21:01:55 +00:00
|
|
|
if (General.Map.UDMF)
|
|
|
|
{
|
|
|
|
if (pickingmode == PickingMode.SidedefSlopeHandles && sidedefslopehandles.ContainsKey(General.Map.VisualCamera.Sector))
|
|
|
|
pickables.AddRange(sidedefslopehandles[General.Map.VisualCamera.Sector]);
|
|
|
|
else if (pickingmode == PickingMode.VertexSlopeHandles && vertexslopehandles.ContainsKey(General.Map.VisualCamera.Sector))
|
|
|
|
pickables.AddRange(vertexslopehandles[General.Map.VisualCamera.Sector]);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Go for all lines to see which ones we intersect
|
|
|
|
// We will collect geometry from the sectors and sidedefs
|
|
|
|
foreach(VisualBlockEntry b in blocks)
|
|
|
|
{
|
|
|
|
foreach(Linedef ld in b.Lines)
|
|
|
|
{
|
|
|
|
// Make sure we don't test a line twice
|
|
|
|
if(!lines.ContainsKey(ld))
|
|
|
|
{
|
|
|
|
lines.Add(ld, ld);
|
2020-05-18 16:14:54 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Intersecting?
|
2020-05-18 16:14:54 +00:00
|
|
|
double u;
|
2009-04-19 18:07:22 +00:00
|
|
|
if(ld.Line.GetIntersection(ray2d, out u))
|
|
|
|
{
|
|
|
|
// Check on which side we are
|
2020-05-21 12:20:02 +00:00
|
|
|
double side = ld.SideOfLine(ray2d.v1);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Calculate intersection point
|
|
|
|
Vector3D intersect = from + delta * u;
|
|
|
|
|
|
|
|
// We must add the sectors of both sides of the line
|
|
|
|
// If we wouldn't, then aiming at a sector that is just within range
|
|
|
|
// could result in an incorrect hit (because the far line of the
|
|
|
|
// sector may not be included in this loop)
|
|
|
|
if(ld.Front != null)
|
|
|
|
{
|
|
|
|
// Find the visualsector
|
2019-12-26 08:08:11 +00:00
|
|
|
if(allsectors.ContainsKey(ld.Front.Sector))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2019-12-26 08:08:11 +00:00
|
|
|
VisualSector vs = allsectors[ld.Front.Sector];
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Add sector if not already added
|
|
|
|
if(!sectors.ContainsKey(ld.Front.Sector))
|
|
|
|
{
|
|
|
|
sectors.Add(ld.Front.Sector, vs);
|
2020-02-23 00:07:40 +00:00
|
|
|
foreach (VisualGeometry g in vs.FixedGeometry)
|
2009-07-04 10:06:35 +00:00
|
|
|
{
|
2020-02-23 00:07:40 +00:00
|
|
|
// Must have content
|
|
|
|
if (g.Triangles > 0)
|
|
|
|
pickables.Add(g);
|
2009-07-04 10:06:35 +00:00
|
|
|
}
|
2019-12-30 23:08:17 +00:00
|
|
|
|
|
|
|
// Add slope handles
|
2021-01-30 21:01:55 +00:00
|
|
|
if (General.Map.UDMF)
|
|
|
|
{
|
|
|
|
if (pickingmode == PickingMode.SidedefSlopeHandles && sidedefslopehandles.ContainsKey(ld.Front.Sector))
|
|
|
|
pickables.AddRange(sidedefslopehandles[ld.Front.Sector]);
|
|
|
|
else if (pickingmode == PickingMode.VertexSlopeHandles && vertexslopehandles.ContainsKey(ld.Front.Sector))
|
|
|
|
pickables.AddRange(vertexslopehandles[ld.Front.Sector]);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add sidedef if on the front side
|
2020-02-23 00:07:40 +00:00
|
|
|
if(side < 0.0f)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
List<VisualGeometry> sidedefgeo = vs.GetSidedefGeometry(ld.Front);
|
|
|
|
foreach(VisualGeometry g in sidedefgeo)
|
|
|
|
{
|
2009-07-04 10:06:35 +00:00
|
|
|
// Must have content
|
|
|
|
if(g.Triangles > 0)
|
|
|
|
{
|
|
|
|
g.SetPickResults(intersect, u);
|
|
|
|
pickables.Add(g);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add back side also
|
|
|
|
if(ld.Back != null)
|
|
|
|
{
|
|
|
|
// Find the visualsector
|
2019-12-26 08:08:11 +00:00
|
|
|
if(allsectors.ContainsKey(ld.Back.Sector))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2019-12-26 08:08:11 +00:00
|
|
|
VisualSector vs = allsectors[ld.Back.Sector];
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Add sector if not already added
|
|
|
|
if(!sectors.ContainsKey(ld.Back.Sector))
|
|
|
|
{
|
|
|
|
sectors.Add(ld.Back.Sector, vs);
|
2020-02-23 00:07:40 +00:00
|
|
|
foreach (VisualGeometry g in vs.FixedGeometry)
|
2009-07-04 10:06:35 +00:00
|
|
|
{
|
2020-02-23 00:07:40 +00:00
|
|
|
// Must have content
|
|
|
|
if (g.Triangles > 0)
|
|
|
|
pickables.Add(g);
|
2009-07-04 10:06:35 +00:00
|
|
|
}
|
2019-12-30 23:08:17 +00:00
|
|
|
|
|
|
|
// Add slope handles
|
2021-01-30 21:01:55 +00:00
|
|
|
if (General.Map.UDMF)
|
|
|
|
{
|
|
|
|
if (pickingmode == PickingMode.SidedefSlopeHandles && sidedefslopehandles.ContainsKey(ld.Back.Sector))
|
|
|
|
pickables.AddRange(sidedefslopehandles[ld.Back.Sector]);
|
|
|
|
else if (pickingmode == PickingMode.VertexSlopeHandles && vertexslopehandles.ContainsKey(ld.Back.Sector))
|
|
|
|
pickables.AddRange(vertexslopehandles[ld.Back.Sector]);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add sidedef if on the front side
|
2020-02-23 00:07:40 +00:00
|
|
|
if(side > 0.0f)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
List<VisualGeometry> sidedefgeo = vs.GetSidedefGeometry(ld.Back);
|
|
|
|
foreach(VisualGeometry g in sidedefgeo)
|
|
|
|
{
|
2009-07-04 10:06:35 +00:00
|
|
|
// Must have content
|
|
|
|
if(g.Triangles > 0)
|
|
|
|
{
|
|
|
|
g.SetPickResults(intersect, u);
|
|
|
|
pickables.Add(g);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add all the visible things
|
2020-02-23 00:07:40 +00:00
|
|
|
foreach(VisualThing vt in visiblethings) pickables.Add(vt);
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
|
|
//mxd. And all visual vertices
|
2020-02-23 00:07:40 +00:00
|
|
|
if (General.Map.UDMF && General.Settings.GZShowVisualVertices)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2020-02-19 20:59:42 +00:00
|
|
|
foreach (KeyValuePair<Vertex, VisualVertexPair> pair in vertices)
|
2013-03-18 13:52:27 +00:00
|
|
|
pickables.AddRange(pair.Value.Vertices);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Now we have a list of potential geometry that lies along the trace line.
|
|
|
|
// We still don't know what geometry actually hits, but we ruled out that which doesn't get even close.
|
|
|
|
// This is still too much for accurate intersection testing, so we do a fast reject pass first.
|
|
|
|
Vector3D direction = to - from;
|
|
|
|
direction = direction.GetNormal();
|
|
|
|
List<IVisualPickable> potentialpicks = new List<IVisualPickable>(pickables.Count);
|
|
|
|
foreach(IVisualPickable p in pickables)
|
|
|
|
{
|
|
|
|
if(p.PickFastReject(from, to, direction)) potentialpicks.Add(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we do an accurate intersection test for all resulting geometry
|
|
|
|
// We keep only the closest hit!
|
|
|
|
foreach(IVisualPickable p in potentialpicks)
|
|
|
|
{
|
2020-05-21 12:20:02 +00:00
|
|
|
double u = result.u_ray;
|
2009-04-19 18:07:22 +00:00
|
|
|
if(p.PickAccurate(from, to, direction, ref u))
|
|
|
|
{
|
|
|
|
// Closer than previous find?
|
|
|
|
if((u > 0.0f) && (u < result.u_ray))
|
|
|
|
{
|
|
|
|
result.u_ray = u;
|
|
|
|
result.picked = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup final result
|
|
|
|
result.hitpos = from + to * result.u_ray;
|
2012-08-05 19:18:05 +00:00
|
|
|
|
2020-02-23 00:07:40 +00:00
|
|
|
// If picking mode is for slope handles only return slope handles. We have to do it this
|
|
|
|
// way because otherwise it's possible to pick slope handles through other geometry
|
2021-01-30 21:01:55 +00:00
|
|
|
if (pickingmode != PickingMode.Default && !(result.picked is VisualSlope))
|
2020-02-23 00:07:40 +00:00
|
|
|
result.picked = null;
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Done
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Processing
|
|
|
|
|
|
|
|
/// <summary>
|
2009-06-11 21:21:20 +00:00
|
|
|
/// This disposes all resources. Needed geometry will be rebuild automatically.
|
2009-04-19 18:07:22 +00:00
|
|
|
/// </summary>
|
|
|
|
protected virtual void ResourcesReloaded()
|
|
|
|
{
|
2019-12-26 08:08:11 +00:00
|
|
|
// Dispose
|
|
|
|
foreach(KeyValuePair<Sector, VisualSector> vs in allsectors)
|
|
|
|
if(vs.Value != null) vs.Value.Dispose();
|
|
|
|
|
|
|
|
foreach(KeyValuePair<Thing, VisualThing> vt in allthings)
|
|
|
|
if(vt.Value != null) vt.Value.Dispose();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Clear collections
|
2019-12-26 08:08:11 +00:00
|
|
|
allsectors.Clear();
|
|
|
|
allthings.Clear();
|
2009-04-19 18:07:22 +00:00
|
|
|
visiblesectors.Clear();
|
|
|
|
visibleblocks.Clear();
|
|
|
|
visiblegeometry.Clear();
|
|
|
|
visiblethings.Clear();
|
2014-10-29 13:11:35 +00:00
|
|
|
vertices.Clear(); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Make new blockmap
|
2009-06-16 08:49:14 +00:00
|
|
|
FillBlockMap();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Visibility culling (this re-creates the needed resources)
|
|
|
|
DoCulling();
|
|
|
|
}
|
2009-06-11 21:21:20 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This disposes orphaned resources and resources on changed geometry.
|
|
|
|
/// This usually happens when geometry is changed by undo, redo, cut or paste actions
|
|
|
|
/// and uses the marks to check what needs to be reloaded.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual void ResourcesReloadedPartial()
|
|
|
|
{
|
2019-12-26 08:08:11 +00:00
|
|
|
Dictionary<Sector, VisualSector> newsectors = new Dictionary<Sector,VisualSector>(allsectors.Count);
|
|
|
|
|
2009-06-11 21:21:20 +00:00
|
|
|
// Neighbour sectors must be updated as well
|
|
|
|
foreach(Sector s in General.Map.Map.Sectors)
|
|
|
|
{
|
|
|
|
if(s.Marked)
|
|
|
|
{
|
|
|
|
foreach(Sidedef sd in s.Sidedefs)
|
|
|
|
if(sd.Other != null) sd.Other.Marked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go for all sidedefs to mark sectors that need updating
|
|
|
|
foreach(Sidedef sd in General.Map.Map.Sidedefs)
|
|
|
|
if(sd.Marked) sd.Sector.Marked = true;
|
|
|
|
|
|
|
|
// Go for all vertices to mark linedefs that need updating
|
|
|
|
foreach(Vertex v in General.Map.Map.Vertices)
|
|
|
|
{
|
|
|
|
if(v.Marked)
|
|
|
|
{
|
|
|
|
foreach(Linedef ld in v.Linedefs)
|
|
|
|
ld.Marked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go for all linedefs to mark sectors that need updating
|
|
|
|
foreach(Linedef ld in General.Map.Map.Linedefs)
|
|
|
|
{
|
|
|
|
if(ld.Marked)
|
|
|
|
{
|
|
|
|
if(ld.Front != null) ld.Front.Sector.Marked = true;
|
|
|
|
if(ld.Back != null) ld.Back.Sector.Marked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-26 08:08:11 +00:00
|
|
|
// Dispose if source was disposed or marked
|
|
|
|
foreach(KeyValuePair<Sector, VisualSector> vs in allsectors)
|
2009-06-11 21:21:20 +00:00
|
|
|
{
|
2019-12-26 08:08:11 +00:00
|
|
|
if(vs.Value != null)
|
2011-12-02 23:11:16 +00:00
|
|
|
{
|
2019-12-26 08:08:11 +00:00
|
|
|
if(vs.Key.IsDisposed || vs.Key.Marked)
|
|
|
|
vs.Value.Dispose();
|
|
|
|
else
|
|
|
|
newsectors.Add(vs.Key, vs.Value);
|
2011-12-02 23:11:16 +00:00
|
|
|
}
|
2009-06-11 21:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Things depend on the sector they are in and because we can't
|
|
|
|
// easily determine which ones changed, we dispose all things
|
2019-12-26 08:08:11 +00:00
|
|
|
foreach(KeyValuePair<Thing, VisualThing> vt in allthings)
|
|
|
|
if(vt.Value != null) vt.Value.Dispose();
|
|
|
|
|
|
|
|
// Apply new lists
|
|
|
|
allsectors = newsectors;
|
|
|
|
allthings = new Dictionary<Thing, VisualThing>(allthings.Count);
|
|
|
|
|
2009-06-11 21:21:20 +00:00
|
|
|
// Clear visibility collections
|
|
|
|
visiblesectors.Clear();
|
|
|
|
visibleblocks.Clear();
|
|
|
|
visiblegeometry.Clear();
|
|
|
|
visiblethings.Clear();
|
|
|
|
|
|
|
|
// Make new blockmap
|
2009-06-16 08:49:14 +00:00
|
|
|
FillBlockMap();
|
2009-06-11 21:21:20 +00:00
|
|
|
|
|
|
|
// Visibility culling (this re-creates the needed resources)
|
|
|
|
DoCulling();
|
|
|
|
}
|
2009-06-16 08:49:14 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Implement this to create an instance of your VisualSector implementation.
|
|
|
|
/// </summary>
|
|
|
|
protected abstract VisualSector CreateVisualSector(Sector s);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Implement this to create an instance of your VisualThing implementation.
|
|
|
|
/// </summary>
|
|
|
|
protected abstract VisualThing CreateVisualThing(Thing t);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This returns the VisualSector for the given Sector.
|
|
|
|
/// </summary>
|
2014-12-03 23:15:26 +00:00
|
|
|
public VisualSector GetVisualSector(Sector s)
|
|
|
|
{
|
2019-12-26 08:08:11 +00:00
|
|
|
if(!allsectors.ContainsKey(s)) return CreateVisualSector(s); //mxd
|
|
|
|
return allsectors[s];
|
2013-06-19 11:18:13 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This returns the VisualThing for the given Thing.
|
|
|
|
/// </summary>
|
2019-12-26 08:08:11 +00:00
|
|
|
public VisualThing GetVisualThing(Thing t) { return allthings[t]; }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2014-05-20 09:09:28 +00:00
|
|
|
public List<VisualThing> GetSelectedVisualThings(bool refreshSelection)
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
if(refreshSelection || selectedVisualThings == null)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
selectedVisualThings = new List<VisualThing>();
|
2019-12-26 08:08:11 +00:00
|
|
|
foreach(KeyValuePair<Thing, VisualThing> group in allthings)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2019-12-26 08:08:11 +00:00
|
|
|
if(group.Value != null && group.Value.Selected)
|
|
|
|
selectedVisualThings.Add(group.Value);
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//if nothing is selected - try to get thing from hilighted object
|
2015-12-28 15:01:53 +00:00
|
|
|
if(selectedVisualThings.Count == 0)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
Vector3D start = General.Map.VisualCamera.Position;
|
|
|
|
Vector3D delta = General.Map.VisualCamera.Target - General.Map.VisualCamera.Position;
|
|
|
|
delta = delta.GetFixedLength(General.Settings.ViewDistance * 0.98f);
|
|
|
|
VisualPickResult target = PickObject(start, start + delta);
|
|
|
|
|
|
|
|
//not appropriate way to do this, but...
|
2015-12-28 15:01:53 +00:00
|
|
|
if(target.picked is VisualThing)
|
2013-09-11 09:47:53 +00:00
|
|
|
selectedVisualThings.Add((VisualThing)target.picked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return selectedVisualThings;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// mxd. This returns list of selected sectors based on surfaces selected in visual mode
|
|
|
|
/// </summary>
|
2014-05-20 09:09:28 +00:00
|
|
|
public List<VisualSector> GetSelectedVisualSectors(bool refreshSelection)
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
if(refreshSelection || selectedVisualSectors == null)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
selectedVisualSectors = new List<VisualSector>();
|
2019-12-26 08:08:11 +00:00
|
|
|
foreach(KeyValuePair<Sector, VisualSector> group in allsectors)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2019-12-26 08:08:11 +00:00
|
|
|
foreach(VisualGeometry vg in group.Value.AllGeometry)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
if(vg.Selected)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2019-12-26 08:08:11 +00:00
|
|
|
selectedVisualSectors.Add(group.Value);
|
2013-09-11 09:47:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//if nothing is selected - try to get sector from hilighted object
|
2015-12-28 15:01:53 +00:00
|
|
|
if(selectedVisualSectors.Count == 0)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
|
|
|
VisualGeometry vg = GetHilightedSurface();
|
2015-12-28 15:01:53 +00:00
|
|
|
if(vg != null) selectedVisualSectors.Add(vg.Sector);
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return selectedVisualSectors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// mxd. This returns list of surfaces selected in visual mode
|
|
|
|
/// </summary>
|
2014-05-20 09:09:28 +00:00
|
|
|
public List<VisualGeometry> GetSelectedSurfaces()
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
List<VisualGeometry> selectedSurfaces = new List<VisualGeometry>();
|
2019-12-26 08:08:11 +00:00
|
|
|
foreach(KeyValuePair<Sector, VisualSector> group in allsectors)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2019-12-26 08:08:11 +00:00
|
|
|
foreach(VisualGeometry vg in group.Value.AllGeometry)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
if(vg.Selected) selectedSurfaces.Add(vg);
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//if nothing is selected - try to get hilighted surface
|
2015-12-28 15:01:53 +00:00
|
|
|
if(selectedSurfaces.Count == 0)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
|
|
|
VisualGeometry vg = GetHilightedSurface();
|
2015-12-28 15:01:53 +00:00
|
|
|
if(vg != null) selectedSurfaces.Add(vg);
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
|
|
|
return selectedSurfaces;
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd
|
2014-12-03 23:15:26 +00:00
|
|
|
private VisualGeometry GetHilightedSurface()
|
2014-05-20 09:09:28 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
Vector3D start = General.Map.VisualCamera.Position;
|
|
|
|
Vector3D delta = General.Map.VisualCamera.Target - General.Map.VisualCamera.Position;
|
|
|
|
delta = delta.GetFixedLength(General.Settings.ViewDistance * 0.98f);
|
|
|
|
VisualPickResult target = PickObject(start, start + delta);
|
2012-06-26 08:54:25 +00:00
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
if(target.picked is VisualGeometry)
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
VisualGeometry vg = (VisualGeometry)target.picked;
|
2015-12-28 15:01:53 +00:00
|
|
|
if(vg.Sector != null) return vg;
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2012-05-20 00:56:59 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns True when a VisualSector has been created for the specified Sector.
|
|
|
|
/// </summary>
|
2019-12-26 08:08:11 +00:00
|
|
|
public bool VisualSectorExists(Sector s) { return allsectors.ContainsKey(s) && (allsectors[s] != null); }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns True when a VisualThing has been created for the specified Thing.
|
|
|
|
/// </summary>
|
2019-12-26 08:08:11 +00:00
|
|
|
public bool VisualThingExists(Thing t) { return allthings.ContainsKey(t) && (allthings[t] != null); }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// This is called when the blockmap needs to be refilled, because it was invalidated.
|
|
|
|
/// This usually happens when geometry is changed by undo, redo, cut or paste actions.
|
|
|
|
/// Lines and Things are added to the block map by the base implementation.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual void FillBlockMap()
|
|
|
|
{
|
2013-08-05 13:03:08 +00:00
|
|
|
blockmap.Clear();//mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
blockmap.AddLinedefsSet(General.Map.Map.Linedefs);
|
|
|
|
blockmap.AddThingsSet(General.Map.Map.Things);
|
|
|
|
blockmap.AddSectorsSet(General.Map.Map.Sectors);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// While this mode is active, this is called continuously to process whatever needs processing.
|
|
|
|
/// </summary>
|
2016-03-14 00:01:21 +00:00
|
|
|
public override void OnProcess(long deltatime)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
base.OnProcess(deltatime);
|
|
|
|
|
|
|
|
// Camera vectors
|
|
|
|
Vector3D camvec = Vector3D.FromAngleXYZ(General.Map.VisualCamera.AngleXY, General.Map.VisualCamera.AngleZ);
|
|
|
|
Vector3D camvecstrafe = Vector3D.FromAngleXY(General.Map.VisualCamera.AngleXY + Angle2D.PIHALF);
|
|
|
|
Vector3D cammovemul = General.Map.VisualCamera.MoveMultiplier;
|
|
|
|
Vector3D camdeltapos = new Vector3D();
|
2020-05-23 08:37:42 +00:00
|
|
|
Vector3D upvec = new Vector3D(0.0, 0.0, 1.0);
|
2010-05-08 13:14:48 +00:00
|
|
|
|
2020-05-23 08:37:42 +00:00
|
|
|
double multiplier;
|
2010-08-14 18:07:38 +00:00
|
|
|
if(General.Interface.ShiftState) multiplier = MOVE_SPEED_MULTIPLIER * 2.0f; else multiplier = MOVE_SPEED_MULTIPLIER;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2022-01-03 14:46:00 +00:00
|
|
|
if (orbit)
|
|
|
|
{
|
|
|
|
if (keyforward) orbitRadius -= General.Settings.MoveSpeed * multiplier * deltatime;
|
|
|
|
if (keybackward) orbitRadius += General.Settings.MoveSpeed * multiplier * deltatime;
|
|
|
|
|
|
|
|
if (orbitRadius < 1) orbitRadius = 1f;
|
|
|
|
|
|
|
|
General.Map.VisualCamera.ProcessMovement(new Vector3D());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Move the camera
|
|
|
|
|
|
|
|
if(keyforward) camdeltapos += camvec * cammovemul * General.Settings.MoveSpeed * multiplier * deltatime;
|
|
|
|
if(keybackward) camdeltapos -= camvec * cammovemul * General.Settings.MoveSpeed * multiplier * deltatime;
|
|
|
|
if(keyleft) camdeltapos -= camvecstrafe * cammovemul * General.Settings.MoveSpeed * multiplier * deltatime;
|
|
|
|
if(keyright) camdeltapos += camvecstrafe * cammovemul * General.Settings.MoveSpeed * multiplier * deltatime;
|
|
|
|
if(keyup) camdeltapos += upvec * cammovemul * General.Settings.MoveSpeed * multiplier * deltatime;
|
|
|
|
if(keydown) camdeltapos += -upvec * cammovemul * General.Settings.MoveSpeed * multiplier * deltatime;
|
|
|
|
|
|
|
|
// Move the camera
|
|
|
|
General.Map.VisualCamera.ProcessMovement(camdeltapos);
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Apply new camera matrices
|
|
|
|
renderer.PositionAndLookAt(General.Map.VisualCamera.Position, General.Map.VisualCamera.Target);
|
|
|
|
|
|
|
|
// Visibility culling
|
|
|
|
DoCulling();
|
|
|
|
|
|
|
|
// Update labels in main window
|
2014-02-21 14:42:12 +00:00
|
|
|
General.MainWindow.UpdateCoordinates(General.Map.VisualCamera.Position);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Now redraw
|
|
|
|
General.Interface.RedrawDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Actions
|
|
|
|
|
2014-02-10 09:26:13 +00:00
|
|
|
//mxd
|
|
|
|
[BeginAction("centeroncoordinates", BaseAction = true)]
|
2014-12-03 23:15:26 +00:00
|
|
|
protected virtual void CenterOnCoordinates()
|
|
|
|
{
|
2016-07-13 23:28:06 +00:00
|
|
|
// Show form...
|
2014-02-10 09:26:13 +00:00
|
|
|
CenterOnCoordinatesForm form = new CenterOnCoordinatesForm();
|
2016-07-13 23:28:06 +00:00
|
|
|
if(form.ShowDialog() == DialogResult.OK) CenterOnCoordinates(form.Coordinates);
|
|
|
|
}
|
2014-02-10 09:26:13 +00:00
|
|
|
|
2016-07-13 23:28:06 +00:00
|
|
|
//mxd
|
|
|
|
public void CenterOnCoordinates(Vector2D coords)
|
|
|
|
{
|
|
|
|
Sector s = General.Map.Map.GetSectorByCoordinates(coords, blockmap);
|
|
|
|
|
|
|
|
if(s == null)
|
|
|
|
General.Map.VisualCamera.Position = coords;
|
|
|
|
else
|
|
|
|
General.Map.VisualCamera.Position = new Vector3D(coords.x, coords.y, s.FloorHeight + 54);
|
|
|
|
|
|
|
|
General.Map.VisualCamera.Sector = s;
|
2014-02-10 09:26:13 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 22:35:11 +00:00
|
|
|
//mxd
|
|
|
|
[BeginAction("togglehighlight", BaseAction = true)]
|
|
|
|
public void ToggleHighlight()
|
|
|
|
{
|
|
|
|
General.Settings.UseHighlight = !General.Settings.UseHighlight;
|
2022-11-06 14:08:22 +00:00
|
|
|
|
|
|
|
string shorttext = "Highlight is now " + (General.Settings.UseHighlight ? "ON" : "OFF") + ".";
|
|
|
|
string text = shorttext;
|
|
|
|
|
|
|
|
string key = Actions.Action.GetShortcutKeyDesc(General.Actions.Current.ShortcutKey);
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(key))
|
|
|
|
text += $" Press '{key}' to toggle.";
|
|
|
|
|
|
|
|
General.ToastManager.ShowToast("togglehighlight", ToastType.INFO, "Changed highlight", text, shorttext);
|
2016-05-12 22:35:11 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|