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