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