質問編集履歴
1
ソースコードの追加 文章訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
|
5
|
+
```
|
6
|
-
|
7
|
-
|
8
6
|
|
9
7
|
#include "GL/glut.h"
|
10
8
|
|
@@ -12,11 +10,7 @@
|
|
12
10
|
|
13
11
|
#include <stdlib.h>
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
#
|
13
|
+
#include <stdio.h>
|
18
|
-
|
19
|
-
#define GRAVITY -0.0005
|
20
14
|
|
21
15
|
|
22
16
|
|
@@ -26,17 +20,19 @@
|
|
26
20
|
|
27
21
|
|
28
22
|
|
29
|
-
#define M_PI
|
23
|
+
#define M_PI 3.1415926535897932384626433832795
|
30
24
|
|
31
25
|
|
32
26
|
|
33
27
|
double drand48()
|
34
28
|
|
29
|
+
{
|
30
|
+
|
35
|
-
|
31
|
+
return (rand()%10000)/10000.0;
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
|
39
|
-
|
33
|
+
}
|
34
|
+
|
35
|
+
|
40
36
|
|
41
37
|
#endif
|
42
38
|
|
@@ -44,129 +40,105 @@
|
|
44
40
|
|
45
41
|
|
46
42
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
GLfloat x
|
54
|
-
|
55
|
-
GLfloat
|
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
|
-
gl
|
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
|
-
if (NumDrops + newdrops > MAX_DROPS)
|
148
|
-
|
149
|
-
newdrops = MAX_DROPS - NumDrops;
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
for ( i=NumDrops ; i<NumDrops+newdrops ; i++ ) {
|
154
|
-
|
155
|
-
water[i].alive = 1;
|
156
|
-
|
157
|
-
water[i].xpos = -0.8 + 0.01*drand48();
|
158
|
-
|
159
|
-
water[i].ypos = 0.8 + 0.01*drand48();
|
160
|
-
|
161
|
-
water[i].xdir = 0.0075 + 0.0025*drand48();
|
162
|
-
|
163
|
-
water[i].ydir = 0.0;
|
164
|
-
|
165
|
-
water[i].mass = 0.5 + 0.5*drand48();
|
166
|
-
|
167
|
-
}
|
168
|
-
|
169
|
-
NumDrops += newdrops;
|
43
|
+
#define MAX_POINTS 5000
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
int num;
|
48
|
+
|
49
|
+
GLfloat curx, cury;
|
50
|
+
|
51
|
+
GLfloat x[MAX_POINTS], y[MAX_POINTS];
|
52
|
+
|
53
|
+
GLfloat xacc[MAX_POINTS], yacc[MAX_POINTS];
|
54
|
+
|
55
|
+
GLfloat red, green, blue;
|
56
|
+
|
57
|
+
int step; int length;
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
void initialize()
|
62
|
+
|
63
|
+
{
|
64
|
+
|
65
|
+
int j;
|
66
|
+
|
67
|
+
double temp, temp2;
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
num = drand48()*(MAX_POINTS-1); //疑似乱数の生成
|
72
|
+
|
73
|
+
curx = -0.5 + drand48();
|
74
|
+
|
75
|
+
cury = 0.0 + drand48();
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
red = 0.5 + 0.5*drand48();
|
80
|
+
|
81
|
+
green = 0.5 + 0.5*drand48();
|
82
|
+
|
83
|
+
blue = 0.5 + 0.5*drand48();
|
84
|
+
|
85
|
+
glPointSize(123.0);
|
86
|
+
|
87
|
+
step = 0;
|
88
|
+
|
89
|
+
length = 700 + 300*drand48();
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
for (j=0 ; j<num; j++ ) {
|
94
|
+
|
95
|
+
x[j] = curx;
|
96
|
+
|
97
|
+
y[j] = cury;
|
98
|
+
|
99
|
+
temp = drand48();
|
100
|
+
|
101
|
+
temp2 = drand48()*2.0*M_PI;
|
102
|
+
|
103
|
+
xacc[j] = (cos(temp2) * temp)/length;
|
104
|
+
|
105
|
+
yacc[j] = (sin(temp2) * temp)/length;
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
void draw_blast(void)
|
116
|
+
|
117
|
+
{
|
118
|
+
|
119
|
+
int i;
|
120
|
+
|
121
|
+
double glow = (length - step) / (double)length;
|
122
|
+
|
123
|
+
glColor3f(red*glow, green*glow, blue*glow);
|
124
|
+
|
125
|
+
glBegin(GL_POINTS);
|
126
|
+
|
127
|
+
for (i=0;i<num;i++) {
|
128
|
+
|
129
|
+
x[i] += xacc[i];
|
130
|
+
|
131
|
+
y[i] += yacc[i];
|
132
|
+
|
133
|
+
glVertex2f(x[i], y[i]);
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
glEnd();
|
138
|
+
|
139
|
+
glFlush();
|
140
|
+
|
141
|
+
glutSwapBuffers();
|
170
142
|
|
171
143
|
}
|
172
144
|
|
@@ -174,17 +146,35 @@
|
|
174
146
|
|
175
147
|
void display(void)
|
176
148
|
|
177
|
-
{
|
149
|
+
{
|
150
|
+
|
178
|
-
|
151
|
+
int i;
|
152
|
+
|
179
|
-
|
153
|
+
glClear(GL_COLOR_BUFFER_BIT);
|
154
|
+
|
180
|
-
|
155
|
+
if (step < 1.9*length) {
|
156
|
+
|
181
|
-
|
157
|
+
for (i=0; i<num; i++)
|
158
|
+
|
182
|
-
|
159
|
+
yacc[i] -= 3.2 / length; // 重力
|
160
|
+
|
183
|
-
draw_
|
161
|
+
draw_blast();
|
162
|
+
|
184
|
-
|
163
|
+
}
|
164
|
+
|
185
|
-
|
165
|
+
step ++;
|
166
|
+
|
186
|
-
|
167
|
+
if (step > length) initialize();
|
168
|
+
|
187
|
-
|
169
|
+
}
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
void idle(void)
|
174
|
+
|
175
|
+
{
|
176
|
+
|
177
|
+
glutPostRedisplay();
|
188
178
|
|
189
179
|
}
|
190
180
|
|
@@ -194,11 +184,15 @@
|
|
194
184
|
|
195
185
|
{
|
196
186
|
|
197
|
-
switch (key) {
|
187
|
+
switch (key) {
|
198
|
-
|
188
|
+
|
199
|
-
case 27:
|
189
|
+
case 27:
|
190
|
+
|
200
|
-
|
191
|
+
exit(0);
|
192
|
+
|
193
|
+
break;
|
194
|
+
|
201
|
-
}
|
195
|
+
}
|
202
196
|
|
203
197
|
}
|
204
198
|
|
@@ -208,39 +202,29 @@
|
|
208
202
|
|
209
203
|
{
|
210
204
|
|
211
|
-
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
|
205
|
+
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
|
212
|
-
|
206
|
+
|
213
|
-
glMatrixMode(GL_PROJECTION);
|
207
|
+
glMatrixMode(GL_PROJECTION);
|
214
|
-
|
208
|
+
|
215
|
-
glLoadIdentity();
|
209
|
+
glLoadIdentity();
|
216
|
-
|
210
|
+
|
217
|
-
if (w <= h)
|
211
|
+
if (w <= h)
|
218
|
-
|
212
|
+
|
219
|
-
glOrtho(-1.0, 1.0,
|
213
|
+
glOrtho(-1.0, 1.0,
|
220
|
-
|
214
|
+
|
221
|
-
-1.0*(GLfloat)h/(GLfloat)w, 1.0*(GLfloat)h/(GLfloat)w,
|
215
|
+
-1.0*(GLfloat)h/(GLfloat)w, 1.0*(GLfloat)h/(GLfloat)w,
|
222
|
-
|
216
|
+
|
223
|
-
-1.0, 1.0);
|
217
|
+
-1.0, 1.0);
|
224
|
-
|
218
|
+
|
225
|
-
else
|
219
|
+
else
|
226
|
-
|
220
|
+
|
227
|
-
glOrtho(-1.0*(GLfloat)w/(GLfloat)h, 1.0*(GLfloat)w/(GLfloat)h,
|
221
|
+
glOrtho(-1.0*(GLfloat)w/(GLfloat)h, 1.0*(GLfloat)w/(GLfloat)h,
|
228
|
-
|
222
|
+
|
229
|
-
-1.0, 1.0,
|
223
|
+
-1.0, 1.0,
|
230
|
-
|
224
|
+
|
231
|
-
-1.0, 1.0);
|
225
|
+
-1.0, 1.0);
|
232
|
-
|
226
|
+
|
233
|
-
glMatrixMode(GL_MODELVIEW);
|
227
|
+
glMatrixMode(GL_MODELVIEW);
|
234
|
-
|
235
|
-
}
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
void idle(void)
|
240
|
-
|
241
|
-
{
|
242
|
-
|
243
|
-
glutPostRedisplay();
|
244
228
|
|
245
229
|
}
|
246
230
|
|
@@ -250,36 +234,40 @@
|
|
250
234
|
|
251
235
|
{
|
252
236
|
|
253
|
-
glutInit(&argc, argv);
|
237
|
+
glutInit(&argc, argv);
|
254
|
-
|
238
|
+
|
255
|
-
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
|
239
|
+
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
|
256
|
-
|
240
|
+
|
257
|
-
glutInitWindowSize (
|
241
|
+
glutInitWindowSize (800, 800);
|
258
|
-
|
242
|
+
|
259
|
-
glutInitWindowPosition(0, 0);
|
243
|
+
glutInitWindowPosition(0, 0);
|
260
|
-
|
244
|
+
|
261
|
-
glutCreateWindow ("
|
245
|
+
glutCreateWindow ("Fireworks");
|
262
|
-
|
263
|
-
|
264
|
-
|
246
|
+
|
247
|
+
|
248
|
+
|
265
|
-
glClearColor (0.0, 0.0, 0.0, 0.0);
|
249
|
+
glClearColor (0.0, 0.0, 0.0, 0.0);
|
266
|
-
|
250
|
+
|
267
|
-
|
251
|
+
initialize();
|
268
|
-
|
269
|
-
|
270
|
-
|
252
|
+
|
253
|
+
|
254
|
+
|
271
|
-
glutDisplayFunc(display);
|
255
|
+
glutDisplayFunc(display);
|
272
|
-
|
256
|
+
|
273
|
-
glutReshapeFunc(reshape);
|
257
|
+
glutReshapeFunc(reshape);
|
274
|
-
|
258
|
+
|
275
|
-
glutIdleFunc(idle);
|
259
|
+
glutIdleFunc(idle);
|
276
|
-
|
260
|
+
|
277
|
-
glutKeyboardFunc(keyboard);
|
261
|
+
glutKeyboardFunc(keyboard);
|
278
|
-
|
262
|
+
|
279
|
-
glutMainLoop();
|
263
|
+
glutMainLoop();
|
280
|
-
|
281
|
-
|
282
|
-
|
264
|
+
|
265
|
+
|
266
|
+
|
283
|
-
return
|
267
|
+
return 0;
|
284
|
-
|
268
|
+
|
285
|
-
}
|
269
|
+
}
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
```
|