Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/SceneGraph.cc @ 909:2683838396c6
fix..
author | Yutaka_Kinjyo |
---|---|
date | Tue, 20 Jul 2010 04:45:36 +0900 |
parents | 830bcfbde3bc |
children | 655e11f6e437 |
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 | |
467 return texture_image; | |
468 } | |
469 | |
470 int | |
471 SceneGraph::makeTapestries(TaskManager *manager, SDL_Surface *texture_image, int id) { | |
472 uint32 *tapestry; | |
473 int scale = 1; | |
474 int tex_w = texture_image->w; | |
475 int tex_h = texture_image->h; | |
476 int all_pixel_num = 0; | |
477 | |
478 /** | |
479 * テクスチャの w or h が 8 pixel で分割できる間、 | |
480 * 1/2 の縮小画像を作る。 | |
481 * ここでは、最大の scale (1/scale) を見つける | |
482 * | |
483 * (ex) | |
484 * (128,128) => 64,64 : 32,32: 16,16 : 8,8 | |
485 * scale = 16 | |
486 * (128, 64) => 64,32 : 32,16: 16,8 | |
487 * scale = 8 | |
488 */ | |
489 while (tex_w % TEXTURE_SPLIT_PIXEL == 0 && | |
490 tex_h % TEXTURE_SPLIT_PIXEL == 0) { | |
491 all_pixel_num += tex_w*tex_h; | |
492 tex_w >>= 1; /* tex_w /= 2 */ | |
493 tex_h >>= 1; | |
494 scale <<= 1; /* scale *= 2 */ | |
495 } | |
496 | |
497 scale >>= 1; | |
498 | |
499 tapestry = makeTapestry(manager, texture_image->w, texture_image->h, | |
500 (uint32*)texture_image->pixels, | |
501 all_pixel_num, scale); | |
502 | |
503 list[id].t_w = texture_image->w; | |
504 list[id].t_h = texture_image->h; | |
505 list[id].pixels_orig = (Uint32*)texture_image->pixels; | |
506 list[id].pixels = tapestry; | |
507 list[id].scale_max = scale; | |
508 | |
509 return id; | |
510 } | |
511 | |
512 void | |
513 SceneGraph::get_image(TaskManager *manager, xmlNodePtr cur) | |
514 { | |
515 char image_name[20] = "/tmp/image_XXXXXX"; | |
516 char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); | |
517 | |
518 if (filename == NULL || filename[0] == 0) { | |
519 return; | |
520 } | |
521 | |
522 /** | |
523 * image_name を既に Load していれば何もしない | |
524 */ | |
525 int tex_id; | |
526 if (!texture_hash.hash_regist(filename, tex_id)) { | |
527 | |
528 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
|
529 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
|
530 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
|
531 exit(0); |
da82a47ece92
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
507
diff
changeset
|
532 } |
507 | 533 |
534 texture_id = makeTapestries(manager, texture_image, tex_id); | |
535 | |
536 if (unlink(image_name)) { | |
537 cout << "unlink error\n"; | |
538 } | |
539 } else { | |
540 /** | |
541 * 以前に Load されている Texture を共用 | |
542 */ | |
543 texture_id = tex_id; | |
544 } | |
545 | |
860 | 546 // こんなことすると list[] のいみあるのかなーと |
547 // 微妙に思う、自分で書き換えた感想 by gongo | |
548 texture_info.t_w = list[texture_id].t_w; | |
549 texture_info.t_h = list[texture_id].t_h;; | |
550 texture_info.pixels_orig = list[texture_id].pixels_orig; | |
551 texture_info.pixels = list[texture_id].pixels; | |
552 texture_info.scale_max = list[texture_id].scale_max; | |
553 | |
507 | 554 } |
555 | |
556 | |
557 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
558 SceneGraph::delete_data() |
507 | 559 { |
560 SceneGraphPtr n = this->next, m; | |
561 | |
562 //n = this; | |
563 //delete [] n->data; | |
564 | |
565 if (next) { | |
566 while (n) { | |
567 m = n->next; | |
568 delete n; | |
569 n = m; | |
570 } | |
571 } | |
572 } | |
573 | |
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
|
574 /* move_func 実行 sgroot 渡す */ |
507 | 575 void |
576 SceneGraph::move_execute(int w, int h) | |
577 { | |
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
|
578 (*move)(this, this->sgroot, w, h); |
507 | 579 } |
580 | |
581 void | |
582 SceneGraph::collision_check(int w, int h, SceneGraphPtr tree) | |
583 { | |
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
|
584 (*collision)(this, this->sgroot, w, h, tree); |
507 | 585 } |
586 | |
760
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
587 void |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
588 SceneGraph::create_sg_execute() |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
589 { |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
590 (*create_sg)(this->sgroot, property, update_property); |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
591 } |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
592 |
507 | 593 |
594 void | |
595 SceneGraph::set_move_collision(move_func new_move, | |
596 collision_func new_collision) | |
597 { | |
598 this->move = new_move; | |
599 this->collision = new_collision; | |
600 } | |
601 | |
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
|
602 |
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 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
|
604 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
|
605 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
|
606 { |
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 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
|
608 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
|
609 // 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
|
610 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
|
611 } |
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 |
507 | 613 void |
760
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
614 SceneGraph::set_move_collision(move_func new_move, |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
615 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
|
616 { |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
617 this->move = new_move; |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
618 this->collision = new_collision; |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
619 this->create_sg = new_create_sg; |
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
620 } |
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 void |
507 | 623 SceneGraph::add_next(SceneGraphPtr next) |
624 { | |
625 /* next のリストの最後に加える */ | |
626 if (this->next != NULL) { | |
627 SceneGraphPtr tmp = this->last; | |
628 tmp->next = next; | |
629 } else { | |
630 this->next = next; | |
631 } | |
632 | |
633 this->last = next; | |
634 } | |
635 | |
636 /** | |
637 * SceneGraph の clone | |
638 * @return clone SceneGraph | |
639 */ | |
640 SceneGraphPtr | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
641 SceneGraph::clone() { |
507 | 642 SceneGraphPtr p = new SceneGraph(this); |
643 return p; | |
644 } | |
645 | |
646 /** | |
647 * SceneGraph の clone | |
648 * 予め allocate されてる領域への placement new を行う | |
649 * | |
650 * @param buf clone 領域 | |
651 * @return clone SceneGraph | |
652 */ | |
653 SceneGraphPtr | |
654 SceneGraph::clone(void *buf) { | |
655 SceneGraphPtr p = new(buf) SceneGraph(this); | |
656 return p; | |
657 } | |
658 | |
659 void | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
660 SceneGraph::remove() |
507 | 661 { |
662 this->flag_remove = 1; | |
663 } | |
664 | |
665 /** | |
666 * tree から node を削除する | |
667 * | |
668 * @param tree SceneGraphTree | |
669 * @return node削除後の SceneGraphTree | |
670 */ | |
671 SceneGraphPtr | |
672 SceneGraph::realRemoveFromTree(SceneGraphPtr tree) | |
673 { | |
674 SceneGraphPtr node = this; | |
675 SceneGraphPtr parent = node->parent; | |
676 SceneGraphPtr ret = tree; | |
677 | |
678 if (parent) { | |
679 SceneGraphPtr brother = parent->children; | |
680 SceneGraphPtr p, p1 = NULL; | |
681 | |
682 p = brother; | |
683 if (p) { | |
684 if (p == node) { | |
685 parent->children = NULL; | |
686 parent->lastChild = NULL; | |
687 } else { | |
688 p1 = p->brother; | |
689 | |
690 while (p1 && p1 != node) { | |
691 p1 = p1->brother; | |
692 p = p->brother; | |
693 } | |
694 | |
695 if (p1) { | |
696 p->brother = p1->brother; | |
697 | |
698 // node が最後尾なら、lastChild を変更 | |
699 if (parent->lastChild == p1) { | |
700 parent->lastChild = p; | |
701 } | |
702 } else { | |
703 // Can't find remove node | |
704 } | |
705 } | |
706 } | |
707 } else { | |
708 // 親が居ない = tree root なので | |
709 // NULL を返す | |
710 ret = NULL; | |
711 } | |
712 | |
713 return ret; | |
714 } | |
715 | |
716 /** | |
717 * list から node を削除する | |
718 * | |
719 * @param list SceneGraphList | |
720 * @return node削除後の SceneGraphList | |
721 */ | |
722 SceneGraphPtr | |
723 SceneGraph::realRemoveFromList(SceneGraphPtr list) | |
724 { | |
725 SceneGraphPtr node = this; | |
726 SceneGraphPtr prev = node->prev; | |
727 SceneGraphPtr next = node->next; | |
728 SceneGraphPtr ret = list; | |
729 | |
730 if (prev) { | |
731 prev->next = next; | |
732 } else { | |
733 ret = next; | |
734 } | |
735 | |
736 if (next) { | |
737 next->prev = prev; | |
738 } | |
739 | |
740 return ret; | |
741 } | |
742 | |
743 int | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
744 SceneGraph::isRemoved() |
507 | 745 { |
746 return flag_remove; | |
747 } | |
748 | |
749 /** | |
750 * 平行移動 | |
751 * | |
752 * @param x Ttranslate in the x direction | |
753 * @param y Ttranslate in the y direction | |
754 * @param z Ttranslate in the z direction | |
755 */ | |
756 void | |
757 SceneGraph::translate(float x, float y, float z) | |
758 { | |
759 this->xyz[0] = x; | |
760 this->xyz[1] = y; | |
761 this->xyz[2] = z; | |
762 } | |
763 | |
764 /** | |
765 * x 軸方向への平行移動 | |
766 * | |
767 * @param x Ttranslate in the x direction | |
768 */ | |
769 void | |
770 SceneGraph::translateX(float x) | |
771 { | |
772 this->xyz[0] = x; | |
773 } | |
774 | |
775 /** | |
776 * y 軸方向への平行移動 | |
777 * | |
778 * @param y Ttranslate in the y direction | |
779 */ | |
780 void | |
781 SceneGraph::translateY(float y) | |
782 { | |
783 this->xyz[1] = y; | |
784 } | |
785 | |
786 /** | |
787 * z 軸方向への平行移動 | |
788 * | |
789 * @param z Ttranslate in the z direction | |
790 */ | |
791 void | |
792 SceneGraph::translateZ(float z) | |
793 { | |
794 this->xyz[2] = z; | |
795 } | |
724
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
796 |
6d11ecef3b74
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
656
diff
changeset
|
797 /* end */ |