質問編集履歴

3

文章を編集しました。

2020/09/10 10:11

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,26 +1,464 @@
1
- 提示コードのメイン関数部です。画面サイズ(ピクセル)(640,400.1)のワールド座標で頂点を設定してその頂点を画面である正規化座標(1.0 ~ -1.0)に変換画面の真ん中四角い正方形を描画たいですがどうすればいいのでしょうか?正しい計算をしいれば(-0.5,0.5,1)になるはずなのですがなん。画面サイズとはピクセルサイズです。ま座標系は3Dですが今回2Dの物を表示させたいです。
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
- 質問 **ワールド座標から正化座標変換する計算式を知りたいです
10
-
11
- **
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
- ```ここに言語を入力
1
+ 質問1、提示コードのメイン関数部です。 画面サイズ(640,400)ピクセルです。OpenGLなで左手座標す。こで自分は画面サイズ上での頂点座標作成しました。正規化座標である(+1 ~ -1) し画面に描画させたいです。提示コード座標はすべて0.5と-0.5になるはずです。つま正方形を描画させたいのですが上手くいきませんこれどうしいのしょうか?
2
+
3
+
4
+
5
+ 質問2、またシェーダーで4 x (4x4)の行列で(3x3)と3までの値しか使っていないのですがこれは大丈夫なのでしょうか?
6
+
7
+
8
+
9
+ 質問3、この処理をコンソール出力(新プロジェクト)で確認したあとシェーダー乗っけたいですがどうするのが適切なのでしょうか?
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+ ![イメージ説明](64eaf395a821f39415bcf1b169cc2c59.png)
20
+
21
+
22
+
23
+ ```cpp
24
+
25
+ #include "Game.hpp"
26
+
27
+ #include <iostream>
28
+
29
+
30
+
31
+
32
+
33
+ //コンストラクタ
34
+
35
+ Game::Game()
36
+
37
+ {
38
+
39
+ mIsRunLoop = true;
40
+
41
+
42
+
43
+ }
44
+
45
+
46
+
47
+ bool Game::RunLoop()
48
+
49
+ {
50
+
51
+ if (mIsRunLoop == true)
52
+
53
+ {
54
+
55
+ Update();
56
+
57
+ GenerateOutput();
58
+
59
+
60
+
61
+ }
62
+
63
+ else {
64
+
65
+ return false;
66
+
67
+ }
68
+
69
+ return true;
70
+
71
+
72
+
73
+ }
74
+
75
+
76
+
77
+
78
+
79
+ //シェーダー関係のログを取得
80
+
81
+ void Game::GetShader_Log(GLuint shader_type, GLuint Log_type)
82
+
83
+ {
84
+
85
+ GLint bufferSize = 0;
86
+
87
+ GLchar* infoLog = nullptr;
88
+
89
+
90
+
91
+ //成功したかどうか?
92
+
93
+ glGetShaderiv(shader_type, Log_type, &bufferSize);
94
+
95
+
96
+
97
+
98
+
99
+ //ログの長さを取得する
100
+
101
+ glGetShaderiv(shader_type, GL_INFO_LOG_LENGTH, &bufferSize);
102
+
103
+
104
+
105
+ infoLog = (GLchar*)malloc(bufferSize);
106
+
107
+
108
+
109
+ if (infoLog != NULL)
110
+
111
+ {
112
+
113
+ GLsizei length;//ログの長さ
114
+
115
+ glGetShaderInfoLog(shader_type, bufferSize, &length, infoLog);
116
+
117
+
118
+
119
+ if (length > 1)//null文字を含むため一文字以上の場合ログ出力
120
+
121
+ {
122
+
123
+ fprintf(stderr, "InfoLog: %s\n\n", infoLog);
124
+
125
+
126
+
127
+ }
128
+
129
+ // printf("ああああ\n");
130
+
131
+
132
+
133
+ free(infoLog);
134
+
135
+ infoLog = NULL;
136
+
137
+ // printf("いいいいいい\n");
138
+
139
+
140
+
141
+
142
+
143
+ }
144
+
145
+
146
+
147
+ //return true;
148
+
149
+ }
150
+
151
+
152
+
153
+ void Game::Shader()
154
+
155
+ {
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+ program = glCreateProgram();
166
+
167
+ GLuint out_vert = glCreateShader(GL_VERTEX_SHADER);
168
+
169
+ GLuint out_frag = glCreateShader(GL_FRAGMENT_SHADER);
170
+
171
+
172
+
173
+
174
+
175
+ std::string fileName = "Basic.vert";
176
+
177
+ std::ifstream shaderfile(fileName);
178
+
179
+ if (shaderfile.is_open())
180
+
181
+ {
182
+
183
+ std::stringstream sstream;
184
+
185
+ sstream << shaderfile.rdbuf();
186
+
187
+ std::string str = sstream.str();
188
+
189
+ const char* cc = str.c_str();
190
+
191
+
192
+
193
+ out_vert = glCreateShader(GL_VERTEX_SHADER);
194
+
195
+ glShaderSource(out_vert, 1, &cc, nullptr);
196
+
197
+ glCompileShader(out_vert);
198
+
199
+ printf("Basic.vert ファイル読み込み\n");
200
+
201
+
202
+
203
+ GetShader_Log(out_vert, GL_COMPILE_STATUS);
204
+
205
+ glAttachShader(program, out_vert);
206
+
207
+ shaderfile.close();
208
+
209
+
210
+
211
+ }
212
+
213
+ else {
214
+
215
+ shaderfile.close();
216
+
217
+ printf("Basic.vert読み込みエラー");
218
+
219
+ }
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+ fileName = "Basic.frag";
228
+
229
+ shaderfile.open(fileName);
230
+
231
+
232
+
233
+ if (shaderfile.is_open())
234
+
235
+ {
236
+
237
+
238
+
239
+ std::stringstream sstream;
240
+
241
+ sstream << shaderfile.rdbuf();
242
+
243
+ std::string str = sstream.str();
244
+
245
+ const char* cc = str.c_str();
246
+
247
+
248
+
249
+ out_frag = glCreateShader(GL_FRAGMENT_SHADER);
250
+
251
+ glShaderSource(out_frag, 1, &cc, nullptr);
252
+
253
+ glCompileShader(out_frag);
254
+
255
+ GetShader_Log(out_frag, GL_COMPILE_STATUS);
256
+
257
+ glAttachShader(program, out_frag);
258
+
259
+ shaderfile.close();
260
+
261
+
262
+
263
+ printf("Basic.frag ファイル読み込み\n");
264
+
265
+ }
266
+
267
+ else {
268
+
269
+ shaderfile.close();
270
+
271
+ printf("Basic.frag読み込みエラー");
272
+
273
+ }
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+ //シェーダーに値を設定
282
+
283
+ /////////////////////////////////////////////////////////////////////////
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+ //カラーインデックス
292
+
293
+ struct Color_idx {
294
+
295
+ float R;
296
+
297
+ float G;
298
+
299
+ float B;
300
+
301
+
302
+
303
+ float A;//不透明度
304
+
305
+ };
306
+
307
+
308
+
309
+ float idx[4] = { 1.0,1.0,0.0 , 1.0};
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+ //フラグメントシェーダー
318
+
319
+ glBindAttribLocation(program, 0, "idx");
320
+
321
+
322
+
323
+
324
+
325
+ //頂点シェーダー
326
+
327
+ //glBindAttribLocation(program, 0, "Vertex");
328
+
329
+ //void glUniform1fv(GLint location, GLsizei count, const GLfloat* value);
330
+
331
+ glUniform1fv(0, 18, Vertex);
332
+
333
+ glUniformMatrix3fv(0, 18, GL_TRUE, view);
334
+
335
+
336
+
337
+ //glUniformMatrix3fv(1, 9 ,GL_TRUE,view);
338
+
339
+
340
+
341
+
342
+
343
+ glLinkProgram(program);
344
+
345
+
346
+
347
+ //Link_log(program);
348
+
349
+ ///////////////////////////////////////////////////////////////////////////
350
+
351
+ glDeleteShader(out_frag);
352
+
353
+ glDeleteShader(out_vert);
354
+
355
+ }
356
+
357
+
358
+
359
+
360
+
361
+ //////////////////////初期化
362
+
363
+ bool Game::Initialization()
364
+
365
+ {
366
+
367
+ Shader();
368
+
369
+
370
+
371
+
372
+
373
+ glGenVertexArrays(1, &vbo);
374
+
375
+ glBindVertexArray(vbo);
376
+
377
+ glGenBuffers(1,&vbo);
378
+
379
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
380
+
381
+ glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(float) * 3, Vertex, GL_STATIC_DRAW);
382
+
383
+ glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
384
+
385
+ glEnableVertexAttribArray(0);
386
+
387
+ glBindVertexArray(vbo);
388
+
389
+
390
+
391
+
392
+
393
+ mIsRunLoop = true;
394
+
395
+ return mIsRunLoop;
396
+
397
+ }
398
+
399
+
400
+
401
+ //アップデート
402
+
403
+ void Game::Update()
404
+
405
+ {
406
+
407
+
408
+
409
+ }
410
+
411
+
412
+
413
+ //描画アップデート
414
+
415
+ void Game::GenerateOutput()
416
+
417
+ {
418
+
419
+
420
+
421
+ glUseProgram(program);
422
+
423
+
424
+
425
+ glDrawArrays(GL_POLYGON, 0, 6);
426
+
427
+
428
+
429
+ glViewport(0,0,640,300);
430
+
431
+
432
+
433
+ }
434
+
435
+
436
+
437
+ ```
438
+
439
+
440
+
441
+
442
+
443
+ ```hpp
444
+
445
+ #ifndef ___GMAE_H_
446
+
447
+ #define ___GMAE_H_
448
+
449
+
450
+
451
+ #define WIDTH 640
452
+
453
+ #define HEIGHT 400
454
+
455
+
20
456
 
21
457
  #include "stdio.h"
22
458
 
23
- #include "math.h"
459
+ #include <fstream>
460
+
461
+ #include <sstream>
24
462
 
25
463
  #include <iostream>
26
464
 
@@ -30,115 +468,131 @@
30
468
 
31
469
 
32
470
 
33
-
471
+ #include "GLEW/include/GL/glew.h"
472
+
473
+
474
+
34
-
475
+ #include "gl/GL.h"
476
+
477
+ #include "GLFW/include/GLFW/glfw3.h"
478
+
479
+ #include "Vector.hpp"
480
+
481
+ //#include "Vector.hpp"
482
+
483
+
484
+
485
+
486
+
487
+
488
+
35
- class Position
489
+ class Game
36
490
 
37
491
  {
38
492
 
39
493
  public:
40
494
 
41
- float x;
42
-
43
- float y;
44
-
45
- float z;
46
-
47
-
48
-
49
- public:
50
-
51
- Position(float xx = 0, float yy = 0, float zz = 0)
52
-
53
- {
54
-
55
- x = xx;
56
-
57
- y = yy;
58
-
59
- z = zz;
60
-
61
- }
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
- //掛け算
70
-
71
- Position operator* (Position pos)
72
-
73
- {
74
-
75
- this->x = pos.x * this->x;
76
-
77
- this->y = pos.y * this->y;
78
-
79
- this->z = pos.z * this->z;
80
-
81
-
82
-
83
-
84
-
85
- return *this;
86
-
87
- }
88
-
89
-
90
-
91
- //掛け算
92
-
93
- Position operator- (Position pos)
94
-
95
- {
96
-
97
- this->x = this->x - pos.x;
98
-
99
- this->y = this->y - pos.y;
100
-
101
- this->z = this->z - pos.z;
102
-
103
-
104
-
105
-
106
-
107
- return *this;
108
-
109
- }
110
-
111
-
112
-
113
- static Position Cross(Position a, Position b)
114
-
115
- {
116
-
117
- Position temp;
118
-
119
- temp.x = a.y * b.z - a.z * b.y;
120
-
121
- temp.y = a.z * b.x - a.x * b.z;
122
-
123
- temp.z = a.x * b.y - a.y * b.x;
124
-
125
- return temp;
126
-
127
- }
128
-
129
-
130
-
131
-
132
-
133
- static float Dot(Position a, Position b)
134
-
135
- {
136
-
137
- float t = (a.x * a.x) + (a.y * a.y);
138
-
139
- return t;
140
-
141
- }
495
+ Vector3 cv;
496
+
497
+
498
+
499
+ Game();
500
+
501
+
502
+
503
+ bool Initialization();
504
+
505
+
506
+
507
+ bool RunLoop();
508
+
509
+
510
+
511
+ void Update();
512
+
513
+ void GenerateOutput();
514
+
515
+
516
+
517
+
518
+
519
+ private:
520
+
521
+ bool mIsRunLoop;//メインループ
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+ //ビュー行列
532
+
533
+ const GLfloat view[9] = {
534
+
535
+ (2.0f / 640.0f),0.0f,0.0f,
536
+
537
+ 0.0f,(2.0f / 400.0f),0.0f,
538
+
539
+ 0.0f,0.0f,1.0f
540
+
541
+ };
542
+
543
+
544
+
545
+
546
+
547
+ //頂点バッファー
548
+
549
+ const GLfloat Vertex[18] =
550
+
551
+ {
552
+
553
+
554
+
555
+ -160, +100, 1.0,
556
+
557
+ -160, -100, 1.0,
558
+
559
+ +160, -100, 1.0,
560
+
561
+
562
+
563
+ -160, +100, 1.0,
564
+
565
+ +160, +100, 1.0,
566
+
567
+ +160, -100, 1.0
568
+
569
+ };
570
+
571
+
572
+
573
+
574
+
575
+ GLuint vbo = 0;//頂点配列バッファオブジェクト名
576
+
577
+ GLuint vao = 0;//頂点バッファオブジェクト名
578
+
579
+
580
+
581
+
582
+
583
+ GLuint program = 0;
584
+
585
+ void Shader();//シェーダ読み込み
586
+
587
+ void Compile_log(GLuint Shader);//シェーダーコンパイルログ
588
+
589
+ void Link_log(GLuint Shader);//シェーダーリンクログ
590
+
591
+
592
+
593
+ void GetShader_Log(GLuint shader_type,GLuint Log_type);
594
+
595
+
142
596
 
143
597
  };
144
598
 
@@ -148,608 +602,72 @@
148
602
 
149
603
 
150
604
 
151
- class Matrix4
152
-
153
- {
154
-
155
- public:
605
+ #endif
156
-
157
- float x;
606
+
158
-
159
- float y;
607
+
160
-
161
- float z;
162
-
163
-
164
-
165
- float w;
166
-
167
-
168
-
169
-
170
-
171
- //コンストラクタ
172
-
173
- Matrix4()
174
-
175
- {
176
-
177
- x = 0.0;
178
-
179
- y = 0.0;
180
-
181
- z = 0.0;
182
-
183
-
184
-
185
- w = 0.0;
186
-
187
- }
188
-
189
-
190
-
191
-
192
-
193
- Matrix4(Position p)
194
-
195
- {
196
-
197
- x = p.x;
198
-
199
- y = p.y;
200
-
201
- z = p.z;
202
-
203
-
204
-
205
- w = 1.0f;
206
-
207
- }
208
-
209
-
210
-
211
- Matrix4(float xx, float yy, float zz, float ww)
212
-
213
- {
214
-
215
- x = xx;
216
-
217
- y = yy;
218
-
219
- z = zz;
220
-
221
-
222
-
223
- w = ww;
224
-
225
- }
226
-
227
-
228
-
229
- Matrix4(float xx, float yy, float zz)
230
-
231
- {
232
-
233
- x = xx;
234
-
235
- y = yy;
236
-
237
- z = zz;
238
-
239
-
240
-
241
- w = 1.0f;
242
-
243
- }
244
-
245
-
246
-
247
-
248
-
249
- //一列と行列を掛け算
250
-
251
- Matrix4 operator * (const Matrix4 &M)const
252
-
253
- {
254
-
255
- Matrix4 t;
256
-
257
- t.x = (x * 1) + (y * 0) + (z * 0) + (w * M.x);
258
-
259
-
260
-
261
- t.y = (x * 0) + (y * 1) + (z * 0) + (w * M.y);
262
-
263
-
264
-
265
- t.z = (x * 0) + (y * 0) + (z * 1) + (w * M.z);
266
-
267
-
268
-
269
- t.w = (x * 0) + (y * 0) + (z * 0) + (w * M.w);
270
-
271
-
272
-
273
- return t;
274
-
275
- }
276
-
277
- };
278
-
279
-
280
-
281
-
282
-
283
- class Matrix3
284
-
285
- {
286
-
287
- public:
288
-
289
-
290
-
291
- float x;
292
-
293
- float y;
294
-
295
- float z;
296
-
297
-
298
-
299
-
300
-
301
-
302
-
303
-
304
-
305
- //コンストラクタ
306
-
307
- Matrix3()
308
-
309
- {
310
-
311
- x = 0.0;
312
-
313
- y = 0.0;
314
-
315
- z = 0.0;
316
-
317
- }
318
-
319
-
320
-
321
-
322
-
323
- Matrix3(Position p)
324
-
325
- {
326
-
327
- this->x = p.x;
328
-
329
- this->y = p.y;
330
-
331
- this->z = p.z;
332
-
333
- }
334
-
335
-
336
-
337
-
338
-
339
-
340
-
341
- Matrix3(float x = 0, float y = 0, float z = 0)
342
-
343
- {
344
-
345
- this->x = x;
346
-
347
- this->y = y;
348
-
349
- this->z = z;
350
-
351
- }
352
-
353
-
354
-
355
-
356
-
357
-
358
-
359
- };
360
-
361
-
362
-
363
-
364
-
365
-
366
-
367
-
368
-
369
- //ベクトルの大きさを出す
370
-
371
- float Vector_scalar(Position p);
372
-
373
- float Vector_scalar(Position p)
374
-
375
- {
376
-
377
- float r = (p.x * p.x) + (p.y * p.y) + (p.z * p.z);
378
-
379
- return r;
380
-
381
- }
382
-
383
-
384
-
385
- //スケール変換
386
-
387
- void Scale_change(float Sx, float Sy, float Sz, float pos_x, float pos_y, float pos_z);
388
-
389
- void Scale_change(float Sx, float Sy, float Sz, float pos_x, float pos_y, float pos_z) {
390
-
391
-
392
-
393
- //Scale行列
394
-
395
- float ScaleMatrix4[4][4] = {
396
-
397
-
398
-
399
- {0,0,0,0},
400
-
401
- {0,0,0,0},
402
-
403
- {0,0,0,0},
404
-
405
- {0,0,0,1},
406
-
407
- };
408
-
409
-
410
-
411
- //行列に大きさを設定
412
-
413
- ScaleMatrix4[0][0] = Sx;
414
-
415
- ScaleMatrix4[1][1] = Sy;
416
-
417
- ScaleMatrix4[2][2] = Sz;
418
-
419
-
420
-
421
- //座標を行列に設定
422
-
423
- float position[4];
424
-
425
- position[0] = pos_x;
426
-
427
- position[1] = pos_y;
428
-
429
- position[2] = pos_z;
430
-
431
- position[3] = 1;
432
-
433
-
434
-
435
-
436
-
437
-
438
-
439
- float t = 0;
440
-
441
-
442
-
443
- t = (position[0] * ScaleMatrix4[0][0]) +
444
-
445
- (position[1] * ScaleMatrix4[0][1]) +
446
-
447
- (position[2] * ScaleMatrix4[0][2]) +
448
-
449
- (position[3] * ScaleMatrix4[0][3]);
450
-
451
- printf("%f\n", t);
452
-
453
-
454
-
455
- t = (position[0] * ScaleMatrix4[1][0]) +
456
-
457
- (position[1] * ScaleMatrix4[1][1]) +
458
-
459
- (position[2] * ScaleMatrix4[1][2]) +
460
-
461
- (position[3] * ScaleMatrix4[1][3]);
462
-
463
- printf("%f\n", t);
464
-
465
-
466
-
467
- t = (position[0] * ScaleMatrix4[2][0]) +
468
-
469
- (position[1] * ScaleMatrix4[2][1]) +
470
-
471
- (position[2] * ScaleMatrix4[2][2]) +
472
-
473
- (position[3] * ScaleMatrix4[2][3]);
474
-
475
- printf("%f\n", t);
476
-
477
-
478
-
479
- t = (position[0] * ScaleMatrix4[3][0]) +
480
-
481
- (position[1] * ScaleMatrix4[3][1]) +
482
-
483
- (position[2] * ScaleMatrix4[3][2]) +
484
-
485
- (position[3] * ScaleMatrix4[3][3]);
486
-
487
- printf("%f\n", t);
488
-
489
- };
490
-
491
-
492
-
493
-
494
-
495
- //三次元回転変換
496
-
497
- class Quaternion
498
-
499
- {
500
-
501
- public:
502
-
503
- float x;
504
-
505
- float y;
506
-
507
- float z;
508
-
509
-
510
-
511
- float w;
512
-
513
-
514
-
515
- public:
516
-
517
-
518
-
519
- Quaternion(float xx = 0, float yy = 0, float zz = 0, float ww = 0)
520
-
521
- {
522
-
523
- x = xx;
524
-
525
- y = yy;
526
-
527
- z = zz;
528
-
529
-
530
-
531
- w = ww;
532
-
533
- }
534
-
535
-
536
-
537
- //今の方向 , 向きたい方向
538
-
539
- void process(Position s, Position p)
540
-
541
- {
542
-
543
- // Position s(1, 1, 0);//今の方向
544
-
545
- // Position p(-1, 1, 0);//新しい方向ベクトル
546
-
547
-
548
-
549
- Position newFacing;//新しい座標に向かうベクトルを計算して正規化
550
-
551
-
552
-
553
- Position t = p - s;
554
-
555
- float len = (float)sqrt(Vector_scalar(t));
556
-
557
-
558
-
559
- newFacing.x = t.x / len;
560
-
561
- newFacing.y = t.y / len;
562
-
563
- newFacing.z = t.z / len;
564
-
565
-
566
-
567
-
568
-
569
- // printf("方向ベクトル x: %f\n", newFacing.x);
570
-
571
- // printf("方向ベクトル y: %f\n", newFacing.y);
572
-
573
- // printf("方向ベクトル z: %f\n\n", newFacing.z);
574
-
575
-
576
-
577
-
578
-
579
- Position pa = Position::Cross(Position(0, 0, 1), newFacing);
580
-
581
- float sp = (float)sqrt(Vector_scalar(pa));
582
-
583
-
584
-
585
- Position a;//回転軸
586
-
587
- a.x = pa.x / sp;
588
-
589
- a.y = pa.y / sp;
590
-
591
- a.z = pa.z / sp;
592
-
593
-
594
-
595
-
596
-
597
- float r = (float)acos(Position::Dot(Position(0, 0, 1), newFacing));
598
-
599
-
600
-
601
- // printf("回転軸 x: %f\n", a.x);
602
-
603
- // printf("回転軸 y: %f\n", a.y);
604
-
605
- // printf("回転軸 z: %f\n\n", a.z);
606
-
607
-
608
-
609
- // printf("回転角 θ: %f\n", r);
610
-
611
-
612
-
613
- Quaternion q;
614
-
615
- q.w = (float)cos(r / 2);
616
-
617
-
618
-
619
- q.x = (float)newFacing.x * (float)cos(r / 2);
620
-
621
- q.y = (float)newFacing.y * (float)sin(r / 2);
622
-
623
- q.z = (float)newFacing.z * (float)sin(r / 2);
624
-
625
-
626
-
627
- //////////////////////////////////////////////////////////
628
-
629
- printf("q w: %f\n", q.w);
630
-
631
- printf("q x: %f\n", q.x);
632
-
633
- printf("q y: %f\n", q.y);
634
-
635
- printf("q z: %f\n", q.z);
636
-
637
- /////////////////////////////////////////////////////////
638
-
639
-
640
-
641
- }
642
-
643
-
644
-
645
- };
646
-
647
-
648
-
649
-
650
-
651
-
652
-
653
-
654
-
655
- ///////////////////////////////////////////////////////////////////////////////////////
656
-
657
- int main()
658
-
659
- {
660
-
661
-
662
-
663
- //ワールド座標
664
-
665
- Matrix3 now[6] =
666
-
667
- {
668
-
669
-
670
-
671
- Matrix3(-160, +100, 1),
672
-
673
-
674
-
675
- Matrix3(-160, -100, 1),
676
-
677
-
678
-
679
- Matrix3(+160, -100, 1),
680
-
681
-
682
-
683
- ///////////////////////////////////
684
-
685
-
686
-
687
- Matrix3(-160, +100, 1),
688
-
689
-
690
-
691
- Matrix3(+160, +100, 1),
692
-
693
-
694
-
695
- Matrix3(+160, -100, 1)
696
-
697
- };
698
-
699
-
700
-
701
- //ビュー行列
702
-
703
- Matrix3 s[3] = {
704
-
705
- Matrix3((640 / 2),0,0),
706
-
707
- Matrix3(0,(400 / 2),0),
708
-
709
- Matrix3(0,0,1),
710
-
711
- };
712
-
713
-
714
-
715
-
716
-
717
- Position p(0,0,0);
718
-
719
- p.x = (now[0].x * s[0].x) + ( now[0].y * s[0].y) + ( now[0].z * s[0].z);
720
-
721
- p.y = (now[0].x * s[1].x) + ( now[0].y * s[1].y) + ( now[0].z * s[1].z);
722
-
723
- p.z = (now[0].x * s[2].x) + ( now[0].y * s[2].y) + ( now[0].z * s[2].z);
724
-
725
-
726
-
727
- printf("%f\n\n\n\n", 640.0 / (-160.0 * 320.0 ));///
728
-
729
-
730
-
731
- // printf("r %f\n\n\n", p.x / 640);
732
-
733
-
734
-
735
- printf("p.x: %.2f\n", p.x);
736
-
737
- printf("p.y: %.2f\n", p.y);
738
-
739
- printf("p.z: %.2f\n", p.z);
740
-
741
-
742
-
743
-
744
-
745
-
746
-
747
- int _C = getchar();
748
-
749
- return 0;
750
-
751
- }
752
-
753
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
754
608
 
755
609
  ```
610
+
611
+
612
+
613
+ ```GLSL
614
+
615
+ #version 400
616
+
617
+ //頂点
618
+
619
+ layout(Location = 0) in vec4 position;//頂点座標
620
+
621
+ layout(Location = 1) in mat4 view;//頂点座標
622
+
623
+
624
+
625
+ void main()
626
+
627
+ {
628
+
629
+ gl_Position = position * view;
630
+
631
+ }
632
+
633
+
634
+
635
+
636
+
637
+ ```
638
+
639
+
640
+
641
+
642
+
643
+ ```GLSL
644
+
645
+ #version 400
646
+
647
+ //フラグメント
648
+
649
+ layout(location = 0) in vec4 fragment;
650
+
651
+ out vec4 f;
652
+
653
+
654
+
655
+ void main()
656
+
657
+ {
658
+
659
+
660
+
661
+
662
+
663
+ //f = fragment;
664
+
665
+
666
+
667
+ f = vec4(0.0,0.0,1.0,1.0);
668
+
669
+ //fragment = vec4(1.0,0.0,1.0,1.0);
670
+
671
+ }
672
+
673
+ ```

2

文章を修正

2020/09/10 10:11

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- 提示コードのメイン関数部です。画面サイズ(640,400.1)のワールド座標で頂点を設定してその頂点を画面である正規化座標(1.0 ~ -1.0)に変換して画面の真ん中に四角い正方形を描画したいのですがどうすればいいのでしょうか?正しい計算をしていれば(-0.5,0.5,1)になるはずなのですがなりません。
1
+ 提示コードのメイン関数部です。画面サイズ(ピクセル)(640,400.1)のワールド座標で頂点を設定してその頂点を画面である正規化座標(1.0 ~ -1.0)に変換して画面の真ん中に四角い正方形を描画したいのですがどうすればいいのでしょうか?正しい計算をしていれば(-0.5,0.5,1)になるはずなのですがなりません。画面サイズとはピクセルサイズです。また座標系は3Dですが今回は2Dの物を表示させたいです。
2
2
 
3
3
 
4
4
 

1

文章を編集

2020/09/10 02:53

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,8 @@
1
- 提示コードのメイン関数部です。画面サイズ(640,400.1)のワールド座標で頂点を設定してその頂点を画面である正規化座標に変換して画面の真ん中に四角い正方形を描画したいのですがどうすればいいのでしょうか?正しい計算をしていれば(-0.5,0.5,1)になるはずなのですがなりません。
1
+ 提示コードのメイン関数部です。画面サイズ(640,400.1)のワールド座標で頂点を設定してその頂点を画面である正規化座標(1.0 ~ -1.0)に変換して画面の真ん中に四角い正方形を描画したいのですがどうすればいいのでしょうか?正しい計算をしていれば(-0.5,0.5,1)になるはずなのですがなりません。
2
+
3
+
4
+
5
+
2
6
 
3
7
 
4
8