質問編集履歴

3

修正

2019/07/29 06:40

投稿

nia_1001
nia_1001

スコア13

test CHANGED
File without changes
test CHANGED
@@ -8,6 +8,14 @@
8
8
 
9
9
 
10
10
 
11
+ player cpp の
12
+
13
+ 3行目でエラーが出ました
14
+
15
+ Player g_player; 
16
+
17
+
18
+
11
19
  エラー文を見てますがよくわかりません
12
20
 
13
21
 

2

修正

2019/07/29 06:40

投稿

nia_1001
nia_1001

スコア13

test CHANGED
File without changes
test CHANGED
@@ -82,7 +82,7 @@
82
82
 
83
83
 
84
84
 
85
- Player g_player;
85
+ Player g_player; //ここでエラーが出ました
86
86
 
87
87
 
88
88
 

1

修正しました

2019/07/29 06:38

投稿

nia_1001
nia_1001

スコア13

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,15 @@
2
2
 
3
3
 
4
4
 
5
+ rectクラスを継承したPlayerクラスを
6
+
5
- extern 宣言したりしたらエラーが出て萎えました
7
+ extern 宣言したらエラーが出ました
8
+
9
+
10
+
11
+ エラー文を見てますがよくわかりません
12
+
13
+
6
14
 
7
15
 
8
16
 
@@ -120,6 +128,238 @@
120
128
 
121
129
  ```
122
130
 
131
+ ```C++
132
+
133
+ #include "Rect.h"
134
+
135
+ #include "glut.h"
136
+
137
+ #include <stdio.h>
138
+
139
+
140
+
141
+ Rect::Rect(float _width, float _height)
142
+
143
+ :m_size(_width, _height),//高さ
144
+
145
+ m_position(vec2()),//幅
146
+
147
+ m_flip(RECT_FLIP_NONE)//クリアする
148
+
149
+ {}
150
+
151
+
152
+
153
+ Rect::Rect( vec2 const & _size,vec2 const & _position)//幅と高さ
154
+
155
+ :m_size(_size)//高さ
156
+
157
+ ,m_position(_position),//幅
158
+
159
+ m_flip(RECT_FLIP_NONE)//クリアする
160
+
161
+ {
162
+
163
+
164
+
165
+ }
166
+
167
+
168
+
169
+ void Rect::Draw()
170
+
171
+ {
172
+
173
+ ////四角形描画
174
+
175
+ //glRectf(
176
+
177
+ //m_position.x, //GLfloat x1,
178
+
179
+ // m_position.y, //GLfloat y1,
180
+
181
+ //m_position.x+m_size.x, //GLfloat x2,
182
+
183
+ //m_position.y+m_size.y); //GLfloat y2,
184
+
185
+
186
+
187
+ glBegin(GL_QUADS);//ワイヤーフレームでもできる
188
+
189
+ {
190
+
191
+ //反転フラグが建っていたら
192
+
193
+ glTexCoord2f((m_flip&RECT_FLIP_HORIZONTAL)?1:0//反転フラグが建っていたら1建ってなかったら0
194
+
195
+ ,( m_flip&RECT_FLIP_VERTICAL) ? 1 : 0);//GLfloat s, GLfloat t
196
+
197
+ glVertex2fv((GLfloat*)&m_position);//const GLfloat *v
198
+
199
+
200
+
201
+ glTexCoord2f((m_flip&RECT_FLIP_HORIZONTAL) ? 1 : 0,
202
+
203
+ (m_flip&RECT_FLIP_VERTICAL) ? 0 : 1);//GLfloat s, GLfloat t
204
+
205
+ glVertex2fv((GLfloat*)&(m_position+vec2(0,m_size.y)));//const GLfloat *v
206
+
207
+
208
+
209
+ glTexCoord2f((m_flip&RECT_FLIP_HORIZONTAL) ? 0 : 1,
210
+
211
+ (m_flip&RECT_FLIP_VERTICAL) ? 0 : 1);//GLfloat s, GLfloat t
212
+
213
+ glVertex2fv((GLfloat*)&(m_position + m_size));//const GLfloat *v
214
+
215
+
216
+
217
+ glTexCoord2f((m_flip&RECT_FLIP_HORIZONTAL) ? 0 : 1,
218
+
219
+ (m_flip&RECT_FLIP_VERTICAL) ? 1 : 0);//GLfloat s, GLfloat t
220
+
221
+ glVertex2fv((GLfloat*)&(m_position + vec2( m_size.x,0)));//const GLfloat *v
222
+
223
+ }
224
+
225
+ glEnd();
226
+
227
+ }
228
+
229
+
230
+
231
+ void Rect::DrawWire() {
232
+
233
+ glPushAttrib(GL_ALL_ATTRIB_BITS);// GLbitfield mask
234
+
235
+ glDisable(GL_TEXTURE_2D);
236
+
237
+ glPolygonMode(
238
+
239
+ GL_FRONT_AND_BACK,//GLenum face,
240
+
241
+ GL_LINE);//線で描画 //GLenum mode);
242
+
243
+ glRectfv(
244
+
245
+ (GLfloat*)&m_position,//const GLfloat *v1,
246
+
247
+ (GLfloat*)&(m_position+m_size)//const GLfloat *v2
248
+
249
+ );
250
+
251
+
252
+
253
+ glPopAttrib();//終了
254
+
255
+ }
256
+
257
+
258
+
259
+ bool Rect::Intersect(vec2 const & _point)
260
+
261
+ {
262
+
263
+ //当たり判定
264
+
265
+ return (_point.x >= m_position.x&&
266
+
267
+ _point.x < m_position.x + m_size.x
268
+
269
+ &&_point.y >= m_position.y
270
+
271
+ &&_point.y < m_position.y + m_size.y);
272
+
273
+
274
+
275
+ }
276
+
277
+
278
+
279
+ bool Rect::Intersect(Rect const & _rect)
280
+
281
+ {
282
+
283
+ return (m_position.x + m_size.x >= _rect.m_position.x&&
284
+
285
+ m_position.x <= _rect.m_position.x + _rect.m_size.x&&
286
+
287
+ m_position.y + m_size.y >= _rect.m_position.y&&
288
+
289
+ m_position.y <= _rect.m_position.y + _rect.m_size.y);
290
+
291
+
292
+
293
+
294
+
295
+ }
296
+
297
+
298
+
299
+ ```
300
+
301
+
302
+
303
+ ```C++
304
+
305
+ #pragma once
306
+
307
+ #include"glm/glm.hpp"
308
+
309
+
310
+
311
+ using namespace glm;
312
+
313
+
314
+
315
+
316
+
317
+ #define RECT_FLIP_NONE 0 //初期化
318
+
319
+ #define RECT_FLIP_HORIZONTAL (1<<0)//横反転フラグ
320
+
321
+ #define RECT_FLIP_VERTICAL (1<<1)//縦反転フラグ
322
+
323
+
324
+
325
+ struct Rect
326
+
327
+ {
328
+
329
+ vec2 m_position;//位置を保持
330
+
331
+ vec2 m_size;//大きさを保持
332
+
333
+ int m_flip;//反転を指示
334
+
335
+
336
+
337
+ //コンストラクタ
338
+
339
+ Rect(float _width, float _height);
340
+
341
+ Rect( vec2 const&_size,vec2 const & _position );
342
+
343
+
344
+
345
+ //描画
346
+
347
+ void Draw();
348
+
349
+
350
+
351
+ void DrawWire();//ワイヤーを描画
352
+
353
+ //当たり判定
354
+
355
+ bool Intersect(vec2 const& _point);
356
+
357
+ bool Intersect(Rect const& _rect);
358
+
359
+ };
360
+
361
+ ```
362
+
123
363
  ### 試したこと
124
364
 
125
365