teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

6

文章を修正

2021/11/11 05:45

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- terminate called after throwing an instance of 'std::out_of_range' what(): の原因が知りたい。
1
+ 基底クラスサイズが変わってしまいアクセスエラーが出る原因が知りたい。
body CHANGED
File without changes

5

文章を修正

2021/11/11 05:45

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,10 +1,9 @@
1
- 提示コードですが下記コメント部のコードで以下の端末のエラーが出ますこれは何が原因なのでしょうか?Actor.hppを継承してlightCub.cppやGround.cppを作成してそれをCamera.cppのメン関数で基底のアドレス取得てそれを参照してループさせているのですがRendererDepth()関数の時だけ例外出る原因がわかりません。これはなでしょうか?
1
+ 提示コードですがActorクラスサイズが変わっているためアクセスエラーが出る原因がわかりせん。これはなぜなのでしょうか?printfデッグをした結果void RendererDepth()関数が原因なのでその定義をみました問題ありません。これは何が原因でしょうか?
2
- Ground.cpp以外のvoid RendererDepth()は空の定義のみです。
3
2
 
4
3
 
5
4
 
6
5
  GithubコードのCamera.chpp Renderer()関数部 Ground.cpp void RendererDepth()関数部です。
7
- Github: https://github.com/Shigurechan/TopViewGame
6
+ Github: [https://github.com/Shigurechan/TopViewGame](https://github.com/Shigurechan/TopViewGame)
8
7
 
9
8
  ##### 端末
10
9
  ```
@@ -88,7 +87,7 @@
88
87
  model->setBindBuffer();
89
88
  model->shader.setEnable();
90
89
 
91
-
90
+ /*文字数の関係で割愛*/
92
91
  model->shader.setDisable();
93
92
  model->setUnBindBuffer();
94
93
 

4

文章を修正

2021/11/11 05:44

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,9 @@
1
1
  提示コードですが下記のコメント部のコードで以下の端末のエラーが出ますこれは何が原因なのでしょうか?Actor.hppを継承してlightCub.cppやGround.cppを作成してそれをCamera.cppのメンバ関数で基底のアドレスを取得してそれを参照してループさせているのですがRendererDepth()関数の時だけ例外が出る原因がわかりません。これはなぜでしょうか?
2
2
  Ground.cpp以外のvoid RendererDepth()は空の定義のみです。
3
3
 
4
+
5
+
6
+ GithubコードのCamera.chpp Renderer()関数部 Ground.cpp void RendererDepth()関数部です。
4
7
  Github: https://github.com/Shigurechan/TopViewGame
5
8
 
6
9
  ##### 端末

3

文章を修正

2021/11/11 05:37

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,8 +1,8 @@
1
1
  提示コードですが下記のコメント部のコードで以下の端末のエラーが出ますこれは何が原因なのでしょうか?Actor.hppを継承してlightCub.cppやGround.cppを作成してそれをCamera.cppのメンバ関数で基底のアドレスを取得してそれを参照してループさせているのですがRendererDepth()関数の時だけ例外が出る原因がわかりません。これはなぜでしょうか?
2
2
  Ground.cpp以外のvoid RendererDepth()は空の定義のみです。
3
3
 
4
+ Github: https://github.com/Shigurechan/TopViewGame
4
5
 
5
-
6
6
  ##### 端末
7
7
  ```
8
8
  [shigurechan@localhost TopViewGame]$ ./program

2

文章を修正

2021/11/11 05:29

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,8 +1,8 @@
1
1
  提示コードですが下記のコメント部のコードで以下の端末のエラーが出ますこれは何が原因なのでしょうか?Actor.hppを継承してlightCub.cppやGround.cppを作成してそれをCamera.cppのメンバ関数で基底のアドレスを取得してそれを参照してループさせているのですがRendererDepth()関数の時だけ例外が出る原因がわかりません。これはなぜでしょうか?
2
+ Ground.cpp以外のvoid RendererDepth()は空の定義のみです。
2
3
 
3
4
 
4
5
 
5
-
6
6
  ##### 端末
7
7
  ```
8
8
  [shigurechan@localhost TopViewGame]$ ./program
@@ -21,13 +21,6 @@
21
21
  #ifndef ___ACTOR_HPP___
22
22
  #define ___ACTOR_HPP___
23
23
 
24
- #include <memory>
25
- #include <GL/glew.h>
26
-
27
- #include "../../FrameWork/header/Resource.hpp"
28
- #include "../../FrameWork/header/Shader.hpp"
29
- #include "../../FrameWork/header/Model.hpp"
30
-
31
24
  class Actor
32
25
  {
33
26
  public:
@@ -54,67 +47,168 @@
54
47
  #endif
55
48
  ```
56
49
 
57
- ##### Game.chpp
50
+ ##### Ground.cpp
58
51
  ```
52
+ Ground::Ground() : Actor()
53
+ {
59
- #include "../header/Game.hpp"
54
+ FrameWork::D3::LoadObj("Game/model/ground.obj",file);
60
- #include <glm/glm.hpp>
61
- #include <glm/gtc/matrix_transform.hpp>
55
+ model = std::make_shared<FrameWork::D3::Object>(&file,GL_STATIC_DRAW);
56
+ shader.Load("FrameWork/shader/3D//ShadowMap/ShadowMap.vert","FrameWork/shader/3D/ShadowMap/ShadowMap.frag");
57
+ shaderDepth.Load("FrameWork/shader/3D//ShadowMap/ShadowTexture.vert","FrameWork/shader/3D/ShadowMap/ShadowTexture.frag");
58
+
62
59
 
60
+
61
+ }
62
+
63
- Game::Game() : Scene(Sequence::Game)
63
+ void Ground::Renderer(glm::mat4 view)const
64
64
  {
65
+ model->shader = shaderDepth;
65
66
 
67
+ model->setBindBuffer();
66
- camera = std::make_shared<FrameWork::Camera>();
68
+ model->shader.setEnable();
67
69
 
68
- lightCube = std::make_shared<LightCube>();
69
- ground = std::make_shared<Ground>();
70
- control = std::make_shared<Control>();
71
- cube = std::make_shared<Cube>();
72
70
 
71
+ model->shader.setUniformMatrix4fv("lightSpaceMatrix",lightSpaceMatrix);
73
72
 
74
73
 
75
- control->setObject(lightCube);
76
- control->setObject(cube);
77
- control->setCamera(camera);
78
74
 
75
+
76
+ model->shader.setDisable();
77
+ model->setUnBindBuffer();
78
+
79
79
  }
80
80
 
81
81
 
82
+ void Ground::RendererDepth(GLuint depth,glm::mat4 view)const
83
+ {
84
+ model->shader = shader;
85
+ model->setBindBuffer();
86
+ model->shader.setEnable();
82
87
 
88
+
89
+ model->shader.setDisable();
90
+ model->setUnBindBuffer();
91
+
92
+ }
93
+
94
+
83
- void Game::Update()
95
+ Ground::~Ground()
84
96
  {
85
- control->Update();
97
+
86
- lightCube->Update();
87
- ground->Update();
88
- cube->Update();
98
+ }
89
99
 
90
- }
91
100
 
92
- void Game::Renderer() const
101
+ Ground::Ground() : Actor()
93
- {
102
+ {
103
+ FrameWork::D3::LoadObj("Game/model/ground.obj",file);
104
+ model = std::make_shared<FrameWork::D3::Object>(&file,GL_STATIC_DRAW);
105
+ shader.Load("FrameWork/shader/3D//ShadowMap/ShadowMap.vert","FrameWork/shader/3D/ShadowMap/ShadowMap.frag");
106
+ shaderDepth.Load("FrameWork/shader/3D//ShadowMap/ShadowTexture.vert","FrameWork/shader/3D/ShadowMap/ShadowTexture.frag");
107
+
108
+ texture = FrameWork::LoadTexture("Game/Assets/debug.png");
94
- camera->setView(lightCube);
109
+ model->setTexture(texture);
95
- //camera->setView(control);
96
- camera->setView(ground);
97
- printf("ああああ\n");
98
110
 
111
+ model->setPosition(glm::vec3(0,0,-5));
112
+ model->setScale(glm::vec3(100,1,100));
99
- camera->Renderer();
113
+ model->setRotate(glm::vec3(1,0,0),0);
100
114
  }
101
115
 
116
+
102
- void Game::Loop()
117
+ void Ground::setLightPosition(glm::vec3 pos)
103
118
  {
104
- Update();
105
- Renderer();
119
+ model->shader.setEnable();
120
+ model->shader.setUniform4f("uFragment",FrameWork::GetGlColor(glm::vec4(200,255,255,255)));
121
+ model->shader.setDisable();
106
122
  }
107
123
 
108
124
 
125
+ void Ground::Update()
126
+ {
127
+ model->shader.setEnable();
109
128
 
110
129
 
130
+ /*
131
+
132
+ glActiveTexture(GL_TEXTURE1);
133
+ glBindTexture(GL_TEXTURE_2D, depthMap);
134
+ */
135
+ model->shader.setDisable();
111
136
 
137
+ }
112
138
 
113
- Game::~Game()
139
+ void Ground::Renderer(glm::mat4 view)const
114
140
  {
141
+ model->shader = shaderDepth;
115
142
 
143
+ model->setBindBuffer();
144
+ model->shader.setEnable();
145
+
146
+ glm::mat4 lightProjection, lightView;
147
+ glm::mat4 lightSpaceMatrix;
148
+ float near_plane = 1.0f, far_plane = 7.5f;
149
+ //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
150
+ lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
151
+ lightView = glm::lookAt(glm::vec3(0,0,-5), glm::vec3(0.0f), glm::vec3(0.0, 1.0, 0.0));
152
+ lightSpaceMatrix = lightProjection * lightView;
153
+ // render scene from light's point of view
154
+
155
+
156
+
157
+ model->shader.setUniformMatrix4fv("lightSpaceMatrix",lightSpaceMatrix);
158
+
159
+
160
+
161
+
162
+ model->shader.setDisable();
163
+ model->setUnBindBuffer();
164
+
116
165
  }
117
166
 
167
+
168
+ void Ground::RendererDepth(GLuint depth,glm::mat4 view)const
169
+ {
170
+ model->shader = shader;
171
+ model->setBindBuffer();
172
+ model->shader.setEnable();
173
+
174
+
175
+
176
+
177
+
178
+
179
+ glm::mat4 lightProjection, lightView;
180
+ glm::mat4 lightSpaceMatrix;
181
+ float near_plane = 1.0f, far_plane = 7.5f;
182
+ //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
183
+ lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
184
+ lightView = glm::lookAt(glm::vec3(0,0,-5), glm::vec3(0.0f), glm::vec3(0.0, 1.0, 0.0));
185
+ lightSpaceMatrix = lightProjection * lightView;
186
+ // render scene from light's point of view
187
+
188
+ model->shader.setUniformMatrix4fv("lightSpaceMatrix",lightSpaceMatrix);
189
+ model->shader.setUniform3f("viewPos", glm::vec3(0,0,-5));
190
+ model->shader.setUniform3f("lightPos", glm::vec3(0,100,-5));
191
+ model->setEnableTexture(texture);
192
+
193
+ glActiveTexture(GL_TEXTURE1);
194
+ glBindTexture(GL_TEXTURE_2D, depth);
195
+ model->Renderer(view);
196
+
197
+
198
+
199
+
200
+
201
+ model->shader.setDisable();
202
+ model->setUnBindBuffer();
203
+
204
+ }
205
+
206
+
207
+ Ground::~Ground()
208
+ {
209
+
210
+ }
211
+
118
212
  ```
119
213
 
120
214
 

1

文章を修正

2021/11/11 05:01

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -54,6 +54,71 @@
54
54
  #endif
55
55
  ```
56
56
 
57
+ ##### Game.chpp
58
+ ```
59
+ #include "../header/Game.hpp"
60
+ #include <glm/glm.hpp>
61
+ #include <glm/gtc/matrix_transform.hpp>
62
+
63
+ Game::Game() : Scene(Sequence::Game)
64
+ {
65
+
66
+ camera = std::make_shared<FrameWork::Camera>();
67
+
68
+ lightCube = std::make_shared<LightCube>();
69
+ ground = std::make_shared<Ground>();
70
+ control = std::make_shared<Control>();
71
+ cube = std::make_shared<Cube>();
72
+
73
+
74
+
75
+ control->setObject(lightCube);
76
+ control->setObject(cube);
77
+ control->setCamera(camera);
78
+
79
+ }
80
+
81
+
82
+
83
+ void Game::Update()
84
+ {
85
+ control->Update();
86
+ lightCube->Update();
87
+ ground->Update();
88
+ cube->Update();
89
+
90
+ }
91
+
92
+ void Game::Renderer() const
93
+ {
94
+ camera->setView(lightCube);
95
+ //camera->setView(control);
96
+ camera->setView(ground);
97
+ printf("ああああ\n");
98
+
99
+ camera->Renderer();
100
+ }
101
+
102
+ void Game::Loop()
103
+ {
104
+ Update();
105
+ Renderer();
106
+ }
107
+
108
+
109
+
110
+
111
+
112
+
113
+ Game::~Game()
114
+ {
115
+
116
+ }
117
+
118
+ ```
119
+
120
+
121
+
57
122
  ##### Camera.cpp
58
123
  ```
59
124