Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/SceneGraph.cc @ 885:d0273488f50c
fix
author | Yutaka_Kinjyo |
---|---|
date | Tue, 13 Jul 2010 16:23:04 +0900 |
parents | f525427ae30f |
children | dd0801f355a2 |
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 |
154 | |
155 /* CreatePolygon を spe 側でやるために。 | |
156 size は頂点の数。speに渡す場合には、16の倍数にして | |
157 16Kbyte以上の場合、16Kbyte毎に分割できるようにしなければならない。 | |
158 CreatePolygonFromSceneGraphTaskをspeで動かすために、speに渡すのは | |
159 TrianglePackでよい。 | |
160 polygon_pack 1つには triangle が 128 になってる。polygon_pack の | |
161 triangle 数に合わせる方が楽だよね。なんか変な気もするけど、polygon | |
162 クラスにもTrianglePackを持たす。SceneGraph は自分の polygon 数が入る | |
163 分だけ、TrianglePackを持つ。CreatePolygonTask にはSceneGraph 側の | |
164 TrianglePack を input に、polygon_pack の TriganlePack を output とする | |
165 */ | |
166 | |
885 | 167 init(); |
168 | |
169 int tri_pack_size = sizeof(TrianglePack)*(size/3); | |
170 printf("tri_pack_size %d\n", tri_pack_size); | |
860 | 171 tri_pack = (TrianglePackPtr)manager->allocate(tri_pack_size); |
172 texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); | |
173 sg_matrix = (float*)manager->allocate(sizeof(float)*32); | |
174 matrix = sg_matrix; | |
175 real_matrix = sg_matrix + 16; | |
176 | |
177 #else | |
178 | |
507 | 179 coord_xyz = (float*)manager->allocate(sizeof(float)*size*3); |
180 coord_tex = (float*)manager->allocate(sizeof(float)*size*3); | |
181 normal = (float*)manager->allocate(sizeof(float)*size*3); | |
182 | |
860 | 183 #endif |
184 | |
507 | 185 get_data(manager, surface->children); |
186 | |
187 finalize = &SceneGraph::finalize_original; | |
188 } | |
189 | |
190 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
191 SceneGraph::init() |
507 | 192 { |
193 next = NULL; | |
194 prev = NULL; | |
195 last = NULL; | |
196 | |
197 parent = NULL; | |
198 brother = NULL; | |
199 children = NULL; | |
200 lastChild = NULL; | |
201 | |
202 stack_xyz[0] = 0.0f; | |
203 stack_xyz[2] = 0.0f; | |
204 stack_xyz[1] = 0.0f; | |
205 stack_angle[0] = 0.0f; | |
206 stack_angle[1] = 0.0f; | |
207 stack_angle[2] = 0.0f; | |
208 | |
209 size = 0; | |
210 //data = NULL; | |
860 | 211 |
212 #if SPE_CREATE_POLYGON | |
213 | |
861 | 214 //tri_pack = NULL; |
215 //sg_matrix = NULL; | |
216 //matrix = NULL; | |
217 //real_matrix = NULL; | |
218 //texture_info = NULL; | |
860 | 219 |
220 #else | |
221 | |
507 | 222 coord_xyz = NULL; |
223 normal = NULL; | |
224 coord_tex = NULL; | |
225 | |
860 | 226 #endif |
227 | |
507 | 228 texture_id = -1; |
229 move = no_move; | |
230 collision = no_collision; | |
231 | |
232 flag_remove = 0; | |
233 flag_drawable = 1; | |
234 sgid = -1; | |
235 gid = -1; | |
236 | |
237 frame = 0; | |
238 } | |
239 | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
240 SceneGraph::~SceneGraph() |
507 | 241 { |
242 (this->*finalize)(); | |
243 } | |
244 | |
245 /** | |
246 * xml ファイルから生成されたオリジナル SceneGraph なので | |
247 * polygon data を削除 | |
248 */ | |
249 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
250 SceneGraph::finalize_original() |
507 | 251 { |
252 //delete [] data; | |
860 | 253 |
254 #if SPE_CREATE_POLYGON | |
255 | |
256 free(tri_pack); | |
257 free(sg_matrix); | |
861 | 258 //free(matrix); |
259 //free(real_matrix); | |
860 | 260 free(texture_info); |
261 | |
262 #else | |
263 | |
507 | 264 free(coord_xyz); |
265 free(coord_tex); | |
266 free(normal); | |
860 | 267 |
268 #endif | |
269 | |
507 | 270 } |
271 | |
272 /** | |
273 * SceneGraph ID から生成された、コピー SceneGraph なので | |
274 * polygon data は削除しない。オリジナルの方で削除する。 | |
275 */ | |
276 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
277 SceneGraph::finalize_copy() |
507 | 278 { |
279 } | |
280 | |
281 | |
282 /** | |
283 * add Children | |
284 * 親の登録と、brother のリストへ加える | |
285 * | |
286 * @param child new child | |
287 */ | |
288 SceneGraphPtr | |
289 SceneGraph::addChild(SceneGraphPtr child) | |
290 { | |
291 /* childrenのリストの最後に加える (brother として)*/ | |
292 if (this->lastChild != NULL) { | |
293 SceneGraphPtr last = this->lastChild; | |
294 last->brother = child; | |
850 | 295 //child->parent = this; |
296 //return child; | |
507 | 297 } |
298 | |
299 this->lastChild = child; | |
300 | |
301 if (this->children == NULL) { | |
302 this->children = child; | |
303 } | |
304 | |
305 child->parent = this; | |
306 | |
307 return child; | |
308 } | |
309 | |
310 | |
311 /** | |
312 * add Brother | |
313 * addChild() でも brother の操作をしないといけないので、そっちに回す | |
314 * | |
315 * @param bro new Brother | |
316 */ | |
317 SceneGraphPtr | |
318 SceneGraph::addBrother(SceneGraphPtr bro) | |
319 { | |
320 if (this->parent) { | |
321 parent->addChild(bro); | |
322 } else { | |
323 fprintf(stderr, "error : SceneGraph::%s : %s doesn't have parent\n", | |
324 __FUNCTION__, this->name); | |
325 } | |
326 | |
327 return bro; | |
328 } | |
329 | |
330 /* thisの子や子孫にnameのものが存在すればそいつを返す なければNULL. */ | |
331 SceneGraphPtr | |
332 SceneGraph::searchSceneGraph(const char *name) | |
333 { | |
334 SceneGraphPtr tmp; | |
335 SceneGraphPtr result; | |
336 | |
337 /* 本人か */ | |
338 if( 0==strcmp(this->name, name) ) return this; | |
339 | |
340 /* 子供から再帰的に探す */ | |
341 for(tmp = this->children; tmp; tmp = tmp->next) { | |
342 if ((result=tmp->searchSceneGraph(name)) != NULL) | |
343 return result; | |
344 } | |
345 | |
346 /* 無かったら NULL. */ | |
347 return NULL; | |
348 } | |
349 | |
350 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
351 SceneGraph::tree_check() |
507 | 352 { |
353 SceneGraphPtr t = this; | |
354 | |
355 while(t) | |
356 { | |
357 cout << "my_name : " << t->name << endl; | |
358 if(t->children != NULL) | |
359 { | |
360 cout << "--move children : " << t->children->name << endl; | |
361 t = t->children; | |
362 } | |
363 else if(t->brother != NULL) | |
364 { | |
365 cout << "--move brother : " << t->brother->name << endl; | |
366 t = t->brother; | |
367 } | |
368 else | |
369 { | |
370 while(t) | |
371 { | |
372 if(t->brother != NULL) | |
373 { | |
374 cout << "--move brother : " << t->brother->name << endl; | |
375 t = t->brother; | |
376 break; | |
377 } | |
378 else | |
379 { | |
380 if(t->parent) | |
381 { | |
382 cout << "--move parent : " << t->parent->name << endl; | |
383 } | |
384 t = t->parent; | |
385 } | |
386 } | |
387 } | |
388 } | |
389 } | |
390 | |
391 | |
392 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
393 SceneGraph::print_member() |
507 | 394 { |
395 cout << "size = " << size << endl; | |
396 cout << "name = " << name << endl; | |
397 cout << "parent_name = " << parent_name << endl; | |
398 | |
399 if (parent != NULL) { | |
400 cout << "parent->name = " << parent->name << endl; | |
401 } | |
402 | |
403 if (children != NULL) { | |
404 cout << "children->name = " << children->name << endl; | |
405 } | |
406 } | |
407 | |
408 | |
409 /* | |
410 * surface nodeからポリゴンの情報を読み出す 再帰しない | |
411 */ | |
412 void | |
413 SceneGraph::get_data(TaskManager *manager, xmlNodePtr cur) | |
414 { | |
415 //char *image_name; | |
416 | |
417 for(;cur;cur=cur->next) | |
418 { | |
419 if(!xmlStrcmp(cur->name,(xmlChar*)"coordinate")) | |
420 { | |
421 char *cont = (char *)xmlNodeGetContent(cur); | |
422 pickup_coordinate(cont); | |
423 } | |
424 else if(!xmlStrcmp(cur->name,(xmlChar*)"normal")) | |
425 { | |
426 char *cont = (char *)xmlNodeGetContent(cur); | |
427 pickup_normal(cont); | |
428 } | |
429 else if(!xmlStrcmp(cur->name,(xmlChar*)"model")) | |
430 { | |
431 char *cont = (char *)xmlNodeGetContent(cur); | |
432 pickup_model(cont); | |
433 } | |
434 else if(!xmlStrcmp(cur->name,(xmlChar*)"texture")) | |
435 { | |
436 char *cont = (char *)xmlNodeGetContent(cur); | |
437 pickup_texture(cont); | |
438 } | |
439 else if(!xmlStrcmp(cur->name,(xmlChar*)"imageflag")) | |
440 { | |
441 int id; | |
442 char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); | |
443 texture_hash.hash_regist(filename, id); | |
444 } | |
445 else if(!xmlStrcmp(cur->name,(xmlChar*)"image")) | |
446 { | |
447 get_image(manager, cur); | |
448 } | |
449 } | |
450 } | |
451 | |
452 SDL_Surface* | |
453 SceneGraph::load_decode_image(char *image_name, xmlNodePtr cur) | |
454 { | |
455 int fd = mkstemp(image_name); | |
456 FILE *outfile = fdopen(fd, "wb"); | |
457 | |
458 if (NULL == outfile) { | |
459 cout << "error open file\n"; | |
460 return 0; | |
461 } | |
462 | |
463 char *cont = (char *)xmlNodeGetContent(cur); | |
464 //decode(cont, image_name); | |
465 decode(cont, outfile); | |
466 fclose(outfile); | |
467 | |
468 | |
469 /** | |
470 * image を 32bit(RGBA) に変換する | |
471 */ | |
472 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
|
473 if (!texture_image) return 0; |
507 | 474 SDL_Surface *tmpImage |
475 = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w, | |
476 texture_image->h, 32, redMask, | |
477 greenMask, blueMask, alphaMask); | |
478 SDL_Surface *converted; | |
479 converted = SDL_ConvertSurface(texture_image, tmpImage->format, | |
480 SDL_HWSURFACE); | |
481 if (converted != NULL) { | |
482 SDL_FreeSurface(texture_image); | |
483 texture_image = converted; | |
484 } | |
485 | |
486 return texture_image; | |
487 } | |
488 | |
489 int | |
490 SceneGraph::makeTapestries(TaskManager *manager, SDL_Surface *texture_image, int id) { | |
491 uint32 *tapestry; | |
492 int scale = 1; | |
493 int tex_w = texture_image->w; | |
494 int tex_h = texture_image->h; | |
495 int all_pixel_num = 0; | |
496 | |
497 /** | |
498 * テクスチャの w or h が 8 pixel で分割できる間、 | |
499 * 1/2 の縮小画像を作る。 | |
500 * ここでは、最大の scale (1/scale) を見つける | |
501 * | |
502 * (ex) | |
503 * (128,128) => 64,64 : 32,32: 16,16 : 8,8 | |
504 * scale = 16 | |
505 * (128, 64) => 64,32 : 32,16: 16,8 | |
506 * scale = 8 | |
507 */ | |
508 while (tex_w % TEXTURE_SPLIT_PIXEL == 0 && | |
509 tex_h % TEXTURE_SPLIT_PIXEL == 0) { | |
510 all_pixel_num += tex_w*tex_h; | |
511 tex_w >>= 1; /* tex_w /= 2 */ | |
512 tex_h >>= 1; | |
513 scale <<= 1; /* scale *= 2 */ | |
514 } | |
515 | |
516 scale >>= 1; | |
517 | |
518 tapestry = makeTapestry(manager, texture_image->w, texture_image->h, | |
519 (uint32*)texture_image->pixels, | |
520 all_pixel_num, scale); | |
521 | |
522 list[id].t_w = texture_image->w; | |
523 list[id].t_h = texture_image->h; | |
524 list[id].pixels_orig = (Uint32*)texture_image->pixels; | |
525 list[id].pixels = tapestry; | |
526 list[id].scale_max = scale; | |
527 | |
528 return id; | |
529 } | |
530 | |
531 void | |
532 SceneGraph::get_image(TaskManager *manager, xmlNodePtr cur) | |
533 { | |
534 char image_name[20] = "/tmp/image_XXXXXX"; | |
535 char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); | |
536 | |
537 if (filename == NULL || filename[0] == 0) { | |
538 return; | |
539 } | |
540 | |
541 /** | |
542 * image_name を既に Load していれば何もしない | |
543 */ | |
544 int tex_id; | |
545 if (!texture_hash.hash_regist(filename, tex_id)) { | |
546 | |
547 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
|
548 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
|
549 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
|
550 exit(0); |
da82a47ece92
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
507
diff
changeset
|
551 } |
507 | 552 |
553 texture_id = makeTapestries(manager, texture_image, tex_id); | |
554 | |
555 if (unlink(image_name)) { | |
556 cout << "unlink error\n"; | |
557 } | |
558 } else { | |
559 /** | |
560 * 以前に Load されている Texture を共用 | |
561 */ | |
562 texture_id = tex_id; | |
563 } | |
564 | |
860 | 565 |
566 #if SPE_CREATE_POLYGON | |
567 | |
568 | |
569 texture_info->t_w = list[texture_id].t_w; | |
570 texture_info->t_h = list[texture_id].t_h;; | |
571 texture_info->pixels_orig = list[texture_id].pixels_orig; | |
572 texture_info->pixels = list[texture_id].pixels; | |
573 texture_info->scale_max = list[texture_id].scale_max; | |
574 | |
575 | |
576 #else | |
577 | |
578 // こんなことすると list[] のいみあるのかなーと | |
579 // 微妙に思う、自分で書き換えた感想 by gongo | |
580 texture_info.t_w = list[texture_id].t_w; | |
581 texture_info.t_h = list[texture_id].t_h;; | |
582 texture_info.pixels_orig = list[texture_id].pixels_orig; | |
583 texture_info.pixels = list[texture_id].pixels; | |
584 texture_info.scale_max = list[texture_id].scale_max; | |
585 | |
586 #endif | |
587 | |
507 | 588 } |
589 | |
590 | |
591 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
592 SceneGraph::delete_data() |
507 | 593 { |
594 SceneGraphPtr n = this->next, m; | |
595 | |
596 //n = this; | |
597 //delete [] n->data; | |
598 | |
599 if (next) { | |
600 while (n) { | |
601 m = n->next; | |
602 delete n; | |
603 n = m; | |
604 } | |
605 } | |
606 } | |
607 | |
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
|
608 /* move_func 実行 sgroot 渡す */ |
507 | 609 void |
610 SceneGraph::move_execute(int w, int h) | |
611 { | |
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
|
612 (*move)(this, this->sgroot, w, h); |
507 | 613 } |
614 | |
615 void | |
616 SceneGraph::collision_check(int w, int h, SceneGraphPtr tree) | |
617 { | |
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
|
618 (*collision)(this, this->sgroot, w, h, tree); |
507 | 619 } |
620 | |
760
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
621 void |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
622 SceneGraph::create_sg_execute() |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
623 { |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
624 (*create_sg)(this->sgroot, property, update_property); |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
625 } |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
626 |
507 | 627 |
628 void | |
629 SceneGraph::set_move_collision(move_func new_move, | |
630 collision_func new_collision) | |
631 { | |
632 this->move = new_move; | |
633 this->collision = new_collision; | |
634 } | |
635 | |
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
|
636 |
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
|
637 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
|
638 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
|
639 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
|
640 { |
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
|
641 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
|
642 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
|
643 // 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
|
644 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
|
645 } |
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
|
646 |
507 | 647 void |
760
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
648 SceneGraph::set_move_collision(move_func new_move, |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
649 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
|
650 { |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
651 this->move = new_move; |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
652 this->collision = new_collision; |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
653 this->create_sg = new_create_sg; |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
654 } |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
655 |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
656 void |
507 | 657 SceneGraph::add_next(SceneGraphPtr next) |
658 { | |
659 /* next のリストの最後に加える */ | |
660 if (this->next != NULL) { | |
661 SceneGraphPtr tmp = this->last; | |
662 tmp->next = next; | |
663 } else { | |
664 this->next = next; | |
665 } | |
666 | |
667 this->last = next; | |
668 } | |
669 | |
670 /** | |
671 * SceneGraph の clone | |
672 * @return clone SceneGraph | |
673 */ | |
674 SceneGraphPtr | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
675 SceneGraph::clone() { |
507 | 676 SceneGraphPtr p = new SceneGraph(this); |
677 return p; | |
678 } | |
679 | |
680 /** | |
681 * SceneGraph の clone | |
682 * 予め allocate されてる領域への placement new を行う | |
683 * | |
684 * @param buf clone 領域 | |
685 * @return clone SceneGraph | |
686 */ | |
687 SceneGraphPtr | |
688 SceneGraph::clone(void *buf) { | |
689 SceneGraphPtr p = new(buf) SceneGraph(this); | |
690 return p; | |
691 } | |
692 | |
693 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
694 SceneGraph::remove() |
507 | 695 { |
696 this->flag_remove = 1; | |
697 } | |
698 | |
699 /** | |
700 * tree から node を削除する | |
701 * | |
702 * @param tree SceneGraphTree | |
703 * @return node削除後の SceneGraphTree | |
704 */ | |
705 SceneGraphPtr | |
706 SceneGraph::realRemoveFromTree(SceneGraphPtr tree) | |
707 { | |
708 SceneGraphPtr node = this; | |
709 SceneGraphPtr parent = node->parent; | |
710 SceneGraphPtr ret = tree; | |
711 | |
712 if (parent) { | |
713 SceneGraphPtr brother = parent->children; | |
714 SceneGraphPtr p, p1 = NULL; | |
715 | |
716 p = brother; | |
717 if (p) { | |
718 if (p == node) { | |
719 parent->children = NULL; | |
720 parent->lastChild = NULL; | |
721 } else { | |
722 p1 = p->brother; | |
723 | |
724 while (p1 && p1 != node) { | |
725 p1 = p1->brother; | |
726 p = p->brother; | |
727 } | |
728 | |
729 if (p1) { | |
730 p->brother = p1->brother; | |
731 | |
732 // node が最後尾なら、lastChild を変更 | |
733 if (parent->lastChild == p1) { | |
734 parent->lastChild = p; | |
735 } | |
736 } else { | |
737 // Can't find remove node | |
738 } | |
739 } | |
740 } | |
741 } else { | |
742 // 親が居ない = tree root なので | |
743 // NULL を返す | |
744 ret = NULL; | |
745 } | |
746 | |
747 return ret; | |
748 } | |
749 | |
750 /** | |
751 * list から node を削除する | |
752 * | |
753 * @param list SceneGraphList | |
754 * @return node削除後の SceneGraphList | |
755 */ | |
756 SceneGraphPtr | |
757 SceneGraph::realRemoveFromList(SceneGraphPtr list) | |
758 { | |
759 SceneGraphPtr node = this; | |
760 SceneGraphPtr prev = node->prev; | |
761 SceneGraphPtr next = node->next; | |
762 SceneGraphPtr ret = list; | |
763 | |
764 if (prev) { | |
765 prev->next = next; | |
766 } else { | |
767 ret = next; | |
768 } | |
769 | |
770 if (next) { | |
771 next->prev = prev; | |
772 } | |
773 | |
774 return ret; | |
775 } | |
776 | |
777 int | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
778 SceneGraph::isRemoved() |
507 | 779 { |
780 return flag_remove; | |
781 } | |
782 | |
783 /** | |
784 * 平行移動 | |
785 * | |
786 * @param x Ttranslate in the x direction | |
787 * @param y Ttranslate in the y direction | |
788 * @param z Ttranslate in the z direction | |
789 */ | |
790 void | |
791 SceneGraph::translate(float x, float y, float z) | |
792 { | |
793 this->xyz[0] = x; | |
794 this->xyz[1] = y; | |
795 this->xyz[2] = z; | |
796 } | |
797 | |
798 /** | |
799 * x 軸方向への平行移動 | |
800 * | |
801 * @param x Ttranslate in the x direction | |
802 */ | |
803 void | |
804 SceneGraph::translateX(float x) | |
805 { | |
806 this->xyz[0] = x; | |
807 } | |
808 | |
809 /** | |
810 * y 軸方向への平行移動 | |
811 * | |
812 * @param y Ttranslate in the y direction | |
813 */ | |
814 void | |
815 SceneGraph::translateY(float y) | |
816 { | |
817 this->xyz[1] = y; | |
818 } | |
819 | |
820 /** | |
821 * z 軸方向への平行移動 | |
822 * | |
823 * @param z Ttranslate in the z direction | |
824 */ | |
825 void | |
826 SceneGraph::translateZ(float z) | |
827 { | |
828 this->xyz[2] = z; | |
829 } | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
830 |
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
831 /* end */ |