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