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