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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
| #pragma once
#include "man.h"
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
using namespace System::Windows::Forms;
namespace OpenGLForm
{
public ref class COpenGL: public System::Windows::Forms::NativeWindow
{
public:
COpenGL(System::Windows::Forms::Panel ^ parentForm, GLsizei iWidth, GLsizei iHeight)
{
CreateParams^ cp = gcnew CreateParams;
// Set the position on the form
cp->X = 0;
cp->Y = 0;
cp->Height = iHeight;
cp->Width = iWidth;
// Specify the form as the parent.
cp->Parent = parentForm->Handle;
// Create as a child of the specified parent and make OpenGL compliant (no clipping)
cp->Style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
// Create the actual window
this->CreateHandle(cp);
m_hDC = GetDC((HWND)this->Handle.ToPointer());
if(m_hDC)
{
MySetPixelFormat(m_hDC);
ReSizeGLScene(iWidth, iHeight);
InitGL();
}
rtri = 0.0f;
rquad = 0.0f;
m=0.4;
}
void renderBitmapString(float x ,float y, char *LPCSTR )
{
glColor4f(1.0,1.0,1.0,1.0);
glRasterPos2i(x,y);
glDisable(GL_TEXTURE);
glDisable(GL_TEXTURE_2D);
for(int i=0,len = strlen(LPCSTR);i<len;i++)
{
glutBitmapCharacter(GLUT_BITMAP_9_BY_15,(int)LPCSTR[i]);
}
glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE);
}
System::Void Render(System::Void)
{
initStars();
while(1)
{
/* while( PeekMessage(&msg,NULL,0,0,PM_NOREMOVE) )
if(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
return 0;*/
display();
date(0);
model(0);
//glutReshapeFunc(resize);
// keyboard();
} // Decrease the rotation variable for the quad
}
void display(void)
{
float b;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(TranslatefX, TranslatefY, -100.0); //ПЕРЕМЕЩЕНИЕ
glScalef(m,m,5); //МАСШТАБ
glClearColor(0, 0, 0, 0);
glPointSize(0.001);
glColor4f(0.5,0.5,0.5,0.5);
if(c==1)
{
renderBitmapString(-550,580," do n.e.");
}
if (d<10 && w<10)
{
j = sprintf( ch, "Date:0%d.0%d.%d", d,w,o );
}
if (d<10 && w>9 )
{
j = sprintf( ch, "Date:0%d.%d.%d", d,w,o );
}
if (d>9 && w<10) //этот код отвечает за вывод даты и формат 01.01.2013 без него пишется так 1.1.2012
{
j = sprintf( ch, "Date:%d.0%d.%d", d,w,o);
}
if (d>9 && w>9)
{
j = sprintf( ch, "Date:%d.%d.%d", d,w,o);
}
renderBitmapString(-550,580,ch);
for(int i=0;i<100;i++)
{ //ПЛОТНОСТЬ ЗВЁЗД.ИХ КОЛЛИЧЕСТВО
for(int j=0;j<100;j++)
{
glBegin(GL_POINTS);
glVertex2i(-stars[i][j],-stars[i+1][j+1]);
glEnd();
glBegin(GL_POINTS);
glVertex2i(stars[i+2][j+2],-stars[i+1][j+1]);
glEnd(); //ЗВЁЗДЫ. РИСУЮТСЯ ПО ЧЕТВЕРТЯМ
glBegin(GL_POINTS);
glVertex2i(-stars[i+3][j+3],stars[i+2][j+1]);
glEnd();
glBegin(GL_POINTS);
glVertex2i(stars[i+2][j+5],stars[i+3][j+1]);
glEnd();
}
}
glBegin(GL_LINES);
for(int i=0;i<4900;i++)
{
glColor3f(1,0.6,0);
glVertex2f(0,0);
glColor3f(0,0,0);
glVertex2f(0+cos(i/3.14)*(180),0+sin(i/3.14)*(180));
}
glEnd(); //SOLNCE
glColor3f((0.9),(0.35),(0.1));
glBegin(GL_TRIANGLE_FAN);
glVertex2i(0,0);
for(int i=0; i<=51; i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2f(0+cos(b)*(75.0),0+sin(b)*(73.0));
glColor3f(1,(0.6),0);
}
glEnd();
/*
mercuriy
*/
glColor3f(0.3,0.3,0.3);
glBegin(GL_POINTS);
for(int i=0;i<10000;i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2i(90*cos(b),0+sin(b)*80);
}
glEnd();
glBegin(GL_LINES);
for(int i=0; i<500; i++)
{
glColor3f(0.3,0.3,0.3);
glVertex2f(0+cos(i/3.14)*5+sin((-merc_speed*3.14)/180)*90,0+sin(i/3.14)*5+cos((-merc_speed*3.14)/180)*80);
glColor3f(1.0,1.0,1.0);
glVertex2f(0+sin((-merc_speed*3.14)/180)*90,0+cos((-merc_speed*3.14)/180)*80);
}
glEnd();
glBegin(GL_LINES);
for(int i=0; i<500; i++)
{
glColor3f(1.0,1.0,1.0);
glVertex2f(0+cos(i/3.14)*10+sin((-merc_speed*3.14)/180)*90,0+sin(i/3.14)*10+cos((-merc_speed*3.14)/180)*80);
}
glEnd();
glBegin(GL_LINES);
for(int i=0; i<500; i++)
{
glColor3f(1.0,1.0,1.0);
glVertex2f(0+cos(i/3.14)*11+sin((-merc_speed*3.14)/180)*90,0+sin(i/3.14)*11+cos((-merc_speed*3.14)/180)*80);
}
glEnd();
/*
glColor4f(0.3,0.5,0.6,1);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0+sin((-merc_speed*3.14)/180)*90,0+cos((-merc_speed*3.14)/180)*100);
for(int i=0; i<=51; i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2f(0+cos(b)*4+sin((-merc_speed*3.14)/180)*90,0+sin(b)*4+cos((-merc_speed*3.14)/180)*100);
}
glEnd();
*/
/*
venera
*/
glColor3f(0.3,0.3,0.3);
glBegin(GL_POINTS);
for(int i=0;i<10000;i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2i(0+sin(b)*140,0+cos(b)*130); //ОРБИТА С РАДИУСОМ 160 ПО X И 140 ПО Y
//РАДИУС ПЛАНЕТЫ ВЫЧИСЛЯЕТСЯ АНАЛОГИЧНЫМ ОБРАЗОМ
}
glEnd();
glColor4f(0.7,0.3,0,1);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0+sin((-venera_speed*3.14)/180)*140,0+cos((-venera_speed*3.14)/180)*130);
for(int i=0; i<=51; i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2f(0+cos(b)*7+sin((-venera_speed*3.14)/180)*140,0+sin(b)*7+cos((-venera_speed*3.14)/180)*130);
}
glEnd();
/*
zemlya
*/
glColor3f(0.3,0.3,0.3);
glBegin(GL_POINTS);
for(int i=0;i<10000;i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2i(0+cos(b)*190,0+sin(b)*180);
}
glEnd();
glBegin(GL_LINES);
for(int i=0; i<500; i++)
{
glColor3f(255, 228, 196);
glVertex2f(0+sin((-earth_speed*3.14)/180)*190,0+cos((-earth_speed*3.14)/180)*180);
glColor3f(0,0,0);
glVertex2f(0+cos(i/3.14)*13+sin((-earth_speed*3.14)/180)*190,0+sin(i/3.14)*13+cos((-earth_speed*3.14)/180)*180);
}
glEnd();
glColor4f(0.3,0.5,0.6,1);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0+sin((-earth_speed*3.14)/180)*190,0+cos((-earth_speed*3.14)/180)*180);
for(int i=0; i<=51; i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2f(0+cos(b)*5+sin((-earth_speed*3.14)/180)*190,0+sin(b)*5+cos((-earth_speed*3.14)/180)*180);
}
glEnd();
/*mars*/
glColor3f(0.3,0.3,0.3);
glBegin(GL_POINTS);
for(int i=0;i<10000;i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2i(0+cos(b)*230,0+sin(b)*220);
}
glEnd();
glBegin(GL_LINES);
for(int i=0; i<=500; i++)
{
glColor3f(0.4,0.8,0.1);
glVertex2f(0+sin((-mars_speed*3.14)/180)*230,0+cos((-mars_speed*3.14)/180)*220);
glColor3f(0,0,0);
glVertex2f(0+cos(i/3.14)*15+sin((-mars_speed*3.14)/180)*230,0+sin(i/3.14)*15+cos((-mars_speed*3.14)/180)*220);
}
glEnd();
glColor4f(0.8,0.3,0.1,1);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0+sin((-mars_speed*3.14)/180)*230,0+cos((-mars_speed*3.14)/180)*220);
for(int i=0; i<=51; i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2f(0+cos(b)*8+sin((-mars_speed*3.14)/180)*230,0+sin(b)*8+cos((-mars_speed*3.14)/180)*220);
}
glEnd();
/*jupiter*/
glColor3f(0.3,0.3,0.3);
glBegin(GL_POINTS);
for(int i=0;i<10000;i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2i(0+cos(b)*360,0+sin(b)*350);
}
glEnd();
glBegin(GL_LINES);
for(int i=0; i<=500; i++)
{
glColor3f(0.3,0.3,0.3);
glVertex2f(0+sin((-jupiter_speed*3.14)/180)*360,0+cos((-jupiter_speed*3.14)/180)*350);
glColor3f(0,0,0);
glVertex2f(0+cos(i/3.14)*20+sin((-jupiter_speed*3.14)/180)*360,0+sin(i/3.14)*20+cos((-jupiter_speed*3.14)/180)*350);
}
glEnd();
glColor4f(0.3,0.3,0.3,1);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0+sin((-jupiter_speed*3.14)/180)*360,0+cos((-jupiter_speed*3.14)/180)*350);
for(int i=0; i<=51; i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2f(0+cos(i/3.14)*20+sin((-jupiter_speed*3.14)/180)*360,0+sin(i/3.14)*20+cos((-jupiter_speed*3.14)/180)*350);
}
glEnd();
/*saturn*/
glColor3f(0.3,0.3,0.3);
glBegin(GL_POINTS);
for(int i=0;i<10000;i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2i(0+cos(b)*510,0+sin(b)*500);
}
glEnd();
glBegin(GL_LINES);
for(int i=0; i<=500; i++)
{
glColor3f(0.4,0.4,0.6);
glVertex2f(0+sin((-saturn_speed*3.14)/180)*510,0+cos((-saturn_speed*3.14)/180)*500);
glColor3f(0,0,0);
glVertex2f(0+cos(i/3.14)*20+sin((-saturn_speed*3.14)/180)*510,0+sin(i/3.14)*20+cos((-saturn_speed*3.14)/180)*500);
}
glEnd();
glColor4f(0.4,0.4,0.6,1);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0+sin((-saturn_speed*3.14)/180)*510,0+cos((-saturn_speed*3.14)/180)*500);
for(int i=0; i<=51; i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2f(0+cos(i/3.14)*20+sin((-saturn_speed*3.14)/180)*510,0+sin(i/3.14)*20+cos((-saturn_speed*3.14)/180)*500);
}
glEnd();
/*uranus*/
glColor3f(0.3,0.3,0.3);
glBegin(GL_POINTS);
for(int i=0;i<10000;i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2i(0+cos(b)*660,0+sin(b)*650);
}
glEnd();
glBegin(GL_LINES);
for(int i=0; i<=500; i++)
{
glColor3f(0.4,0.4,0.6);
glVertex2f(0+sin((-uran_speed*3.14)/180)*660,0+cos((-uran_speed*3.14)/180)*650);
glColor3f(0,0,0);
glVertex2f(0+cos(i/3.14)*20+sin((-uran_speed*3.14)/180)*660,0+sin(i/3.14)*20+cos((-uran_speed*3.14)/180)*650);
}
glEnd();
glColor4f(0.3,0.3,0.3,1);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0+sin((-uran_speed*3.14)/180)*660,0+cos((-uran_speed*3.14)/180)*650);
for(int i=0; i<=51; i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2f(0+cos(i/3.14)*20+sin((-uran_speed*3.14)/180)*660,0+sin(i/3.14)*20+cos((-uran_speed*3.14)/180)*650);
}
glEnd();
/*neptune*/
glColor3f(0.3,0.3,0.3);
glBegin(GL_POINTS);
for(int i=0;i<10000;i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2i(0+cos(b)*760,0+sin(b)*750);
}
glEnd();
glBegin(GL_LINES);
for(int i=0; i<=500; i++)
{
glColor3f(0.4,0.4,0.6);
glVertex2f(0+sin((-neptune_speed*3.14)/180)*760,0+cos((-neptune_speed*3.14)/180)*750);
glColor3f(0,0,0);
glVertex2f(0+cos(i/3.14)*20+sin((-neptune_speed*3.14)/180)*760,0+sin(i/3.14)*20+cos((-neptune_speed*3.14)/180)*750);
}
glEnd();
//asteroids
glColor3f(5.0,5.0,5.0);
for(int j=0; j<50; j++)
{
if(asters==-1)
{
for(int k=0; k<50; k++)
{
glBegin(GL_TRIANGLE_FAN);
glVertex2i(-700+asteroids[j][k]+aster_speed,-500+asteroids[j+1][k+1]);
for(int i=0; i<50;i++)
{
b=(float)i/50.0*3.1415*2.0;
glVertex2i(-700+asteroids[j][k]+aster_speed+cos(b)*radius[j],-500+asteroids[j+1][k+1]+sin(b)*radius[j]);
glColor3f(0.1,0.1,0.1);
}
glEnd();
}
}
}
glFinish();
SwapBuffers(m_hDC) ;
}
void date (int value)
{
if(nap==1)
{
s=s+0.986;
d=d+1; //счетчик дней
if(s>p)
{
w=w+1; //счетчик месяцев
d=1; //обнуляет месяц
s=1;
}
if(w>12)
{
o=o+1; //счетчик лет
e=e+1; //счетчик высокосного года
w=1;
}
if(w==1 || w==3 || w==5 || w==12 || w==7 || w==12 || w==10)
{
p=31;
} //этот код отвечает за колличество дней в месяце,
//ведь в каких то 30 а в каких то и 28.
if(w==4 || w==6 || w==9 || w==11)
{
p=30;
}
if(w==2)
{
if(e<4)
{
p=28;
}
if(e==4)
{
p=29; //тут учитывается высокосный год
if (e>4)
{
e=0;
}
}
}
}
if(nap==-1)
{
d=d-1;
if (d==1)
{
w=w-1;
d=p;
}
if(w<1)
{
w=12;
o=o-1;
}
if(o<1)
{
nap=1;
s=0;
c=c*-1;
}
}
// glutTimerFunc(times, date, 0);
}
void model(int value)
{
if (napr==1) //направление(по часовой и против часовой)
{
aster_speed=aster_speed+0.09;
merc_speed=merc_speed+2/k;
venera_speed=venera_speed+1.17/k;
earth_speed=earth_speed+0.986/k;
mars_speed=mars_speed+0.9/k;
jupiter_speed=jupiter_speed+0.43/k; //SPEED(при увеличении коэфициента увеличивается скорость планеты)
saturn_speed=saturn_speed+0.3/k;
uran_speed=uran_speed+0.23/k;
neptune_speed=neptune_speed+0.17/k;
}
if (napr==-1)
{
aster_speed=aster_speed-0.09;
merc_speed=merc_speed-2/k;
venera_speed=venera_speed-1.17/k;
earth_speed=earth_speed-0.986/k;
mars_speed=mars_speed-0.9/k;
jupiter_speed=jupiter_speed-0.43/k; //SPEED(при увеличении коэфициента увеличивается скорость планеты)
saturn_speed=saturn_speed-0.3/k;
uran_speed=uran_speed-0.23/k;
neptune_speed=neptune_speed-0.17/k;
}
// glutPostRedisplay();
// glutTimerFunc(40, model, 0);
}
System::Void SwapOpenGLBuffers(System::Void)
{
SwapBuffers(m_hDC) ;
}
System::Void wglmakecur()
{
wglMakeCurrent(m_hDC,m_hglrc);
}
HDC m_hDC;
HGLRC m_hglrc;
GLfloat rtri; // Angle for the triangle
GLfloat rquad; // Angle for the quad
GLfloat m;
~COpenGL(System::Void)
{
this->DestroyHandle();
}
GLint MySetPixelFormat(HDC hdc)
{
static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
16, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
GLint iPixelFormat;
// get the device context's best, available pixel format match
if((iPixelFormat = ChoosePixelFormat(hdc, &pfd)) == 0)
{
MessageBox::Show("ChoosePixelFormat Failed");
return 0;
}
// make that match the device context's current pixel format
if(SetPixelFormat(hdc, iPixelFormat, &pfd) == FALSE)
{
MessageBox::Show("SetPixelFormat Failed");
return 0;
}
if((m_hglrc = wglCreateContext(m_hDC)) == NULL)
{
MessageBox::Show("wglCreateContext Failed");
return 0;
}
if((wglMakeCurrent(m_hDC, m_hglrc)) == NULL)
{
MessageBox::Show("wglMakeCurrent Failed");
return 0;
}
return 1;
}
bool InitGL(GLvoid) // All setup for opengl goes here
{
glShadeModel(GL_SMOOTH); // Enable smooth shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black background
glClearDepth(1.0f); // Depth buffer setup
glEnable(GL_DEPTH_TEST); // Enables depth testing
glDepthFunc(GL_LEQUAL); // The type of depth testing to do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really nice perspective calculations
return TRUE;
}
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize and initialise the gl window
{
glViewport(0,0, 0,-300);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(reshape_perspective+2,1.4-RS/10000,1+RS/500,1200);
glMatrixMode(GL_MODELVIEW);
// Reset The Modelview Matrix
}
};
} |