質問編集履歴

1

追加

2019/02/08 13:16

投稿

miiichat
miiichat

スコア72

test CHANGED
File without changes
test CHANGED
@@ -37,3 +37,401 @@
37
37
  const int j(i & 3), k(i & ~3);
38
38
 
39
39
  の部分の & は何をしてますか?
40
+
41
+
42
+
43
+ ---追記---
44
+
45
+ GLFW による OpenGL 入門(130p)
46
+
47
+ http://marina.sys.wakayama-u.ac.jp/~tokoi/GLFWdraft.pdf
48
+
49
+
50
+
51
+ をやってます。実行できます
52
+
53
+ ```
54
+
55
+ #pragma once
56
+
57
+ #include <algorithm>
58
+
59
+ #include <GL/glew.h>
60
+
61
+ #include <cmath>
62
+
63
+
64
+
65
+ class Matrix
66
+
67
+ {
68
+
69
+ GLfloat matrix[16];
70
+
71
+
72
+
73
+ public:
74
+
75
+
76
+
77
+ Matrix() {}
78
+
79
+
80
+
81
+ Matrix(const GLfloat *a)
82
+
83
+ {
84
+
85
+ std::copy(a, a + 16, matrix);
86
+
87
+ }
88
+
89
+
90
+
91
+ const GLfloat *data() const
92
+
93
+ {
94
+
95
+ return matrix;
96
+
97
+ }
98
+
99
+
100
+
101
+ void loadIdentity()
102
+
103
+ {
104
+
105
+ std::fill(matrix, matrix + 16, 0.0f);
106
+
107
+ matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1.0f;
108
+
109
+ }
110
+
111
+
112
+
113
+ static Matrix identity()
114
+
115
+ {
116
+
117
+ Matrix t;
118
+
119
+ t.loadIdentity();
120
+
121
+ return t;
122
+
123
+ }
124
+
125
+
126
+
127
+ static Matrix translate(GLfloat x, GLfloat y, GLfloat z)
128
+
129
+ {
130
+
131
+ Matrix t;
132
+
133
+ t.loadIdentity();
134
+
135
+ t.matrix[12] = x;
136
+
137
+ t.matrix[13] = y;
138
+
139
+ t.matrix[14] = z;
140
+
141
+
142
+
143
+ return t;
144
+
145
+ }
146
+
147
+
148
+
149
+ static Matrix scale(GLfloat x, GLfloat y, GLfloat z)
150
+
151
+ {
152
+
153
+ Matrix t;
154
+
155
+ t.loadIdentity();
156
+
157
+ t.matrix[0] = x;
158
+
159
+ t.matrix[5] = y;
160
+
161
+ t.matrix[10] = z;
162
+
163
+
164
+
165
+ return t;
166
+
167
+ }
168
+
169
+
170
+
171
+ static Matrix shearXY(GLfloat angle)
172
+
173
+ {
174
+
175
+ Matrix t;
176
+
177
+ t.loadIdentity();
178
+
179
+ t.matrix[4] = angle;
180
+
181
+
182
+
183
+ return t;
184
+
185
+ }
186
+
187
+
188
+
189
+ static Matrix shearYZ(GLfloat angle)
190
+
191
+ {
192
+
193
+ Matrix t;
194
+
195
+ t.loadIdentity();
196
+
197
+ t.matrix[9] = angle;
198
+
199
+
200
+
201
+ return t;
202
+
203
+ }
204
+
205
+
206
+
207
+ static Matrix shearZX(GLfloat angle)
208
+
209
+ {
210
+
211
+ Matrix t;
212
+
213
+ t.loadIdentity();
214
+
215
+ t.matrix[2] = angle;
216
+
217
+
218
+
219
+ return t;
220
+
221
+ }
222
+
223
+
224
+
225
+ static Matrix shearYX(GLfloat angle)
226
+
227
+ {
228
+
229
+ Matrix t;
230
+
231
+ t.loadIdentity();
232
+
233
+ t.matrix[1] = angle;
234
+
235
+
236
+
237
+ return t;
238
+
239
+ }
240
+
241
+
242
+
243
+ static Matrix shearZY(GLfloat angle)
244
+
245
+ {
246
+
247
+ Matrix t;
248
+
249
+ t.loadIdentity();
250
+
251
+ t.matrix[6] = angle;
252
+
253
+
254
+
255
+ return t;
256
+
257
+ }
258
+
259
+
260
+
261
+ static Matrix shearXZ(GLfloat angle)
262
+
263
+ {
264
+
265
+ Matrix t;
266
+
267
+ t.loadIdentity();
268
+
269
+ t.matrix[8] = angle;
270
+
271
+
272
+
273
+ return t;
274
+
275
+ }
276
+
277
+
278
+
279
+ static Matrix rotationX(GLfloat angle)
280
+
281
+ {
282
+
283
+ Matrix t;
284
+
285
+ t.loadIdentity();
286
+
287
+ t.matrix[5] = cos(angle);
288
+
289
+ t.matrix[6] = sin(angle);
290
+
291
+ t.matrix[9] = -sin(angle);
292
+
293
+ t.matrix[10] = cos(angle);
294
+
295
+
296
+
297
+ return t;
298
+
299
+ }
300
+
301
+
302
+
303
+ static Matrix rotationY(GLfloat angle)
304
+
305
+ {
306
+
307
+ Matrix t;
308
+
309
+ t.loadIdentity();
310
+
311
+ t.matrix[0] = cos(angle);
312
+
313
+ t.matrix[2] = sin(angle);
314
+
315
+ t.matrix[8] = -sin(angle);
316
+
317
+ t.matrix[10] = cos(angle);
318
+
319
+
320
+
321
+ return t;
322
+
323
+ }
324
+
325
+
326
+
327
+ static Matrix rotationZ(GLfloat angle)
328
+
329
+ {
330
+
331
+ Matrix t;
332
+
333
+ t.loadIdentity();
334
+
335
+ t.matrix[0] = cos(angle);
336
+
337
+ t.matrix[1] = sin(angle);
338
+
339
+ t.matrix[4] = -sin(angle);
340
+
341
+ t.matrix[5] = cos(angle);
342
+
343
+
344
+
345
+ return t;
346
+
347
+ }
348
+
349
+
350
+
351
+ static Matrix rotate(GLfloat a, GLfloat x, GLfloat y, GLfloat z)
352
+
353
+ {
354
+
355
+ Matrix t;
356
+
357
+ const GLfloat d(sqrt(x * x + y * y + z * z));
358
+
359
+
360
+
361
+ if (d > 0.0f)
362
+
363
+ {
364
+
365
+ const GLfloat l(x / d), m(y / d), n(z / d);
366
+
367
+ const GLfloat l2(l * l), m2(m * m), n2(n * n);
368
+
369
+ const GLfloat lm(l * m), mn(m * n), nl(n * l);
370
+
371
+ const GLfloat c(cos(a)), c1(1.0f - c), s(sin(a));
372
+
373
+
374
+
375
+ t.loadIdentity();
376
+
377
+ t.matrix[0] = (1.0f - l2) * c + l2;
378
+
379
+ t.matrix[1] = lm * c1 + n * s;
380
+
381
+ t.matrix[2] = nl * c1 - m * s;
382
+
383
+ t.matrix[4] = lm * c1 - n * s;
384
+
385
+ t.matrix[5] = (1.0f - m2) * c + m2;
386
+
387
+ t.matrix[6] = mn * c1 + l * s;
388
+
389
+ t.matrix[8] = nl * c1 + m * s;
390
+
391
+ t.matrix[9] = mn * c1 - l * s;
392
+
393
+ t.matrix[10] = (1.0f - n2) * c + n2;
394
+
395
+ }
396
+
397
+ return t;
398
+
399
+ }
400
+
401
+
402
+
403
+ Matrix operator*(const Matrix &m) const
404
+
405
+ {
406
+
407
+ Matrix t;
408
+
409
+
410
+
411
+ for (int i = 0; i < 16; ++i)
412
+
413
+ {
414
+
415
+ const int j(i & 3), k(i & ~3);
416
+
417
+
418
+
419
+ t.matrix[i] =
420
+
421
+ matrix[0 + j] * matrix[k + 0] +
422
+
423
+ matrix[4 + j] * matrix[k + 1] +
424
+
425
+ matrix[8 + j] * matrix[k + 2] +
426
+
427
+ matrix[12+j] * matrix[k + 3];
428
+
429
+ }
430
+
431
+ return t;
432
+
433
+ }
434
+
435
+ };
436
+
437
+ ```