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