質問編集履歴

1

提示コードと文章を編集しました。

2020/10/11 12:23

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,5 +1,9 @@
1
1
  参考サイトのようにテトリスのブロック回転を実装しているのですがなぜ回転するときに座標がずれてしまうのでしょうか?
2
2
 
3
+
4
+
5
+ Set_rotate();関数
6
+
3
7
  printf("ああああ");部ですが最初の表示で-2という値が来てしまいます。 R = 0;のときです。 R = 1;にすると2という値が来てしまいます。
4
8
 
5
9
  参考サイトでは3x3マスですが4x4なのでサイトの式の3 /2の部分を4 / 2にしています。ちなみにこれは正しいのでしょうか?ブロックの表示する座標と各ブロック座標は分けていますのでposに来るのは単一にブロックの座標です。
@@ -14,6 +18,138 @@
14
18
 
15
19
  ```cpp
16
20
 
21
+
22
+
23
+ //描画アップデート
24
+
25
+ void Game::GenerateOutput()
26
+
27
+ {
28
+
29
+
30
+
31
+ //画面クリア関係
32
+
33
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
34
+
35
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
36
+
37
+
38
+
39
+
40
+
41
+ //ステージ
42
+
43
+ for (int y = 0; y < 8; y++)
44
+
45
+ {
46
+
47
+ for (int x = 0; x < 10; x++)
48
+
49
+ {
50
+
51
+ if (stage[y][x] == 1) {
52
+
53
+ DrawMap->DrawGraph(stage_pos.x + (CELL * x) , stage_pos.y + (-CELL * y));
54
+
55
+ printf("stage: %d\n", stage_pos.x + (CELL * x));
56
+
57
+ }
58
+
59
+ }
60
+
61
+ }
62
+
63
+
64
+
65
+ printf("あああああ\n");
66
+
67
+ for (int i = 0; i < 4; i++) {
68
+
69
+ for (int j = 0; j < 4; j++) {
70
+
71
+
72
+
73
+ if (block[i][j] == 1) {
74
+
75
+
76
+
77
+ glm::ivec2 v;
78
+
79
+ v.x = (CELL * j);
80
+
81
+ v.y = (CELL * i);
82
+
83
+
84
+
85
+ Set_rotate(&v,r);
86
+
87
+ printf("block: %d\n", v.x);
88
+
89
+
90
+
91
+ v.x = move_sprite.x + v.x;
92
+
93
+ v.y = move_sprite.y + v.y;
94
+
95
+
96
+
97
+ sprite->DrawGraph(v.x, v.y);
98
+
99
+
100
+
101
+
102
+
103
+ }
104
+
105
+ }
106
+
107
+ }
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+ char str[1000];
116
+
117
+ // sprintf_s(str, sizeof(str), "block x %.2f , y %.2f", move_sprite.x, move_sprite.y);
118
+
119
+ sprintf_s(str, sizeof(str),"block x %d , y %d", move_sprite.x, move_sprite.y);
120
+
121
+ font->RenderText(str, -CELL * 7, -CELL * 2, 0.5, glm::vec3(1.0, 1.0, 1.0));
122
+
123
+
124
+
125
+ // sprintf_s(str, sizeof(str), "stage x %.2f , y %.2f", stage_pos.x, stage_pos.y);
126
+
127
+ sprintf_s(str, sizeof(str), "stage x %d , y %d", stage_pos.x, stage_pos.y);
128
+
129
+ font->RenderText(str, -CELL * 7, -CELL * 3, 0.5, glm::vec3(1.0, 1.0, 1.0));
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+ glViewport(0, 0, WIDTH, HEIGHT); //ビューポート
138
+
139
+ glfwSwapBuffers(Window); //ダブルバッファリング
140
+
141
+ glfwPollEvents(); //イベント処理
142
+
143
+
144
+
145
+
146
+
147
+ }
148
+
149
+
150
+
151
+
152
+
17
153
  void Game::Set_rotate(glm::ivec2 *pos,const int R)
18
154
 
19
155
  {
@@ -44,9 +180,9 @@
44
180
 
45
181
  float p[2];
46
182
 
47
- p[0] = posX - (4.0f / 2.0f);
183
+ p[0] = posX - (4.0f / 3.0f);
48
-
184
+
49
- p[1] = posY - (4.0f / 2.0f);
185
+ p[1] = posY - (4.0f / 3.0f);
50
186
 
51
187
 
52
188