-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPunktfeld.cs
514 lines (433 loc) · 16.4 KB
/
Punktfeld.cs
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.OpenGl;
using System.Windows.Forms;
namespace GL3DLab
{
class ParticleField : BaseFigure
{
private Object lockobj = new Object();
private bool draw = true;
private float DotSize = 1f;
private bool f1 = false;
private bool f2 = false;
private bool f3 = false;
private bool f4 = false;
private bool f5 = false;
private bool f6 = false;
List<Point3> points = new List<Point3>();
/// <summary>
/// Liste enthält alle Punkte des Partikelfeldes.
/// </summary>
public List<Point3> m_lPointField = new List<Point3>();
/// <summary>
/// Zufallsgenerator
/// </summary>
private Random r = new Random();
/// <summary>
/// Höhe des höchsten Punktes (in Z-Richtung)
/// </summary>
private float zmax = 1;
/// <summary>
/// Höhe des tiefsten Punktes (in Z-Richtung)
/// </summary>
private float zmin = -1;
/// <summary>
/// Kantenlänge der dargestellten Würfel und Flächen
/// </summary>
public float delta = 0.5f;
/// <summary>
/// Initialisierungsmuster der Punkte
/// </summary>
initForms forms = initForms.flat;
/// <summary>
/// Bewegungsgeschwindigkeit der Partikel
/// </summary>
int speed = 100;
/// <summary>
/// Bewegungsmuster der Partikel
/// </summary>
ParticleForms form;
/// <summary>
/// Sollen Ausbreitung der Punkte verringert werden?
/// </summary>
bool shrink;
/// <summary>
/// Sollen Punkte rückwärts laufen?
/// </summary>
bool reverse = false;
/// <summary>
/// Form der Punkte
/// </summary>
DotStyle Dots;
/// <summary>
/// Interne Zeichenfunktion
/// </summary>
protected override void InternalDraw()
{
lock(lockobj){
if (draw)
{
foreach (Point3 p in points) // ToArray sorgt für Threadsicherheit des Enummerators
{
float red;
float green;
float blue;
float alpha;
//if (form == ParticleForms.universe)
//{
// float du = (float)Math.Sqrt(Math.Pow(p.x, 2) + Math.Pow(p.y, 2));
// red = (float)Math.Sqrt(1f / (4f * du / 20f + 1f));
// green = (float)Math.Sqrt(1f / (Math.Pow(du / 20f, 3f) + 1f));
// blue = (float)Math.Sqrt(1f / (Math.Pow(2f * du / 20f, 2f) + 1f));
// alpha = 0f;
//}
//else
//{
float cole = (zmax - p.z) / (zmax - zmin);
red = 1 - cole;
green = cole;
blue = 0f;
alpha = 1f;
//}
switch (Dots)
{
//case DotStyle.Rounds:
// #region Spheres
// {
// float X = p.x;
// float Y = p.y;
// float Z = p.z;
// float r = delta;
// Gl.glPushMatrix();
// Gl.glTranslatef(X, Y, Z);
// Glu.GLUquadric obj = Glu.gluNewQuadric();
// Glu.gluSphere(obj, r, 5, 5);
// Gl.glColor3f(red, green, blue);
// Gl.glPopMatrix();
// break;
// #endregion
// }
case DotStyle.Point:
#region Point
{
// schon scheen
Gl.glBegin(Gl.GL_POINTS);
Gl.glVertex3f(p.x, p.y, p.z);
Gl.glColor3f(red, green, blue);
Gl.glEnd();
break;
#endregion
}
case DotStyle.Vertects:
#region 3Flächen
{
// scheener.
Gl.glNormal3f(1f, 0f, 0f);
Gl.glBegin(Gl.GL_QUADS);
Gl.glVertex3f(p.x, p.y - delta, p.z - delta);
Gl.glVertex3f(p.x, p.y - delta, p.z + delta);
Gl.glVertex3f(p.x, p.y + delta, p.z + delta);
Gl.glVertex3f(p.x, p.y + delta, p.z - delta);
Gl.glEnd();
Gl.glNormal3f(0f, 1f, 0f);
Gl.glColor4f(red + 0.01f, green + 0.01f, blue + 0.01f, alpha);
Gl.glBegin(Gl.GL_QUADS);
Gl.glVertex3f(p.x + delta, p.y, p.z + delta);
Gl.glVertex3f(p.x - delta, p.y, p.z + delta);
Gl.glVertex3f(p.x - delta, p.y, p.z - delta);
Gl.glVertex3f(p.x + delta, p.y, p.z - delta);
Gl.glEnd();
Gl.glNormal3f(0f, 0f, 1f);
Gl.glColor4f(red + 0.02f, green + 0.02f, blue + 0.02f, alpha);
Gl.glBegin(Gl.GL_QUADS);
Gl.glVertex3f(p.x + delta, p.y + delta, p.z);
Gl.glVertex3f(p.x + delta, p.y - delta, p.z);
Gl.glVertex3f(p.x - delta, p.y - delta, p.z);
Gl.glVertex3f(p.x - delta, p.y + delta, p.z);
Gl.glEnd();
break;
#endregion
}
case DotStyle.Cubes:
#region Würfel
{
// für Dolle schön und so.
Gl.glColor4f(red + 0.1f, green + 0.1f, blue + 0.1f, alpha);
Gl.glBegin(Gl.GL_POLYGON);
Gl.glNormal3f(0f, 0f, 1f);
Gl.glVertex3f(p.x + delta, p.y + delta, p.z + delta);
Gl.glVertex3f(p.x + delta, p.y - delta, p.z + delta);
Gl.glVertex3f(p.x - delta, p.y - delta, p.z + delta);
Gl.glVertex3f(p.x - delta, p.y + delta, p.z + delta);
Gl.glEnd();
Gl.glColor4f(red - 0.1f, green - 0.1f, blue - 0.1f, alpha);
Gl.glBegin(Gl.GL_POLYGON);
Gl.glNormal3f(1f, 0f, 0f);
Gl.glVertex3f(p.x + delta, p.y + delta, p.z + delta);
Gl.glVertex3f(p.x + delta, p.y - delta, p.z + delta);
Gl.glVertex3f(p.x + delta, p.y - delta, p.z - delta);
Gl.glVertex3f(p.x + delta, p.y + delta, p.z - delta);
Gl.glEnd();
Gl.glColor4f(red + 0.1f, green + 0.1f, blue + 0.1f, alpha);
Gl.glBegin(Gl.GL_POLYGON);
Gl.glNormal3f(0f, 0f, -1f);
Gl.glVertex3f(p.x + delta, p.y + delta, p.z - delta);
Gl.glVertex3f(p.x + delta, p.y - delta, p.z - delta);
Gl.glVertex3f(p.x - delta, p.y - delta, p.z - delta);
Gl.glVertex3f(p.x - delta, p.y + delta, p.z - delta);
Gl.glEnd();
Gl.glColor4f(red - 0.1f, green - 0.1f, blue - 0.1f, alpha);
Gl.glBegin(Gl.GL_POLYGON);
Gl.glNormal3f(-1f, 0f, 0f);
Gl.glVertex3f(p.x - delta, p.y - delta, p.z - delta);
Gl.glVertex3f(p.x - delta, p.y - delta, p.z + delta);
Gl.glVertex3f(p.x - delta, p.y + delta, p.z + delta);
Gl.glVertex3f(p.x - delta, p.y + delta, p.z - delta);
Gl.glEnd();
Gl.glColor4f(red, green, blue, alpha);
Gl.glBegin(Gl.GL_POLYGON);
Gl.glNormal3f(0f, 1f, 0f);
Gl.glVertex3f(p.x + delta, p.y + delta, p.z + delta);
Gl.glVertex3f(p.x - delta, p.y + delta, p.z + delta);
Gl.glVertex3f(p.x - delta, p.y + delta, p.z - delta);
Gl.glVertex3f(p.x + delta, p.y + delta, p.z - delta);
Gl.glEnd();
Gl.glColor4f(red, green, blue, alpha);
Gl.glBegin(Gl.GL_POLYGON);
Gl.glNormal3f(0f, -1f, 0f);
Gl.glVertex3f(p.x - delta, p.y - delta, p.z + delta);
Gl.glVertex3f(p.x - delta, p.y - delta, p.z - delta);
Gl.glVertex3f(p.x + delta, p.y - delta, p.z - delta);
Gl.glVertex3f(p.x + delta, p.y - delta, p.z + delta);
Gl.glEnd();
break;
#endregion
}
}
}
}
}
}
/// <summary>
/// Interner Threadtick für die Simulation der Punkte
/// </summary>
protected override void InternalTick()
{
lock (lockobj)
{
if (draw)
{
if (f1)
{
Funktion1();
}
if (f2)
{
Funktion2();
}
if (f3)
{
Funktion3();
}
if (f4)
{
Funktion4();
}
if (f5)
{
Funktion5();
}
if (f6)
{
Funktion6();
}
}
}
}
/// <summary>
/// Initialisierung der Punktmenge
/// </summary>
public override void Init()
{
InitPoints();
Cam.X = 0;
Cam.Y = 0;
Cam.Z = 200;
}
/// <summary>
/// Wird bei Tastendruck ausgelöst
/// </summary>
/// <param name="e"></param>
public override void KeyPressed(KeyEventArgs e)
{
//M swich Dotmode
if (e.KeyCode == Keys.M)
{ Dots = (DotStyle)(((int)Dots + 1) % 3); } // % 4 für Kugeln aber sehr langsam
//F7 Pointfield grow on/off
if (e.KeyCode == Keys.F7)
{ reverse = !reverse; }
//F8 shrink/grow Punktfeld
if (e.KeyCode == Keys.F8)
{ shrink = !shrink; }
//F9 Simulationsart switch
if (e.KeyCode == Keys.F9)
{ form = (ParticleForms)(((int)form + 1) % 4); }
if (e.KeyCode == Keys.D1)
{ f1 = !f1; }
if (e.KeyCode == Keys.D2)
{ f2 = !f2; }
if (e.KeyCode == Keys.D3)
{ f3 = !f3; }
if (e.KeyCode == Keys.D4)
{ f4 = !f4; }
if (e.KeyCode == Keys.D5)
{ f5 = !f5; }
if (e.KeyCode == Keys.D6)
{ f6 = !f6; }
//L Pointfield Flat
if (e.KeyCode == Keys.L)
{
forms = initForms.flat;
InitPoints();
}
//B Pointfield Würfel
if (e.KeyCode == Keys.B)
{
forms = initForms.cube;
InitPoints();
}
////U Pointfields Universe
//if (e.KeyCode == Keys.U)
//{
// forms = initForms.universe;
// InitPoints();
//}
}
/// <summary>
/// Wird beim Beenden des Programmes aufgerufen
/// </summary>
public override void OnShutdown()
{
}
private void Funktion1()
{
zmin = 1;
zmax = 1;
foreach (Point3 item in points)
{
item.x = (float)(item.x + Math.Sin(item.z * 0.01) - Math.Sin(item.y * 0.01));
item.y = (float)(item.y + Math.Sin(item.x * 0.01) - Math.Sin(item.z * 0.01));
item.z = (float)(item.z + Math.Sin(item.y * 0.01) - Math.Sin(item.x * 0.01));
if (item.z > zmax) { zmax = item.z; }
if (item.z < zmin) { zmin = item.z; }
}
}
private void Funktion2()
{
zmin = 1;
zmax = 1;
foreach (Point3 item in points)
{
item.x = (float)(item.x + 5 * Math.Cos(0.02 * item.y));
item.y = (float)(item.y + 5 * Math.Cos(0.02 * item.x));
item.z = (float)(item.z + 0.2 * (Math.Cos(0.025 * item.y)));
if (item.z > zmax) { zmax = item.z; }
if (item.z < zmin) { zmin = item.z; }
}
}
private void Funktion3()
{
zmin = 1;
zmax = 1;
foreach (Point3 item in points)
{
item.x = (float)(item.x + Math.Sin(item.z * 0.01) - Math.Tan(item.y * 0.01));
item.y = (float)(item.y + Math.Sin(item.x * 0.01) - Math.Tan(item.z * 0.01));
item.z = (float)(item.z + Math.Sin(item.y * 0.01) - Math.Tan(item.x * 0.01));
if (item.z > zmax) { zmax = item.z; }
if (item.z < zmin) { zmin = item.z; }
}
}
private void Funktion4()
{
zmin = 1;
zmax = 1;
foreach (Point3 item in points)
{
float x = item.x;
float y = item.y;
float z = item.z;
item.x = (float)(x + Math.Cos(z * 0.01) - Math.Cos(y * 0.01));
item.y = (float)(y + Math.Cos(x * 0.01) - Math.Cos(z * 0.01));
item.z = (float)(z + Math.Cos(y * 0.01) - Math.Cos(x * 0.01));
if (item.z > zmax) { zmax = item.z; }
if (item.z < zmin) { zmin = item.z; }
}
}
private void Funktion5()
{
zmin = 1;
zmax = 1;
foreach (Point3 item in points)
{
float x = item.x;
float y = item.y;
float z = item.z;
item.x = (float)(x + Math.Tan(z * 0.01) - Math.Tan(y * 0.01));
item.y = (float)(y + Math.Tan(x * 0.01) - Math.Tan(z * 0.01));
item.z = (float)(z + Math.Tan(y * 0.01) - Math.Tan(x * 0.01));
if (item.z > zmax) { zmax = item.z; }
if (item.z < zmin) { zmin = item.z; }
}
}
private void Funktion6()
{
zmin = 1;
zmax = 1;
foreach (Point3 item in points)
{
item.x = (float)(item.x + Math.Tan(item.z * 0.01) - Math.Cos(item.y * 0.01));
//item.y = (float)(item.y + Math.Sin(item.x * 0.01) - Math.Sin(item.z * 0.01));
item.z = (float)(item.z + Math.Cos(item.y * 0.01) - Math.Tan(item.x * 0.01));
if (item.z > zmax) { zmax = item.z; }
if (item.z < zmin) { zmin = item.z; }
}
}
private void InitPoints()
{
lock (lockobj)
{
draw = false;
System.Threading.Thread.Sleep(10);
points.Clear();
if (forms == initForms.flat)
{
for (int x = -150; x < 150; x++)
{
for (int y = -150; y < 150; y++)
{
points.Add(new Point3(x, y, 0));
}
}
}
if (forms == initForms.cube)
{
for (int x = -50; x < 50; x++)
{
for (int y = -50; y < 50; y++)
{
for (int z = -10; z < 10; z++)
{
points.Add(new Point3(x, y, z));
}
}
}
}
draw = true;
}
}
}
}