2009-04-19 18:07:22 +00:00
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.VisualModes
|
|
|
|
{
|
2009-05-21 08:18:34 +00:00
|
|
|
/// <summary>
|
|
|
|
/// This class provides the camera in Visual Mode
|
|
|
|
/// </summary>
|
2009-04-19 18:07:22 +00:00
|
|
|
public class VisualCamera
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
2020-05-18 16:14:54 +00:00
|
|
|
private const double ANGLE_FROM_MOUSE = 0.0001f;
|
|
|
|
public const double MAX_ANGLEZ_LOW = 91f / Angle2D.PIDEG;
|
|
|
|
public const double MAX_ANGLEZ_HIGH = (360f - 91f) / Angle2D.PIDEG;
|
|
|
|
public const double THING_Z_OFFSET = 41.0f;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
private Vector3D position;
|
|
|
|
private Vector3D target;
|
|
|
|
private Vector3D movemultiplier;
|
2020-05-18 16:14:54 +00:00
|
|
|
private double anglexy, anglez;
|
2009-04-19 18:07:22 +00:00
|
|
|
private Sector sector;
|
2020-05-22 19:39:18 +00:00
|
|
|
private double gravity = 1.0; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public Vector3D Position { get { return position; } set { position = value; } }
|
|
|
|
public Vector3D Target { get { return target; } }
|
2020-05-18 16:14:54 +00:00
|
|
|
public double AngleXY { get { return anglexy; } set { anglexy = value; } }
|
|
|
|
public double AngleZ { get { return anglez; } set { anglez = value; } }
|
2014-12-03 23:15:26 +00:00
|
|
|
public Sector Sector { get { return sector; } internal set { sector = value; UpdateGravity(); } } //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
public Vector3D MoveMultiplier { get { return movemultiplier; } set { movemultiplier = value; } }
|
2020-05-22 19:39:18 +00:00
|
|
|
public double Gravity { get { return gravity; } } //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Destructor
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public VisualCamera()
|
|
|
|
{
|
|
|
|
// Initialize
|
2013-08-02 12:50:53 +00:00
|
|
|
movemultiplier = new Vector3D(1.0f, 1.0f, 1.0f);
|
|
|
|
anglexy = 0.0f;
|
|
|
|
anglez = Angle2D.PI;
|
|
|
|
sector = null;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
PositionAtThing();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// Mouse input
|
|
|
|
internal void ProcessMouseInput(Vector2D delta)
|
|
|
|
{
|
|
|
|
// Change camera angles with the mouse changes
|
|
|
|
anglexy -= delta.x * ANGLE_FROM_MOUSE;
|
|
|
|
if(General.Settings.InvertYAxis)
|
|
|
|
anglez -= delta.y * ANGLE_FROM_MOUSE;
|
|
|
|
else
|
|
|
|
anglez += delta.y * ANGLE_FROM_MOUSE;
|
|
|
|
|
|
|
|
// Normalize angles
|
|
|
|
anglexy = Angle2D.Normalized(anglexy);
|
|
|
|
anglez = Angle2D.Normalized(anglez);
|
|
|
|
|
|
|
|
// Limit vertical angle
|
|
|
|
if(anglez < MAX_ANGLEZ_LOW) anglez = MAX_ANGLEZ_LOW;
|
|
|
|
if(anglez > MAX_ANGLEZ_HIGH) anglez = MAX_ANGLEZ_HIGH;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Key input
|
|
|
|
internal void ProcessMovement(Vector3D deltavec)
|
|
|
|
{
|
|
|
|
// Calculate camera direction vectors
|
|
|
|
Vector3D camvec = Vector3D.FromAngleXYZ(anglexy, anglez);
|
|
|
|
|
|
|
|
// Position the camera
|
|
|
|
position += deltavec;
|
|
|
|
|
|
|
|
// Target the camera
|
|
|
|
target = position + camvec;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This applies the position and angle from the 3D Camera Thing
|
|
|
|
// Returns false when it couldn't find a 3D Camera Thing
|
|
|
|
public virtual bool PositionAtThing()
|
|
|
|
{
|
2015-10-09 21:57:32 +00:00
|
|
|
if(General.Settings.GZSynchCameras) return true; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
Thing modething = null;
|
2015-10-09 21:57:32 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Find a 3D Mode thing
|
|
|
|
foreach(Thing t in General.Map.Map.Things)
|
2015-10-09 21:57:32 +00:00
|
|
|
{
|
|
|
|
if(t.Type == General.Map.Config.Start3DModeThingType)
|
|
|
|
{
|
|
|
|
modething = t;
|
|
|
|
break; //mxd
|
|
|
|
}
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Found one?
|
|
|
|
if(modething != null)
|
|
|
|
{
|
|
|
|
modething.DetermineSector();
|
2020-05-18 16:14:54 +00:00
|
|
|
double z = modething.Position.z;
|
2015-10-26 19:58:38 +00:00
|
|
|
if(modething.Sector != null) z += modething.Sector.FloorHeight;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Position camera here
|
|
|
|
Vector3D wantedposition = new Vector3D(modething.Position.x, modething.Position.y, z + THING_Z_OFFSET);
|
2015-10-09 21:57:32 +00:00
|
|
|
Vector3D delta = position - wantedposition;
|
2009-04-19 18:07:22 +00:00
|
|
|
if(delta.GetLength() > 1.0f) position = wantedposition;
|
2020-05-18 16:14:54 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Change angle
|
2020-05-18 16:14:54 +00:00
|
|
|
double wantedanglexy = modething.Angle + Angle2D.PI;
|
2009-04-19 18:07:22 +00:00
|
|
|
if(anglexy != wantedanglexy)
|
|
|
|
{
|
|
|
|
anglexy = wantedanglexy;
|
|
|
|
anglez = Angle2D.PI;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 09:26:13 +00:00
|
|
|
|
|
|
|
return false;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This applies the camera position and angle to the 3D Camera Thing
|
|
|
|
// Returns false when it couldn't find a 3D Camera Thing
|
|
|
|
public virtual bool ApplyToThing()
|
|
|
|
{
|
2015-10-09 21:57:32 +00:00
|
|
|
if(General.Settings.GZSynchCameras) return true; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
Thing modething = null;
|
|
|
|
|
|
|
|
// Find a 3D Mode thing
|
|
|
|
foreach(Thing t in General.Map.Map.Things)
|
2015-10-09 21:57:32 +00:00
|
|
|
{
|
|
|
|
if(t.Type == General.Map.Config.Start3DModeThingType)
|
|
|
|
{
|
|
|
|
modething = t;
|
|
|
|
break; //mxd
|
|
|
|
}
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Found one?
|
|
|
|
if(modething != null)
|
|
|
|
{
|
2015-10-26 19:58:38 +00:00
|
|
|
int z = (int)position.z; //mxd
|
|
|
|
if(sector != null) z -= sector.FloorHeight;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Position the thing to match camera
|
|
|
|
modething.Move((int)position.x, (int)position.y, z - THING_Z_OFFSET);
|
|
|
|
modething.Rotate(anglexy - Angle2D.PI);
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 09:26:13 +00:00
|
|
|
|
|
|
|
return false;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2013-08-02 12:50:53 +00:00
|
|
|
|
|
|
|
//mxd
|
2014-12-03 23:15:26 +00:00
|
|
|
private void UpdateGravity()
|
|
|
|
{
|
2015-10-09 21:57:32 +00:00
|
|
|
if(!General.Map.UDMF || sector == null) return;
|
2020-05-22 19:39:18 +00:00
|
|
|
gravity = sector.Fields.GetValue("gravity", 1.0);
|
2013-08-02 12:50:53 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|