-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
150 lines (134 loc) · 3.04 KB
/
main.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
#include <iostream>
#include <ctime>
#include "figures.h"
using namespace std;
void glDraw();
void glDrawPause();
void glDrawAcc();
void glDrawDec();
void glDrawMove();
void TimeStep(int n);
void getKey(unsigned char key, int x, int y);
void mouse(int button, int state, int x, int y);
#define GLUT_WHEEL_UP 3
#define GLUT_WHEEL_DOWN 4
void onMenu(int id)
{
switch (id)
{
case 1:
glutDisplayFunc(glDrawAcc);
break;
case 2:
glutDisplayFunc(glDrawDec);
break;
case 3:
glutDisplayFunc(glDrawMove);
break;
default:break;
}
}
void initMenu()
{
GLint mainMenu = glutCreateMenu(onMenu);
glutAddMenuEntry("Accelerate", 1);
glutAddMenuEntry("Decelerate", 2);
glutAddMenuEntry("Rocket & UFO Move / Pause", 3);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}
int main(int argc, char *argv[]) {
int static i = 0;
srand(std::time(0));
glutInit(&argc, argv);
glutInitWindowSize(800, 800);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutCreateWindow("Project");
//glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glutDisplayFunc(glDraw);
glutTimerFunc(25, TimeStep, 0);
glutKeyboardFunc(getKey);
glutMouseFunc(mouse);
initMenu();
glutMainLoop();
return 0;
}
void getKey(unsigned char key, int x, int y) {
static int isPause = 0;
if (key == 27) exit(0);
if (key == 'a' || key == 'A') {//accelerate
glutDisplayFunc(glDrawAcc);
}
if (key == 'd' || key == 'D')//decelerate
{
glutDisplayFunc(glDrawDec);
}
if (key == 's' || key == 'S')//standard
{
glutDisplayFunc(glDraw);
}
if (key == 'p' || key == 'P')//stop&resume
{
if (isPause == 0)
{
isPause = 1;
glutDisplayFunc(glDrawPause);
}
else
{
isPause = 0;
glutDisplayFunc(glDraw);
}
}
if (key == 'w' || key == 'W')//rocket
{
glutDisplayFunc(glDrawMove);
}
}
void mouse(int button, int state, int x, int y) {
static int isPause = 0;
switch (button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
{
if (isPause == 0)
{
isPause = 1;
glutDisplayFunc(glDrawPause);
}
else
{
isPause = 0;
glutDisplayFunc(glDraw);
}
}
break;
default:
break;
}
}
void glDraw() {
logic(0.01,0);
glFlush();
glClear(GL_COLOR_BUFFER_BIT);
}
void glDrawPause() {}
void glDrawAcc() {
logic(0.04,0);
glFlush();
glClear(GL_COLOR_BUFFER_BIT);
}
void glDrawDec() {
logic(0.005,0);
glFlush();
glClear(GL_COLOR_BUFFER_BIT);
}
void glDrawMove() {
logic(0.01,1);
glFlush();
glClear(GL_COLOR_BUFFER_BIT);
}
void TimeStep(int n) {
glutTimerFunc(25, TimeStep, 0);
glutPostRedisplay();
}