comparison Renderer/Engine/SceneGraphRoot.cc @ 764:987d4cced279

merge
author hiroki@henri.cr.ie.u-ryukyu.ac.jp
date Sun, 07 Feb 2010 17:52:52 +0900
parents 10a8a80c2ea7
children dc26593f8c40
comparison
equal deleted inserted replaced
763:87390c99c900 764:987d4cced279
23 // SGLIST_LENGTH 決め打ちかぁ、動的生成にする場合上限決めておいた方がいいのかな 23 // SGLIST_LENGTH 決め打ちかぁ、動的生成にする場合上限決めておいた方がいいのかな
24 // 24 //
25 sg_src = (SceneGraphPtr*) malloc(sizeof(SceneGraphPtr)*SGLIST_LENGTH); 25 sg_src = (SceneGraphPtr*) malloc(sizeof(SceneGraphPtr)*SGLIST_LENGTH);
26 26
27 camera = new Camera(w, h, this); 27 camera = new Camera(w, h, this);
28 light = new SceneGraph;
29 iterator = new SceneGraphIterator; 28 iterator = new SceneGraphIterator;
30 controller = create_controller(); 29 controller = create_controller();
31 30
32 sg_exec_tree = NULL; 31 sg_exec_tree = NULL;
33 sg_draw_tree = NULL; 32 sg_draw_tree = NULL;
39 screen_w = (int)w; 38 screen_w = (int)w;
40 screen_h = (int)h; 39 screen_h = (int)h;
41 //int size = 4; 40 //int size = 4;
42 //light_vector = (float*)malloc(sizeof(float)*size); 41 //light_vector = (float*)malloc(sizeof(float)*size);
43 42
44 light->xyz[0] = 0; 43 int light_num = 4;
45 light->xyz[1] = 0; 44
46 light->xyz[2] = 0; 45 for (int i = 0; i < light_num; i++) {
46 light[i] = new SceneGraph;
47 light[i]->xyz[0] = 0;
48 light[i]->xyz[1] = 0;
49 light[i]->xyz[2] = 0;
50 }
47 51
48 move_finish_flag = 0; 52 move_finish_flag = 0;
49 // TODO 53 // TODO
50 // 今はとりあえず camera を Root にしています 54 // 今はとりあえず camera を Root にしています
51 // 今はそれすらもしてません 55 // 今はそれすらもしてません
72 cnt--; 76 cnt--;
73 } 77 }
74 78
75 free(sg_src); 79 free(sg_src);
76 delete camera; 80 delete camera;
77 delete light; 81 int light_num = 4;
82 for (int i = 0; i < light_num; i++) {
83 delete light[i];
84 }
78 delete iterator; 85 delete iterator;
79 delete controller; 86 delete controller;
80 } 87 }
81 88
82 /** 89 /**
321 */ 328 */
322 329
323 sg_exec_tree = camera->children; 330 sg_exec_tree = camera->children;
324 } 331 }
325 332
326 void
327 SceneGraphRoot::speExecute(int screen_w, int screen_h, Application *app)
328 {
329 // SceneGraphPtr t = sg_exec_tree;
330 // SceneGraphPtr cur_parent = camera;
331
332 // 前フレームで描画した SceneGraph は削除
333 allRemove(sg_remove_list);
334
335 // 前フレームに作られた SceneGraph は描画用に移行
336 // 現フレームでの操作は以下の tree,list には適用されない
337 sg_draw_tree = sg_exec_tree;
338 sg_remove_list = sg_available_list;
339
340 // 現フレームで新しく SceneGraph がコピーされるので初期化
341 sg_exec_tree = NULL;
342 sg_available_list = NULL;
343
344 camera->move_execute(screen_w, screen_h);
345 camera->update(screen_w, screen_h);
346
347 camera->children = NULL;
348 camera->lastChild = NULL;
349
350
351 if(sg_exec_tree != NULL) {
352 return;
353 }
354
355 /*removeのflagをもとにtreeを形成*/
356 /* spe から送り返されてきた property の配列を見て生成する for()*/
357 /* Application内に移動 */
358
359 // app->property_ope(sg_available_list);
360
361 /*
362 for (Property *t = (Property *)properties[0]; is_end(t); t++){
363 SceneGraphPtr s = app->scenegraph_factory(t); // SceneGraphNode を作る
364 t->scenegraph = s; // property list には SceneGraphへのポインタが入っている
365 app->scenegraph_connector(property[0], s); // add する
366 }
367 */
368
369
370
371 // 現在、allExecute が終わった時点では
372 // camera->children が User SceneGraph の root になる
373
374 /**
375 * NULL じゃなかったら、setSceneData が呼ばれてるから
376 * そっちを次の Scene にする
377 */
378
379 sg_exec_tree = camera->children;
380 }
381 333
382 334
383 void 335 void
384 SceneGraphRoot::allExecute(int screen_w, int screen_h) 336 SceneGraphRoot::allExecute(int screen_w, int screen_h)
385 { 337 {
413 365
414 list->frame++; 366 list->frame++;
415 list = list->next; 367 list = list->next;
416 } 368 }
417 369
418 get_matrix(light->matrix, light->angle, light->xyz, camera->matrix); 370 int light_num = 4;
419 371 for (int i = 0; i < light_num; i++) {
420 light_vector[0] = 0.0f; 372
421 light_vector[1] = 0.0f; 373 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix);
422 light_vector[2] = 0.0f; 374
423 light_vector[3] = 1.0f; 375 light_vector[i*4] = 0.0f;
424 376 light_vector[i*4+1] = 0.0f;
425 ApplyMatrix(light_vector, light->matrix); 377 light_vector[i*4+2] = 0.0f;
426 378 light_vector[i*4+3] = 1.0f;
427 light_vector[0] /= light_vector[2]; 379
428 light_vector[1] /= light_vector[2]; 380 ApplyMatrix(&light_vector[i*4], light[i]->matrix);
381
382 light_vector[i*4] /= light_vector[i*4+2];
383 light_vector[i*4+1] /= light_vector[i*4+2];
384
385 }
386
429 387
430 if(sg_exec_tree != NULL) { 388 if(sg_exec_tree != NULL) {
431 return; 389 return;
432 } 390 }
433 391
520 478
521 /* ここから下を exec_task の post_func に*/ 479 /* ここから下を exec_task の post_func に*/
522 list->frame++; 480 list->frame++;
523 list = list->next; 481 list = list->next;
524 482
525 get_matrix(light->matrix, light->angle, light->xyz, camera->matrix); 483
526 484 int light_num = 4;
527 light_vector[0] = 0.0f; 485 for (int i = 0; i < light_num; i++) {
528 light_vector[1] = 0.0f; 486
529 light_vector[2] = 0.0f; 487 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix);
530 light_vector[3] = 1.0f; 488
531 489 light_vector[i*4] = 0.0f;
532 ApplyMatrix(light_vector, light->matrix); 490 light_vector[i*4+1] = 0.0f;
533 491 light_vector[i*4+2] = 0.0f;
534 light_vector[0] /= light_vector[2]; 492 light_vector[i*4+3] = 1.0f;
535 light_vector[1] /= light_vector[2]; 493
494 ApplyMatrix(&light_vector[i*4], light[i]->matrix);
495
496 light_vector[i*4] /= light_vector[i*4+2];
497 light_vector[i*4+1] /= light_vector[i*4+2];
498
499 }
536 500
537 if(sg_exec_tree != NULL) { 501 if(sg_exec_tree != NULL) {
538 return; 502 return;
539 } 503 }
540 } 504 }
547 { 511 {
548 list->collision_check(screen_w, screen_h, list); 512 list->collision_check(screen_w, screen_h, list);
549 513
550 list->frame++; 514 list->frame++;
551 //list = list->next; 515 //list = list->next;
552 516
553 get_matrix(light->matrix, light->angle, light->xyz, camera->matrix); 517 int light_num = 4;
554 518 for (int i = 0; i < light_num; i++) {
555 light_vector[0] = 0.0f; 519
556 light_vector[1] = 0.0f; 520 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix);
557 light_vector[2] = 0.0f; 521
558 light_vector[3] = 1.0f; 522 light_vector[i*4] = 0.0f;
559 523 light_vector[i*4+1] = 0.0f;
560 ApplyMatrix(light_vector, light->matrix); 524 light_vector[i*4+2] = 0.0f;
561 525 light_vector[i*4+3] = 1.0f;
562 light_vector[0] /= light_vector[2]; 526
563 light_vector[1] /= light_vector[2]; 527 ApplyMatrix(&light_vector[i*4], light[i]->matrix);
528
529 light_vector[i*4] /= light_vector[i*4+2];
530 light_vector[i*4+1] /= light_vector[i*4+2];
531
532 }
564 533
565 //sgchange->viewer->light_xyz_stock = getLightVector(); 534 //sgchange->viewer->light_xyz_stock = getLightVector();
566 } 535 }
567 536
568 537
658 return camera; 627 return camera;
659 } 628 }
660 629
661 630
662 SceneGraphPtr 631 SceneGraphPtr
663 SceneGraphRoot::getLight() 632 SceneGraphRoot::getLight(int id)
664 { 633 {
665 634
666 return light; 635 return light[id];
667 636
668 } 637 }
669 638
670 639
671 float* 640 float*