Moved slope arching code into its own class

Improved functionality
This commit is contained in:
biwa 2020-06-03 23:34:22 +02:00
parent b4e89974bd
commit aaa252bd35
4 changed files with 182 additions and 94 deletions

View file

@ -491,6 +491,8 @@
<Compile Include="VisualModes\SectorLevel.cs" />
<Compile Include="VisualModes\SectorLevelComparer.cs" />
<Compile Include="VisualModes\SectorLevelType.cs" />
<Compile Include="VisualModes\SlopeArcher.cs" />
<Compile Include="VisualModes\SlopeArchSettings.cs" />
<Compile Include="VisualModes\TexturePlane.cs" />
<Compile Include="VisualModes\ThingData.cs" />
<Compile Include="VisualModes\VertexData.cs" />

View file

@ -1,4 +1,4 @@
namespace CodeImp.DoomBuilder.BuilderModes.Interface
namespace CodeImp.DoomBuilder.BuilderModes
{
partial class SlopeArchForm
{
@ -36,6 +36,13 @@
this.accept = new System.Windows.Forms.Button();
this.up = new System.Windows.Forms.RadioButton();
this.down = new System.Windows.Forms.RadioButton();
this.scale = new CodeImp.DoomBuilder.Controls.ButtonsNumericTextbox();
this.label3 = new System.Windows.Forms.Label();
this.quartercircleleft = new System.Windows.Forms.Button();
this.quartercircleright = new System.Windows.Forms.Button();
this.halfcircle = new System.Windows.Forms.Button();
this.heightoffset = new CodeImp.DoomBuilder.Controls.ButtonsNumericTextbox();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// theta
@ -60,11 +67,12 @@
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(19, 17);
this.label1.Location = new System.Drawing.Point(61, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(31, 13);
this.label1.Size = new System.Drawing.Size(37, 13);
this.label1.TabIndex = 19;
this.label1.Text = "theta";
this.label1.Text = "Angle:";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// offset
//
@ -88,11 +96,11 @@
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(22, 47);
this.label2.Location = new System.Drawing.Point(32, 43);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(33, 13);
this.label2.Size = new System.Drawing.Size(66, 13);
this.label2.TabIndex = 21;
this.label2.Text = "offset";
this.label2.Text = "Angle offset:";
//
// cancel
//
@ -118,7 +126,7 @@
//
this.up.AutoSize = true;
this.up.Checked = true;
this.up.Location = new System.Drawing.Point(22, 96);
this.up.Location = new System.Drawing.Point(22, 131);
this.up.Name = "up";
this.up.Size = new System.Drawing.Size(39, 17);
this.up.TabIndex = 24;
@ -130,7 +138,7 @@
// down
//
this.down.AutoSize = true;
this.down.Location = new System.Drawing.Point(22, 119);
this.down.Location = new System.Drawing.Point(22, 154);
this.down.Name = "down";
this.down.Size = new System.Drawing.Size(53, 17);
this.down.TabIndex = 25;
@ -138,12 +146,105 @@
this.down.UseVisualStyleBackColor = true;
this.down.CheckedChanged += new System.EventHandler(this.UpdateArch);
//
// scale
//
this.scale.AllowDecimal = true;
this.scale.AllowExpressions = false;
this.scale.AllowNegative = false;
this.scale.AllowRelative = false;
this.scale.ButtonStep = 5;
this.scale.ButtonStepBig = 15F;
this.scale.ButtonStepFloat = 5F;
this.scale.ButtonStepSmall = 15F;
this.scale.ButtonStepsUseModifierKeys = true;
this.scale.ButtonStepsWrapAround = false;
this.scale.Location = new System.Drawing.Point(104, 67);
this.scale.Name = "scale";
this.scale.Size = new System.Drawing.Size(63, 24);
this.scale.StepValues = null;
this.scale.TabIndex = 26;
this.scale.WhenTextChanged += new System.EventHandler(this.UpdateArch);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(61, 72);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(37, 13);
this.label3.TabIndex = 27;
this.label3.Text = "Scale:";
//
// quartercircleleft
//
this.quartercircleleft.Location = new System.Drawing.Point(173, 12);
this.quartercircleleft.Name = "quartercircleleft";
this.quartercircleleft.Size = new System.Drawing.Size(113, 23);
this.quartercircleleft.TabIndex = 28;
this.quartercircleleft.Text = "Quarter circle left";
this.quartercircleleft.UseVisualStyleBackColor = true;
this.quartercircleleft.Click += new System.EventHandler(this.quartercircleleft_Click);
//
// quartercircleright
//
this.quartercircleright.Location = new System.Drawing.Point(173, 67);
this.quartercircleright.Name = "quartercircleright";
this.quartercircleright.Size = new System.Drawing.Size(113, 23);
this.quartercircleright.TabIndex = 29;
this.quartercircleright.Text = "Quarter circle right";
this.quartercircleright.UseVisualStyleBackColor = true;
this.quartercircleright.Click += new System.EventHandler(this.quartercircleright_Click);
//
// halfcircle
//
this.halfcircle.Location = new System.Drawing.Point(173, 38);
this.halfcircle.Name = "halfcircle";
this.halfcircle.Size = new System.Drawing.Size(113, 23);
this.halfcircle.TabIndex = 30;
this.halfcircle.Text = "Half circle";
this.halfcircle.UseVisualStyleBackColor = true;
this.halfcircle.Click += new System.EventHandler(this.halfcircle_Click);
//
// heightoffset
//
this.heightoffset.AllowDecimal = true;
this.heightoffset.AllowExpressions = false;
this.heightoffset.AllowNegative = true;
this.heightoffset.AllowRelative = false;
this.heightoffset.ButtonStep = 8;
this.heightoffset.ButtonStepBig = 16F;
this.heightoffset.ButtonStepFloat = 8F;
this.heightoffset.ButtonStepSmall = 16F;
this.heightoffset.ButtonStepsUseModifierKeys = true;
this.heightoffset.ButtonStepsWrapAround = false;
this.heightoffset.Location = new System.Drawing.Point(104, 97);
this.heightoffset.Name = "heightoffset";
this.heightoffset.Size = new System.Drawing.Size(63, 24);
this.heightoffset.StepValues = null;
this.heightoffset.TabIndex = 31;
this.heightoffset.WhenTextChanged += new System.EventHandler(this.UpdateArch);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(29, 102);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(70, 13);
this.label4.TabIndex = 32;
this.label4.Text = "Height offset:";
//
// SlopeArchForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancel;
this.ClientSize = new System.Drawing.Size(205, 251);
this.ClientSize = new System.Drawing.Size(298, 230);
this.Controls.Add(this.label4);
this.Controls.Add(this.heightoffset);
this.Controls.Add(this.halfcircle);
this.Controls.Add(this.quartercircleright);
this.Controls.Add(this.quartercircleleft);
this.Controls.Add(this.label3);
this.Controls.Add(this.scale);
this.Controls.Add(this.down);
this.Controls.Add(this.up);
this.Controls.Add(this.accept);
@ -158,6 +259,7 @@
this.Name = "SlopeArchForm";
this.ShowIcon = false;
this.Text = "SlopeArchForm";
this.Shown += new System.EventHandler(this.SlopeArchForm_Shown);
this.ResumeLayout(false);
this.PerformLayout();
@ -173,5 +275,12 @@
private System.Windows.Forms.Button accept;
private System.Windows.Forms.RadioButton up;
private System.Windows.Forms.RadioButton down;
private Controls.ButtonsNumericTextbox scale;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button quartercircleleft;
private System.Windows.Forms.Button quartercircleright;
private System.Windows.Forms.Button halfcircle;
private Controls.ButtonsNumericTextbox heightoffset;
private System.Windows.Forms.Label label4;
}
}

View file

@ -12,35 +12,41 @@ using CodeImp.DoomBuilder.Controls;
using CodeImp.DoomBuilder.Editing;
using CodeImp.DoomBuilder.Geometry;
namespace CodeImp.DoomBuilder.BuilderModes.Interface
namespace CodeImp.DoomBuilder.BuilderModes
{
public partial class SlopeArchForm : DelayedForm
internal partial class SlopeArchForm : DelayedForm
{
private EditMode mode;
private double originaltheta;
private double originaloffset;
private Vector2D p1;
private Vector2D p2;
private double originalscale;
private double originalheightoffset;
private SlopeArcher slopearcher;
public event EventHandler UpdateChangedObjects;
public SlopeArchForm(EditMode mode, Vector2D p1, Vector2D p2)
internal SlopeArchForm(EditMode mode, SlopeArcher slopearcher)
{
InitializeComponent();
this.mode = mode;
this.p1 = p1;
this.p2 = p2;
this.slopearcher = slopearcher;
originaltheta = 90.0;
originaloffset = 45.0;
originaltheta = Angle2D.RadToDeg(this.slopearcher.Theta);
originaloffset = Angle2D.RadToDeg(this.slopearcher.OffsetAngle);
originalscale = this.slopearcher.Scale;
originalheightoffset = this.slopearcher.HeightOffset;
theta.Text = originaltheta.ToString();
offset.Text = originaloffset.ToString();
scale.Text = (originalscale * 100.0).ToString();
heightoffset.Text = originalheightoffset.ToString();
}
private void UpdateArch(object sender, EventArgs e)
{
double t = theta.GetResultFloat(originaltheta);
double o = offset.GetResultFloat(originaloffset);
double s = scale.GetResultFloat(originalscale * 100.0) / 100.0;
if (t > 180.0)
theta.Text = "180";
@ -48,9 +54,46 @@ namespace CodeImp.DoomBuilder.BuilderModes.Interface
if (t + o > 180.0 || t + o < 0.0)
return;
double s = up.Checked ? 1.0 : -1.0;
if(!up.Checked)
s *= -1.0;
slopearcher.Theta = Angle2D.DegToRad(t);
slopearcher.OffsetAngle = Angle2D.DegToRad(o);
slopearcher.Scale = s;
slopearcher.HeightOffset = heightoffset.GetResultFloat(originalheightoffset);
slopearcher.ApplySlope();
UpdateChangedObjects?.Invoke(this, EventArgs.Empty);
}
private void SlopeArchForm_Shown(object sender, EventArgs e)
{
slopearcher.ApplySlope();
UpdateChangedObjects?.Invoke(this, EventArgs.Empty);
}
private void halfcircle_Click(object sender, EventArgs e)
{
theta.Text = "180";
offset.Text = "0";
}
private void quartercircleleft_Click(object sender, EventArgs e)
{
theta.Text = "90";
offset.Text = "90";
}
private void quartercircleright_Click(object sender, EventArgs e)
{
theta.Text = "90";
offset.Text = "0";
}
private void label1_Click(object sender, EventArgs e)
{
((BaseVisualMode)mode).DoArchBetweenHandles(p1, p2, t, o, s);
}
}
}

View file

@ -4273,9 +4273,14 @@ namespace CodeImp.DoomBuilder.BuilderModes
Vector2D p1 = handles[0].GetCenterPoint();
Vector2D p2 = handles[1].GetCenterPoint();
int baseheight = handles[0].Level.type == SectorLevelType.Ceiling ? handles[0].Sidedef.Sector.CeilHeight : handles[0].Sidedef.Sector.FloorHeight;
SlopeArchForm saf = new SlopeArchForm(this, p1, p2);
SlopeArcher sa = new SlopeArcher(this, selectedsectors, handles[0], handles[1], Angle2D.DegToRad(90.0), Angle2D.DegToRad(45.0), 1.0);
SlopeArchForm saf = new SlopeArchForm(this, sa);
saf.UpdateChangedObjects += Interface_OnUpdateChangedObjects;
DialogResult result = saf.ShowDialog();
saf.UpdateChangedObjects -= Interface_OnUpdateChangedObjects;
if (result == DialogResult.Cancel)
General.Map.UndoRedo.WithdrawUndo();
@ -4286,79 +4291,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
General.Interface.DisplayStatus(StatusType.Action, "Arched between slope handles.");
}
public void DoArchBetweenHandles(Vector2D p1, Vector2D p2, double _theta, double _offsetangle, double scale)
private void Interface_OnUpdateChangedObjects(object sender, EventArgs e)
{
List<IVisualEventReceiver> selectedsectors = GetSelectedObjects(true, false, false, false, false);
Line2D handleline = new Line2D(p1, p2);
double offsetangle = Angle2D.DegToRad(_offsetangle);
double theta = Angle2D.DegToRad(_theta);
double length = handleline.GetLength();
double right = Math.Cos(0.0);
double left = Math.Cos(theta + offsetangle);
double middle = Math.Cos(offsetangle);
double radius = length / (middle - left);
double leftdelimiter = Math.Cos(offsetangle + theta);
double rightdelimiter = Math.Cos(offsetangle);
double sectionstart = Math.Cos(offsetangle + theta) * radius;
foreach (BaseVisualGeometrySector bvgs in selectedsectors)
{
double u1 = 1.0;
double u2 = 0.0;
foreach (Sidedef sd in bvgs.Sector.Sides.Keys)
{
double intersection;
double bla;
if (!Line2D.GetIntersection(handleline.v1, handleline.v2, sd.Line.Line.v1.x, sd.Line.Line.v1.y, sd.Line.Line.v2.x, sd.Line.Line.v2.y, out bla, out intersection, false))
continue;
if (intersection < u1)
u1 = intersection;
if (intersection > u2)
u2 = intersection;
}
if (u1 == u2)
{
if(u1 >= 0.5)
{
u1 = 1.0;
}
else
{
u2 = 0.0;
}
}
double xpos1 = sectionstart + (u1 * length);
double xpos2 = sectionstart + (u2 * length);
double height1 = Math.Sqrt(radius * radius - xpos1 * xpos1) * scale;
double height2 = Math.Sqrt(radius * radius - xpos2 * xpos2) * scale;
if (double.IsNaN(height1))
height1 = 0.0;
if (double.IsNaN(height2))
height2 = 0.0;
double slopeangle = Vector2D.GetAngle(new Vector2D(xpos1, height1), new Vector2D(xpos2, height2));
Plane plane = new Plane(new Vector3D(handleline.GetCoordinatesAt(u1), height1), handleline.GetAngle() + Angle2D.PIHALF, slopeangle, true);
VisualSidedefSlope.ApplySlope(bvgs.Level, plane, this);
bvgs.Sector.UpdateSectorGeometry(true);
Debug.WriteLine(string.Format("sector: {0} | xpos1: {1}, height1: {2} | xpos2: {3}, height2: {4} | slope angle: {5}", bvgs.Sector.Sector.Index, xpos1, xpos2, height1, height2, slopeangle));
}
UpdateChangedObjects();
}