質問編集履歴
1
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
提示コードのsetRotate関数部ですが原点を中心に回転させて最後それを戻しているのですがなぜ座標がおかしくなるのでしょうか?
|
1
|
+
提示コードのsetRotate関数部ですが原点を中心に回転させて最後それを戻しているのですがなぜ座標がおかしくなるのでしょうか?この関数をどうすれば真ん中を中心に回転して最後元に戻せるのでしょうか?いろいろいじりましたがわかりません。
|
2
2
|
|
3
3
|
|
4
4
|
|
@@ -22,147 +22,29 @@
|
|
22
22
|
|
23
23
|
```cpp
|
24
24
|
|
25
|
+
//回転
|
25
26
|
|
26
|
-
|
27
|
-
//描画
|
28
|
-
|
29
|
-
void FrameWork::
|
27
|
+
void FrameWork::Transform_2D::setRotate(float a)
|
30
28
|
|
31
29
|
{
|
32
|
-
|
33
|
-
if (isDefaultShader == true)
|
34
|
-
|
35
|
-
{
|
36
|
-
|
37
|
-
setEnable();
|
38
|
-
|
39
|
-
}
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
setDrawTextureID((unsigned char)texNum); //テクチャーユニットを設定
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
// ####################### 頂点属性のUVデータを更新 #######################
|
48
|
-
|
49
|
-
//UVサイズからピクセルサイズを算出
|
50
|
-
|
51
|
-
const float sizeX = 1.0f / (float)textureID.at(texNum).size.x;
|
52
|
-
|
53
|
-
const float sizeY = 1.0f / (float)textureID.at(texNum).size.y;
|
54
|
-
|
55
|
-
//std::cout<< sizeX << std::endl;
|
56
|
-
|
57
|
-
//左上
|
58
|
-
|
59
|
-
rectangleVertex[0].uv[0] = sizeX * startSize.x;
|
60
|
-
|
61
|
-
rectangleVertex[0].uv[1] = 1.0f - (sizeY * startSize.y);
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
//左下
|
66
|
-
|
67
|
-
rectangleVertex[1].uv[0] = sizeX * startSize.x;
|
68
|
-
|
69
|
-
rectangleVertex[1].uv[1] = 1.0f - (sizeY * ((endSize.y - startSize.y) + startSize.y));
|
70
|
-
|
71
|
-
rectangleVertex[4].uv[0] = sizeX * startSize.x;
|
72
|
-
|
73
|
-
rectangleVertex[4].uv[1] = 1.0f - (sizeY * ((endSize.y - startSize.y) + startSize.y));
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
//右上
|
78
|
-
|
79
|
-
rectangleVertex[2].uv[0] = (sizeX * endSize.x);
|
80
|
-
|
81
|
-
rectangleVertex[2].uv[1] = 1.0f - (sizeY * startSize.y);
|
82
|
-
|
83
|
-
rectangleVertex[3].uv[0] = (sizeX * endSize.x);
|
84
|
-
|
85
|
-
rectangleVertex[3].uv[1] = 1.0f - (sizeY * startSize.y);
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
//右下
|
90
|
-
|
91
|
-
rectangleVertex[5].uv[0] = sizeX * endSize.x;
|
92
|
-
|
93
|
-
rectangleVertex[5].uv[1] = 1.0f - (sizeY * ((endSize.y - startSize.y) + startSize.y));
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
// ###################################################
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
//Transform
|
104
|
-
|
105
|
-
setSizeScale(glm::vec2((endSize.x - startSize.x), (endSize.y - startSize.y))); //サイズ
|
106
|
-
|
107
|
-
setScale(s); //スケール
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
setTranslate(glm::vec3(pos.x + (getSizeScale().x / 2.0f), pos.y + ((getSizeScale().y) / 2.0f), 0.0f)); //平行移動
|
112
|
-
|
113
|
-
setRotate(r); //回転
|
114
30
|
|
115
31
|
|
116
32
|
|
117
33
|
|
118
34
|
|
35
|
+
// std::cout << size.x << std::endl;
|
119
36
|
|
37
|
+
glm::mat4 m = glm::translate(translate, glm::vec3(size.x / 2.0f, size.y / 2.0f, 0)); //平行移動
|
120
38
|
|
121
|
-
//uniform
|
122
|
-
|
123
|
-
|
39
|
+
rotate = glm::rotate(m, a, glm::vec3(0.0,0.0,1.0)); //回転
|
124
|
-
|
125
|
-
setUniformMatrix4fv("uRotate", rotate);
|
126
|
-
|
127
|
-
setUniformMatrix4fv("uScale", scale);
|
128
|
-
|
129
|
-
setUniformMatrix4fv("uViewProjection", glm::ortho(0.0f, windowContext->getSize().x, windowContext->getSize().y, 0.0f, -1.0f, 1.0f));
|
130
40
|
|
131
41
|
|
132
42
|
|
43
|
+
//m = glm::translate(translate, glm::vec3(-size.x / 2.0f, -size.y / 2.0f, 0)); //平行移動
|
133
44
|
|
45
|
+
m = glm::translate(m, glm::vec3(-size.x / 2.0f, -size.y / 2.0f, 0)); //平行移動
|
134
46
|
|
135
|
-
|
136
|
-
|
137
|
-
//バインド&描画
|
138
|
-
|
139
|
-
gl
|
47
|
+
rotate = glm::rotate(m, a, glm::vec3(0.0, 0.0, 1.0)); //回転
|
140
|
-
|
141
|
-
glBindVertexArray(vao);
|
142
|
-
|
143
|
-
glBindTexture(GL_TEXTURE_2D, textureID.at(texNum).ID);
|
144
|
-
|
145
|
-
glDrawArrays(GL_TRIANGLES, 0, 6);
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
//バインドを解除
|
154
|
-
|
155
|
-
glBindVertexArray(0);
|
156
|
-
|
157
|
-
glBindTexture(GL_TEXTURE_2D, 0);
|
158
|
-
|
159
|
-
if (isDefaultShader == true)
|
160
|
-
|
161
|
-
{
|
162
|
-
|
163
|
-
setDisable();
|
164
|
-
|
165
|
-
}
|
166
48
|
|
167
49
|
|
168
50
|
|
@@ -172,134 +54,4 @@
|
|
172
54
|
|
173
55
|
|
174
56
|
|
175
|
-
|
176
|
-
|
177
57
|
```
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
```cpp
|
182
|
-
|
183
|
-
#include "Transform_2D.hpp"
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
// ###################### コンストラクタ ######################
|
188
|
-
|
189
|
-
FrameWork::Transform_2D::Transform_2D()
|
190
|
-
|
191
|
-
{
|
192
|
-
|
193
|
-
size = glm::vec2(0,0);
|
194
|
-
|
195
|
-
vao = 0;
|
196
|
-
|
197
|
-
vbo = 0;
|
198
|
-
|
199
|
-
isDefaultShader = false;
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
//行列を初期化
|
204
|
-
|
205
|
-
scale = glm::scale(glm::mat4(1), glm::vec3(1.0f,1.0f,1.0f));
|
206
|
-
|
207
|
-
rotate = glm::rotate(0.0f,glm::vec3(0.0, 0.0, 1.0));
|
208
|
-
|
209
|
-
translate = glm::translate(glm::mat4(1), glm::vec3(0.0f,0.0f,0.0f));
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
// ###################### メンバ関数 ######################
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
//スケール
|
220
|
-
|
221
|
-
void FrameWork::Transform_2D::setScale(glm::vec2 s)
|
222
|
-
|
223
|
-
{
|
224
|
-
|
225
|
-
scale = glm::scale(glm::mat4(1), glm::vec3(s.x,s.y,0.0f) + glm::vec3(size.x,size.y,0.0f));
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
//回転
|
232
|
-
|
233
|
-
void FrameWork::Transform_2D::setRotate(float a)
|
234
|
-
|
235
|
-
{
|
236
|
-
|
237
|
-
// std::cout << size.x << std::endl;
|
238
|
-
|
239
|
-
glm::mat4 m = glm::translate(translate, glm::vec3(size.x / 2.0f, size.y / 2.0f, 0)); //平行移動
|
240
|
-
|
241
|
-
rotate = glm::rotate(m, a, glm::vec3(0.0,0.0,1.0)); //回転
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
m = glm::translate(translate, glm::vec3(-size.x / 2.0f, -size.y / 2.0f, 0)); //平行移動
|
246
|
-
|
247
|
-
rotate = glm::rotate(m, a, glm::vec3(0.0, 0.0, 1.0)); //回転
|
248
|
-
|
249
|
-
}
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
//平行移動
|
254
|
-
|
255
|
-
void FrameWork::Transform_2D::setTranslate(glm::vec3 t)
|
256
|
-
|
257
|
-
{
|
258
|
-
|
259
|
-
translate = glm::translate(glm::mat4(1), t);
|
260
|
-
|
261
|
-
}
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
//画像サイズを設定
|
266
|
-
|
267
|
-
void FrameWork::Transform_2D::setSizeScale(glm::vec2 s)
|
268
|
-
|
269
|
-
{
|
270
|
-
|
271
|
-
size = s;
|
272
|
-
|
273
|
-
scale = glm::scale(glm::mat4(1), glm::vec3(s.x, s.y, 0.0f));
|
274
|
-
|
275
|
-
}
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
//画像サイズを設定
|
280
|
-
|
281
|
-
glm::vec2 FrameWork::Transform_2D::getSizeScale()
|
282
|
-
|
283
|
-
{
|
284
|
-
|
285
|
-
return size;
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
}
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
// ###################### デストラクタ ######################
|
294
|
-
|
295
|
-
FrameWork::Transform_2D::~Transform_2D()
|
296
|
-
|
297
|
-
{
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
}
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
```
|