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