UltimateZoneBuilder/Source/Plugins/BuilderModes/VisualModes/EffectThingVertexSlope.cs

83 lines
2.3 KiB
C#
Raw Normal View History

2010-09-14 19:14:44 +00:00
#region === Copyright (c) 2010 Pascal van der Heiden ===
using System.Collections.Generic;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Map;
#endregion
namespace CodeImp.DoomBuilder.BuilderModes
2010-09-14 19:14:44 +00:00
{
internal class EffectThingVertexSlope : SectorEffect
{
// Thing used to create this effect
// The thing is in the sector that must receive the slope and the
// Thing's arg 0 indicates the linedef to start the slope at.
private List<Thing> things;
// Floor or ceiling?
private bool slopefloor;
// Constructor
public EffectThingVertexSlope(SectorData data, List<Thing> sourcethings, bool floor) : base(data)
{
things = sourcethings;
slopefloor = floor;
// New effect added: This sector needs an update!
if(data.Mode.VisualSectorExists(data.Sector))
{
BaseVisualSector vs = (BaseVisualSector)data.Mode.GetVisualSector(data.Sector);
vs.UpdateSectorGeometry(true);
}
}
// This makes sure we are updated with the source linedef information
public override void Update()
{
// Create vertices in clockwise order
Vector3D[] verts = new Vector3D[3];
int index = 0;
foreach(Sidedef sd in data.Sector.Sidedefs)
{
Vertex v = sd.IsFront ? sd.Line.End : sd.Line.Start;
// Presume not sloped
if(slopefloor)
verts[index] = new Vector3D(v.Position.x, v.Position.y, data.Floor.plane.GetZ(v.Position));
else
verts[index] = new Vector3D(v.Position.x, v.Position.y, data.Ceiling.plane.GetZ(v.Position));
2013-03-18 13:52:27 +00:00
//mxd. UDMF vertex offset overrides this effect
if(General.Map.UDMF)
{
if((slopefloor && !float.IsNaN(v.ZFloor)) || !float.IsNaN(v.ZCeiling))
{
2013-03-18 13:52:27 +00:00
index++;
continue;
}
}
2010-09-15 09:08:40 +00:00
2010-09-14 19:14:44 +00:00
// Find the thing at this position
foreach(Thing t in things)
{
if((Vector2D)t.Position == v.Position)
2010-09-15 09:08:40 +00:00
{
ThingData td = data.Mode.GetThingData(t);
td.AddUpdateSector(data.Sector, true);
2010-09-14 19:14:44 +00:00
verts[index] = t.Position;
2010-09-15 09:08:40 +00:00
}
2010-09-14 19:14:44 +00:00
}
index++;
}
// Make new plane
if(slopefloor)
data.Floor.plane = new Plane(verts[0], verts[1], verts[2], true);
else
data.Ceiling.plane = new Plane(verts[0], verts[2], verts[1], false);
}
}
}