forked from bastelfreak/crane2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.cs
More file actions
229 lines (195 loc) · 7.6 KB
/
Copy pathGUI.cs
File metadata and controls
229 lines (195 loc) · 7.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
using DemoOpenGLBasicsCS.movements;
using System;
using System.Windows.Forms;
using System.Threading;
namespace DemoOpenGLBasicsCS
{
public partial class GUI : Form
{
private TView oglView;
private Boolean buttonDown;
private int iterations;
private double delta_angle;
private double delta_ropeposition;
private double delta_ropelenght;
private double mark_rotationangle;
private double mark_ropelength;
private double mark_ropeposition;
public GUI()
{
InitializeComponent();
oglView = new TView();
oglView.Dock = DockStyle.Fill;
panel.Controls.Add(oglView);
panel.Focus();
this.buttonDown = false; //needed for press the button and can hold it. It will be used in every button feature.
iterations = 100;
Update_positions();
}
private void Update_positions()
{
tbx_x.Text = Math.Round(oglView.Kran1.X, 3).ToString();
tbx_y.Text = Math.Round(oglView.Kran1.Y, 3).ToString();
tbx_z.Text = Math.Round(oglView.Kran1.Z, 3).ToString();
tbx_xz_movement.Text = Math.Round(oglView.Kran1.MovementfactorXZ, 3).ToString();
tbx_y_movement.Text = Math.Round(oglView.Kran1.MovementfactorY, 3).ToString();
tbx_tri_x.Text = Math.Round(Math.Cos(Math.PI * oglView.Kran1.Rotationangle / 180) * oglView.Kran1.Ropeposition, 3).ToString();
tbx_tri_y.Text = Math.Round(oglView.Kran1.Towerheight - oglView.Kran1.Ropelength, 3).ToString();
tbx_tri_z.Text = Math.Round(Math.Sin(Math.PI * oglView.Kran1.Rotationangle / 180) * oglView.Kran1.Ropeposition, 3).ToString();
tbx_alpha.Text = oglView.Kran1.Rotationangle.ToString();
tbx_rad.Text = Math.Round(oglView.Kran1.Radiant, 3).ToString();
tbx_boomlength.Text = Math.Round(oglView.Kran1.Boomlength, 3).ToString();
tbx_towerheight.Text = Math.Round(oglView.Kran1.Towerheight, 3).ToString();
tbx_ropelength.Text = Math.Round(oglView.Kran1.Ropelength, 3).ToString();
tbx_ropeposition.Text = Math.Round(oglView.Kran1.Ropeposition, 3).ToString();
}
private void Movement(interfaces.IMovement b)
{
while (buttonDown)
{
oglView.Kran1.setMovement(b);
oglView.Kran1.move();
Redraw();
Thread.Sleep(50);
Application.DoEvents();
}
}
private void Redraw()
{
oglView.Kran1.Draw();
oglView.Refresh();
oglView.Focus();
Update_positions();
}
private void btn_links_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
buttonDown = true;
Movement(new Left());
}
}
private void btn_links_MouseUp(object sender, MouseEventArgs e)
{
buttonDown = false;
}
private void btn_rechts_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
buttonDown = true;
Movement(new Right());
}
}
private void btn_rechts_MouseUp(object sender, MouseEventArgs e)
{
buttonDown = false;
}
private void btn_ausleger_vor_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
buttonDown = true;
Movement(new Forth());
}
}
private void btn_ausleger_vor_MouseUp(object sender, MouseEventArgs e)
{
buttonDown = false;
}
private void btn_ausleger_zurueck_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
buttonDown = true;
Movement(new Back());
}
}
private void btn_ausleger_zurueck_MouseUp(object sender, MouseEventArgs e)
{
buttonDown = false;
}
private void btn_seil_hoch_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
buttonDown = true;
Movement(new Up());
}
}
private void btn_seil_hoch_MouseUp(object sender, MouseEventArgs e)
{
buttonDown = false;
}
private void btn_seil_runter_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
buttonDown = true;
Movement(new Down());
}
}
private void btn_seil_runter_MouseUp(object sender, MouseEventArgs e)
{
buttonDown = false;
}
public void btn_mark_position_Click(object sender, EventArgs e)
{
// write the current vectors into our fields
tbx_mark_x.Text = tbx_tri_x.Text;
tbx_mark_y.Text = tbx_tri_y.Text;
tbx_mark_z.Text = tbx_tri_z.Text;
}
public Boolean ValidateAgainstZero (string input)
{
return input == "0" ? false : true;
}
private Boolean ValidateAgainstEmptyString (string input)
{
return input == "" ? false : true;
}
public void btn_goto_position_Click(object sender, EventArgs e)
{
Boolean nope = true;
foreach (string input in new String[] { tbx_mark_x.Text, tbx_mark_y.Text, tbx_mark_z.Text })
{
if (ValidateAgainstEmptyString(input) == false)
{
MessageBox.Show("Missing input");
}
else if (ValidateAgainstZero(input) == false)
{
MessageBox.Show("Something is 0...");
}
// todo: validate if the coordinates are withing our working area
else
{
nope = false;
}
}
// save the vector from the textboxes into vars
// we need them a few this this allows us to easier access them
if (nope == false)
{
Double x = Convert.ToDouble(tbx_mark_x.Text);
Double y = Convert.ToDouble(tbx_mark_y.Text);
Double z = Convert.ToDouble(tbx_mark_z.Text.ToString());
// calculate the current position as polar coordinates
mark_ropeposition = Math.Sqrt(Math.Pow(x, x) + Math.Pow(z, z));
mark_ropelength = oglView.Kran1.Towerheight - y;
mark_rotationangle = Math.Asin(z / mark_ropeposition);
delta_angle = ((mark_rotationangle - oglView.Kran1.Rotationangle) / iterations);
delta_ropeposition = ((mark_ropeposition - oglView.Kran1.Ropeposition) / iterations);
delta_ropelenght = ((mark_ropelength - oglView.Kran1.Ropelength) / iterations);
for (int i = 1; i <= iterations; i++)
{
oglView.Kran1.Rotationangle = oglView.Kran1.Rotationangle + delta_angle;
oglView.Kran1.Ropeposition = oglView.Kran1.Ropeposition + delta_ropeposition;
oglView.Kran1.Ropelength = oglView.Kran1.Ropelength + delta_ropelenght;
Redraw();
Thread.Sleep(50);
}
}
}
}
}