-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrbitCollisionRotationTrigonometry.cpp
833 lines (630 loc) · 17.8 KB
/
OrbitCollisionRotationTrigonometry.cpp
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
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
/*********
ERAY ALTAY
----------
PROBLEMS:
I could control player with arrow keys, not with mouse movement. However, shooting is still left click.
First target positins are at 0,0 and you have to shoot them first for entering action phase.
----------
FEATURES:
You have to start game with pressing F1 key, also that key restarts countdown and pauses action.
Arrow keys are the control.
Targets are triangle, they can rotate randomly around themselves and around the player.
20 seconds countdown can be increased by hitting stars. Each star adds +2 seconds.
Scores and how many second you have added can be seen in the bottom right of the screen.
Player object has rotating triangle.
Throwing object is triangle, also it is rotating.
*********/
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdarg.h>
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
#define TIMER_PERIOD 16 // Period for the timer.
#define TIMER_ON 1 // 0:disable timer, 1:enable timer
#define D2R 0.0174532
#define TARGET_RADIUS 20
#define RUN 0
#define ENDGAME 1
#define DURATION 2000
/* Global Variables for Template File */
bool up = false, down = false, right = false, left = false, shot = false;
int winWidth, winHeight; // current Window width and height
bool activeTimer = false;
double timeCounter = DURATION;
int appState = ENDGAME;
float A = 200, A2=250, A3=300, //amplitude
fq = 1, //frequency
C = 0, //horizontal phase shift
B = 0; //vertical phase shift
int scorestreak = 0;
typedef struct point_t{
double x, y;
} point_t;
typedef struct color_t{
int r, g, b;
} color_t;
typedef struct player_t{
point_t pos; // position of the object
float angle; // view angle
float r;
} player_t;
typedef struct fire_t{
point_t pos;
float angle;
float startangle = 10;
bool active;
} fire_t;
typedef struct entity_t{
point_t pos;
double angle;
float startangle; //start angle
unsigned char r, g, b;
bool hit; // collision state
bool active;
double radius = 20;
double speed1; //on its self
double speed2; //outer road
} entity_t;
typedef struct circlem_t{
point_t posm;
float anglem;
float rm;//medium circle
}circlem_t;
#define MAX 1
#define MAX_FIRE 1 // 10 fires at a time.
#define FIRE_RATE 4 // after 8 frames you can throw another one.
int ammo = MAX_FIRE;
player_t p = { {0,0}, 45, 24 };
point_t mouse;
fire_t fr[MAX_FIRE];
int fire_rate = 0;
entity_t i1;
entity_t i2;
entity_t i3;
int count = 0;
//
// to draw circle, center at (x,y)
// radius r
//
void circle(int x, int y, int r)
{
#define PI 3.1415
float angle;
glBegin(GL_POLYGON);
for (int i = 0; i < 100; i++)
{
angle = 2 * PI * i / 100;
glVertex2f(x + r * cos(angle), y + r * sin(angle));
}
glEnd();
}
void circle_wire(int x, int y, int r)
{
#define PI 3.1415
float angle;
glBegin(GL_LINE_LOOP);
for (int i = 0; i < 100; i++)
{
angle = 2 * PI * i / 100;
glVertex2f(x + r * cos(angle), y + r * sin(angle));
}
glEnd();
}
void print(int x, int y, const char* string, void* font)
{
int len, i;
glRasterPos2f(x, y);
len = (int)strlen(string);
for (i = 0; i < len; i++)
{
glutBitmapCharacter(font, string[i]);
}
}
// display text with variables.
// vprint(-winWidth / 2 + 10, winHeight / 2 - 20, GLUT_BITMAP_8_BY_13, "ERROR: %d", numClicks);
void vprint(int x, int y, void* font, const char* string, ...)
{
va_list ap;
va_start(ap, string);
char str[1024];
vsprintf_s(str, string, ap);
va_end(ap);
int len, i;
glRasterPos2f(x, y);
len = (int)strlen(str);
for (i = 0; i < len; i++)
{
glutBitmapCharacter(font, str[i]);
}
}
// vprint2(-50, 0, 0.35, "00:%02d", timeCounter);
void vprint2(int x, int y, float size, const char* string, ...) {
va_list ap;
va_start(ap, string);
char str[1024];
vsprintf_s(str, string, ap);
va_end(ap);
glPushMatrix();
glTranslatef(x, y, 0);
glScalef(size, size, 1);
int len, i;
len = (int)strlen(str);
for (i = 0; i < len; i++)
{
glutStrokeCharacter(GLUT_STROKE_ROMAN, str[i]);
}
glPopMatrix();
}
void vertex(point_t P, point_t Tr, double angle) {
double xp = (P.x * cos(angle) - P.y * sin(angle)) + Tr.x;
double yp = (P.x * sin(angle) + P.y * cos(angle)) + Tr.y;
glVertex2d(xp, yp);
}
float f(float x) {
return A * sin((fq * x + C) * D2R) + B;
}
void drawIcon1(entity_t e) {
double r = fabs(A);
//double r2 = fabs(A2);//amplitude
//double r3 = fabs(A3);
glColor3ub(e.r, e.g, e.b);
glBegin(GL_TRIANGLES);
vertex({ 0, 20 }, { r * cos(e.startangle * D2R), r * sin(e.startangle * D2R) }, e.angle);
vertex({ -17.3, -10 }, { r * cos(e.startangle * D2R), r * sin(e.startangle * D2R) }, e.angle);
vertex({ 17.3, -10 }, { r * cos(e.startangle * D2R), r * sin(e.startangle * D2R) }, e.angle);
glEnd();
glColor3ub(105, 105, 105);
glLineWidth(0.5);
glBegin(GL_LINE_LOOP);
vertex({ 0, 20 }, { r * cos(e.startangle * D2R), r * sin(e.startangle * D2R) }, e.angle);
vertex({ -17.3, -10 }, { r * cos(e.startangle * D2R), r * sin(e.startangle * D2R) }, e.angle);
vertex({ 17.3, -10 }, { r * cos(e.startangle * D2R), r * sin(e.startangle * D2R) }, e.angle);
glEnd();
glLineWidth(1);
}
void drawIcon2(entity_t e) {
//double r = fabs(A);
double r2 = fabs(A2);//amplitude
//double r3 = fabs(A3);
glColor3ub(e.r, e.g, e.b);
glBegin(GL_TRIANGLES);
vertex({ 0, 20 }, { r2 * cos(e.startangle * D2R), r2 * sin(e.startangle * D2R) }, e.angle);
vertex({ -17.3, -10 }, { r2 * cos(e.startangle * D2R), r2 * sin(e.startangle * D2R) }, e.angle);
vertex({ 17.3, -10 }, { r2 * cos(e.startangle * D2R), r2 * sin(e.startangle * D2R) }, e.angle);
glEnd();
glColor3ub(105, 105, 105);
glLineWidth(1);
glBegin(GL_LINE_LOOP);
vertex({ 0, 20 }, { r2 * cos(e.startangle * D2R), r2 * sin(e.startangle * D2R) }, e.angle);
vertex({ -17.3, -10 }, { r2 * cos(e.startangle * D2R), r2 * sin(e.startangle * D2R) }, e.angle);
vertex({ 17.3, -10 }, { r2 * cos(e.startangle * D2R), r2 * sin(e.startangle * D2R) }, e.angle);
glEnd();
glLineWidth(1);
}
void drawIcon3(entity_t e) {
//double r = fabs(A);
//double r2 = fabs(A2);//amplitude
double r3 = fabs(A3);
glColor3ub(e.r, e.g, e.b);
glBegin(GL_TRIANGLES);
vertex({ 0, 20 }, { r3 * cos(e.startangle * D2R), r3 * sin(e.startangle * D2R) }, e.angle);
vertex({ -17.3, -10 }, { r3 * cos(e.startangle * D2R), r3 * sin(e.startangle * D2R) }, e.angle);
vertex({ 17.3, -10 }, { r3 * cos(e.startangle * D2R), r3 * sin(e.startangle * D2R) }, e.angle);
glEnd();
glColor3ub(105, 105, 105);
glLineWidth(1.5);
glBegin(GL_LINE_LOOP);
vertex({ 0, 20 }, { r3 * cos(e.startangle * D2R), r3 * sin(e.startangle * D2R) }, e.angle);
vertex({ -17.3, -10 }, { r3 * cos(e.startangle * D2R), r3 * sin(e.startangle * D2R) }, e.angle);
vertex({ 17.3, -10 }, { r3 * cos(e.startangle * D2R), r3 * sin(e.startangle * D2R) }, e.angle);
glEnd();
glLineWidth(1);
}
void drawCircle() {
float r = fabs(A);
float r2 = fabs(A2);//amplitude
float r3 = fabs(A3);
glColor3ub(238, 130, 238);
circle_wire(0, 0, r);
glColor3ub(148, 0, 211);
circle_wire(0, 0, r2);
glColor3ub(75, 0, 130);
circle_wire(0, 0, r3);
}
void drawPlayer(player_t tp) {
double angle = p.angle * D2R;
glColor3ub(255, 215, 0);
glLineWidth(3);
glBegin(GL_LINES);
glVertex2f(tp.pos.x, tp.pos.y);
glVertex2f(tp.pos.x + 50 * cos(tp.angle * D2R), tp.pos.y + 50 * sin(tp.angle * D2R));
glEnd();
glLineWidth(1);
glColor3ub(192,192,192);
circle(tp.pos.x, tp.pos.y, tp.r);
glColor3ub(30, 144, 255);
circle(tp.pos.x, tp.pos.y, tp.r - 4);
glColor3ub(135, 206, 250);
glBegin(GL_TRIANGLES);
vertex({ 0, 20 }, { 0, 0 }, angle);
vertex({ -17.3, -10 }, { 0,0 }, angle);
vertex({ 17.3, -10 }, {0, 0}, angle);
glEnd();
glColor3ub(255, 20, 147);
vprint(tp.pos.x + 170 * cos(tp.angle * D2R), tp.pos.y + 170 * sin(tp.angle * D2R), GLUT_BITMAP_8_BY_13, "%.0f", tp.angle);
//vprint(tp.pos.x - 12, tp.pos.y - 5, GLUT_BITMAP_8_BY_13, "%.0f", tp.angle);
}
void drawFires() {
for (int i = 0; i < MAX_FIRE; i++) {
if (fr[i].active) {
/*glColor3f(1, 0, 0);
circle(fr[i].pos.x, fr[i].pos.y, 5);*/
glColor3ub(255, 215, 0);
glBegin(GL_TRIANGLES);
vertex({ 0, 15 }, fr[i].pos, fr[i].startangle);
vertex({ -12.3, -5 }, fr[i].pos, fr[i].startangle);
vertex({ 12.3, -5 }, fr[i].pos, fr[i].startangle);
glEnd();
}
}
}
void drawBackground() {
glColor3ub(0, 0, 0);
glRectf(-400, -300, 400, 300);
glColor3ub(255, 255, 0);
vprint2(-370, 260, 0.09, "HOMEWORKK 3");
glColor3ub(255, 255, 0);
vprint2(-370, 240, 0.09, "by ERAY ALTAY");
glColor3ub(255, 255, 255);
glBegin(GL_LINES);
glVertex2f(-400, 0);
glVertex2f(400, 0);
glVertex2f(0, -300);
glVertex2f(0, 300);
glEnd();
}
void displayMessage() {
glColor3ub(255, 0, 0);
vprint2(245, 255, 0.10, "Press F1 to Start");
}
void displayScore() {
glColor3ub(0, 255, 171);
vprint2(200, -255, 0.09, "You have destroyed %d stars", scorestreak-3);
glColor3ub(213, 0, 255);
vprint2(200, -275, 0.09, "+%d seconds added",(scorestreak-3)*2);
}
void displayRun() {
glColor3ub(0, 255, 0);
vprint2(245, 255, 0.10, "%.0f Seconds Left", timeCounter / 100);
}
//
// To display onto window using OpenGL commands
//
void display() {
//
// clear window to black
//
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
switch (appState) {
case ENDGAME:
drawBackground();
drawPlayer(p);
displayMessage();
drawCircle();
//drawIcon1(i1);
//drawIcon2(i2);
//drawIcon3(i3);
displayScore();
if (activeTimer = activeTimer)
activeTimer = !activeTimer;
else
activeTimer = activeTimer;
break;
case RUN:
drawBackground();
drawPlayer(p);
displayRun();
drawCircle();
drawFires();
drawIcon1(i1);
drawIcon2(i2);
drawIcon3(i3);
displayScore();
if (activeTimer = !activeTimer)
activeTimer = activeTimer;
break;
}
glutSwapBuffers();
}
int findAvailableFire() {
for (int i = 0; i < MAX_FIRE; i++) {
if (fr[i].active == false)
return i;
}
return -1;
}
void resetTarget1() {
i1.startangle = rand() % 361;
i1.r = rand() % 256;
i1.g = rand() % 256;
i1.b = rand() % 256;
i1.speed1 = 1.5 * (rand() % 200 + (-100)) / 100.0 + 0.5;
i1.speed2 = 2.0 * (rand() % 200 + (-100)) / 100.0 + 0.5;
}
void resetTarget2() {
i2.startangle = rand() % 361;
i2.r = rand() % 256;
i2.g = rand() % 256;
i2.b = rand() % 256;
i2.speed1 = 1.5 * (rand() % 200 + (-100)) / 100.0 + 0.5;
i2.speed2 = 2.0 * (rand() % 200 + (-100)) / 100.0 + 0.5;
}
void resetTarget3() {
i3.startangle = rand() % 361;
i3.r = rand() % 256;
i3.g = rand() % 256;
i3.b = rand() % 256;
i3.speed1 = 1.5 * (rand() % 200 + (-100)) / 100.0 + 0.5;
i3.speed2 = 2.0 * (rand() % 200 + (-100)) / 100.0 + 0.5;
}
void turnPlayer(player_t* tp, float inc) {
tp->angle += inc;
if (tp->angle > 360)
tp->angle -= 360;
if (tp->angle < 0)
tp->angle += 360;
}
bool testCollision(fire_t fr, entity_t i1) {
double r = fabs(A);
float dx = (r * cos(i1.startangle * D2R)) - fr.pos.x;
float dy = (r * sin(i1.startangle * D2R)) - fr.pos.y;
float d = sqrt(dx * dx + dy * dy);
return d <= i1.radius;
}
bool testCollision2(fire_t fr, entity_t i2) {
double r2 = fabs(A2);
float dx = (r2 * cos(i2.startangle * D2R)) - fr.pos.x;
float dy = (r2 * sin(i2.startangle * D2R)) - fr.pos.y;
float d = sqrt(dx * dx + dy * dy);
return d <= i2.radius;
}
bool testCollision3(fire_t fr, entity_t i3) {
double r3 = fabs(A3);
float dx = (r3 * cos(i3.startangle * D2R)) - fr.pos.x;
float dy = (r3 * sin(i3.startangle * D2R)) - fr.pos.y;
float d = sqrt(dx * dx + dy * dy);
return d <= i3.radius;
}
#if TIMER_ON == 1
void onTimer(int v) {
//glutTimerFunc(TIMER_PERIOD, onTimer, 0);
// Write your codes here.
if (appState == RUN) {
timeCounter -= 2;
if (timeCounter > 0) {
glutTimerFunc(TIMER_PERIOD, onTimer, 0);
}
else {
// time expires
appState = ENDGAME;
}
}
if (right) {
turnPlayer(&p, -3);
}
if (left) {
turnPlayer(&p, 3);
}
if (shot && fire_rate == 0) {
int availFire = findAvailableFire();
if (availFire != -1) {
fr[availFire].pos = p.pos;
fr[availFire].angle = p.angle;
fr[availFire].startangle += 100;
if (fr[availFire].startangle > 360)
fr[availFire].startangle -= 360;
fr[availFire].active = true;
fire_rate = FIRE_RATE;
}
}
if (fire_rate > 0)
fire_rate--;
for (int i = 0; i < MAX_FIRE; i++) {
if (fr[i].active) {
fr[i].pos.x += 10 * cos(fr[i].angle * D2R);
fr[i].pos.y += 10 * sin(fr[i].angle * D2R);
if (fr[i].pos.x > 500 || fr[i].pos.x < -500 || fr[i].pos.y>500 || fr[i].pos.y < -500) {
fr[i].active = false;
}
if (testCollision(fr[i], i1)) {
fr[i].active = false;
resetTarget1();
scorestreak++;
timeCounter=timeCounter + 200;
ammo += 1;
}
if (testCollision(fr[i], i2)) {
fr[i].active = false;
resetTarget2();
scorestreak++;
timeCounter = timeCounter + 200;
ammo += 1;
}
if (testCollision(fr[i], i3)) {
fr[i].active = false;
resetTarget3();
scorestreak++;
timeCounter = timeCounter + 200;
ammo += 1;
}
}
}
i1.startangle += i1.speed2;
if (i1.startangle > 360)
i1.startangle -= 360;
i1.angle += i1.speed1;
//i2
i2.startangle += i2.speed2;
if (i2.startangle > 360)
i2.startangle -= 360;
i2.angle += i2.speed1;
//i3
i3.startangle += i3.speed2;
if (i3.startangle > 360)
i3.startangle -= 360;
i3.angle += i3.speed1;
// to refresh the window it calls display() function
glutPostRedisplay(); // display()
}
#endif
//
// key function for ASCII charachters like ESC, a,b,c..,A,B,..Z
//
void onKeyDown(unsigned char key, int x, int y)
{
// exit when ESC is pressed.
if (key == 27)
exit(0);
// to refresh the window it calls display() function
glutPostRedisplay();
}
void onKeyUp(unsigned char key, int x, int y)
{
// exit when ESC is pressed.
if (key == 27)
exit(0);
// to refresh the window it calls display() function
glutPostRedisplay();
}
//
// Special Key like GLUT_KEY_F1, F2, F3,...
// Arrow Keys, GLUT_KEY_UP, GLUT_KEY_DOWN, GLUT_KEY_RIGHT, GLUT_KEY_RIGHT
//
void onSpecialKeyDown(int key, int x, int y)
{
// Write your codes here.
switch (key) {
case GLUT_KEY_UP: up = true; break;
case GLUT_KEY_DOWN: down = true; break;
case GLUT_KEY_LEFT: left = true; break;
case GLUT_KEY_RIGHT: right = true; break;
}
if (key == GLUT_KEY_F1 && appState == ENDGAME) {
appState = RUN;
timeCounter = DURATION;
glutTimerFunc(TIMER_PERIOD, onTimer, 0);
/*for (int i = 0; i < MAX; i++) {
f1cars[i].active = true;
}*/
}
else if (key == GLUT_KEY_F1 && appState == RUN) {
appState = ENDGAME;
}
// to refresh the window it calls display() function
glutPostRedisplay();
}
//
// Special Key like GLUT_KEY_F1, F2, F3,...
// Arrow Keys, GLUT_KEY_UP, GLUT_KEY_DOWN, GLUT_KEY_RIGHT, GLUT_KEY_RIGHT
//
void onSpecialKeyUp(int key, int x, int y)
{
// Write your codes here.
switch (key) {
case GLUT_KEY_UP: up = false; break;
case GLUT_KEY_DOWN: down = false; break;
case GLUT_KEY_LEFT: left = false; break;
case GLUT_KEY_RIGHT: right = false; break;
}
// to refresh the window it calls display() function
glutPostRedisplay();
}
//
// When a click occurs in the window,
// It provides which button
// buttons : GLUT_LEFT_BUTTON , GLUT_RIGHT_BUTTON
// states : GLUT_UP , GLUT_DOWN
// x, y is the coordinate of the point that mouse clicked.
//
void onClick(int button, int stat, int x, int y)
{
// Write your codes here.
if (button == GLUT_LEFT_BUTTON && stat == GLUT_DOWN) {
shot = true;
}
if (button == GLUT_LEFT_BUTTON && stat == GLUT_UP) {
shot = false;
}
// to refresh the window it calls display() function
glutPostRedisplay();
}
//
// This function is called when the window size changes.
// w : is the new width of the window in pixels.
// h : is the new height of the window in pixels.
//
void onResize(int w, int h)
{
winWidth = w;
winHeight = h;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-w / 2, w / 2, -h / 2, h / 2, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
display(); // refresh window.
}
void onMoveDown(int x, int y) {
// Write your codes here.
// to refresh the window it calls display() function
glutPostRedisplay();
}
// GLUT to OpenGL coordinate conversion:
// x2 = x1 - winWidth / 2
// y2 = winHeight / 2 - y1
void onMove(int x, int y) {
// Write your codes here.
// to refresh the window it calls display() function
glutPostRedisplay();
}
void Init() {
// Smoothing shapes
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void main(int argc, char* argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
//glutInitWindowPosition(100, 100);
glutCreateWindow("Shooting Stars");
glutDisplayFunc(display);
glutReshapeFunc(onResize);
//
// keyboard registration
//
glutKeyboardFunc(onKeyDown);
glutSpecialFunc(onSpecialKeyDown);
glutKeyboardUpFunc(onKeyUp);
glutSpecialUpFunc(onSpecialKeyUp);
//
// mouse registration
//
glutMouseFunc(onClick);
glutMotionFunc(onMoveDown);
glutPassiveMotionFunc(onMove);
#if TIMER_ON == 1
// timer event
glutTimerFunc(TIMER_PERIOD, onTimer, 0);
#endif
Init();
glutMainLoop();
}