質問編集履歴
6
文章を修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
基底クラスのサイズが変わってしまいアクセスエラーが出る原因が知りたい。
|
test
CHANGED
File without changes
|
5
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
提示コードですが
|
1
|
+
提示コードですがActorクラスのサイズが変わっているためアクセスエラーが出る原因がわかりせん。これはなぜなのでしょうか?printfデバッグをした結果void RendererDepth()関数が原因なのでその定義をみましたが問題ありません。これは何が原因なのでしょうか?
|
2
|
-
|
3
|
-
Ground.cpp以外のvoid RendererDepth()は空の定義のみです。
|
4
2
|
|
5
3
|
|
6
4
|
|
@@ -10,7 +8,7 @@
|
|
10
8
|
|
11
9
|
GithubコードのCamera.chpp Renderer()関数部 Ground.cpp void RendererDepth()関数部です。
|
12
10
|
|
13
|
-
Github: https://github.com/Shigurechan/TopViewGame
|
11
|
+
Github: [https://github.com/Shigurechan/TopViewGame](https://github.com/Shigurechan/TopViewGame)
|
14
12
|
|
15
13
|
|
16
14
|
|
@@ -178,7 +176,7 @@
|
|
178
176
|
|
179
177
|
|
180
178
|
|
181
|
-
|
179
|
+
/*文字数の関係で割愛*/
|
182
180
|
|
183
181
|
model->shader.setDisable();
|
184
182
|
|
4
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,6 +4,12 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
GithubコードのCamera.chpp Renderer()関数部 Ground.cpp void RendererDepth()関数部です。
|
12
|
+
|
7
13
|
Github: https://github.com/Shigurechan/TopViewGame
|
8
14
|
|
9
15
|
|
3
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
|
7
|
+
Github: https://github.com/Shigurechan/TopViewGame
|
8
8
|
|
9
9
|
|
10
10
|
|
2
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
提示コードですが下記のコメント部のコードで以下の端末のエラーが出ますこれは何が原因なのでしょうか?Actor.hppを継承してlightCub.cppやGround.cppを作成してそれをCamera.cppのメンバ関数で基底のアドレスを取得してそれを参照してループさせているのですがRendererDepth()関数の時だけ例外が出る原因がわかりません。これはなぜでしょうか?
|
2
2
|
|
3
|
-
|
3
|
+
Ground.cpp以外のvoid RendererDepth()は空の定義のみです。
|
4
4
|
|
5
5
|
|
6
6
|
|
@@ -44,20 +44,6 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
-
#include <memory>
|
48
|
-
|
49
|
-
#include <GL/glew.h>
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#include "../../FrameWork/header/Resource.hpp"
|
54
|
-
|
55
|
-
#include "../../FrameWork/header/Shader.hpp"
|
56
|
-
|
57
|
-
#include "../../FrameWork/header/Model.hpp"
|
58
|
-
|
59
|
-
|
60
|
-
|
61
47
|
class Actor
|
62
48
|
|
63
49
|
{
|
@@ -110,123 +96,325 @@
|
|
110
96
|
|
111
97
|
|
112
98
|
|
113
|
-
##### G
|
114
|
-
|
115
|
-
```
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
{
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
99
|
+
##### Ground.cpp
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
Ground::Ground() : Actor()
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
FrameWork::D3::LoadObj("Game/model/ground.obj",file);
|
108
|
+
|
109
|
+
model = std::make_shared<FrameWork::D3::Object>(&file,GL_STATIC_DRAW);
|
110
|
+
|
111
|
+
shader.Load("FrameWork/shader/3D//ShadowMap/ShadowMap.vert","FrameWork/shader/3D/ShadowMap/ShadowMap.frag");
|
112
|
+
|
113
|
+
shaderDepth.Load("FrameWork/shader/3D//ShadowMap/ShadowTexture.vert","FrameWork/shader/3D/ShadowMap/ShadowTexture.frag");
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
void Ground::Renderer(glm::mat4 view)const
|
126
|
+
|
127
|
+
{
|
128
|
+
|
129
|
+
model->shader = shaderDepth;
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
model->setBindBuffer();
|
134
|
+
|
135
|
+
model->shader.setEnable();
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
model->shader.setUniformMatrix4fv("lightSpaceMatrix",lightSpaceMatrix);
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
model->shader.setDisable();
|
152
|
+
|
153
|
+
model->setUnBindBuffer();
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
void Ground::RendererDepth(GLuint depth,glm::mat4 view)const
|
164
|
+
|
165
|
+
{
|
166
|
+
|
167
|
+
model->shader = shader;
|
168
|
+
|
169
|
+
model->setBindBuffer();
|
170
|
+
|
171
|
+
model->shader.setEnable();
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
model->shader.setDisable();
|
178
|
+
|
179
|
+
model->setUnBindBuffer();
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
Ground::~Ground()
|
190
|
+
|
191
|
+
{
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
Ground::Ground() : Actor()
|
202
|
+
|
203
|
+
{
|
204
|
+
|
205
|
+
FrameWork::D3::LoadObj("Game/model/ground.obj",file);
|
206
|
+
|
207
|
+
model = std::make_shared<FrameWork::D3::Object>(&file,GL_STATIC_DRAW);
|
208
|
+
|
209
|
+
shader.Load("FrameWork/shader/3D//ShadowMap/ShadowMap.vert","FrameWork/shader/3D/ShadowMap/ShadowMap.frag");
|
210
|
+
|
211
|
+
shaderDepth.Load("FrameWork/shader/3D//ShadowMap/ShadowTexture.vert","FrameWork/shader/3D/ShadowMap/ShadowTexture.frag");
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
texture = FrameWork::LoadTexture("Game/Assets/debug.png");
|
216
|
+
|
217
|
+
model->setTexture(texture);
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
model->setPosition(glm::vec3(0,0,-5));
|
222
|
+
|
223
|
+
model->setScale(glm::vec3(100,1,100));
|
224
|
+
|
225
|
+
model->setRotate(glm::vec3(1,0,0),0);
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
void Ground::setLightPosition(glm::vec3 pos)
|
234
|
+
|
235
|
+
{
|
236
|
+
|
237
|
+
model->shader.setEnable();
|
238
|
+
|
239
|
+
model->shader.setUniform4f("uFragment",FrameWork::GetGlColor(glm::vec4(200,255,255,255)));
|
240
|
+
|
241
|
+
model->shader.setDisable();
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
void Ground::Update()
|
250
|
+
|
251
|
+
{
|
252
|
+
|
253
|
+
model->shader.setEnable();
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
/*
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
glActiveTexture(GL_TEXTURE1);
|
264
|
+
|
265
|
+
glBindTexture(GL_TEXTURE_2D, depthMap);
|
266
|
+
|
267
|
+
*/
|
268
|
+
|
269
|
+
model->shader.setDisable();
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
void Ground::Renderer(glm::mat4 view)const
|
278
|
+
|
279
|
+
{
|
280
|
+
|
281
|
+
model->shader = shaderDepth;
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
model->setBindBuffer();
|
286
|
+
|
287
|
+
model->shader.setEnable();
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
glm::mat4 lightProjection, lightView;
|
292
|
+
|
293
|
+
glm::mat4 lightSpaceMatrix;
|
294
|
+
|
295
|
+
float near_plane = 1.0f, far_plane = 7.5f;
|
296
|
+
|
297
|
+
//lightProjection = glm::perspective(glm::radians(45.0f), (GLfloat)SHADOW_WIDTH / (GLfloat)SHADOW_HEIGHT, near_plane, far_plane); // note that if you use a perspective projection matrix you'll have to change the light position as the current light position isn't enough to reflect the whole scene
|
298
|
+
|
299
|
+
lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
|
300
|
+
|
301
|
+
lightView = glm::lookAt(glm::vec3(0,0,-5), glm::vec3(0.0f), glm::vec3(0.0, 1.0, 0.0));
|
302
|
+
|
303
|
+
lightSpaceMatrix = lightProjection * lightView;
|
304
|
+
|
305
|
+
// render scene from light's point of view
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
model->shader.setUniformMatrix4fv("lightSpaceMatrix",lightSpaceMatrix);
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
model->shader.setDisable();
|
324
|
+
|
325
|
+
model->setUnBindBuffer();
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
void Ground::RendererDepth(GLuint depth,glm::mat4 view)const
|
336
|
+
|
337
|
+
{
|
338
|
+
|
339
|
+
model->shader = shader;
|
340
|
+
|
341
|
+
model->setBindBuffer();
|
342
|
+
|
343
|
+
model->shader.setEnable();
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
glm::mat4 lightProjection, lightView;
|
358
|
+
|
359
|
+
glm::mat4 lightSpaceMatrix;
|
360
|
+
|
361
|
+
float near_plane = 1.0f, far_plane = 7.5f;
|
362
|
+
|
363
|
+
//lightProjection = glm::perspective(glm::radians(45.0f), (GLfloat)SHADOW_WIDTH / (GLfloat)SHADOW_HEIGHT, near_plane, far_plane); // note that if you use a perspective projection matrix you'll have to change the light position as the current light position isn't enough to reflect the whole scene
|
364
|
+
|
365
|
+
lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
|
366
|
+
|
367
|
+
lightView = glm::lookAt(glm::vec3(0,0,-5), glm::vec3(0.0f), glm::vec3(0.0, 1.0, 0.0));
|
368
|
+
|
369
|
+
lightSpaceMatrix = lightProjection * lightView;
|
370
|
+
|
371
|
+
// render scene from light's point of view
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
model->shader.setUniformMatrix4fv("lightSpaceMatrix",lightSpaceMatrix);
|
376
|
+
|
377
|
+
model->shader.setUniform3f("viewPos", glm::vec3(0,0,-5));
|
378
|
+
|
379
|
+
model->shader.setUniform3f("lightPos", glm::vec3(0,100,-5));
|
380
|
+
|
381
|
+
model->setEnableTexture(texture);
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
glActiveTexture(GL_TEXTURE1);
|
386
|
+
|
387
|
+
glBindTexture(GL_TEXTURE_2D, depth);
|
388
|
+
|
389
|
+
model->Renderer(view);
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
model->shader.setDisable();
|
402
|
+
|
403
|
+
model->setUnBindBuffer();
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
}
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
Ground::~Ground()
|
414
|
+
|
415
|
+
{
|
416
|
+
|
417
|
+
|
230
418
|
|
231
419
|
}
|
232
420
|
|
1
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -110,6 +110,136 @@
|
|
110
110
|
|
111
111
|
|
112
112
|
|
113
|
+
##### Game.chpp
|
114
|
+
|
115
|
+
```
|
116
|
+
|
117
|
+
#include "../header/Game.hpp"
|
118
|
+
|
119
|
+
#include <glm/glm.hpp>
|
120
|
+
|
121
|
+
#include <glm/gtc/matrix_transform.hpp>
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
Game::Game() : Scene(Sequence::Game)
|
126
|
+
|
127
|
+
{
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
camera = std::make_shared<FrameWork::Camera>();
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
lightCube = std::make_shared<LightCube>();
|
136
|
+
|
137
|
+
ground = std::make_shared<Ground>();
|
138
|
+
|
139
|
+
control = std::make_shared<Control>();
|
140
|
+
|
141
|
+
cube = std::make_shared<Cube>();
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
control->setObject(lightCube);
|
150
|
+
|
151
|
+
control->setObject(cube);
|
152
|
+
|
153
|
+
control->setCamera(camera);
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
void Game::Update()
|
166
|
+
|
167
|
+
{
|
168
|
+
|
169
|
+
control->Update();
|
170
|
+
|
171
|
+
lightCube->Update();
|
172
|
+
|
173
|
+
ground->Update();
|
174
|
+
|
175
|
+
cube->Update();
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
void Game::Renderer() const
|
184
|
+
|
185
|
+
{
|
186
|
+
|
187
|
+
camera->setView(lightCube);
|
188
|
+
|
189
|
+
//camera->setView(control);
|
190
|
+
|
191
|
+
camera->setView(ground);
|
192
|
+
|
193
|
+
printf("ああああ\n");
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
camera->Renderer();
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
void Game::Loop()
|
204
|
+
|
205
|
+
{
|
206
|
+
|
207
|
+
Update();
|
208
|
+
|
209
|
+
Renderer();
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
Game::~Game()
|
226
|
+
|
227
|
+
{
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
```
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
|
113
243
|
##### Camera.cpp
|
114
244
|
|
115
245
|
```
|