2008-05-15 08:25:45 +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;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
2008-05-29 11:54:45 +00:00
|
|
|
using CodeImp.DoomBuilder.Windows;
|
2008-05-15 08:25:45 +00:00
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using CodeImp.DoomBuilder.Editing;
|
2008-09-28 21:20:56 +00:00
|
|
|
using CodeImp.DoomBuilder.Actions;
|
2008-11-19 16:18:36 +00:00
|
|
|
using CodeImp.DoomBuilder.VisualModes;
|
2008-05-15 08:25:45 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2008-11-27 13:42:18 +00:00
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
2008-05-15 08:25:45 +00:00
|
|
|
{
|
2008-11-27 13:42:18 +00:00
|
|
|
[EditMode(DisplayName = "Visual Mode",
|
|
|
|
SwitchAction = "visualmode", // Action name used to switch to this mode
|
2008-05-15 08:25:45 +00:00
|
|
|
ButtonImage = "VisualMode.png", // Image resource name for the button
|
2008-11-27 19:25:13 +00:00
|
|
|
ButtonOrder = 0, // Position of the button (lower is more to the left)
|
|
|
|
UseByDefault = true)]
|
2008-05-15 08:25:45 +00:00
|
|
|
|
|
|
|
public class BaseVisualMode : VisualMode
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
2008-12-02 15:47:06 +00:00
|
|
|
|
|
|
|
// Object picking interval
|
2008-12-04 22:35:45 +00:00
|
|
|
private const double PICK_INTERVAL = 100.0d;
|
|
|
|
private const float PICK_RANGE = 0.98f;
|
2008-12-02 15:47:06 +00:00
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
#endregion
|
2008-12-02 15:47:06 +00:00
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
#region ================== Variables
|
2008-12-02 15:47:06 +00:00
|
|
|
|
|
|
|
// Object picking
|
|
|
|
private VisualPickResult target;
|
|
|
|
private double lastpicktime;
|
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
#endregion
|
2008-12-02 15:47:06 +00:00
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
#endregion
|
2008-12-02 15:47:06 +00:00
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public BaseVisualMode()
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
public override void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
|
|
|
|
// Done
|
|
|
|
base.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2008-12-02 15:47:06 +00:00
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
#region ================== Methods
|
2008-12-02 15:47:06 +00:00
|
|
|
|
2008-11-25 21:54:50 +00:00
|
|
|
// This creates a visual sector
|
|
|
|
protected override VisualSector CreateVisualSector(Sector s)
|
2008-09-28 21:20:56 +00:00
|
|
|
{
|
2008-11-25 21:54:50 +00:00
|
|
|
return new BaseVisualSector(s);
|
2008-09-28 21:20:56 +00:00
|
|
|
}
|
|
|
|
|
2008-12-02 15:47:06 +00:00
|
|
|
// This picks a new target
|
|
|
|
private void PickTarget()
|
|
|
|
{
|
2008-12-03 07:04:57 +00:00
|
|
|
// Find the object we are aiming at
|
2008-12-02 15:47:06 +00:00
|
|
|
Vector3D start = CameraPosition;
|
|
|
|
Vector3D delta = CameraTarget - CameraPosition;
|
2008-12-04 22:35:45 +00:00
|
|
|
delta = delta.GetFixedLength(General.Settings.ViewDistance * PICK_RANGE);
|
2008-12-02 15:47:06 +00:00
|
|
|
VisualPickResult newtarget = PickObject(start, start + delta);
|
|
|
|
|
|
|
|
// Object changed?
|
|
|
|
if(newtarget.geometry != target.geometry)
|
|
|
|
{
|
|
|
|
// Any result?
|
|
|
|
if(newtarget.geometry != null)
|
|
|
|
{
|
2008-12-04 23:01:52 +00:00
|
|
|
if(newtarget.geometry.Sidedef != null)
|
2008-12-02 15:47:06 +00:00
|
|
|
{
|
2008-12-04 23:01:52 +00:00
|
|
|
if((target.geometry != null) && (target.geometry.Sidedef == null)) General.Interface.HideInfo();
|
|
|
|
General.Interface.ShowLinedefInfo(newtarget.geometry.Sidedef.Line);
|
2008-12-02 15:47:06 +00:00
|
|
|
}
|
2008-12-04 23:01:52 +00:00
|
|
|
else if(newtarget.geometry.Sidedef == null)
|
2008-12-02 15:47:06 +00:00
|
|
|
{
|
2008-12-04 23:01:52 +00:00
|
|
|
if((target.geometry == null) || (target.geometry.Sidedef != null)) General.Interface.HideInfo();
|
|
|
|
General.Interface.ShowSectorInfo(newtarget.geometry.Sector.Sector);
|
2008-12-02 15:47:06 +00:00
|
|
|
}
|
2008-12-03 07:04:57 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
General.Interface.HideInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
General.Interface.HideInfo();
|
2008-12-02 15:47:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply new target
|
|
|
|
target = newtarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
// Processing
|
|
|
|
public override void OnProcess(double deltatime)
|
|
|
|
{
|
|
|
|
// Do processing
|
|
|
|
base.OnProcess(deltatime);
|
|
|
|
|
|
|
|
// Time to pick a new target?
|
|
|
|
if(General.Clock.CurrentTime > (lastpicktime + PICK_INTERVAL))
|
|
|
|
{
|
|
|
|
PickTarget();
|
|
|
|
lastpicktime = General.Clock.CurrentTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
// This draws a frame
|
|
|
|
public override void OnRedrawDisplay()
|
|
|
|
{
|
|
|
|
// Start drawing
|
|
|
|
if(renderer.Start())
|
|
|
|
{
|
2008-12-04 22:35:45 +00:00
|
|
|
// Use fog!
|
|
|
|
renderer.SetFogMode(true);
|
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
// Begin with geometry
|
|
|
|
renderer.StartGeometry();
|
2008-12-02 15:47:06 +00:00
|
|
|
|
2008-12-01 06:51:00 +00:00
|
|
|
// This adds all visible geometry for rendering
|
|
|
|
AddGeometry();
|
2008-12-02 15:47:06 +00:00
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
// Done rendering geometry
|
|
|
|
renderer.FinishGeometry();
|
2008-12-02 15:47:06 +00:00
|
|
|
|
2008-12-03 07:04:57 +00:00
|
|
|
// Render crosshair
|
|
|
|
renderer.RenderCrosshair();
|
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
// Present!
|
|
|
|
renderer.Finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|