Mercurial > hg > Game > Cerium
comparison Renderer/Engine/SceneGraph.cc @ 1351:e51127dbd63c draft
operate directly on matrix. not work yet.
author | Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 15 Jan 2012 23:21:39 +0900 |
parents | 3f95f61faef6 |
children | ba6c080bf9a4 |
comparison
equal
deleted
inserted
replaced
1340:b6ee60edacf0 | 1351:e51127dbd63c |
---|---|
122 */ | 122 */ |
123 SceneGraph::SceneGraph(TaskManager *manager) | 123 SceneGraph::SceneGraph(TaskManager *manager) |
124 { | 124 { |
125 | 125 |
126 init(); | 126 init(); |
127 | 127 allocate_init(manager); |
128 matrix = (float*)manager->allocate(sizeof(float)*16); | |
129 texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); | |
130 | |
131 texture_info->texture_id = -1; | 128 texture_info->texture_id = -1; |
132 | |
133 for (int i = 0; i < 16; i++) { | |
134 matrix[i] = 0; | |
135 } | |
136 | |
137 for (int i = 0; i < 4; i++) { | |
138 matrix[i*4+i] = 1; | |
139 } | |
140 | |
141 | 129 |
142 finalize = &SceneGraph::finalize_copy; | 130 finalize = &SceneGraph::finalize_copy; |
143 | 131 |
144 this->name = "NULLPO"; | 132 this->name = "NULLPO"; |
145 | 133 |
153 | 141 |
154 init(); | 142 init(); |
155 | 143 |
156 memcpy(this, orig, sizeof(SceneGraph)); | 144 memcpy(this, orig, sizeof(SceneGraph)); |
157 | 145 |
158 matrix = (float*)manager->allocate(sizeof(float)*16); | 146 allocate_init(manager); |
159 texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); | |
160 | 147 |
161 for (int i = 0; i < 16; i++) { | 148 for (int i = 0; i < 16; i++) { |
162 matrix[i] = orig->matrix[i]; | 149 matrix[i] = orig->matrix[i]; |
163 } | 150 } |
164 | 151 |
185 /* construct polygon from xmlNode. */ | 172 /* construct polygon from xmlNode. */ |
186 SceneGraph::SceneGraph(TaskManager *manager, xmlNodePtr surface) | 173 SceneGraph::SceneGraph(TaskManager *manager, xmlNodePtr surface) |
187 { | 174 { |
188 | 175 |
189 init(); | 176 init(); |
190 | 177 allocate_init(manager); |
191 matrix = (float*)manager->allocate(sizeof(float)*16*2); | |
192 texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); | |
193 texture_info->texture_id = -1; | 178 texture_info->texture_id = -1; |
194 | 179 |
195 //size : 頂点の数かな | 180 //size : 頂点の数かな |
196 size = atoi((char *)xmlGetProp(surface,(xmlChar *)"size")); | 181 size = atoi((char *)xmlGetProp(surface,(xmlChar *)"size")); |
197 name = (char *)xmlGetProp(surface,(xmlChar *)"name"); | 182 name = (char *)xmlGetProp(surface,(xmlChar *)"name"); |
198 parent_name = (char *)xmlGetProp(surface,(xmlChar *)"parent"); | 183 parent_name = (char *)xmlGetProp(surface,(xmlChar *)"parent"); |
199 | |
200 for (int i = 0; i < 16; i++) { | |
201 matrix[i] = 0; | |
202 } | |
203 for (int i = 0; i < 4; i++) { | |
204 matrix[i*4+i] = 1; | |
205 } | |
206 | 184 |
207 if (size % 3 != 0) { | 185 if (size % 3 != 0) { |
208 printf("vertex size is error. size %% 3 = %lld\n", size % 3); | 186 printf("vertex size is error. size %% 3 = %lld\n", size % 3); |
209 } | 187 } |
210 | 188 |
235 | 213 |
236 | 214 |
237 SceneGraph::SceneGraph(TaskManager *manager,const char *font,int pixels,Uint32 color,const char *string_name) { | 215 SceneGraph::SceneGraph(TaskManager *manager,const char *font,int pixels,Uint32 color,const char *string_name) { |
238 | 216 |
239 init(); | 217 init(); |
240 | 218 allocate_init(manager); |
241 this->matrix = (float*)manager->allocate(sizeof(float)*16); | |
242 this->texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); | |
243 texture_info->texture_id = -1; | 219 texture_info->texture_id = -1; |
220 | |
221 for (int i = 0; i < 16; i++) { | |
222 matrix[i] = 0; | |
223 } | |
224 for (int i = 0; i < 4; i++) { | |
225 matrix[i*4+i] = 1; | |
226 } | |
244 | 227 |
245 //size : 頂点の数かな | 228 //size : 頂点の数かな |
246 size = 6; | 229 size = 6; |
247 parent_name = NULL; | 230 parent_name = NULL; |
248 name = string_name; | 231 name = string_name; |
249 for (int i = 0; i < 16; i++) { | |
250 matrix[i] = 0; | |
251 } | |
252 for (int i = 0; i < 4; i++) { | |
253 matrix[i*4+i] = 1; | |
254 } | |
255 | 232 |
256 if (size % 3 != 0) { | 233 if (size % 3 != 0) { |
257 printf("vertex size is error. size %% 3 = %lld\n", size % 3); | 234 printf("vertex size is error. size %% 3 = %lld\n", size % 3); |
258 } | 235 } |
259 | 236 |
458 flag_drawable = 1; | 435 flag_drawable = 1; |
459 sgid = -1; | 436 sgid = -1; |
460 gid = -1; | 437 gid = -1; |
461 | 438 |
462 frame = 0; | 439 frame = 0; |
463 } | 440 |
441 } | |
442 | |
443 // spe に渡すために 16アラインメント に allocate をする | |
444 void | |
445 SceneGraph::allocate_init(TaskManager *manager) | |
446 { | |
447 matrix = (float*)manager->allocate(sizeof(float)*16); | |
448 out_matrix = (float*)manager->allocate(sizeof(float)*16); | |
449 texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); | |
450 | |
451 for (int i = 0; i < 16; i++) { | |
452 matrix[i] = 0; | |
453 out_matrix[i] = 0; | |
454 } | |
455 for (int i = 0; i < 4; i++) { | |
456 matrix[i*4+i] = 1; | |
457 out_matrix[i*4+i] = 1; | |
458 } | |
459 } | |
460 | |
464 | 461 |
465 SceneGraph::~SceneGraph() | 462 SceneGraph::~SceneGraph() |
466 { | 463 { |
467 (this->*finalize)(); | 464 (this->*finalize)(); |
468 } | 465 } |
1226 * @param z Ttranslate in the z direction | 1223 * @param z Ttranslate in the z direction |
1227 */ | 1224 */ |
1228 void | 1225 void |
1229 SceneGraph::translate(float x, float y, float z) | 1226 SceneGraph::translate(float x, float y, float z) |
1230 { | 1227 { |
1231 this->matrix[3] += x; | 1228 this->matrix[12] += x; |
1232 this->matrix[4+3] += y; | 1229 this->matrix[13] += y; |
1233 this->matrix[8+3] += z; | 1230 this->matrix[14] += z; |
1234 } | 1231 } |
1235 | 1232 |
1236 /** | 1233 /** |
1237 * x 軸方向への平行移動 | 1234 * x 軸方向への平行移動 |
1238 * | 1235 * |
1239 * @param x Ttranslate in the x direction | 1236 * @param x Ttranslate in the x direction |
1240 */ | 1237 */ |
1241 void | 1238 void |
1242 SceneGraph::translateX(float x) | 1239 SceneGraph::translateX(float x) |
1243 { | 1240 { |
1244 this->matrix[3] += x; | 1241 this->matrix[12] += x; |
1245 } | 1242 } |
1246 | 1243 |
1247 /** | 1244 /** |
1248 * y 軸方向への平行移動 | 1245 * y 軸方向への平行移動 |
1249 * | 1246 * |
1250 * @param y Ttranslate in the y direction | 1247 * @param y Ttranslate in the y direction |
1251 */ | 1248 */ |
1252 void | 1249 void |
1253 SceneGraph::translateY(float y) | 1250 SceneGraph::translateY(float y) |
1254 { | 1251 { |
1255 this->matrix[4+3] += y; | 1252 this->matrix[13] += y; |
1256 } | 1253 } |
1257 | 1254 |
1258 /** | 1255 /** |
1259 * z 軸方向への平行移動 | 1256 * z 軸方向への平行移動 |
1260 * | 1257 * |
1261 * @param z Ttranslate in the z direction | 1258 * @param z Ttranslate in the z direction |
1262 */ | 1259 */ |
1263 void | 1260 void |
1264 SceneGraph::translateZ(float z) | 1261 SceneGraph::translateZ(float z) |
1265 { | 1262 { |
1266 this->matrix[8+3] += z; | 1263 this->matrix[14] += z; |
1267 } | 1264 } |
1268 | 1265 |
1269 void | 1266 void |
1270 SceneGraph::angleIt(float *angle) | 1267 SceneGraph::angleIt(float xangle, float yangle, float zangle) |
1271 { | 1268 { |
1272 float m[16]; | 1269 float m[16]; |
1273 float t[4] = {0,0,0,0}; | 1270 float t[4] = {0,0,0,0}; |
1271 float angle[4] = {xangle, yangle, zangle, 1}; | |
1274 for(int i=0;i<16;i++) m[i] = matrix[i]; | 1272 for(int i=0;i<16;i++) m[i] = matrix[i]; |
1275 get_matrix(matrix, angle, t, m); | 1273 get_matrix(matrix, angle, t, m); |
1276 } | 1274 } |
1277 | 1275 |
1278 void | 1276 void |