From e962a49f839558374428b3c329d43ae3818856f4 Mon Sep 17 00:00:00 2001 From: codeimp Date: Thu, 15 May 2008 08:25:45 +0000 Subject: [PATCH] what?! these files were not in the svn?! --- .../VisualModes/BaseVisualMode.cs | 269 ++++++++++++++++++ .../VisualModes/BaseVisualSector.cs | 109 +++++++ Source/BuilderModes/VisualModes/Clipper.cs | 269 ++++++++++++++++++ .../BuilderModes/VisualModes/VisualCeiling.cs | 111 ++++++++ .../BuilderModes/VisualModes/VisualFloor.cs | 98 +++++++ .../BuilderModes/VisualModes/VisualLower.cs | 125 ++++++++ .../BuilderModes/VisualModes/VisualMiddle.cs | 140 +++++++++ .../BuilderModes/VisualModes/VisualUpper.cs | 125 ++++++++ 8 files changed, 1246 insertions(+) create mode 100644 Source/BuilderModes/VisualModes/BaseVisualMode.cs create mode 100644 Source/BuilderModes/VisualModes/BaseVisualSector.cs create mode 100644 Source/BuilderModes/VisualModes/Clipper.cs create mode 100644 Source/BuilderModes/VisualModes/VisualCeiling.cs create mode 100644 Source/BuilderModes/VisualModes/VisualFloor.cs create mode 100644 Source/BuilderModes/VisualModes/VisualLower.cs create mode 100644 Source/BuilderModes/VisualModes/VisualMiddle.cs create mode 100644 Source/BuilderModes/VisualModes/VisualUpper.cs diff --git a/Source/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/BuilderModes/VisualModes/BaseVisualMode.cs new file mode 100644 index 00000000..d1e7f1dc --- /dev/null +++ b/Source/BuilderModes/VisualModes/BaseVisualMode.cs @@ -0,0 +1,269 @@ + +#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.Geometry; +using CodeImp.DoomBuilder.Editing; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes.Editing +{ + [EditMode(SwitchAction = "visualmode", // Action name used to switch to this mode + ButtonDesc = "Visual Mode", // Description on the button in toolbar/menu + ButtonImage = "VisualMode.png", // Image resource name for the button + ButtonOrder = 0)] // Position of the button (lower is more to the left) + + public class BaseVisualMode : VisualMode + { + #region ================== Constants + + #endregion + + #region ================== Variables + + // All constructed visual sectors + private Dictionary allsectors; + + // List of visible sectors + private Dictionary visiblesectors; + + // Visual view range ^ 2 + private float visualviewrange2; + + #endregion + + #region ================== Properties + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public BaseVisualMode() + { + // Initialize + allsectors = new Dictionary(General.Map.Map.Sectors.Count); + visiblesectors = new Dictionary(); + visualviewrange2 = General.Settings.VisualViewRange * General.Settings.VisualViewRange; + + // We have no destructor + GC.SuppressFinalize(this); + } + + // Disposer + public override void Dispose() + { + // Not already disposed? + if(!isdisposed) + { + // Clean up + foreach(KeyValuePair s in allsectors) s.Value.Dispose(); + visiblesectors = null; + allsectors = null; + + // Done + base.Dispose(); + } + } + + #endregion + + #region ================== Private Tools + + // This finds the nearest sector to the camera + private Sector FindStartSector(Vector2D campos) + { + float side; + Linedef l; + + // Get nearest linedef + l = General.Map.Map.NearestLinedef(campos); + if(l != null) + { + // Check if we are on front or back side + side = l.SideOfLine(campos); + if(side > 0) + { + // Is there a sidedef here? + if(l.Back != null) + return l.Back.Sector; + else if(l.Front != null) + return l.Front.Sector; + else + return null; + } + else + { + // Is there a sidedef here? + if(l.Front != null) + return l.Front.Sector; + else if(l.Back != null) + return l.Back.Sector; + else + return null; + } + } + else + return null; + } + + // This recursively finds and adds visible sectors + private void ProcessVisibleSectors(Sector start, Vector2D campos, Clipper clipper) + { + BaseVisualSector vs; + Clipper newclip; + Sector os; + float side; + + // Find the basesector and make it if needed + if(allsectors.ContainsKey(start)) + { + // Take existing visualsector + vs = allsectors[start]; + } + else + { + // Make new visualsector + vs = new BaseVisualSector(start); + allsectors.Add(start, vs); + } + + // Add sector to visibility list + visiblesectors.Add(start, vs); + + // Go for all sidedefs in the sector + foreach(Sidedef sd in start.Sidedefs) + { + // Camera on the front of this side? + side = sd.Line.SideOfLine(campos); + if(((side > 0) && sd.IsFront) || + ((side < 0) && !sd.IsFront)) + { + // Sidedef blocking the view? + if((sd.Other == null) || + (sd.Other.Sector.FloorHeight >= (sd.Sector.CeilHeight - 0.0001f)) || + (sd.Other.Sector.CeilHeight <= (sd.Sector.FloorHeight + 0.0001f)) || + (sd.Other.Sector.FloorHeight >= (sd.Other.Sector.CeilHeight - 0.0001f))) + { + // This blocks the view + //clipper.InsertRange(sd.Line.Start.Position, sd.Line.End.Position); + } + } + } + + // Go for all sidedefs in the sector + foreach(Sidedef sd in start.Sidedefs) + { + // Doublesided and not referring to same sector? + if((sd.Other != null) && (sd.Other.Sector != sd.Sector)) + { + // Get the other sector + os = sd.Other.Sector; + + // Sector not yet added? + if(!visiblesectors.ContainsKey(os)) + { + // Within view range? + if(sd.Line.DistanceToSq(campos, true) < visualviewrange2) + { + // Check if the sector can be seen + //if(clipper.TestRange(sd.Line.Start.Position, sd.Line.End.Position)) + { + // Make a copy of the visibility clipper + newclip = new Clipper(clipper); + + // Process this sector as well + ProcessVisibleSectors(os, campos, newclip); + + // Done with this clipper + newclip.Dispose(); + } + } + } + } + } + } + + #endregion + + #region ================== Methods + + // This draws a frame + public override void OnRedrawDisplay() + { + // Start drawing + if(renderer.Start()) + { + // Begin with geometry + renderer.StartGeometry(); + + // Render all visible sectors + foreach(KeyValuePair vs in visiblesectors) + renderer.RenderGeometry(vs.Value); + + // Done rendering geometry + renderer.FinishGeometry(); + + // Present! + renderer.Finish(); + } + + // Call base + base.OnRedrawDisplay(); + } + + // This processes a frame + public override void OnProcess() + { + Vector2D campos; + Clipper clipper; + + // Process base class first + base.OnProcess(); + + // Get the 2D camera position + campos = new Vector2D(base.CameraPosition.x, base.CameraPosition.y); + + // Make visibility clipper + clipper = new Clipper((Vector2D)base.CameraPosition); + + // Make new visibility list + visiblesectors = new Dictionary(General.Map.Map.Sectors.Count); + + // Process all visible sectors starting with the nearest + ProcessVisibleSectors(FindStartSector(campos), campos, clipper); + + // Clean up + clipper.Dispose(); + } + + #endregion + } +} diff --git a/Source/BuilderModes/VisualModes/BaseVisualSector.cs b/Source/BuilderModes/VisualModes/BaseVisualSector.cs new file mode 100644 index 00000000..f3176382 --- /dev/null +++ b/Source/BuilderModes/VisualModes/BaseVisualSector.cs @@ -0,0 +1,109 @@ + +#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.Geometry; +using CodeImp.DoomBuilder.Editing; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes.Editing +{ + internal class BaseVisualSector : VisualSector + { + #region ================== Constants + + #endregion + + #region ================== Variables + + #endregion + + #region ================== Properties + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public BaseVisualSector(Sector s) : base(s) + { + // Initialize + Rebuild(); + + // We have no destructor + GC.SuppressFinalize(this); + } + + // Disposer + public override void Dispose() + { + // Not already disposed? + if(!IsDisposed) + { + // Clean up + + // Dispose base + base.Dispose(); + } + } + + #endregion + + #region ================== Methods + + // This (re)builds the visual sector, calculating all geometry from scratch + public void Rebuild() + { + // Forget old geometry + base.ClearGeometry(); + + // Make the floor and ceiling + base.AddGeometry(new VisualFloor(base.Sector)); + base.AddGeometry(new VisualCeiling(base.Sector)); + + // Go for all sidedefs + foreach(Sidedef sd in base.Sector.Sidedefs) + { + // Make middle wall + base.AddGeometry(new VisualMiddle(sd)); + + // Check if upper and lower parts are possible at all + if(sd.Other != null) + { + // Make upper and lower walls + base.AddGeometry(new VisualLower(sd)); + base.AddGeometry(new VisualUpper(sd)); + } + } + } + + #endregion + } +} diff --git a/Source/BuilderModes/VisualModes/Clipper.cs b/Source/BuilderModes/VisualModes/Clipper.cs new file mode 100644 index 00000000..f075578c --- /dev/null +++ b/Source/BuilderModes/VisualModes/Clipper.cs @@ -0,0 +1,269 @@ + +#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.Geometry; +using CodeImp.DoomBuilder.Editing; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes +{ + internal class Clipper + { + #region ================== Constants + + private const float MULTIPLIER = 10000f; + private const int MAXRANGE = (int)(Angle2D.PI2 * MULTIPLIER); + private const int HALFRANGE = (int)(Angle2D.PI * MULTIPLIER); + private const int MINRANGE = 0; + + #endregion + + #region ================== ClipRange struct + + // ClipRange structure + private struct ClipRange + { + // Variables + public int low; + public int high; + + // Constructor + public ClipRange(int low, int high) + { + this.low = low; + this.high = high; + } + } + + #endregion + + #region ================== Variables + + // Position where we are viewing from + private Vector2D position; + + // Clipping ranges + private LinkedList ranges; + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public Clipper(Vector2D pos) + { + // Initialize + this.position = pos; + this.ranges = new LinkedList(); + } + + // Constructor + public Clipper(Clipper copy) + { + // Initialize + this.position = copy.position; + this.ranges = new LinkedList(copy.ranges); + } + + // Disposer + public void Dispose() + { + this.ranges.Clear(); + } + + #endregion + + #region ================== Testing methods + + // This tests a range to see if it is at least partially visible + public bool TestRange(Vector2D a, Vector2D b) + { + int i1, i2, c1, c2, m; + float a1, a2; + + // Get angles + a1 = Angle2D.Normalized(Vector2D.GetAngle(position, a)); + a2 = Angle2D.Normalized(Vector2D.GetAngle(position, b)); + + // Convert angles to ranges + i1 = (int)(a1 * MULTIPLIER); + i2 = (int)(a2 * MULTIPLIER); + c1 = Math.Min(i1, i2); + c2 = Math.Max(i1, i2); + + // Determine rotation direction + m = c2 - c1; + if(m < MINRANGE) m += MAXRANGE; + if(m < HALFRANGE) + { + // Check if the range goes through zero point + if(c2 < c1) + { + // Test two ranges + return RangeVisible(new ClipRange(c1, MAXRANGE)) || + RangeVisible(new ClipRange(MINRANGE, c2)); + } + else + { + // Test a single range + return RangeVisible(new ClipRange(c1, c2)); + } + } + else + { + // Check if the range goes through zero point + if(c2 > c1) + { + // Test two ranges + return RangeVisible(new ClipRange(MINRANGE, c1)) || + RangeVisible(new ClipRange(c2, MAXRANGE)); + } + else + { + // Test a single range + return RangeVisible(new ClipRange(c2, c1)); + } + } + } + + // This tests a single range for visibility + private bool RangeVisible(ClipRange r) + { + // Go for all clipped ranges + foreach(ClipRange c in ranges) + { + // Does clipped range completely hide the given range? + if((c.low <= r.low) && (c.high >= r.high)) + { + // No further testing needed, range is clipped + return false; + } + } + + // Not completely clipped + return true; + } + + #endregion + + #region ================== Clipping methods + + // This tests a range to see if it is at least partially visible + public bool InsertRange(Vector2D a, Vector2D b) + { + int i1, i2, c1, c2, m; + float a1, a2; + + // Get angles + a1 = Angle2D.Normalized(Vector2D.GetAngle(position, a)); + a2 = Angle2D.Normalized(Vector2D.GetAngle(position, b)); + + // Convert angles to ranges + i1 = (int)(a1 * MULTIPLIER); + i2 = (int)(a2 * MULTIPLIER); + c1 = Math.Min(i1, i2); + c2 = Math.Max(i1, i2); + + // Determine rotation direction + m = c2 - c1; + if(m < MINRANGE) m += MAXRANGE; + if(m < HALFRANGE) + { + // Check if the range goes through zero point + if(c2 < c1) + { + // Add two ranges + return AddRange(new ClipRange(c1, MAXRANGE)) || + AddRange(new ClipRange(MINRANGE, c2)); + } + else + { + // Add a single range + return AddRange(new ClipRange(c1, c2)); + } + } + else + { + // Check if the range goes through zero point + if(c2 > c1) + { + // Add two ranges + return AddRange(new ClipRange(MINRANGE, c1)) || + AddRange(new ClipRange(c2, MAXRANGE)); + } + else + { + // Add a single range + return AddRange(new ClipRange(c2, c1)); + } + } + } + + // This tests a single range for visibility + // Returns true when the entire range has been clipped + private bool AddRange(ClipRange r) + { + LinkedListNode current, next; + ClipRange c; + + // Go for all ranges to find overlappings + current = ranges.First; + while(current != null) + { + // Keep reference to the next + next = current.Next; + c = current.Value; + + // Check if ranges overlap + if((c.low <= (r.high + 1)) && (c.high >= (r.low - 1))) + { + // Remove old range from list + ranges.Remove(current); + + // Extend range with overlapping range + if(c.low < r.low) r.low = c.low; + if(c.high > r.high) r.high = c.high; + } + + // Move to the next + current = next; + } + + // Insert the new range + ranges.AddLast(r); + + // Return true when entire range is now clipped + return (r.low == MINRANGE) && (r.high == MAXRANGE); + } + + #endregion + } +} diff --git a/Source/BuilderModes/VisualModes/VisualCeiling.cs b/Source/BuilderModes/VisualModes/VisualCeiling.cs new file mode 100644 index 00000000..08764e28 --- /dev/null +++ b/Source/BuilderModes/VisualModes/VisualCeiling.cs @@ -0,0 +1,111 @@ + +#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 System.Drawing; +using System.ComponentModel; +using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Geometry; +using System.Drawing.Imaging; +using CodeImp.DoomBuilder.Data; +using CodeImp.DoomBuilder.Editing; +using CodeImp.DoomBuilder.IO; +using CodeImp.DoomBuilder.Rendering; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes.Editing +{ + internal class VisualCeiling : VisualGeometry + { + #region ================== Constants + + #endregion + + #region ================== Variables + + #endregion + + #region ================== Properties + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public VisualCeiling(Sector s) + { + WorldVertex[] verts; + WorldVertex v; + + // Load floor texture + base.Texture = General.Map.Data.GetFlatImage(s.LongCeilTexture); + base.Texture.LoadImage(); + + // Make vertices + verts = new WorldVertex[s.Triangles.Count]; + for(int i = 0; i < s.Triangles.Count; i++) + { + // Use sector brightness for color shading + //pc = new PixelColor(255, unchecked((byte)s.Brightness), unchecked((byte)s.Brightness), unchecked((byte)s.Brightness)); + //verts[i].c = pc.ToInt(); + verts[i].c = -1; + + // Grid aligned texture coordinates + verts[i].u = s.Triangles[i].x / base.Texture.ScaledWidth; + verts[i].v = s.Triangles[i].y / base.Texture.ScaledHeight; + + // Vertex coordinates + verts[i].x = s.Triangles[i].x; + verts[i].y = s.Triangles[i].y; + verts[i].z = (float)s.CeilHeight; + } + + // The sector triangulation created clockwise triangles that + // are right up for the floor. For the ceiling we must flip + // the triangles upside down. + // Swap some vertices to flip all triangles + for(int i = 0; i < verts.Length; i += 3) + { + // Swap + v = verts[i]; + verts[i] = verts[i + 1]; + verts[i + 1] = v; + } + + // Apply vertices + base.SetVertices(verts); + + // We have no destructor + GC.SuppressFinalize(this); + } + + #endregion + + #region ================== Methods + + #endregion + } +} diff --git a/Source/BuilderModes/VisualModes/VisualFloor.cs b/Source/BuilderModes/VisualModes/VisualFloor.cs new file mode 100644 index 00000000..2ea27ffc --- /dev/null +++ b/Source/BuilderModes/VisualModes/VisualFloor.cs @@ -0,0 +1,98 @@ + +#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 System.Drawing; +using System.ComponentModel; +using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Geometry; +using System.Drawing.Imaging; +using CodeImp.DoomBuilder.Data; +using CodeImp.DoomBuilder.Editing; +using CodeImp.DoomBuilder.IO; +using CodeImp.DoomBuilder.Rendering; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes.Editing +{ + internal class VisualFloor : VisualGeometry + { + #region ================== Constants + + #endregion + + #region ================== Variables + + #endregion + + #region ================== Properties + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public VisualFloor(Sector s) + { + WorldVertex[] verts; + + // Load floor texture + base.Texture = General.Map.Data.GetFlatImage(s.LongFloorTexture); + base.Texture.LoadImage(); + + // Make vertices + verts = new WorldVertex[s.Triangles.Count]; + for(int i = 0; i < s.Triangles.Count; i++) + { + // Use sector brightness for color shading + //pc = new PixelColor(255, unchecked((byte)s.Brightness), unchecked((byte)s.Brightness), unchecked((byte)s.Brightness)); + //verts[i].c = pc.ToInt(); + verts[i].c = -1; + + // Grid aligned texture coordinates + verts[i].u = s.Triangles[i].x / base.Texture.ScaledWidth; + verts[i].v = s.Triangles[i].y / base.Texture.ScaledHeight; + + // Vertex coordinates + verts[i].x = s.Triangles[i].x; + verts[i].y = s.Triangles[i].y; + verts[i].z = (float)s.FloorHeight; + } + + // Apply vertices + base.SetVertices(verts); + + // We have no destructor + GC.SuppressFinalize(this); + } + + #endregion + + #region ================== Methods + + #endregion + } +} diff --git a/Source/BuilderModes/VisualModes/VisualLower.cs b/Source/BuilderModes/VisualModes/VisualLower.cs new file mode 100644 index 00000000..88fdb3de --- /dev/null +++ b/Source/BuilderModes/VisualModes/VisualLower.cs @@ -0,0 +1,125 @@ + +#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 System.Drawing; +using System.ComponentModel; +using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Geometry; +using System.Drawing.Imaging; +using CodeImp.DoomBuilder.Data; +using CodeImp.DoomBuilder.Editing; +using CodeImp.DoomBuilder.IO; +using CodeImp.DoomBuilder.Rendering; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes.Editing +{ + internal class VisualLower : VisualGeometry + { + #region ================== Constants + + #endregion + + #region ================== Variables + + #endregion + + #region ================== Properties + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public VisualLower(Sidedef s) + { + WorldVertex[] verts; + float geotop; + float geobottom; + float geoheight; + Vector2D v1, v2; + + // Calculate size of this wall part + geotop = (float)s.Other.Sector.FloorHeight; + geobottom = (float)s.Sector.FloorHeight; + geoheight = geotop - geobottom; + if(geoheight > 0.001f) + { + // Texture given? + if((s.LowTexture.Length > 0) && (s.LowTexture[0] != '-')) + { + // Load texture + base.Texture = General.Map.Data.GetTextureImage(s.LongLowTexture); + base.Texture.LoadImage(); + } + else + { + // Use missing texture + base.Texture = General.Map.Data.MissingTexture3D; + } + + // Get coordinates + if(s.IsFront) + { + v1 = s.Line.Start.Position; + v2 = s.Line.End.Position; + } + else + { + v1 = s.Line.End.Position; + v2 = s.Line.Start.Position; + } + + // Make vertices + verts = new WorldVertex[6]; + verts[0] = new WorldVertex(v1.x, v1.y, geobottom, -1, 0.0f, 1.0f); + verts[1] = new WorldVertex(v1.x, v1.y, geotop, -1, 0.0f, 0.0f); + verts[2] = new WorldVertex(v2.x, v2.y, geotop, -1, 1.0f, 0.0f); + verts[3] = verts[0]; + verts[4] = verts[2]; + verts[5] = new WorldVertex(v2.x, v2.y, geobottom, -1, 1.0f, 1.0f); + } + else + { + // No geometry for invisible wall + verts = new WorldVertex[0]; + } + + // Apply vertices + base.SetVertices(verts); + + // We have no destructor + GC.SuppressFinalize(this); + } + + #endregion + + #region ================== Methods + + #endregion + } +} diff --git a/Source/BuilderModes/VisualModes/VisualMiddle.cs b/Source/BuilderModes/VisualModes/VisualMiddle.cs new file mode 100644 index 00000000..e56879b3 --- /dev/null +++ b/Source/BuilderModes/VisualModes/VisualMiddle.cs @@ -0,0 +1,140 @@ + +#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 System.Drawing; +using System.ComponentModel; +using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Geometry; +using System.Drawing.Imaging; +using CodeImp.DoomBuilder.Data; +using CodeImp.DoomBuilder.Editing; +using CodeImp.DoomBuilder.IO; +using CodeImp.DoomBuilder.Rendering; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes.Editing +{ + internal class VisualMiddle : VisualGeometry + { + #region ================== Constants + + #endregion + + #region ================== Variables + + #endregion + + #region ================== Properties + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public VisualMiddle(Sidedef s) + { + WorldVertex[] verts; + float geotop; + float geobottom; + float geoheight; + bool texturegiven; + bool texturerequired; + Vector2D v1, v2; + + // Calculate size of this wall part + geotop = (float)s.Sector.CeilHeight; + geobottom = (float)s.Sector.FloorHeight; + geoheight = geotop - geobottom; + if(geoheight > 0.001f) + { + // Check texture status + texturegiven = ((s.MiddleTexture.Length > 0) && (s.MiddleTexture[0] != '-')); + texturerequired = s.MiddleRequired(); + + // Only create wall when middle texture is set or the wall requires a texture + if(texturegiven || texturerequired) + { + // Texture given? + if(texturegiven) + { + // Load texture + base.Texture = General.Map.Data.GetTextureImage(s.LongMiddleTexture); + base.Texture.LoadImage(); + } + else + { + // Use missing texture + base.Texture = General.Map.Data.MissingTexture3D; + } + + // Get coordinates + if(s.IsFront) + { + v1 = s.Line.Start.Position; + v2 = s.Line.End.Position; + } + else + { + v1 = s.Line.End.Position; + v2 = s.Line.Start.Position; + } + + // Make vertices + verts = new WorldVertex[6]; + verts[0] = new WorldVertex(v1.x, v1.y, geobottom, -1, 0.0f, 1.0f); + verts[1] = new WorldVertex(v1.x, v1.y, geotop, -1, 0.0f, 0.0f); + verts[2] = new WorldVertex(v2.x, v2.y, geotop, -1, 1.0f, 0.0f); + verts[3] = verts[0]; + verts[4] = verts[2]; + verts[5] = new WorldVertex(v2.x, v2.y, geobottom, -1, 1.0f, 1.0f); + } + else + { + // No geometry for invisible wall + verts = new WorldVertex[0]; + } + } + else + { + // No geometry for invisible wall + verts = new WorldVertex[0]; + } + + // Apply vertices + base.SetVertices(verts); + + // We have no destructor + GC.SuppressFinalize(this); + } + + #endregion + + #region ================== Methods + + #endregion + } +} diff --git a/Source/BuilderModes/VisualModes/VisualUpper.cs b/Source/BuilderModes/VisualModes/VisualUpper.cs new file mode 100644 index 00000000..9483e978 --- /dev/null +++ b/Source/BuilderModes/VisualModes/VisualUpper.cs @@ -0,0 +1,125 @@ + +#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 System.Drawing; +using System.ComponentModel; +using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Geometry; +using System.Drawing.Imaging; +using CodeImp.DoomBuilder.Data; +using CodeImp.DoomBuilder.Editing; +using CodeImp.DoomBuilder.IO; +using CodeImp.DoomBuilder.Rendering; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes.Editing +{ + internal class VisualUpper : VisualGeometry + { + #region ================== Constants + + #endregion + + #region ================== Variables + + #endregion + + #region ================== Properties + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public VisualUpper(Sidedef s) + { + WorldVertex[] verts; + float geotop; + float geobottom; + float geoheight; + Vector2D v1, v2; + + // Calculate size of this wall part + geotop = (float)s.Sector.CeilHeight; + geobottom = (float)s.Other.Sector.CeilHeight; + geoheight = geotop - geobottom; + if(geoheight > 0.001f) + { + // Texture given? + if((s.HighTexture.Length > 0) && (s.HighTexture[0] != '-')) + { + // Load texture + base.Texture = General.Map.Data.GetTextureImage(s.LongHighTexture); + base.Texture.LoadImage(); + } + else + { + // Use missing texture + base.Texture = General.Map.Data.MissingTexture3D; + } + + // Get coordinates + if(s.IsFront) + { + v1 = s.Line.Start.Position; + v2 = s.Line.End.Position; + } + else + { + v1 = s.Line.End.Position; + v2 = s.Line.Start.Position; + } + + // Make vertices + verts = new WorldVertex[6]; + verts[0] = new WorldVertex(v1.x, v1.y, geobottom, -1, 0.0f, 1.0f); + verts[1] = new WorldVertex(v1.x, v1.y, geotop, -1, 0.0f, 0.0f); + verts[2] = new WorldVertex(v2.x, v2.y, geotop, -1, 1.0f, 0.0f); + verts[3] = verts[0]; + verts[4] = verts[2]; + verts[5] = new WorldVertex(v2.x, v2.y, geobottom, -1, 1.0f, 1.0f); + } + else + { + // No geometry for invisible wall + verts = new WorldVertex[0]; + } + + // Apply vertices + base.SetVertices(verts); + + // We have no destructor + GC.SuppressFinalize(this); + } + + #endregion + + #region ================== Methods + + #endregion + } +}