2008-01-04 00:16:58 +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;
|
|
|
|
using CodeImp.DoomBuilder.Interface;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
|
|
using CodeImp.DoomBuilder.Controls;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using System.Drawing;
|
2008-01-05 18:11:29 +00:00
|
|
|
using SlimDX;
|
2008-01-04 00:16:58 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Editing
|
|
|
|
{
|
2008-01-05 18:11:29 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Provides specialized functionality for a visual (3D) Doom Builder editing mode.
|
|
|
|
/// </summary>
|
2008-01-04 00:16:58 +00:00
|
|
|
public abstract class VisualMode : EditMode
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
private const float ANGLE_FROM_MOUSE = 0.0001f;
|
2008-01-13 21:23:59 +00:00
|
|
|
private const float MAX_ANGLEZ_LOW = 100f / Angle2D.PIDEG;
|
|
|
|
private const float MAX_ANGLEZ_HIGH = (360f - 100f) / Angle2D.PIDEG;
|
|
|
|
private const float CAMERA_SPEED = 6f;
|
2008-01-05 18:11:29 +00:00
|
|
|
|
2008-01-04 00:16:58 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
// 3D Mode thing
|
|
|
|
protected Thing modething;
|
|
|
|
|
|
|
|
// Graphics
|
|
|
|
protected IRenderer3D renderer;
|
|
|
|
private Renderer3D renderer3d;
|
|
|
|
|
|
|
|
// Camera
|
|
|
|
private Vector3D campos;
|
|
|
|
private Vector3D camtarget;
|
|
|
|
private float camanglexy, camanglez;
|
2008-01-04 00:16:58 +00:00
|
|
|
|
2008-01-13 21:23:59 +00:00
|
|
|
// Input
|
|
|
|
private bool keyforward;
|
|
|
|
private bool keybackward;
|
|
|
|
private bool keyleft;
|
|
|
|
private bool keyright;
|
|
|
|
|
2008-01-04 00:16:58 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
public Vector3D CameraPosition { get { return campos; } set { campos = value; } }
|
|
|
|
public Vector3D CameraTarget { get { return camtarget; } }
|
|
|
|
|
2008-01-04 00:16:58 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Provides specialized functionality for a visual (3D) Doom Builder editing mode.
|
|
|
|
/// </summary>
|
2008-01-04 00:16:58 +00:00
|
|
|
public VisualMode()
|
|
|
|
{
|
|
|
|
// Initialize
|
2008-01-05 18:11:29 +00:00
|
|
|
this.renderer = General.Map.Renderer3D;
|
|
|
|
this.renderer3d = (Renderer3D)General.Map.Renderer3D;
|
2008-01-13 21:23:59 +00:00
|
|
|
this.campos = new Vector3D(0.0f, 0.0f, 96.0f);
|
|
|
|
this.camanglez = Angle2D.PI;
|
2008-01-04 00:16:58 +00:00
|
|
|
}
|
|
|
|
|
2008-02-19 19:04:19 +00:00
|
|
|
// Disposer
|
2008-01-05 18:11:29 +00:00
|
|
|
public override void Dispose()
|
2008-01-04 00:16:58 +00:00
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
|
|
|
|
// Done
|
2008-01-05 18:11:29 +00:00
|
|
|
base.Dispose();
|
2008-01-04 00:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2008-01-13 21:23:59 +00:00
|
|
|
#region ================== Start / Stop
|
2008-01-04 00:16:58 +00:00
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
// Mode is engaged
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnEngage()
|
2008-01-05 18:11:29 +00:00
|
|
|
{
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnEngage();
|
2008-01-05 18:11:29 +00:00
|
|
|
|
|
|
|
// Find a 3D Mode thing
|
|
|
|
foreach(Thing t in General.Map.Map.Things)
|
|
|
|
if(t.Type == General.Map.Config.Start3DModeThingType) modething = t;
|
|
|
|
|
|
|
|
// Found one?
|
|
|
|
if(modething != null)
|
|
|
|
{
|
|
|
|
// Position camera here
|
|
|
|
modething.DetermineSector();
|
2008-01-13 21:23:59 +00:00
|
|
|
campos = modething.Position + new Vector3D(0.0f, 0.0f, 96.0f);
|
|
|
|
camanglexy = modething.Angle + Angle2D.PI;
|
|
|
|
camanglez = Angle2D.PI;
|
2008-01-05 18:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start special input mode
|
|
|
|
General.Interface.SetProcessorState(true);
|
|
|
|
General.Interface.StartExclusiveMouseInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mode is disengaged
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnDisengage()
|
2008-01-05 18:11:29 +00:00
|
|
|
{
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnDisengage();
|
2008-01-05 18:11:29 +00:00
|
|
|
|
|
|
|
// Do we have a 3D Mode thing?
|
|
|
|
if(modething != null)
|
|
|
|
{
|
|
|
|
// Position the thing to match camera
|
|
|
|
modething.Move((int)campos.x, (int)campos.y, 0);
|
2008-01-13 21:23:59 +00:00
|
|
|
modething.Rotate(camanglexy - Angle2D.PI);
|
2008-01-05 18:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop special input mode
|
|
|
|
General.Interface.SetProcessorState(false);
|
|
|
|
General.Interface.StopExclusiveMouseInput();
|
|
|
|
}
|
|
|
|
|
2008-01-13 21:23:59 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Input
|
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
// Mouse input
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnMouseInput(Vector2D delta)
|
2008-01-05 18:11:29 +00:00
|
|
|
{
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnMouseInput(delta);
|
2008-01-05 18:11:29 +00:00
|
|
|
|
|
|
|
// Change camera angles with the mouse changes
|
2008-01-13 21:23:59 +00:00
|
|
|
camanglexy -= delta.x * ANGLE_FROM_MOUSE;
|
|
|
|
camanglez += delta.y * ANGLE_FROM_MOUSE;
|
2008-01-05 18:11:29 +00:00
|
|
|
|
2008-01-13 21:23:59 +00:00
|
|
|
// Normalize angles
|
2008-01-05 18:11:29 +00:00
|
|
|
camanglexy = Angle2D.Normalized(camanglexy);
|
2008-01-13 21:23:59 +00:00
|
|
|
camanglez = Angle2D.Normalized(camanglez);
|
|
|
|
|
|
|
|
// Limit vertical angle
|
|
|
|
if(camanglez < MAX_ANGLEZ_LOW) camanglez = MAX_ANGLEZ_LOW;
|
|
|
|
if(camanglez > MAX_ANGLEZ_HIGH) camanglez = MAX_ANGLEZ_HIGH;
|
2008-01-05 18:11:29 +00:00
|
|
|
|
|
|
|
General.MainWindow.UpdateCoordinates(new Vector2D(camanglexy, camanglez));
|
|
|
|
}
|
2008-01-13 21:23:59 +00:00
|
|
|
|
|
|
|
// Key down
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnKeyDown(KeyEventArgs e)
|
2008-01-13 21:23:59 +00:00
|
|
|
{
|
|
|
|
string[] actions;
|
|
|
|
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnKeyDown(e);
|
2008-01-13 21:23:59 +00:00
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
/* WRONG
|
2008-01-13 21:23:59 +00:00
|
|
|
// Get the actions for this key
|
|
|
|
actions = General.Actions.GetActionsByKey((int)e.KeyData);
|
|
|
|
foreach(string a in actions)
|
|
|
|
{
|
|
|
|
// Check what key was pressed down
|
|
|
|
switch(a)
|
|
|
|
{
|
|
|
|
case "moveforward": keyforward = true; break;
|
|
|
|
case "movebackward": keybackward = true; break;
|
|
|
|
case "moveleft": keyleft = true; break;
|
|
|
|
case "moveright": keyright = true; break;
|
|
|
|
}
|
|
|
|
}
|
2008-04-27 12:07:26 +00:00
|
|
|
*/
|
2008-01-13 21:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Key up
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnKeyUp(KeyEventArgs e)
|
2008-01-13 21:23:59 +00:00
|
|
|
{
|
|
|
|
string[] actions;
|
|
|
|
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnKeyUp(e);
|
2008-01-13 21:23:59 +00:00
|
|
|
|
2008-04-27 12:07:26 +00:00
|
|
|
/* WRONG
|
2008-01-13 21:23:59 +00:00
|
|
|
// Get the actions for this key
|
|
|
|
actions = General.Actions.GetActionsByKey((int)e.KeyData);
|
|
|
|
foreach(string a in actions)
|
|
|
|
{
|
|
|
|
// Check what key was pressed down
|
|
|
|
switch(a)
|
|
|
|
{
|
|
|
|
case "moveforward": keyforward = false; break;
|
|
|
|
case "movebackward": keybackward = false; break;
|
|
|
|
case "moveleft": keyleft = false; break;
|
|
|
|
case "moveright": keyright = false; break;
|
|
|
|
}
|
|
|
|
}
|
2008-04-27 12:07:26 +00:00
|
|
|
*/
|
2008-01-13 21:23:59 +00:00
|
|
|
}
|
2008-01-05 18:11:29 +00:00
|
|
|
|
2008-01-13 21:23:59 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Processing
|
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
// Processing
|
2008-05-15 08:10:29 +00:00
|
|
|
public override void OnProcess()
|
2008-01-05 18:11:29 +00:00
|
|
|
{
|
2008-01-13 21:23:59 +00:00
|
|
|
Vector3D camvec;
|
|
|
|
Vector3D camvecstrafe;
|
|
|
|
|
2008-05-15 08:10:29 +00:00
|
|
|
base.OnProcess();
|
2008-01-05 18:11:29 +00:00
|
|
|
|
2008-01-13 21:23:59 +00:00
|
|
|
// Calculate camera direction vectors
|
|
|
|
camvec = Vector3D.FromAngleXYZ(camanglexy, camanglez);
|
2008-02-24 21:52:18 +00:00
|
|
|
camvecstrafe = Vector3D.FromAngleXY(camanglexy + Angle2D.PIHALF);
|
2008-01-13 21:23:59 +00:00
|
|
|
|
|
|
|
// Move the camera
|
|
|
|
if(keyforward) campos += camvec * CAMERA_SPEED;
|
|
|
|
if(keybackward) campos -= camvec * CAMERA_SPEED;
|
|
|
|
if(keyleft) campos -= camvecstrafe * CAMERA_SPEED;
|
|
|
|
if(keyright) campos += camvecstrafe * CAMERA_SPEED;
|
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
// Target the camera
|
2008-01-13 21:23:59 +00:00
|
|
|
camtarget = campos + camvec;
|
2008-01-05 18:11:29 +00:00
|
|
|
|
|
|
|
// Apply new camera matrices
|
|
|
|
renderer.PositionAndLookAt(campos, camtarget);
|
|
|
|
|
|
|
|
// Now redraw
|
|
|
|
General.Interface.RedrawDisplay();
|
|
|
|
}
|
|
|
|
|
2008-01-04 00:16:58 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|