forked from 4nu81/3dlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Statix.cs
391 lines (340 loc) · 12.4 KB
/
Statix.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.OpenGl;
using System.Windows.Forms;
namespace GL3DLab
{
/// <summary>
/// Statische Objekte in der 3D umgebung, die nicht simuliert werden
/// </summary>
class Statix : BaseFigure
{
/// <summary>
/// Soll Würfelgitter gezeichnet werden?
/// </summary>
private bool paintCube = false;
/// <summary>
/// Soll solider Würfel gezeichnet werden?
/// </summary>
private bool paintCubeSolid = false;
/// <summary>
/// Soll das Koordinatensystem gezeichnet werden?
/// </summary>
private bool paintsystem = false;
/// <summary>
/// Soll die Sinuskurve gezeichnet werden?
/// </summary>
private bool paintSin = false;
/// <summary>
/// Die Gittergröße des Koordinatensystems
/// </summary>
private float GridSize = 1000f;
/// <summary>
/// Enthält die Darstellungsvektoren für das Würfelgitter
/// </summary>
private List<Vector3> m_lVectorsCube = new List<Vector3>();
/// <summary>
/// Enthält die Quadrate für den soliden Würfel
/// </summary>
private List<Square> m_lPointsCubeSolid = new List<Square>();
/// <summary>
/// Enthält die Eckpunkte für den Würfel
/// </summary>
private List<Point3> m_lPointsCube = new List<Point3>();
#region Internal Statix Methodes
/// <summary>
/// Zeichenmethode für das Koordinatensystem
/// </summary>
/// <param name="GridSize">Gittergröße für das Koordinatensystem</param>
private void DrawSystem(float GridSize)
{
//System zeichnen
Point3 cpx1 = new Point3(GridSize, 0, 0);
Point3 cpx2 = new Point3(-1 * GridSize, 0, 0);
Point3 cpy1 = new Point3(0, GridSize, 0);
Point3 cpy2 = new Point3(0, -1 * GridSize, 0);
Point3 cpz1 = new Point3(0, 0, GridSize);
Point3 cpz2 = new Point3(0, 0, -1 * GridSize);
float fak = 1;
float i = 0;
float delta = 10;
Gl.glPointSize(1f);
Gl.glDisable(Gl.GL_LIGHTING);
Gl.glBegin(Gl.GL_LINES);
{
i = 0;
while (!(i > GridSize))
{
Gl.glColor3f(0.6f + fak * 0.3f, 0.6f + fak * 0.3f, 1f);
Gl.glVertex3f(i, 0, 0);
Gl.glVertex3f(i + delta, 0, 0);
Gl.glColor3f(0.6f - fak * 0.3f, 0.6f - fak * 0.3f, 1f);
Gl.glVertex3f(-i, 0, 0);
Gl.glVertex3f(-(i + delta), 0, 0);
i += delta;
fak *= -1;
}
}
Gl.glEnd();
Gl.glBegin(Gl.GL_LINES);
{
i = 0;
while (!(i > GridSize))
{
Gl.glColor3f(1f, 0.6f + fak * 0.3f, 0.6f + fak * 0.3f);
Gl.glVertex3f(0, i, 0);
Gl.glVertex3f(0, i + delta, 0);
Gl.glColor3f(1f, 0.6f - fak * 0.3f, 0.6f - fak * 0.3f);
Gl.glVertex3f(0, -i, 0);
Gl.glVertex3f(0, -(i + delta), 0);
i += delta;
fak *= -1;
}
}
Gl.glEnd();
Gl.glBegin(Gl.GL_LINES);
{
i = 0;
while (!(i > GridSize))
{
Gl.glColor3f(0.6f + fak * 0.3f, 1f, 0.6f + fak * 0.3f);
Gl.glVertex3f(0, 0, i);
Gl.glVertex3f(0, 0, i + delta);
Gl.glColor3f(0.6f - fak * 0.3f, 1f, 0.6f - fak * 0.3f);
Gl.glVertex3f(0, 0, -i);
Gl.glVertex3f(0, 0, -(i + delta));
i += delta;
fak *= -1;
}
}
Gl.glEnd();
Gl.glEnable(Gl.GL_LIGHTING);
}
/// <summary>
/// Zeichenmethode für das Würfelgitter
/// </summary>
/// <param name="Linewidth">Linienstärke der Gitterlinien</param>
private void DrawCube(float Linewidth)
{
//Würfel zeichnen
Gl.glLineWidth(Linewidth);
foreach (Vector3 p in m_lVectorsCube)
{
Gl.glBegin(Gl.GL_LINES);
{
Gl.glColor3f(1f, 1f, 1f);
Gl.glVertex3f(p.a.x, p.a.y, p.a.z);
Gl.glVertex3f(p.b.x, p.b.y, p.b.z);
}
}
Gl.glEnd();
}
/// <summary>
/// Zeichenmethode für den soliden Würfel
/// </summary>
private void DrawCubeSolid()
{
Gl.glMatrixMode(Gl.GL_TEXTURE_MATRIX);
for (int i = 0; i < m_lPointsCubeSolid.Count; i++)
{
Square p = m_lPointsCubeSolid.ElementAt(i);
Gl.glColor3f(0.3f, 0.2f, 0.6f);
Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_FILL);
Gl.glMateriali(Gl.GL_FRONT_AND_BACK, Gl.GL_SHININESS, 60);
Gl.glBegin(Gl.GL_QUADS);
{
Gl.glTexCoord3f(p.a.x, p.a.y, p.a.z); Gl.glVertex3f(p.a.x, p.a.y, p.a.z);
Gl.glTexCoord3f(p.a.x, p.a.y, p.a.z); Gl.glVertex3f(p.b.x, p.b.y, p.b.z);
Gl.glTexCoord3f(p.a.x, p.a.y, p.a.z); Gl.glVertex3f(p.c.x, p.c.y, p.c.z);
Gl.glTexCoord3f(p.a.x, p.a.y, p.a.z); Gl.glVertex3f(p.d.x, p.d.y, p.d.z);
}
Gl.glPopMatrix();
Gl.glEnd();
}
Gl.glMatrixMode(Gl.GL_MODELVIEW_MATRIX);
}
/// <summary>
/// Zeichenmethode für die Sinuskurve
/// </summary>
private void DrawSinus()
{
float delta = 0.2f;
float sy = 100;
Gl.glBegin(Gl.GL_LINES);
{
Gl.glColor3f(0.5f, 1f, 0.5f);
for (float i = -100; i <= 100; i += delta)
{
Gl.glVertex3f(i, sy + -delta, (float)(Math.Sin(i) * Math.Pow(i, 2)));
Gl.glVertex3f(i + delta, sy + -delta, (float)(Math.Sin(i + delta) * Math.Pow(i + delta, 2)));
}
}
Gl.glEnd();
Gl.glColor3f(1f, 1f, 1f);
Gl.glBegin(Gl.GL_QUADS);
{
Gl.glVertex3f(0, 0, 0);
Gl.glVertex3f(0, 1, 0);
Gl.glVertex3f(0, 1, 1);
Gl.glVertex3f(0, 0, 1);
}
Gl.glEnd();
Gl.glBegin(Gl.GL_LINES);
{
Gl.glVertex3f(0, 0.5f, 1);
Gl.glVertex3f(0, 0.5f, 3);
Gl.glVertex3f(0, -0.5f, 2);
Gl.glVertex3f(0, 1.5f, 2);
Gl.glVertex3f(0, 0.5f, 3);
Gl.glVertex3f(0, -0.5f, 5);
Gl.glVertex3f(0, 0.5f, 3);
Gl.glVertex3f(0, 1.5f, 5);
}
Gl.glEnd();
}
/// <summary>
/// Initialisierung für das Würfelgitter
/// </summary>
private void initCube()
{
float delta = 100f;
Point3 a = new Point3(-delta, -delta, -delta);
Point3 b = new Point3(delta, delta, -delta);
Point3 c = new Point3(delta, -delta, -delta);
Point3 d = new Point3(delta, -delta, delta);
Point3 f = new Point3(-delta, -delta, delta);
Point3 g = new Point3(-delta, delta, delta);
Point3 h = new Point3(-delta, delta, -delta);
Point3 k = new Point3(delta, delta, delta);
m_lPointsCube.Add(a);
m_lPointsCube.Add(b);
m_lPointsCube.Add(c);
m_lPointsCube.Add(d);
m_lPointsCube.Add(f);
m_lPointsCube.Add(g);
m_lPointsCube.Add(h);
m_lPointsCube.Add(k);
m_lVectorsCube.Add(new Vector3(k, g));
m_lVectorsCube.Add(new Vector3(k, d));
m_lVectorsCube.Add(new Vector3(k, b));
m_lVectorsCube.Add(new Vector3(a, c));
m_lVectorsCube.Add(new Vector3(a, f));
m_lVectorsCube.Add(new Vector3(a, h));
m_lVectorsCube.Add(new Vector3(c, b));
m_lVectorsCube.Add(new Vector3(c, d));
m_lVectorsCube.Add(new Vector3(f, g));
m_lVectorsCube.Add(new Vector3(f, d));
m_lVectorsCube.Add(new Vector3(h, g));
m_lVectorsCube.Add(new Vector3(c, d));
m_lVectorsCube.Add(new Vector3(h, b));
}
/// <summary>
/// Initialisierungsmethode für den soliden Würfel
/// </summary>
private void initCubeSolid()
{
Point3 a = new Point3(-50f, -50f, -50f);
Point3 b = new Point3(50f, 50f, -50f);
Point3 c = new Point3(50f, -50f, -50f);
Point3 d = new Point3(50f, -50f, 50f);
Point3 f = new Point3(-50f, -50f, 50f);
Point3 g = new Point3(-50f, 50f, 50f);
Point3 h = new Point3(-50f, 50f, -50f);
Point3 k = new Point3(50f, 50f, 50f);
m_lPointsCubeSolid.Clear();
m_lPointsCubeSolid.Add(new Square(a, c, b, h));
m_lPointsCubeSolid.Add(new Square(a, h, g, f));
m_lPointsCubeSolid.Add(new Square(g, f, d, k));
m_lPointsCubeSolid.Add(new Square(k, d, c, b));
m_lPointsCubeSolid.Add(new Square(h, b, k, g));
m_lPointsCubeSolid.Add(new Square(a, c, d, f));
}
#endregion
#region BaseFigures & IFigures
/// <summary>
/// Interne Zeichenfunktion spricht die einzelnen Zeichenfunktionen der Klasse an
/// </summary>
protected override void InternalDraw()
{
if (paintCube)
{
DrawCube(StaticVars.Linewidth);
}
if (paintCubeSolid)
{
DrawCubeSolid();
}
if (paintSin)
{
DrawSinus();
}
if (paintsystem)
{
DrawSystem(GridSize);
}
}
/// <summary>
/// Interne Tickfunktion ist bei den statischen Sachen nicht nötig
/// </summary>
protected override void InternalTick()
{
// nicht nötig
}
/// <summary>
/// Initialisierung für die Würfel
/// </summary>
public override void Init()
{
initCube();
initCubeSolid();
}
/// <summary>
/// Tastendruck auswerten
/// </summary>
/// <param name="e"></param>
public override void KeyPressed(System.Windows.Forms.KeyEventArgs e)
{
//C Gitter Cube zeichnen
if (e.KeyCode == Keys.C)
{
paintCube = !paintCube;
}
//G System malen
if (e.KeyCode == Keys.G)
{
paintsystem = !paintsystem;
}
//0 Dec Gridsize
if (e.KeyCode == Keys.D0)
{
if (GridSize > 1000)
{
GridSize -= 1000f;
}
}
//9 Inc Gridsize
if ((e.KeyCode == Keys.D9))
{
if (GridSize < 500000)
{
GridSize += 1000f;
}
}
//R Paint Sinus
if (e.KeyCode == Keys.R)
{
paintSin = !paintSin;
}
Visible = paintsystem || paintSin || paintCubeSolid || paintCube;
}
/// <summary>
/// bei Programmende aufgerufen
/// </summary>
public override void OnShutdown()
{
}
#endregion
}
}