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;
|
|
|
|
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;
|
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-12-05 15:38:50 +00:00
|
|
|
internal sealed class VisualCeiling : BaseVisualGeometrySector
|
2008-05-15 08:25:45 +00:00
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2008-11-30 20:46:39 +00:00
|
|
|
#region ================== Constructor / Setup
|
2008-05-15 08:25:45 +00:00
|
|
|
|
|
|
|
// Constructor
|
2008-12-17 10:58:57 +00:00
|
|
|
public VisualCeiling(BaseVisualMode mode, VisualSector vs) : base(mode, vs)
|
2008-11-30 20:46:39 +00:00
|
|
|
{
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This builds the geometry. Returns false when no geometry created.
|
2009-01-09 22:37:11 +00:00
|
|
|
public override bool Setup()
|
2008-05-15 08:25:45 +00:00
|
|
|
{
|
|
|
|
WorldVertex[] verts;
|
|
|
|
WorldVertex v;
|
2008-12-05 15:38:50 +00:00
|
|
|
Sector s = base.Sector.Sector;
|
2009-01-16 10:28:28 +00:00
|
|
|
byte brightness = (byte)General.Clamp(s.Brightness, 0, 255);
|
2008-12-05 15:38:50 +00:00
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
// Load floor texture
|
|
|
|
base.Texture = General.Map.Data.GetFlatImage(s.LongCeilTexture);
|
2009-01-09 22:37:11 +00:00
|
|
|
if(base.Texture == null)
|
|
|
|
{
|
|
|
|
base.Texture = General.Map.Data.MissingTexture3D;
|
|
|
|
setuponloadedtexture = s.LongCeilTexture;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!base.Texture.IsImageLoaded)
|
|
|
|
setuponloadedtexture = s.LongCeilTexture;
|
|
|
|
}
|
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
// Make vertices
|
2008-10-07 08:20:29 +00:00
|
|
|
verts = new WorldVertex[s.Triangles.Vertices.Count];
|
|
|
|
for(int i = 0; i < s.Triangles.Vertices.Count; i++)
|
2008-05-15 08:25:45 +00:00
|
|
|
{
|
|
|
|
// Use sector brightness for color shading
|
2009-01-16 10:28:28 +00:00
|
|
|
PixelColor pc = new PixelColor(255, brightness, brightness, brightness);
|
2008-10-02 11:36:25 +00:00
|
|
|
verts[i].c = pc.ToInt();
|
|
|
|
//verts[i].c = -1;
|
2008-05-15 08:25:45 +00:00
|
|
|
|
|
|
|
// Grid aligned texture coordinates
|
2008-09-28 21:20:56 +00:00
|
|
|
if(base.Texture.IsImageLoaded)
|
|
|
|
{
|
2008-10-07 05:50:39 +00:00
|
|
|
verts[i].u = s.Triangles.Vertices[i].x / base.Texture.ScaledWidth;
|
2009-01-04 13:58:26 +00:00
|
|
|
verts[i].v = -s.Triangles.Vertices[i].y / base.Texture.ScaledHeight;
|
2008-09-28 21:20:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-07 05:50:39 +00:00
|
|
|
verts[i].u = s.Triangles.Vertices[i].x / 64;
|
2009-01-04 13:58:26 +00:00
|
|
|
verts[i].v = -s.Triangles.Vertices[i].y / 64;
|
2008-09-28 21:20:56 +00:00
|
|
|
}
|
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
// Vertex coordinates
|
2008-10-07 05:50:39 +00:00
|
|
|
verts[i].x = s.Triangles.Vertices[i].x;
|
|
|
|
verts[i].y = s.Triangles.Vertices[i].y;
|
2008-05-15 08:25:45 +00:00
|
|
|
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);
|
2008-11-30 20:46:39 +00:00
|
|
|
return (verts.Length > 0);
|
2008-05-15 08:25:45 +00:00
|
|
|
}
|
2008-11-30 20:46:39 +00:00
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
2008-12-06 00:28:49 +00:00
|
|
|
|
2008-12-27 00:22:31 +00:00
|
|
|
// Paste texture
|
|
|
|
public override void OnPasteTexture()
|
|
|
|
{
|
2009-02-10 12:14:56 +00:00
|
|
|
if(BuilderPlug.Me.CopiedFlat != null)
|
2008-12-31 00:44:04 +00:00
|
|
|
{
|
2009-02-10 12:14:56 +00:00
|
|
|
General.Map.UndoRedo.CreateUndo("Paste ceiling " + BuilderPlug.Me.CopiedFlat);
|
|
|
|
SetTexture(BuilderPlug.Me.CopiedFlat);
|
2008-12-31 00:44:04 +00:00
|
|
|
this.Setup();
|
|
|
|
}
|
2008-12-27 00:22:31 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 00:28:49 +00:00
|
|
|
// This changes the height
|
2008-12-24 14:21:54 +00:00
|
|
|
protected override void ChangeHeight(int amount)
|
2008-12-06 00:28:49 +00:00
|
|
|
{
|
|
|
|
General.Map.UndoRedo.CreateUndo("Change ceiling height", UndoGroup.CeilingHeightChange, this.Sector.Sector.Index);
|
|
|
|
this.Sector.Sector.CeilHeight += amount;
|
|
|
|
}
|
2008-12-02 15:47:06 +00:00
|
|
|
|
|
|
|
// This performs a fast test in object picking
|
|
|
|
public override bool PickFastReject(Vector3D from, Vector3D to, Vector3D dir)
|
|
|
|
{
|
|
|
|
float planez = (float)Sector.Sector.CeilHeight;
|
2008-05-15 08:25:45 +00:00
|
|
|
|
2008-12-02 15:47:06 +00:00
|
|
|
// Check if line crosses the z height
|
|
|
|
if((from.z < planez) && (to.z > planez))
|
|
|
|
{
|
|
|
|
// Calculate intersection point using the z height
|
|
|
|
pickrayu = (planez - from.z) / (to.z - from.z);
|
|
|
|
pickintersect = from + (to - from) * pickrayu;
|
|
|
|
|
|
|
|
// Intersection point within bbox?
|
|
|
|
RectangleF bbox = Sector.Sector.BBox;
|
|
|
|
return ((pickintersect.x >= bbox.Left) && (pickintersect.x <= bbox.Right) &&
|
|
|
|
(pickintersect.y >= bbox.Top) && (pickintersect.y <= bbox.Bottom));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Not even crossing the z height (or not in the right direction)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This performs an accurate test for object picking
|
|
|
|
public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref float u_ray)
|
|
|
|
{
|
|
|
|
u_ray = pickrayu;
|
|
|
|
|
|
|
|
// Check on which side of the nearest sidedef we are
|
|
|
|
Sidedef sd = MapSet.NearestSidedef(Sector.Sector.Sidedefs, pickintersect);
|
|
|
|
float side = sd.Line.SideOfLine(pickintersect);
|
|
|
|
return (((side <= 0.0f) && sd.IsFront) || ((side > 0.0f) && !sd.IsFront));
|
|
|
|
}
|
2008-12-27 00:22:31 +00:00
|
|
|
|
|
|
|
// Return texture name
|
|
|
|
public override string GetTextureName()
|
|
|
|
{
|
|
|
|
return this.Sector.Sector.CeilTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This changes the texture
|
|
|
|
protected override void SetTexture(string texturename)
|
|
|
|
{
|
|
|
|
this.Sector.Sector.SetCeilTexture(texturename);
|
|
|
|
General.Map.Data.UpdateUsedTextures();
|
|
|
|
this.Setup();
|
|
|
|
}
|
2008-12-02 15:47:06 +00:00
|
|
|
|
2008-05-15 08:25:45 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|