質問編集履歴
13
タイトルを修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
GLSLで画面描画に使う行列
|
1
|
+
GLSLで画面描画に使う行列でZ軸の値がおかしくなる原因が知りたい
|
body
CHANGED
File without changes
|
12
提示コードを修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -227,35 +227,33 @@
|
|
227
227
|
//回転行列
|
228
228
|
struct position pos;
|
229
229
|
|
230
|
-
pos.x = 1;
|
230
|
+
pos.x = 1.0f;
|
231
231
|
pos.y = 0;
|
232
232
|
pos.z = 0;
|
233
233
|
|
234
|
-
pos.w = 1;
|
234
|
+
pos.w = 1.0f;
|
235
|
-
float r = 1;
|
235
|
+
float r = 1.0f;
|
236
236
|
|
237
237
|
float rotate[16] = {
|
238
|
-
(pos.x * pos.x
|
238
|
+
(pos.x * pos.x * (1 - cos(r)) + cos(r)),
|
239
|
-
(pos.x * pos.y * (
|
239
|
+
(pos.x * pos.y * (1 - cos(r)) - (pos.z * sin(r))),
|
240
|
-
(
|
240
|
+
(pos.x * pos.z * (1 - cos(r)) + (pos.y * sin(r))),
|
241
241
|
0,
|
242
242
|
|
243
|
-
(pos.x * pos.
|
243
|
+
(pos.x * pos.y * (1 - cos(r)) + (pos.z * sin(r))),
|
244
|
-
(pos.y * pos.y * (1
|
244
|
+
(pos.y * pos.y * (1 - cos(r)) + cos(r)),
|
245
|
-
(pos.y * pos.z * (1
|
245
|
+
(pos.y * pos.z * (1 - cos(r)) - (pos.x * sin(r))),
|
246
246
|
0,
|
247
247
|
|
248
|
-
(pos.x * pos.z * (1
|
248
|
+
(pos.x * pos.z * (1 - cos(r)) - (pos.y * sin(r))),
|
249
|
-
(pos.y * pos.z * (1
|
249
|
+
(pos.y * pos.z * (1 - cos(r)) + (pos.x * sin(r))),
|
250
|
-
(pos.
|
250
|
+
(pos.z * pos.z * (1 - cos(r)) + cos(r)),
|
251
251
|
0,
|
252
252
|
|
253
253
|
0,0,0,1
|
254
|
-
|
255
|
-
|
256
|
-
|
257
254
|
};
|
258
255
|
|
256
|
+
// print_(rotate);
|
259
257
|
|
260
258
|
//平行移動
|
261
259
|
struct position p;
|
@@ -266,12 +264,18 @@
|
|
266
264
|
|
267
265
|
float move[16] =
|
268
266
|
{
|
269
|
-
1,0,0,p.x,
|
270
|
-
0,1,0,p.y,
|
271
|
-
0,0,1,p.z,
|
272
|
-
0,0,0,
|
267
|
+
1,0,0,0,
|
268
|
+
0,1,0,0,
|
269
|
+
0,0,1,0,
|
270
|
+
p.x,p.y,p.z,1,
|
273
271
|
};
|
274
272
|
|
273
|
+
// print_(move);
|
274
|
+
|
275
|
+
float t[16];
|
276
|
+
mul(rotate, move, t);
|
277
|
+
// print_(t);
|
278
|
+
|
275
279
|
//スケール行列
|
276
280
|
float scale[16] = {
|
277
281
|
1,0,0,0,
|
@@ -280,29 +284,26 @@
|
|
280
284
|
0,0,0,1
|
281
285
|
};
|
282
286
|
|
287
|
+
print_(scale);
|
283
288
|
|
284
|
-
|
289
|
+
float t2[16];
|
290
|
+
mul(scale, t, t2);
|
291
|
+
print_(t);
|
285
292
|
|
286
|
-
float t[16];
|
287
|
-
mul_A_B(rotate, move, t);
|
288
|
-
// print_(t);
|
289
293
|
|
290
294
|
|
291
|
-
float t2[16];//M
|
292
|
-
mul_A_B(scale, t, t2);
|
293
|
-
print_(t2);
|
294
295
|
|
295
296
|
|
296
297
|
for (int i = 0; i < 6; i++)
|
297
298
|
{
|
298
299
|
float t3[16];
|
299
|
-
|
300
|
+
mul(Vertex[i], t2, t3);
|
300
|
-
|
301
|
+
// print_(t2);
|
301
302
|
|
302
303
|
|
303
304
|
float t4[16];
|
304
|
-
|
305
|
+
mul(mp, t2, t4);
|
305
|
-
|
306
|
+
// print_(t4);
|
306
307
|
}
|
307
308
|
|
308
309
|
|
11
提示コードを編集しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -226,56 +226,28 @@
|
|
226
226
|
|
227
227
|
//回転行列
|
228
228
|
struct position pos;
|
229
|
-
/*
|
230
|
-
pos.x = Vertex[0][0] * (cos(0) / 2);
|
231
|
-
pos.y = Vertex[0][1] * (sin(0) / 2);
|
232
|
-
pos.z = Vertex[0][2] * (sin(0) / 2);
|
233
|
-
pos.w = Vertex[0][3] * cos(0) / 2;
|
234
|
-
*/
|
235
229
|
|
236
230
|
pos.x = 1;
|
237
231
|
pos.y = 0;
|
238
232
|
pos.z = 0;
|
233
|
+
|
239
234
|
pos.w = 1;
|
240
235
|
float r = 1;
|
241
|
-
/*
|
242
|
-
float rotate[16] = {
|
243
236
|
|
244
|
-
( 1 - (2 * pos.y * pos.y) - (2 * pos.z * pos.z)),
|
245
|
-
((2 * pos.x * pos.y) + (2 * pos.w * pos.z) ),
|
246
|
-
((2 * pos.x * pos.z) - (2 * pos.w * pos.y))
|
247
|
-
,0
|
248
|
-
|
249
|
-
|
250
|
-
(1 - (2 * pos.z * pos.y) - (2 * pos.w * pos.z)),
|
251
|
-
(1 - (2 * pos.x * pos.x) - (2 * pos.z * pos.z)),
|
252
|
-
((2 * pos.y * pos.z) + (2 * pos.w * pos.x))
|
253
|
-
,0
|
254
|
-
|
255
|
-
((2 * pos.x * pos.z) - (2 * pos.w * pos.z)),
|
256
|
-
((2 * pos.y * pos.z) - (2 * pos.w * pos.z)),
|
257
|
-
(1 - (2 * pos.x * pos.x) - (2 * pos.y * pos.y))
|
258
|
-
,0
|
259
|
-
|
260
|
-
,0,0,0,1//追記
|
261
|
-
|
262
|
-
};
|
263
|
-
*/
|
264
|
-
|
265
237
|
float rotate[16] = {
|
266
|
-
(pos.x * pos.x * (1
|
238
|
+
(pos.x * pos.x * (1 * -cos(r)) * -cos(r)),
|
267
|
-
(pos.x * pos.y * ( 1
|
239
|
+
(pos.x * pos.y * ( 1 * -cos(r) + (pos.z * sin(r))) ),
|
268
|
-
( pos.x * pos.z *(1
|
240
|
+
( pos.x * pos.z *(1 * -cos(r)) - (pos.y * sin(r)) ),
|
269
241
|
0,
|
270
242
|
|
271
|
-
(pos.x * pos.x * (1
|
243
|
+
(pos.x * pos.x * (1 * -cos(r)) * (-pos.z * sin(r)) ),
|
272
|
-
(pos.y * pos.y * (1
|
244
|
+
(pos.y * pos.y * (1 * -cos(r) + cos(r))),
|
273
|
-
(pos.y * pos.z * (1
|
245
|
+
(pos.y * pos.z * (1 * -cos(r)) * (-pos.x * sin(r)) ),
|
274
246
|
0,
|
275
247
|
|
276
|
-
(pos.x * pos.z * (1
|
248
|
+
(pos.x * pos.z * (1 * -cos(r)) * (+pos.y * sin(r)) ),
|
277
|
-
(pos.y * pos.z * (1
|
249
|
+
(pos.y * pos.z * (1 * -cos(r) * (pos.x * sin(r))) ),
|
278
|
-
(pos.x * pos.x * (1
|
250
|
+
(pos.x * pos.x * (1 * -cos(r)) + cos(r)),
|
279
251
|
0,
|
280
252
|
|
281
253
|
0,0,0,1
|
@@ -309,9 +281,8 @@
|
|
309
281
|
};
|
310
282
|
|
311
283
|
|
284
|
+
|
312
285
|
|
313
|
-
|
314
|
-
|
315
286
|
float t[16];
|
316
287
|
mul_A_B(rotate, move, t);
|
317
288
|
// print_(t);
|
@@ -319,8 +290,9 @@
|
|
319
290
|
|
320
291
|
float t2[16];//M
|
321
292
|
mul_A_B(scale, t, t2);
|
322
|
-
|
293
|
+
print_(t2);
|
323
294
|
|
295
|
+
|
324
296
|
for (int i = 0; i < 6; i++)
|
325
297
|
{
|
326
298
|
float t3[16];
|
@@ -330,7 +302,7 @@
|
|
330
302
|
|
331
303
|
float t4[16];
|
332
304
|
mul_A_B(mp, t2, t4);
|
333
|
-
|
305
|
+
// print_(t4);
|
334
306
|
}
|
335
307
|
|
336
308
|
|
@@ -358,7 +330,7 @@
|
|
358
330
|
|
359
331
|
float c[16] = { 0 };
|
360
332
|
|
361
|
-
mul_A_B(a,b,c);
|
333
|
+
//mul_A_B(a,b,c);
|
362
334
|
|
363
335
|
// print_(c);
|
364
336
|
|
10
文章を再度編集しました。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
GLSLで画面描画に使う行列で
|
1
|
+
GLSLで画面描画に使う行列 ロドリゲス回転行列で何を誤ったのか知りたい。
|
body
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
シェーダーで行う計算をCPUで普通に計算するテストコードを実装したいのですが予測通り最後**で3次元目がよくわからない値**に変わっているため画面に表示されない等の不具合が発生しているということを突き止めたのですがこれはなぜこんな値になっているのでしょうか?
|
2
2
|
|
3
|
+
追記 ロドリゲス回転行列がおかしいとの修正依頼を多数受けまして自分なりに修正しましたがもうどうしてもわかりません何をしたのか教えてくれますでしょうか?printf();でデバッグするとどうやらrotateの部分で値がおかしいためすべて狂ってるみたいです。
|
3
4
|
|
4
5
|
|
5
|
-
透視変換行列並びにスケール、回転、平行移動の行列は正しいのでしょうか?調べましたが行列コード以外間違えているとはありえないと思うのですが教えてくれますでしょうか?
|
6
|
-
|
7
|
-
|
8
6
|
追記
|
9
7
|
参考サイト: http://marupeke296.sakura.ne.jp/DXG_No58_RotQuaternionTrans.html
|
10
8
|
② クォータニオン→回転行列変換より回転行列を使いかました。
|
9
文章を編集
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
GLSLで画面描画に使う行列
|
1
|
+
GLSLで画面描画に使う行列でZ軸がおかしくなる原因と対処法が知りたい
|
body
CHANGED
@@ -164,6 +164,33 @@
|
|
164
164
|
|
165
165
|
}
|
166
166
|
|
167
|
+
//行列計算 a x b
|
168
|
+
void mul_A_B(float a[16], float b[16], float result[16])
|
169
|
+
{
|
170
|
+
result[0] = (a[0] * b[0]) + (a[1] * b[4]) + (a[2] * b[8] ) + (a[3] * b[12]);
|
171
|
+
result[1] = (a[0] * b[1]) + (a[1] * b[5]) + (a[2] * b[9] ) + (a[3] * b[13]);
|
172
|
+
result[2] = (a[0] * b[2]) + (a[1] * b[6]) + (a[2] * b[10]) + (a[3] * b[14]);
|
173
|
+
result[3] = (a[0] * b[3]) + (a[1] * b[7]) + (a[2] * b[11]) + (a[3] * b[15]);
|
174
|
+
|
175
|
+
result[4] = (a[4] * b[0]) + (a[5] * b[4]) + (a[6] * b[8]) + (a[7] * b[12]);
|
176
|
+
result[5] = (a[4] * b[1]) + (a[5] * b[5]) + (a[6] * b[9]) + (a[7] * b[13]);
|
177
|
+
result[6] = (a[4] * b[2]) + (a[5] * b[6]) + (a[6] * b[10]) + (a[7] * b[14]);
|
178
|
+
result[7] = (a[4] * b[3]) + (a[5] * b[7]) + (a[6] * b[11]) + (a[7] * b[15]);
|
179
|
+
|
180
|
+
|
181
|
+
result[8] = (a[8] * b[0]) + (a[9] * b[4]) + (a[10] * b[8]) + (a[11] * b[12]);
|
182
|
+
result[9] = (a[8] * b[1]) + (a[9] * b[5]) + (a[10] * b[9]) + (a[11] * b[13]);
|
183
|
+
result[10] = (a[8] * b[2]) + (a[9] * b[6]) + (a[10] * b[10]) + (a[11] * b[14]);
|
184
|
+
result[11] = (a[8] * b[3]) + (a[9] * b[7]) + (a[10] * b[11]) + (a[11] * b[15]);
|
185
|
+
|
186
|
+
result[12] = (a[12] * b[0]) + (a[13] * b[4]) + (a[14] * b[8]) + (a[15] * b[12]);
|
187
|
+
result[13] = (a[12] * b[1]) + (a[13] * b[5]) + (a[14] * b[9]) + (a[15] * b[13]);
|
188
|
+
result[14] = (a[12] * b[2]) + (a[13] * b[6]) + (a[14] * b[10]) + (a[15] * b[14]);
|
189
|
+
result[15] = (a[12] * b[3]) + (a[13] * b[7]) + (a[14] * b[11]) + (a[15] * b[15]);
|
190
|
+
}
|
191
|
+
|
192
|
+
|
193
|
+
|
167
194
|
//ベクトルと行列の掛け算
|
168
195
|
void mul_vec3_matrix(float m[16], float v[3], float r[3])
|
169
196
|
{
|
@@ -288,28 +315,57 @@
|
|
288
315
|
|
289
316
|
|
290
317
|
float t[16];
|
291
|
-
|
318
|
+
mul_A_B(rotate, move, t);
|
292
|
-
|
319
|
+
// print_(t);
|
293
320
|
|
294
321
|
|
295
322
|
float t2[16];//M
|
296
|
-
|
323
|
+
mul_A_B(scale, t, t2);
|
297
|
-
|
324
|
+
// print_(t2);
|
298
325
|
|
299
326
|
for (int i = 0; i < 6; i++)
|
300
327
|
{
|
301
328
|
float t3[16];
|
302
|
-
|
329
|
+
mul_A_B(Vertex[i], t2, t3);
|
303
|
-
|
330
|
+
// print_(t2);
|
304
331
|
|
305
332
|
|
306
333
|
float t4[16];
|
307
|
-
|
334
|
+
mul_A_B(mp, t2, t4);
|
308
|
-
|
335
|
+
print_(t4);
|
309
336
|
}
|
310
337
|
|
311
338
|
|
339
|
+
float a[16] =
|
340
|
+
{
|
341
|
+
0,3,2,5,
|
342
|
+
0,2,2,1,
|
312
343
|
|
344
|
+
0,7,4,3,
|
345
|
+
0,3,3,7,
|
346
|
+
|
347
|
+
};
|
348
|
+
|
349
|
+
|
350
|
+
float b[16] =
|
351
|
+
{
|
352
|
+
0,3,5,5,
|
353
|
+
0,5,8,6,
|
354
|
+
|
355
|
+
8,7,3,3,
|
356
|
+
5,8,3,8,
|
357
|
+
|
358
|
+
};
|
359
|
+
|
360
|
+
|
361
|
+
float c[16] = { 0 };
|
362
|
+
|
363
|
+
mul_A_B(a,b,c);
|
364
|
+
|
365
|
+
// print_(c);
|
366
|
+
|
367
|
+
|
368
|
+
|
313
369
|
return 0;
|
314
370
|
}
|
315
371
|
```
|
8
提示コードを再度修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -201,11 +201,17 @@
|
|
201
201
|
|
202
202
|
//回転行列
|
203
203
|
struct position pos;
|
204
|
+
/*
|
204
205
|
pos.x = Vertex[0][0] * (cos(0) / 2);
|
205
206
|
pos.y = Vertex[0][1] * (sin(0) / 2);
|
206
207
|
pos.z = Vertex[0][2] * (sin(0) / 2);
|
207
208
|
pos.w = Vertex[0][3] * cos(0) / 2;
|
209
|
+
*/
|
208
210
|
|
211
|
+
pos.x = 1;
|
212
|
+
pos.y = 0;
|
213
|
+
pos.z = 0;
|
214
|
+
pos.w = 1;
|
209
215
|
float r = 1;
|
210
216
|
/*
|
211
217
|
float rotate[16] = {
|
@@ -232,19 +238,25 @@
|
|
232
238
|
*/
|
233
239
|
|
234
240
|
float rotate[16] = {
|
235
|
-
(pos.x * pos.x
|
241
|
+
(pos.x * pos.x * (1 - cos(r)) * -cos(r)),
|
236
|
-
(pos.x * pos.y
|
242
|
+
(pos.x * pos.y * ( 1 - cos(r) + (pos.z * sin(r))) ),
|
237
|
-
|
243
|
+
( pos.x * pos.z *(1 - cos(r)) - (pos.y * sin(r)) ),
|
244
|
+
0,
|
238
245
|
|
239
|
-
(pos.x * pos.x
|
246
|
+
(pos.x * pos.x * (1 - cos(r)) * (-pos.z * sin(r)) ),
|
240
|
-
(pos.y * pos.y
|
247
|
+
(pos.y * pos.y * (1 - cos(r) + cos(r))),
|
241
|
-
(pos.y * pos.z
|
248
|
+
(pos.y * pos.z * (1 - cos(r)) * (-pos.x * sin(r)) ),
|
249
|
+
0,
|
242
250
|
|
243
|
-
(pos.x * pos.z
|
251
|
+
(pos.x * pos.z * (1 - cos(r)) * (+pos.y * sin(r)) ),
|
244
|
-
(pos.y * pos.z
|
252
|
+
(pos.y * pos.z * (1 - cos(r) * (pos.x * sin(r))) ),
|
245
|
-
(pos.
|
253
|
+
(pos.x * pos.x * (1 - cos(r)) + cos(r)),
|
254
|
+
0,
|
246
255
|
|
247
256
|
0,0,0,1
|
257
|
+
|
258
|
+
|
259
|
+
|
248
260
|
};
|
249
261
|
|
250
262
|
|
7
提示コードを編集しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -207,6 +207,7 @@
|
|
207
207
|
pos.w = Vertex[0][3] * cos(0) / 2;
|
208
208
|
|
209
209
|
float r = 1;
|
210
|
+
/*
|
210
211
|
float rotate[16] = {
|
211
212
|
|
212
213
|
( 1 - (2 * pos.y * pos.y) - (2 * pos.z * pos.z)),
|
@@ -221,13 +222,32 @@
|
|
221
222
|
,0
|
222
223
|
|
223
224
|
((2 * pos.x * pos.z) - (2 * pos.w * pos.z)),
|
224
|
-
|
225
225
|
((2 * pos.y * pos.z) - (2 * pos.w * pos.z)),
|
226
|
+
(1 - (2 * pos.x * pos.x) - (2 * pos.y * pos.y))
|
227
|
+
,0
|
226
228
|
|
227
|
-
|
229
|
+
,0,0,0,1//追記
|
228
|
-
|
230
|
+
|
229
231
|
};
|
232
|
+
*/
|
230
233
|
|
234
|
+
float rotate[16] = {
|
235
|
+
(pos.x * pos.x + (1 - cos(r)) + cos(r)),
|
236
|
+
(pos.x * pos.y + (1 - cos(r)) + pos.z * sin(r))
|
237
|
+
,(pos.x * pos.z + (1 - cos(r)) - pos.y * sin(r)),0,
|
238
|
+
|
239
|
+
(pos.x * pos.x + (1 - cos(r)) + sin(r)),
|
240
|
+
(pos.y * pos.y + (1 - cos(r)) + cos(r)),
|
241
|
+
(pos.y * pos.z + (1 - cos(r)) + pos.x * sin(r)),0,
|
242
|
+
|
243
|
+
(pos.x * pos.z + (1 - cos(r)) - pos.z * sin(r)),
|
244
|
+
(pos.y * pos.z + (1 - cos(r)) - pos.x * sin(r)),
|
245
|
+
(pos.z * pos.z + (1 - cos(r)) + cos(r)),0,
|
246
|
+
|
247
|
+
0,0,0,1
|
248
|
+
};
|
249
|
+
|
250
|
+
|
231
251
|
//平行移動
|
232
252
|
struct position p;
|
233
253
|
p.x = 0;
|
@@ -257,23 +277,23 @@
|
|
257
277
|
|
258
278
|
float t[16];
|
259
279
|
mul(rotate, move, t);
|
260
|
-
|
280
|
+
//print_(t);
|
261
281
|
|
262
282
|
|
263
283
|
float t2[16];//M
|
264
284
|
mul(scale, t, t2);
|
265
|
-
|
285
|
+
// print_(t2);
|
266
286
|
|
267
287
|
for (int i = 0; i < 6; i++)
|
268
288
|
{
|
269
289
|
float t3[16];
|
270
290
|
mul(Vertex[i], t2, t3);
|
271
|
-
|
291
|
+
print_(t2);
|
272
292
|
|
273
293
|
|
274
294
|
float t4[16];
|
275
295
|
mul(mp, t2, t4);
|
276
|
-
|
296
|
+
// print_(t4);
|
277
297
|
}
|
278
298
|
|
279
299
|
|
6
文章と提示コードを編集しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,7 +5,11 @@
|
|
5
5
|
透視変換行列並びにスケール、回転、平行移動の行列は正しいのでしょうか?調べましたが行列コード以外間違えているとはありえないと思うのですが教えてくれますでしょうか?
|
6
6
|
|
7
7
|
|
8
|
+
追記
|
9
|
+
参考サイト: http://marupeke296.sakura.ne.jp/DXG_No58_RotQuaternionTrans.html
|
10
|
+
② クォータニオン→回転行列変換より回転行列を使いかました。
|
8
11
|
|
12
|
+
|
9
13
|
下記サイトの163ページの透視射形変換行列の数式を移しました。
|
10
14
|
参考サイト: https://tokoik.github.io/GLFWdraft.pdf
|
11
15
|
|
@@ -63,19 +67,21 @@
|
|
63
67
|
float x;
|
64
68
|
float y;
|
65
69
|
float z;
|
70
|
+
|
71
|
+
float w;
|
66
72
|
};
|
67
73
|
|
68
74
|
|
69
75
|
//頂点バッファー
|
70
|
-
float Vertex[6][
|
76
|
+
float Vertex[6][4] =
|
71
77
|
{
|
72
|
-
{-0.5, 0.5, 1.0},
|
78
|
+
{-0.5, 0.5, 1.0,1.0},
|
73
|
-
{-0.5, -0.5, 1.0},
|
79
|
+
{-0.5, -0.5, 1.0,1.0},
|
74
|
-
{0.5, -0.5, 1.0},
|
80
|
+
{0.5, -0.5, 1.0,1.0},
|
75
81
|
|
76
|
-
{-0.5, 0.5, 1.0},
|
82
|
+
{-0.5, 0.5, 1.0,1.0},
|
77
|
-
{0.5, 0.5, 1.0 },
|
83
|
+
{0.5, 0.5, 1.0,1.0 },
|
78
|
-
{0.5, -0.5, 1.0}
|
84
|
+
{0.5, -0.5, 1.0,1.0}
|
79
85
|
};
|
80
86
|
|
81
87
|
|
@@ -158,6 +164,7 @@
|
|
158
164
|
|
159
165
|
}
|
160
166
|
|
167
|
+
//ベクトルと行列の掛け算
|
161
168
|
void mul_vec3_matrix(float m[16], float v[3], float r[3])
|
162
169
|
{
|
163
170
|
printf("\n\n");
|
@@ -169,7 +176,7 @@
|
|
169
176
|
}
|
170
177
|
|
171
178
|
|
172
|
-
|
179
|
+
//画面表示
|
173
180
|
void print_(float tmp[16])
|
174
181
|
{
|
175
182
|
for (int i = 0; i < 16; i++)
|
@@ -194,28 +201,31 @@
|
|
194
201
|
|
195
202
|
//回転行列
|
196
203
|
struct position pos;
|
197
|
-
pos.x =
|
204
|
+
pos.x = Vertex[0][0] * (cos(0) / 2);
|
198
|
-
pos.y = 0;
|
205
|
+
pos.y = Vertex[0][1] * (sin(0) / 2);
|
199
|
-
pos.z = 0;
|
206
|
+
pos.z = Vertex[0][2] * (sin(0) / 2);
|
207
|
+
pos.w = Vertex[0][3] * cos(0) / 2;
|
200
208
|
|
201
209
|
float r = 1;
|
202
210
|
float rotate[16] = {
|
203
211
|
|
212
|
+
( 1 - (2 * pos.y * pos.y) - (2 * pos.z * pos.z)),
|
204
|
-
(pos.x * pos.
|
213
|
+
((2 * pos.x * pos.y) + (2 * pos.w * pos.z) ),
|
205
|
-
(pos.x * pos.y + (1 - cos(r)) + pos.z * sin(r))
|
206
|
-
|
214
|
+
((2 * pos.x * pos.z) - (2 * pos.w * pos.y))
|
207
|
-
|
215
|
+
,0
|
216
|
+
|
208
217
|
|
209
|
-
(pos.x * pos.x + (1 - cos(r)) + sin(r)),
|
210
|
-
(pos.
|
218
|
+
(1 - (2 * pos.z * pos.y) - (2 * pos.w * pos.z)),
|
219
|
+
(1 - (2 * pos.x * pos.x) - (2 * pos.z * pos.z)),
|
211
|
-
(pos.y * pos.z
|
220
|
+
((2 * pos.y * pos.z) + (2 * pos.w * pos.x))
|
212
|
-
|
221
|
+
,0
|
213
222
|
|
214
|
-
(pos.x * pos.z + (1 - cos(r)) - pos.z * sin(r)),
|
215
|
-
(pos.y * pos.z + (1 - cos(r)) - pos.x * sin(r)),
|
216
|
-
(pos.
|
223
|
+
((2 * pos.x * pos.z) - (2 * pos.w * pos.z)),
|
217
|
-
0,
|
218
224
|
|
225
|
+
((2 * pos.y * pos.z) - (2 * pos.w * pos.z)),
|
226
|
+
|
227
|
+
(1 - (2 * pos.x * pos.x) - (2 * pos.y * pos.y))
|
228
|
+
,1
|
219
229
|
};
|
220
230
|
|
221
231
|
//平行移動
|
@@ -223,6 +233,7 @@
|
|
223
233
|
p.x = 0;
|
224
234
|
p.y = 0;
|
225
235
|
p.z = 0;
|
236
|
+
p.w = 1;
|
226
237
|
|
227
238
|
float move[16] =
|
228
239
|
{
|
5
提示コードを編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -53,14 +53,24 @@
|
|
53
53
|
#include "stdio.h"
|
54
54
|
#include <iostream>
|
55
55
|
|
56
|
-
|
56
|
+
//透視射形行列
|
57
|
+
float mp[16];
|
57
58
|
|
59
|
+
//座標構造体
|
60
|
+
struct position
|
61
|
+
{
|
62
|
+
public:
|
63
|
+
float x;
|
64
|
+
float y;
|
65
|
+
float z;
|
66
|
+
};
|
58
67
|
|
68
|
+
|
59
69
|
//頂点バッファー
|
60
70
|
float Vertex[6][3] =
|
61
71
|
{
|
62
72
|
{-0.5, 0.5, 1.0},
|
63
|
-
{-0.5, -0.5, 1.0
|
73
|
+
{-0.5, -0.5, 1.0},
|
64
74
|
{0.5, -0.5, 1.0},
|
65
75
|
|
66
76
|
{-0.5, 0.5, 1.0},
|
@@ -68,59 +78,11 @@
|
|
68
78
|
{0.5, -0.5, 1.0}
|
69
79
|
};
|
70
80
|
|
71
|
-
//スケール行列
|
72
|
-
float scale[16] = {
|
73
|
-
1,0,0,0,
|
74
|
-
0,1,0,0,
|
75
|
-
0,0,1,0,
|
76
|
-
0,0,0,1
|
77
|
-
};
|
78
81
|
|
79
82
|
|
80
|
-
struct position
|
81
|
-
{
|
82
|
-
public:
|
83
|
-
float x;
|
84
|
-
float y;
|
85
|
-
float z;
|
86
|
-
};
|
87
|
-
|
88
|
-
struct position pos;
|
89
|
-
|
90
|
-
//回転行列
|
91
|
-
float r = 1;
|
92
|
-
float rotate[16] = {
|
93
|
-
(pos.x * pos.x + (1 - cos(r)) + cos(r)),
|
94
|
-
(pos.x * pos.y + (1 - cos(r)) + pos.z * sin(r))
|
95
|
-
,(pos.x * pos.z + (1 - cos(r)) - pos.y * sin(r)),0,
|
96
|
-
|
97
|
-
(pos.x * pos.x + (1 - cos(r)) + sin(r)),
|
98
|
-
(pos.y * pos.y + (1 - cos(r)) + cos(r)),
|
99
|
-
(pos.y * pos.z + (1 - cos(r)) + pos.x * sin(r)),0,
|
100
|
-
|
101
|
-
(pos.x * pos.z + (1 - cos(r)) - pos.z * sin(r)),
|
102
|
-
(pos.y * pos.z + (1 - cos(r)) - pos.x * sin(r)),
|
103
|
-
(pos.z * pos.z + (1 - cos(r)) + cos(r)),0,
|
104
|
-
};
|
105
|
-
|
106
|
-
|
107
|
-
//平行移動
|
108
|
-
float mx = 0;
|
109
|
-
float my = 0;
|
110
|
-
float mz = 0;
|
111
|
-
|
112
|
-
float move[16] =
|
113
|
-
{
|
114
|
-
1,0,0,mx,
|
115
|
-
0,1,0,my,
|
116
|
-
0,0,1,mz,
|
117
|
-
0,0,0,1,
|
118
|
-
};
|
119
|
-
|
120
|
-
|
121
83
|
//透視投影変換行列を作る
|
122
84
|
void create_matri_mp(float top, float bottom, float left, float right,
|
123
|
-
|
85
|
+
float near, float far, float result[16])
|
124
86
|
{
|
125
87
|
result[0] = (2 * near) / (right - left);
|
126
88
|
result[5] = (2 * near) / (top - bottom);
|
@@ -138,9 +100,9 @@
|
|
138
100
|
}
|
139
101
|
|
140
102
|
//行列を表示
|
141
|
-
void print_matrix(const char* str,float mp[4][4])
|
103
|
+
void print_matrix(const char* str, float mp[4][4])
|
142
104
|
{
|
143
|
-
printf("name: %s\n",str);
|
105
|
+
printf("name: %s\n", str);
|
144
106
|
for (int i = 0; i < 4; i++)
|
145
107
|
{
|
146
108
|
for (int j = 0; j < 4; j++)
|
@@ -161,7 +123,7 @@
|
|
161
123
|
result[1] = (a[1] * b[0]) + (a[5] * b[1]) + (a[9] * b[2]) + (a[13] * b[3]);
|
162
124
|
|
163
125
|
result[2] = (a[2] * b[0]) + (a[6] * b[1]) + (a[10] * b[2]) + (a[14] * b[3]);
|
164
|
-
|
126
|
+
|
165
127
|
result[3] = (a[3] * b[0]) + (a[7] * b[1]) + (a[11] * b[2]) + (a[15] * b[3]);
|
166
128
|
|
167
129
|
/////////
|
@@ -184,7 +146,7 @@
|
|
184
146
|
result[11] = (a[3] * b[8]) + (a[7] * b[9]) + (a[11] * b[10]) + (a[15] * b[11]);
|
185
147
|
|
186
148
|
/////////
|
187
|
-
|
149
|
+
|
188
150
|
result[12] = (a[0] * b[12]) + (a[4] * b[13]) + (a[8] * b[14]) + (a[12] * b[15]);
|
189
151
|
|
190
152
|
result[13] = (a[1] * b[12]) + (a[5] * b[13]) + (a[9] * b[14]) + (a[13] * b[15]);
|
@@ -196,16 +158,8 @@
|
|
196
158
|
|
197
159
|
}
|
198
160
|
|
199
|
-
void mul_vec3_matrix(float m[16],float v[3],float r[3])
|
161
|
+
void mul_vec3_matrix(float m[16], float v[3], float r[3])
|
200
162
|
{
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
163
|
printf("\n\n");
|
210
164
|
for (int j = 0; j < 3; j++)
|
211
165
|
{
|
@@ -235,24 +189,75 @@
|
|
235
189
|
|
236
190
|
int main()
|
237
191
|
{
|
238
|
-
create_matri_mp(1.0f,-1.0f,-1.0f,1.0f,1.0,10.f,mp);
|
192
|
+
create_matri_mp(1.0f, -1.0f, -1.0f, 1.0f, 1.0, 10.f, mp);//透視射形変換行列mp
|
239
193
|
|
240
194
|
|
195
|
+
//回転行列
|
196
|
+
struct position pos;
|
197
|
+
pos.x = 1;
|
198
|
+
pos.y = 0;
|
199
|
+
pos.z = 0;
|
241
200
|
|
201
|
+
float r = 1;
|
202
|
+
float rotate[16] = {
|
203
|
+
|
204
|
+
(pos.x * pos.x + (1 - cos(r)) + cos(r)),
|
205
|
+
(pos.x * pos.y + (1 - cos(r)) + pos.z * sin(r))
|
206
|
+
,(pos.x * pos.z + (1 - cos(r)) - pos.y * sin(r)),
|
207
|
+
0,
|
208
|
+
|
209
|
+
(pos.x * pos.x + (1 - cos(r)) + sin(r)),
|
210
|
+
(pos.y * pos.y + (1 - cos(r)) + cos(r)),
|
211
|
+
(pos.y * pos.z + (1 - cos(r)) + pos.x * sin(r)),
|
212
|
+
0,
|
213
|
+
|
214
|
+
(pos.x * pos.z + (1 - cos(r)) - pos.z * sin(r)),
|
215
|
+
(pos.y * pos.z + (1 - cos(r)) - pos.x * sin(r)),
|
216
|
+
(pos.z * pos.z + (1 - cos(r)) + cos(r)),
|
217
|
+
0,
|
218
|
+
|
219
|
+
};
|
220
|
+
|
221
|
+
//平行移動
|
222
|
+
struct position p;
|
223
|
+
p.x = 0;
|
224
|
+
p.y = 0;
|
225
|
+
p.z = 0;
|
226
|
+
|
227
|
+
float move[16] =
|
228
|
+
{
|
229
|
+
1,0,0,p.x,
|
230
|
+
0,1,0,p.y,
|
231
|
+
0,0,1,p.z,
|
232
|
+
0,0,0,1,
|
233
|
+
};
|
234
|
+
|
235
|
+
//スケール行列
|
236
|
+
float scale[16] = {
|
237
|
+
1,0,0,0,
|
238
|
+
0,1,0,0,
|
239
|
+
0,0,1,0,
|
240
|
+
0,0,0,1
|
241
|
+
};
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
242
247
|
float t[16];
|
243
|
-
mul(rotate,move,t);
|
248
|
+
mul(rotate, move, t);
|
244
|
-
|
249
|
+
// print_(t);
|
245
250
|
|
246
251
|
|
247
252
|
float t2[16];//M
|
248
253
|
mul(scale, t, t2);
|
249
|
-
|
254
|
+
// print_(t2);
|
250
255
|
|
251
|
-
for (int i = 0; i < 6; i++)
|
256
|
+
for (int i = 0; i < 6; i++)
|
252
257
|
{
|
253
258
|
float t3[16];
|
254
259
|
mul(Vertex[i], t2, t3);
|
255
|
-
|
260
|
+
// print_(t2);
|
256
261
|
|
257
262
|
|
258
263
|
float t4[16];
|
@@ -262,6 +267,6 @@
|
|
262
267
|
|
263
268
|
|
264
269
|
|
265
|
-
|
270
|
+
return 0;
|
266
271
|
}
|
267
272
|
```
|
4
文章とタイトルを編集
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
GLSLで画面描画に使う
|
1
|
+
GLSLで画面描画に使う行列を上手く設定できない
|
body
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
シェーダーで行う計算をCPUで普通に計算するテストコードを実装したいのですが予測通り最後**で3次元目がよくわからない値**に変わっているため
|
1
|
+
シェーダーで行う計算をCPUで普通に計算するテストコードを実装したいのですが予測通り最後**で3次元目がよくわからない値**に変わっているため画面に表示されない等の不具合が発生しているということを突き止めたのですがこれはなぜこんな値になっているのでしょうか?
|
2
|
-
画面に表示されない等の不具合が発生しているということを突き止めたのですがこれはなぜこんな値になっているのでしょうか?
|
3
2
|
|
4
|
-
最後の行列の値の設定関数**create_matri_mp();**関数ですがこれが悪いのでしょか?数式は変更できないため行列計算が間違えているのでしょうか?両方確認しましたがどれが間違えているのかどうしてもわかりません。また本来来るべき値とは1.0なのでしょうか?
|
5
3
|
|
6
|
-
教えてくれますでしょうか?
|
7
4
|
|
5
|
+
透視変換行列並びにスケール、回転、平行移動の行列は正しいのでしょうか?調べましたが行列コード以外間違えているとはありえないと思うのですが教えてくれますでしょうか?
|
8
6
|
|
9
7
|
|
8
|
+
|
10
9
|
下記サイトの163ページの透視射形変換行列の数式を移しました。
|
11
10
|
参考サイト: https://tokoik.github.io/GLFWdraft.pdf
|
12
11
|
|
@@ -14,7 +13,7 @@
|
|
14
13
|
|
15
14
|
|
16
15
|
|
17
|
-

|
18
17
|
|
19
18
|
```GLSL
|
20
19
|
#version 400
|
@@ -54,27 +53,27 @@
|
|
54
53
|
#include "stdio.h"
|
55
54
|
#include <iostream>
|
56
55
|
|
57
|
-
float mp[
|
56
|
+
float mp[16];//透視射形行列
|
58
57
|
|
59
58
|
|
60
59
|
//頂点バッファー
|
61
60
|
float Vertex[6][3] =
|
62
61
|
{
|
63
62
|
{-0.5, 0.5, 1.0},
|
64
|
-
{-0.5, -0.5, 1.0},
|
63
|
+
{-0.5, -0.5, 1.0 },
|
65
64
|
{0.5, -0.5, 1.0},
|
66
65
|
|
67
66
|
{-0.5, 0.5, 1.0},
|
68
|
-
{0.5, 0.5, 1.0},
|
67
|
+
{0.5, 0.5, 1.0 },
|
69
68
|
{0.5, -0.5, 1.0}
|
70
69
|
};
|
71
70
|
|
72
71
|
//スケール行列
|
73
|
-
float scale[
|
72
|
+
float scale[16] = {
|
74
|
-
|
73
|
+
1,0,0,0,
|
75
|
-
|
74
|
+
0,1,0,0,
|
76
|
-
|
75
|
+
0,0,1,0,
|
77
|
-
|
76
|
+
0,0,0,1
|
78
77
|
};
|
79
78
|
|
80
79
|
|
@@ -90,7 +89,7 @@
|
|
90
89
|
|
91
90
|
//回転行列
|
92
91
|
float r = 1;
|
93
|
-
float rotate[
|
92
|
+
float rotate[16] = {
|
94
93
|
(pos.x * pos.x + (1 - cos(r)) + cos(r)),
|
95
94
|
(pos.x * pos.y + (1 - cos(r)) + pos.z * sin(r))
|
96
95
|
,(pos.x * pos.z + (1 - cos(r)) - pos.y * sin(r)),0,
|
@@ -110,7 +109,7 @@
|
|
110
109
|
float my = 0;
|
111
110
|
float mz = 0;
|
112
111
|
|
113
|
-
float move[
|
112
|
+
float move[16] =
|
114
113
|
{
|
115
114
|
1,0,0,mx,
|
116
115
|
0,1,0,my,
|
@@ -118,36 +117,26 @@
|
|
118
117
|
0,0,0,1,
|
119
118
|
};
|
120
119
|
|
121
|
-
|
120
|
+
|
122
121
|
//透視投影変換行列を作る
|
123
122
|
void create_matri_mp(float top, float bottom, float left, float right,
|
124
|
-
float near, float far, float result[
|
123
|
+
float near, float far, float result[16])
|
125
124
|
{
|
126
|
-
result[0]
|
125
|
+
result[0] = (2 * near) / (right - left);
|
127
|
-
result[0][1] = 0;
|
128
|
-
result[
|
126
|
+
result[5] = (2 * near) / (top - bottom);
|
129
|
-
result[0][3] = 0;
|
130
127
|
|
131
|
-
result[1][0] = 0;
|
132
|
-
result[
|
128
|
+
result[8] = (right + left) / (right - left);
|
133
|
-
result[1][2] = (top + bottom) / (top - bottom);
|
134
|
-
result[1][3] = 0;
|
135
129
|
|
136
|
-
result[2][0] = 0;
|
137
|
-
result[2][1] = 0;
|
138
|
-
result[
|
130
|
+
result[9] = (top + bottom) / (top - bottom);
|
139
|
-
result[2][3] = -(2 * far + near) / (far - near);
|
140
131
|
|
141
|
-
result[3][0] = 0;
|
142
|
-
result[3][1] = 0;
|
143
|
-
result[
|
132
|
+
result[10] = (far + near) / (far - near);
|
144
|
-
result[3][3] = 0;
|
145
|
-
}
|
146
133
|
|
134
|
+
result[11] = -1;
|
135
|
+
result[14] = (2 * far * near) / (far - near);
|
147
136
|
|
148
137
|
|
138
|
+
}
|
149
139
|
|
150
|
-
|
151
140
|
//行列を表示
|
152
141
|
void print_matrix(const char* str,float mp[4][4])
|
153
142
|
{
|
@@ -165,113 +154,114 @@
|
|
165
154
|
|
166
155
|
//行列掛け算
|
167
156
|
//void mul(float a[4][4], float b[4][4])
|
168
|
-
void mul(float a[
|
157
|
+
void mul(float a[16], float b[16], float result[16])
|
169
158
|
{
|
170
|
-
|
159
|
+
result[0] = (a[0] * b[0]) + (a[4] * b[1]) + (a[8] * b[2]) + (a[12] * b[3]);
|
171
160
|
|
172
|
-
result[
|
161
|
+
result[1] = (a[1] * b[0]) + (a[5] * b[1]) + (a[9] * b[2]) + (a[13] * b[3]);
|
173
162
|
|
174
|
-
result[
|
163
|
+
result[2] = (a[2] * b[0]) + (a[6] * b[1]) + (a[10] * b[2]) + (a[14] * b[3]);
|
164
|
+
|
165
|
+
result[3] = (a[3] * b[0]) + (a[7] * b[1]) + (a[11] * b[2]) + (a[15] * b[3]);
|
175
166
|
|
176
|
-
|
167
|
+
/////////
|
177
168
|
|
178
|
-
result[
|
169
|
+
result[4] = (a[0] * b[4]) + (a[4] * b[5]) + (a[8] * b[6]) + (a[12] * b[7]);
|
179
170
|
|
171
|
+
result[5] = (a[1] * b[4]) + (a[5] * b[5]) + (a[9] * b[6]) + (a[13] * b[7]);
|
180
172
|
|
181
|
-
result[
|
173
|
+
result[6] = (a[2] * b[4]) + (a[6] * b[5]) + (a[10] * b[6]) + (a[14] * b[7]);
|
182
174
|
|
183
|
-
result[
|
175
|
+
result[7] = (a[3] * b[4]) + (a[7] * b[5]) + (a[11] * b[6]) + (a[15] * b[7]);
|
184
176
|
|
177
|
+
/////////
|
185
|
-
result[
|
178
|
+
result[8] = (a[0] * b[8]) + (a[4] * b[9]) + (a[8] * b[10]) + (a[12] * b[11]);
|
186
179
|
|
187
|
-
result[
|
180
|
+
result[9] = (a[1] * b[8]) + (a[5] * b[9]) + (a[9] * b[10]) + (a[13] * b[11]);
|
188
181
|
|
182
|
+
result[10] = (a[2] * b[8]) + (a[6] * b[9]) + (a[10] * b[10]) + (a[14] * b[11]);
|
189
183
|
|
190
|
-
result[
|
184
|
+
result[11] = (a[3] * b[8]) + (a[7] * b[9]) + (a[11] * b[10]) + (a[15] * b[11]);
|
191
185
|
|
186
|
+
/////////
|
187
|
+
|
192
|
-
result[
|
188
|
+
result[12] = (a[0] * b[12]) + (a[4] * b[13]) + (a[8] * b[14]) + (a[12] * b[15]);
|
193
189
|
|
194
|
-
result[
|
190
|
+
result[13] = (a[1] * b[12]) + (a[5] * b[13]) + (a[9] * b[14]) + (a[13] * b[15]);
|
195
191
|
|
192
|
+
result[14] = (a[2] * b[12]) + (a[6] * b[13]) + (a[10] * b[14]) + (a[14] * b[15]);
|
196
193
|
|
197
|
-
result[
|
194
|
+
result[15] = (a[3] * b[12]) + (a[7] * b[13]) + (a[11] * b[14]) + (a[15] * b[15]);
|
198
195
|
|
199
|
-
result[3][0] = (a[3][0] * b[0][0]) + (a[3][1] * b[1][0]) + (a[3][2] * b[2][0]) + (a[3][3] * b[3][0]);
|
200
196
|
|
201
|
-
|
197
|
+
}
|
202
198
|
|
203
|
-
|
199
|
+
void mul_vec3_matrix(float m[16],float v[3],float r[3])
|
200
|
+
{
|
204
201
|
|
205
|
-
result[3][3] = (a[3][0] * b[0][3]) + (a[3][1] * b[1][3]) + (a[3][2] * b[2][3]) + (a[3][3] * b[3][3]);
|
206
202
|
|
203
|
+
|
207
204
|
|
208
205
|
|
209
|
-
if (true)
|
210
|
-
{
|
211
|
-
for (int i = 0; i < 4; i++)
|
212
|
-
{
|
213
|
-
for (int j = 0; j < 4; j++)
|
214
|
-
{
|
215
|
-
printf("[ %.2f ] ", result[i][j]);
|
216
|
-
}
|
217
206
|
|
218
|
-
printf("\n");
|
219
|
-
}
|
220
|
-
}
|
221
|
-
|
222
|
-
}
|
223
207
|
|
224
|
-
void mul_vec3_matrix(float m[4][4],float v[3],float r[3])
|
225
|
-
{
|
226
|
-
r[0] = (m[0][0] * v[0]) + (m[0][1] * v[1]) + (m[0][2] * v[2]);
|
227
208
|
|
228
|
-
r[1] = (m[1][0] * v[0]) + (m[1][1] * v[1]) + (m[1][2] * v[2]);
|
229
|
-
|
230
|
-
r[2] = (m[2][0] * v[0]) + (m[2][1] * v[1]) + (m[2][2] * v[2]);
|
231
|
-
|
232
|
-
|
233
209
|
printf("\n\n");
|
234
210
|
for (int j = 0; j < 3; j++)
|
235
211
|
{
|
236
212
|
printf("[ %.2f ] ", r[j]);
|
237
213
|
}
|
238
214
|
printf("\n");
|
239
|
-
|
240
215
|
}
|
241
216
|
|
242
217
|
|
243
218
|
|
219
|
+
void print_(float tmp[16])
|
220
|
+
{
|
221
|
+
for (int i = 0; i < 16; i++)
|
222
|
+
{
|
223
|
+
if (i % 4 == 0)
|
224
|
+
{
|
225
|
+
printf("\n");
|
226
|
+
}
|
244
227
|
|
228
|
+
printf(" [ %.2f ] ", tmp[i]);
|
229
|
+
}
|
245
230
|
|
231
|
+
printf("\n\n");
|
246
232
|
|
233
|
+
}
|
234
|
+
|
235
|
+
|
247
236
|
int main()
|
248
237
|
{
|
249
238
|
create_matri_mp(1.0f,-1.0f,-1.0f,1.0f,1.0,10.f,mp);
|
250
|
-
// print_matrix("透視射形",mp);
|
251
239
|
|
252
240
|
|
253
|
-
|
254
|
-
float t[4][4];
|
255
|
-
mul(rotate,move,t);
|
256
|
-
printf("\n\n\n\n\n");
|
257
241
|
|
242
|
+
float t[16];
|
243
|
+
mul(rotate,move,t);
|
244
|
+
// print_(t);
|
258
245
|
|
259
246
|
|
260
|
-
float t2[
|
247
|
+
float t2[16];//M
|
261
248
|
mul(scale, t, t2);
|
249
|
+
// print_(t2);
|
262
250
|
|
251
|
+
for (int i = 0; i < 6; i++)
|
252
|
+
{
|
253
|
+
float t3[16];
|
254
|
+
mul(Vertex[i], t2, t3);
|
255
|
+
// print_(t2);
|
263
256
|
|
264
|
-
float t3[4];
|
265
|
-
mul_vec3_matrix(t2, Vertex[0], t3);
|
266
|
-
float t4[4];
|
267
257
|
|
258
|
+
float t4[16];
|
259
|
+
mul(mp, t2, t4);
|
260
|
+
print_(t4);
|
261
|
+
}
|
268
262
|
|
269
|
-
mul_vec3_matrix(mp,t3,t4);
|
270
263
|
|
271
264
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
265
|
return 0;
|
276
266
|
}
|
277
267
|
```
|
3
タイトルを編集しました。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
GLSLで画面描画に使う行列を
|
1
|
+
GLSLで画面描画に使う透視投影変換行列を上手く設定できないZの値がマイナスになってしまう
|
body
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
画面に表示されない等の不具合が発生しているということを突き止めたのですがこれはなぜこんな値になっているのでしょうか?
|
3
3
|
|
4
4
|
最後の行列の値の設定関数**create_matri_mp();**関数ですがこれが悪いのでしょか?数式は変更できないため行列計算が間違えているのでしょうか?両方確認しましたがどれが間違えているのかどうしてもわかりません。また本来来るべき値とは1.0なのでしょうか?
|
5
|
+
|
5
6
|
教えてくれますでしょうか?
|
6
7
|
|
7
8
|
|
2
文章を編集しました参考サイトを追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,6 +5,14 @@
|
|
5
5
|
教えてくれますでしょうか?
|
6
6
|
|
7
7
|
|
8
|
+
|
9
|
+
下記サイトの163ページの透視射形変換行列の数式を移しました。
|
10
|
+
参考サイト: https://tokoik.github.io/GLFWdraft.pdf
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
8
16
|

|
9
17
|
|
10
18
|
```GLSL
|
1
文章を編集しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
シェーダーで行う計算をCPUで普通に計算するテストコードを実装したいのですが予測通り最後**で3次元目がよくわからない値**に変わっているため
|
2
2
|
画面に表示されない等の不具合が発生しているということを突き止めたのですがこれはなぜこんな値になっているのでしょうか?
|
3
3
|
|
4
|
-
最後の行列の値の設定関数**create_matri_mp();**関数ですがこれが悪いのでしょか?数式は変更できないため行列計算が間違えているのでしょうか?両方確認しましたがどれが間違えているのかどうしてもわかりません。
|
4
|
+
最後の行列の値の設定関数**create_matri_mp();**関数ですがこれが悪いのでしょか?数式は変更できないため行列計算が間違えているのでしょうか?両方確認しましたがどれが間違えているのかどうしてもわかりません。また本来来るべき値とは1.0なのでしょうか?
|
5
|
+
教えてくれますでしょうか?
|
5
6
|
|
6
7
|
|
7
8
|

|