Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/SceneGraph.cc @ 906:348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
author | Yutaka_Kinjyo |
---|---|
date | Mon, 19 Jul 2010 23:40:53 +0900 |
parents | dd0801f355a2 |
children | 830bcfbde3bc |
rev | line source |
---|---|
507 | 1 #include <iostream> |
2 #include <SDL.h> | |
3 #include <SDL_opengl.h> | |
4 #include <SDL_image.h> | |
5 #include <libxml/parser.h> | |
6 #include "SceneGraph.h" | |
7 #include "xml.h" | |
8 #include "sys.h" | |
9 #include "TextureHash.h" | |
10 #include "texture.h" | |
11 #include "TaskManager.h" | |
12 | |
13 using namespace std; | |
14 | |
15 SceneGraphPtr scene_graph = NULL; | |
16 SceneGraphPtr scene_graph_viewer = NULL; | |
17 | |
18 static TextureHash texture_hash; | |
860 | 19 texture_list list[TABLE_SIZE]; |
20 | |
507 | 21 |
22 extern int decode(char *cont, FILE *outfile); | |
23 | |
24 static void | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
25 no_move(SceneGraphPtr self, void *sgroot_, int screen_w, int screen_h) {} |
507 | 26 |
27 static void | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
28 no_collision(SceneGraphPtr self, void *sgroot_, int screen_w, int screen_h, |
507 | 29 SceneGraphPtr tree) {} |
30 | |
31 /** | |
32 * 事前に計算したテクスチャの最大縮小率 scale まで、 | |
33 * テクスチャを 1/2 縮小していく。 | |
34 * このとき、テクスチャは TEXTURE_SPLIT_PIXELx2 のブロック (Tile) で分割し、 | |
35 * これらを連続したメモリ領域に格納していく。 | |
36 * 以下の (1), (2), (3) を Tapestry と呼ぶ | |
37 * | |
38 * 例 scale = 4 の場合 | |
39 * | |
40 * Tapestry(1) 1/1 | |
41 * +---+---+---+---+ | |
42 * | 0 | 1 | 2 | 3 | | |
43 * +---+---+---+---+ | |
44 * | 4 | 5 | 6 | 7 | (2) 1/2 | |
45 * +---+---+---+---+ +---+---+ | |
46 * | 8 | 9 | 10| 11| | 16| 17| (3) 1/4 | |
47 * +---+---+---+---+ +---+---+ +---+ | |
48 * | 12| 13| 14| 15| | 18| 19| | 20| | |
49 * +---+---+---+---+ +---+---+ +---| | |
50 * | |
51 * (1) (2) (3) | |
52 * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | |
53 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * | * | * | 14| 15| 16| 17| 18| 19| 20| | |
54 * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | |
55 * | |
56 * @param[in] tex_w Width of orignal texture | |
57 * @param[in] tex_h Height of orignal texture | |
58 * @param[in] tex_src Original texture | |
59 * @param[in] all_pixel_num Tapestry の合計 pixel 数 | |
60 * @param[in] scale テクスチャの最大縮小率 (= 2^n) | |
61 * @return (1) のアドレス | |
62 */ | |
63 static uint32* | |
64 makeTapestry(TaskManager *manager, int tex_w, int tex_h, uint32 *tex_src, | |
65 int all_pixel_num, int scale_cnt) | |
66 { | |
67 | |
68 int t = 0; | |
69 int diff = TEXTURE_SPLIT_PIXEL; | |
70 int p_diff = 1; | |
71 | |
72 uint32 *tex_dest = (uint32*)manager->allocate(sizeof(int)*all_pixel_num); | |
73 | |
74 while (scale_cnt) { | |
75 for (int y = 0; y < tex_h; y += diff) { | |
76 for (int x = 0; x < tex_w; x += diff) { | |
77 for (int j = 0; j < diff; j += p_diff) { | |
78 for (int i = 0; i < diff; i += p_diff) { | |
79 tex_dest[t++] | |
80 = tex_src[(x+i) + tex_w*(y+j)]; | |
81 } | |
82 } | |
83 } | |
84 } | |
85 | |
86 diff <<= 1; | |
87 p_diff <<= 1; | |
88 scale_cnt >>= 1; | |
89 } | |
90 | |
91 return tex_dest; | |
92 } | |
93 | |
94 | |
95 /** | |
96 * 何の情報も持ってない SceneGraph の生成 | |
97 * 今のところ、とりあえず木構造の繋がりに使うぐらい | |
98 */ | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
99 SceneGraph::SceneGraph() |
507 | 100 { |
101 init(); | |
102 finalize = &SceneGraph::finalize_copy; | |
103 | |
861 | 104 #if SPE_CREATE_POLYGON |
105 | |
106 sg_matrix = (float*)malloc(sizeof(float)*32); | |
107 matrix = sg_matrix; | |
108 real_matrix = sg_matrix + 16; | |
109 | |
110 #endif | |
111 | |
507 | 112 this->name = "NULLPO"; |
113 } | |
114 | |
115 /** | |
116 * orig のコピーとして SceneGraph を生成する | |
117 */ | |
118 SceneGraph::SceneGraph(SceneGraphPtr orig) | |
119 { | |
120 init(); | |
121 memcpy(this, orig, sizeof(SceneGraph)); | |
122 | |
123 // コピーしない | |
124 //flag_remove = 0; | |
125 //flag_drawable = 1; | |
126 next = NULL; | |
127 prev = NULL; | |
128 last = NULL; | |
129 | |
130 parent = NULL; | |
131 brother = NULL; | |
132 children = NULL; | |
133 lastChild = NULL; | |
134 | |
135 finalize = &SceneGraph::finalize_copy; | |
136 | |
137 | |
138 frame = 0; | |
139 } | |
140 | |
141 | |
142 /* construct polygon from xmlNode. */ | |
143 SceneGraph::SceneGraph(TaskManager *manager, xmlNodePtr surface) | |
144 { | |
145 init(); | |
146 | |
147 size = atoi((char *)xmlGetProp(surface,(xmlChar *)"size")); | |
148 name = (char *)xmlGetProp(surface,(xmlChar *)"name"); | |
149 parent_name = (char *)xmlGetProp(surface,(xmlChar *)"parent"); | |
861 | 150 //texture_info = (texture_list_ptr)manager->allocate(sizeof(texture_list)); |
860 | 151 //data = new float[size*3*3]; |
507 | 152 |
860 | 153 #if SPE_CREATE_POLYGON |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
891
diff
changeset
|
154 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
891
diff
changeset
|
155 coord_pack_size = sizeof(float)*8*size*3; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
891
diff
changeset
|
156 coord_pack = (flaat*)manager->allocate(coord_pack_size); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
891
diff
changeset
|
157 |
860 | 158 #else |
159 | |
507 | 160 coord_xyz = (float*)manager->allocate(sizeof(float)*size*3); |
161 coord_tex = (float*)manager->allocate(sizeof(float)*size*3); | |
162 normal = (float*)manager->allocate(sizeof(float)*size*3); | |
163 | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
891
diff
changeset
|
164 coord_pack_size = sizeof(float)*8*size*3; // coord_pack_vertex size is 32byte. vertex num 3. |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
891
diff
changeset
|
165 coord_pack = (float*)manager->allocate(coord_pack_size); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
891
diff
changeset
|
166 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
891
diff
changeset
|
167 int sg_matrix_size = 32; // matrix 16 + real_matrix 32. |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
891
diff
changeset
|
168 sg_matrix = (float*)manager->allocate(sg_matrix_size); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
891
diff
changeset
|
169 |
860 | 170 #endif |
171 | |
507 | 172 get_data(manager, surface->children); |
173 | |
174 finalize = &SceneGraph::finalize_original; | |
175 } | |
176 | |
177 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
178 SceneGraph::init() |
507 | 179 { |
180 next = NULL; | |
181 prev = NULL; | |
182 last = NULL; | |
183 | |
184 parent = NULL; | |
185 brother = NULL; | |
186 children = NULL; | |
187 lastChild = NULL; | |
188 | |
189 stack_xyz[0] = 0.0f; | |
190 stack_xyz[2] = 0.0f; | |
191 stack_xyz[1] = 0.0f; | |
192 stack_angle[0] = 0.0f; | |
193 stack_angle[1] = 0.0f; | |
194 stack_angle[2] = 0.0f; | |
195 | |
196 size = 0; | |
197 //data = NULL; | |
860 | 198 |
199 #if SPE_CREATE_POLYGON | |
200 | |
861 | 201 //tri_pack = NULL; |
202 //sg_matrix = NULL; | |
203 //matrix = NULL; | |
204 //real_matrix = NULL; | |
205 //texture_info = NULL; | |
860 | 206 |
207 #else | |
208 | |
507 | 209 coord_xyz = NULL; |
210 normal = NULL; | |
211 coord_tex = NULL; | |
212 | |
860 | 213 #endif |
214 | |
507 | 215 texture_id = -1; |
216 move = no_move; | |
217 collision = no_collision; | |
218 | |
219 flag_remove = 0; | |
220 flag_drawable = 1; | |
221 sgid = -1; | |
222 gid = -1; | |
223 | |
224 frame = 0; | |
225 } | |
226 | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
227 SceneGraph::~SceneGraph() |
507 | 228 { |
229 (this->*finalize)(); | |
230 } | |
231 | |
232 /** | |
233 * xml ファイルから生成されたオリジナル SceneGraph なので | |
234 * polygon data を削除 | |
235 */ | |
236 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
237 SceneGraph::finalize_original() |
507 | 238 { |
239 //delete [] data; | |
860 | 240 |
241 #if SPE_CREATE_POLYGON | |
242 | |
243 free(tri_pack); | |
244 free(sg_matrix); | |
861 | 245 //free(matrix); |
246 //free(real_matrix); | |
860 | 247 free(texture_info); |
248 | |
249 #else | |
250 | |
507 | 251 free(coord_xyz); |
252 free(coord_tex); | |
253 free(normal); | |
860 | 254 |
255 #endif | |
256 | |
507 | 257 } |
258 | |
259 /** | |
260 * SceneGraph ID から生成された、コピー SceneGraph なので | |
261 * polygon data は削除しない。オリジナルの方で削除する。 | |
262 */ | |
263 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
264 SceneGraph::finalize_copy() |
507 | 265 { |
266 } | |
267 | |
268 | |
269 /** | |
270 * add Children | |
271 * 親の登録と、brother のリストへ加える | |
272 * | |
273 * @param child new child | |
274 */ | |
275 SceneGraphPtr | |
276 SceneGraph::addChild(SceneGraphPtr child) | |
277 { | |
278 /* childrenのリストの最後に加える (brother として)*/ | |
279 if (this->lastChild != NULL) { | |
280 SceneGraphPtr last = this->lastChild; | |
281 last->brother = child; | |
850 | 282 //child->parent = this; |
283 //return child; | |
507 | 284 } |
891 | 285 |
507 | 286 this->lastChild = child; |
891 | 287 |
507 | 288 if (this->children == NULL) { |
289 this->children = child; | |
290 } | |
891 | 291 |
507 | 292 child->parent = this; |
293 | |
294 return child; | |
295 } | |
296 | |
297 | |
298 /** | |
299 * add Brother | |
300 * addChild() でも brother の操作をしないといけないので、そっちに回す | |
301 * | |
302 * @param bro new Brother | |
303 */ | |
304 SceneGraphPtr | |
305 SceneGraph::addBrother(SceneGraphPtr bro) | |
306 { | |
307 if (this->parent) { | |
308 parent->addChild(bro); | |
309 } else { | |
310 fprintf(stderr, "error : SceneGraph::%s : %s doesn't have parent\n", | |
311 __FUNCTION__, this->name); | |
312 } | |
313 | |
314 return bro; | |
315 } | |
316 | |
317 /* thisの子や子孫にnameのものが存在すればそいつを返す なければNULL. */ | |
318 SceneGraphPtr | |
319 SceneGraph::searchSceneGraph(const char *name) | |
320 { | |
321 SceneGraphPtr tmp; | |
322 SceneGraphPtr result; | |
323 | |
324 /* 本人か */ | |
325 if( 0==strcmp(this->name, name) ) return this; | |
326 | |
327 /* 子供から再帰的に探す */ | |
328 for(tmp = this->children; tmp; tmp = tmp->next) { | |
329 if ((result=tmp->searchSceneGraph(name)) != NULL) | |
330 return result; | |
331 } | |
332 | |
333 /* 無かったら NULL. */ | |
334 return NULL; | |
335 } | |
336 | |
337 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
338 SceneGraph::tree_check() |
507 | 339 { |
340 SceneGraphPtr t = this; | |
341 | |
342 while(t) | |
343 { | |
344 cout << "my_name : " << t->name << endl; | |
345 if(t->children != NULL) | |
346 { | |
347 cout << "--move children : " << t->children->name << endl; | |
348 t = t->children; | |
349 } | |
350 else if(t->brother != NULL) | |
351 { | |
352 cout << "--move brother : " << t->brother->name << endl; | |
353 t = t->brother; | |
354 } | |
355 else | |
356 { | |
357 while(t) | |
358 { | |
359 if(t->brother != NULL) | |
360 { | |
361 cout << "--move brother : " << t->brother->name << endl; | |
362 t = t->brother; | |
363 break; | |
364 } | |
365 else | |
366 { | |
367 if(t->parent) | |
368 { | |
369 cout << "--move parent : " << t->parent->name << endl; | |
370 } | |
371 t = t->parent; | |
372 } | |
373 } | |
374 } | |
375 } | |
376 } | |
377 | |
378 | |
379 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
380 SceneGraph::print_member() |
507 | 381 { |
382 cout << "size = " << size << endl; | |
383 cout << "name = " << name << endl; | |
384 cout << "parent_name = " << parent_name << endl; | |
385 | |
386 if (parent != NULL) { | |
387 cout << "parent->name = " << parent->name << endl; | |
388 } | |
389 | |
390 if (children != NULL) { | |
391 cout << "children->name = " << children->name << endl; | |
392 } | |
393 } | |
394 | |
395 | |
396 /* | |
397 * surface nodeからポリゴンの情報を読み出す 再帰しない | |
398 */ | |
399 void | |
400 SceneGraph::get_data(TaskManager *manager, xmlNodePtr cur) | |
401 { | |
402 //char *image_name; | |
403 | |
404 for(;cur;cur=cur->next) | |
405 { | |
406 if(!xmlStrcmp(cur->name,(xmlChar*)"coordinate")) | |
407 { | |
408 char *cont = (char *)xmlNodeGetContent(cur); | |
409 pickup_coordinate(cont); | |
410 } | |
411 else if(!xmlStrcmp(cur->name,(xmlChar*)"normal")) | |
412 { | |
413 char *cont = (char *)xmlNodeGetContent(cur); | |
414 pickup_normal(cont); | |
415 } | |
416 else if(!xmlStrcmp(cur->name,(xmlChar*)"model")) | |
417 { | |
418 char *cont = (char *)xmlNodeGetContent(cur); | |
419 pickup_model(cont); | |
420 } | |
421 else if(!xmlStrcmp(cur->name,(xmlChar*)"texture")) | |
422 { | |
423 char *cont = (char *)xmlNodeGetContent(cur); | |
424 pickup_texture(cont); | |
425 } | |
426 else if(!xmlStrcmp(cur->name,(xmlChar*)"imageflag")) | |
427 { | |
428 int id; | |
429 char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); | |
430 texture_hash.hash_regist(filename, id); | |
431 } | |
432 else if(!xmlStrcmp(cur->name,(xmlChar*)"image")) | |
433 { | |
434 get_image(manager, cur); | |
435 } | |
436 } | |
437 } | |
438 | |
439 SDL_Surface* | |
440 SceneGraph::load_decode_image(char *image_name, xmlNodePtr cur) | |
441 { | |
442 int fd = mkstemp(image_name); | |
443 FILE *outfile = fdopen(fd, "wb"); | |
444 | |
445 if (NULL == outfile) { | |
446 cout << "error open file\n"; | |
447 return 0; | |
448 } | |
449 | |
450 char *cont = (char *)xmlNodeGetContent(cur); | |
451 //decode(cont, image_name); | |
452 decode(cont, outfile); | |
453 fclose(outfile); | |
454 | |
455 | |
456 /** | |
457 * image を 32bit(RGBA) に変換する | |
458 */ | |
459 SDL_Surface *texture_image = IMG_Load(image_name); | |
580
da82a47ece92
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
507
diff
changeset
|
460 if (!texture_image) return 0; |
507 | 461 SDL_Surface *tmpImage |
462 = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w, | |
463 texture_image->h, 32, redMask, | |
464 greenMask, blueMask, alphaMask); | |
465 SDL_Surface *converted; | |
466 converted = SDL_ConvertSurface(texture_image, tmpImage->format, | |
467 SDL_HWSURFACE); | |
468 if (converted != NULL) { | |
469 SDL_FreeSurface(texture_image); | |
470 texture_image = converted; | |
471 } | |
472 | |
473 return texture_image; | |
474 } | |
475 | |
476 int | |
477 SceneGraph::makeTapestries(TaskManager *manager, SDL_Surface *texture_image, int id) { | |
478 uint32 *tapestry; | |
479 int scale = 1; | |
480 int tex_w = texture_image->w; | |
481 int tex_h = texture_image->h; | |
482 int all_pixel_num = 0; | |
483 | |
484 /** | |
485 * テクスチャの w or h が 8 pixel で分割できる間、 | |
486 * 1/2 の縮小画像を作る。 | |
487 * ここでは、最大の scale (1/scale) を見つける | |
488 * | |
489 * (ex) | |
490 * (128,128) => 64,64 : 32,32: 16,16 : 8,8 | |
491 * scale = 16 | |
492 * (128, 64) => 64,32 : 32,16: 16,8 | |
493 * scale = 8 | |
494 */ | |
495 while (tex_w % TEXTURE_SPLIT_PIXEL == 0 && | |
496 tex_h % TEXTURE_SPLIT_PIXEL == 0) { | |
497 all_pixel_num += tex_w*tex_h; | |
498 tex_w >>= 1; /* tex_w /= 2 */ | |
499 tex_h >>= 1; | |
500 scale <<= 1; /* scale *= 2 */ | |
501 } | |
502 | |
503 scale >>= 1; | |
504 | |
505 tapestry = makeTapestry(manager, texture_image->w, texture_image->h, | |
506 (uint32*)texture_image->pixels, | |
507 all_pixel_num, scale); | |
508 | |
509 list[id].t_w = texture_image->w; | |
510 list[id].t_h = texture_image->h; | |
511 list[id].pixels_orig = (Uint32*)texture_image->pixels; | |
512 list[id].pixels = tapestry; | |
513 list[id].scale_max = scale; | |
514 | |
515 return id; | |
516 } | |
517 | |
518 void | |
519 SceneGraph::get_image(TaskManager *manager, xmlNodePtr cur) | |
520 { | |
521 char image_name[20] = "/tmp/image_XXXXXX"; | |
522 char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); | |
523 | |
524 if (filename == NULL || filename[0] == 0) { | |
525 return; | |
526 } | |
527 | |
528 /** | |
529 * image_name を既に Load していれば何もしない | |
530 */ | |
531 int tex_id; | |
532 if (!texture_hash.hash_regist(filename, tex_id)) { | |
533 | |
534 SDL_Surface *texture_image = load_decode_image(image_name, cur); | |
580
da82a47ece92
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
507
diff
changeset
|
535 if (texture_image==0) { |
da82a47ece92
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
507
diff
changeset
|
536 printf("Can't load image %s\n",filename); |
da82a47ece92
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
507
diff
changeset
|
537 exit(0); |
da82a47ece92
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
507
diff
changeset
|
538 } |
507 | 539 |
540 texture_id = makeTapestries(manager, texture_image, tex_id); | |
541 | |
542 if (unlink(image_name)) { | |
543 cout << "unlink error\n"; | |
544 } | |
545 } else { | |
546 /** | |
547 * 以前に Load されている Texture を共用 | |
548 */ | |
549 texture_id = tex_id; | |
550 } | |
551 | |
860 | 552 |
553 #if SPE_CREATE_POLYGON | |
554 | |
555 | |
556 texture_info->t_w = list[texture_id].t_w; | |
557 texture_info->t_h = list[texture_id].t_h;; | |
558 texture_info->pixels_orig = list[texture_id].pixels_orig; | |
559 texture_info->pixels = list[texture_id].pixels; | |
560 texture_info->scale_max = list[texture_id].scale_max; | |
561 | |
562 | |
563 #else | |
564 | |
565 // こんなことすると list[] のいみあるのかなーと | |
566 // 微妙に思う、自分で書き換えた感想 by gongo | |
567 texture_info.t_w = list[texture_id].t_w; | |
568 texture_info.t_h = list[texture_id].t_h;; | |
569 texture_info.pixels_orig = list[texture_id].pixels_orig; | |
570 texture_info.pixels = list[texture_id].pixels; | |
571 texture_info.scale_max = list[texture_id].scale_max; | |
572 | |
573 #endif | |
574 | |
507 | 575 } |
576 | |
577 | |
578 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
579 SceneGraph::delete_data() |
507 | 580 { |
581 SceneGraphPtr n = this->next, m; | |
582 | |
583 //n = this; | |
584 //delete [] n->data; | |
585 | |
586 if (next) { | |
587 while (n) { | |
588 m = n->next; | |
589 delete n; | |
590 n = m; | |
591 } | |
592 } | |
593 } | |
594 | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
595 /* move_func 実行 sgroot 渡す */ |
507 | 596 void |
597 SceneGraph::move_execute(int w, int h) | |
598 { | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
599 (*move)(this, this->sgroot, w, h); |
507 | 600 } |
601 | |
602 void | |
603 SceneGraph::collision_check(int w, int h, SceneGraphPtr tree) | |
604 { | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
605 (*collision)(this, this->sgroot, w, h, tree); |
507 | 606 } |
607 | |
760
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
608 void |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
609 SceneGraph::create_sg_execute() |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
610 { |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
611 (*create_sg)(this->sgroot, property, update_property); |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
612 } |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
613 |
507 | 614 |
615 void | |
616 SceneGraph::set_move_collision(move_func new_move, | |
617 collision_func new_collision) | |
618 { | |
619 this->move = new_move; | |
620 this->collision = new_collision; | |
621 } | |
622 | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
623 |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
624 void |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
625 SceneGraph::set_move_collision(move_func new_move, |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
626 collision_func new_collision, void *sgroot_) |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
627 { |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
628 this->move = new_move; |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
629 this->collision = new_collision; |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
630 // add |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
631 this->sgroot = sgroot_; |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
632 } |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
633 |
507 | 634 void |
760
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
635 SceneGraph::set_move_collision(move_func new_move, |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
636 collision_func new_collision, create_sg_func new_create_sg) |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
637 { |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
638 this->move = new_move; |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
639 this->collision = new_collision; |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
640 this->create_sg = new_create_sg; |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
641 } |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
642 |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
643 void |
507 | 644 SceneGraph::add_next(SceneGraphPtr next) |
645 { | |
646 /* next のリストの最後に加える */ | |
647 if (this->next != NULL) { | |
648 SceneGraphPtr tmp = this->last; | |
649 tmp->next = next; | |
650 } else { | |
651 this->next = next; | |
652 } | |
653 | |
654 this->last = next; | |
655 } | |
656 | |
657 /** | |
658 * SceneGraph の clone | |
659 * @return clone SceneGraph | |
660 */ | |
661 SceneGraphPtr | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
662 SceneGraph::clone() { |
507 | 663 SceneGraphPtr p = new SceneGraph(this); |
664 return p; | |
665 } | |
666 | |
667 /** | |
668 * SceneGraph の clone | |
669 * 予め allocate されてる領域への placement new を行う | |
670 * | |
671 * @param buf clone 領域 | |
672 * @return clone SceneGraph | |
673 */ | |
674 SceneGraphPtr | |
675 SceneGraph::clone(void *buf) { | |
676 SceneGraphPtr p = new(buf) SceneGraph(this); | |
677 return p; | |
678 } | |
679 | |
680 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
681 SceneGraph::remove() |
507 | 682 { |
683 this->flag_remove = 1; | |
684 } | |
685 | |
686 /** | |
687 * tree から node を削除する | |
688 * | |
689 * @param tree SceneGraphTree | |
690 * @return node削除後の SceneGraphTree | |
691 */ | |
692 SceneGraphPtr | |
693 SceneGraph::realRemoveFromTree(SceneGraphPtr tree) | |
694 { | |
695 SceneGraphPtr node = this; | |
696 SceneGraphPtr parent = node->parent; | |
697 SceneGraphPtr ret = tree; | |
698 | |
699 if (parent) { | |
700 SceneGraphPtr brother = parent->children; | |
701 SceneGraphPtr p, p1 = NULL; | |
702 | |
703 p = brother; | |
704 if (p) { | |
705 if (p == node) { | |
706 parent->children = NULL; | |
707 parent->lastChild = NULL; | |
708 } else { | |
709 p1 = p->brother; | |
710 | |
711 while (p1 && p1 != node) { | |
712 p1 = p1->brother; | |
713 p = p->brother; | |
714 } | |
715 | |
716 if (p1) { | |
717 p->brother = p1->brother; | |
718 | |
719 // node が最後尾なら、lastChild を変更 | |
720 if (parent->lastChild == p1) { | |
721 parent->lastChild = p; | |
722 } | |
723 } else { | |
724 // Can't find remove node | |
725 } | |
726 } | |
727 } | |
728 } else { | |
729 // 親が居ない = tree root なので | |
730 // NULL を返す | |
731 ret = NULL; | |
732 } | |
733 | |
734 return ret; | |
735 } | |
736 | |
737 /** | |
738 * list から node を削除する | |
739 * | |
740 * @param list SceneGraphList | |
741 * @return node削除後の SceneGraphList | |
742 */ | |
743 SceneGraphPtr | |
744 SceneGraph::realRemoveFromList(SceneGraphPtr list) | |
745 { | |
746 SceneGraphPtr node = this; | |
747 SceneGraphPtr prev = node->prev; | |
748 SceneGraphPtr next = node->next; | |
749 SceneGraphPtr ret = list; | |
750 | |
751 if (prev) { | |
752 prev->next = next; | |
753 } else { | |
754 ret = next; | |
755 } | |
756 | |
757 if (next) { | |
758 next->prev = prev; | |
759 } | |
760 | |
761 return ret; | |
762 } | |
763 | |
764 int | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
765 SceneGraph::isRemoved() |
507 | 766 { |
767 return flag_remove; | |
768 } | |
769 | |
770 /** | |
771 * 平行移動 | |
772 * | |
773 * @param x Ttranslate in the x direction | |
774 * @param y Ttranslate in the y direction | |
775 * @param z Ttranslate in the z direction | |
776 */ | |
777 void | |
778 SceneGraph::translate(float x, float y, float z) | |
779 { | |
780 this->xyz[0] = x; | |
781 this->xyz[1] = y; | |
782 this->xyz[2] = z; | |
783 } | |
784 | |
785 /** | |
786 * x 軸方向への平行移動 | |
787 * | |
788 * @param x Ttranslate in the x direction | |
789 */ | |
790 void | |
791 SceneGraph::translateX(float x) | |
792 { | |
793 this->xyz[0] = x; | |
794 } | |
795 | |
796 /** | |
797 * y 軸方向への平行移動 | |
798 * | |
799 * @param y Ttranslate in the y direction | |
800 */ | |
801 void | |
802 SceneGraph::translateY(float y) | |
803 { | |
804 this->xyz[1] = y; | |
805 } | |
806 | |
807 /** | |
808 * z 軸方向への平行移動 | |
809 * | |
810 * @param z Ttranslate in the z direction | |
811 */ | |
812 void | |
813 SceneGraph::translateZ(float z) | |
814 { | |
815 this->xyz[2] = z; | |
816 } | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
817 |
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
818 /* end */ |