Mercurial > hg > Game > Cerium
comparison Renderer/Engine/SceneGraphRoot.cc @ 761:c0a8af52fa43 draft
add lights
author | yutaka@henri.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Sat, 06 Feb 2010 03:02:48 +0900 |
parents | 45f7ab7101ea |
children | 4cc05c023ff9 |
comparison
equal
deleted
inserted
replaced
760:0a602ba186e5 | 761:c0a8af52fa43 |
---|---|
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 /** |
413 | 420 |
414 list->frame++; | 421 list->frame++; |
415 list = list->next; | 422 list = list->next; |
416 } | 423 } |
417 | 424 |
418 get_matrix(light->matrix, light->angle, light->xyz, camera->matrix); | 425 int light_num = 4; |
419 | 426 for (int i = 0; i < light_num; i++) { |
420 light_vector[0] = 0.0f; | 427 |
421 light_vector[1] = 0.0f; | 428 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); |
422 light_vector[2] = 0.0f; | 429 |
423 light_vector[3] = 1.0f; | 430 light_vector[i*4] = 0.0f; |
424 | 431 light_vector[i*4+1] = 0.0f; |
425 ApplyMatrix(light_vector, light->matrix); | 432 light_vector[i*4+2] = 0.0f; |
426 | 433 light_vector[i*4+3] = 1.0f; |
427 light_vector[0] /= light_vector[2]; | 434 |
428 light_vector[1] /= light_vector[2]; | 435 ApplyMatrix(&light_vector[i*4], light[i]->matrix); |
436 | |
437 light_vector[i*4] /= light_vector[i*4+2]; | |
438 light_vector[i*4+1] /= light_vector[i*4+2]; | |
439 | |
440 } | |
441 | |
429 | 442 |
430 if(sg_exec_tree != NULL) { | 443 if(sg_exec_tree != NULL) { |
431 return; | 444 return; |
432 } | 445 } |
433 | 446 |
520 | 533 |
521 /* ここから下を exec_task の post_func に*/ | 534 /* ここから下を exec_task の post_func に*/ |
522 list->frame++; | 535 list->frame++; |
523 list = list->next; | 536 list = list->next; |
524 | 537 |
525 get_matrix(light->matrix, light->angle, light->xyz, camera->matrix); | 538 |
526 | 539 int light_num = 4; |
527 light_vector[0] = 0.0f; | 540 for (int i = 0; i < light_num; i++) { |
528 light_vector[1] = 0.0f; | 541 |
529 light_vector[2] = 0.0f; | 542 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); |
530 light_vector[3] = 1.0f; | 543 |
531 | 544 light_vector[i*4] = 0.0f; |
532 ApplyMatrix(light_vector, light->matrix); | 545 light_vector[i*4+1] = 0.0f; |
533 | 546 light_vector[i*4+2] = 0.0f; |
534 light_vector[0] /= light_vector[2]; | 547 light_vector[i*4+3] = 1.0f; |
535 light_vector[1] /= light_vector[2]; | 548 |
549 ApplyMatrix(&light_vector[i*4], light[i]->matrix); | |
550 | |
551 light_vector[i*4] /= light_vector[i*4+2]; | |
552 light_vector[i*4+1] /= light_vector[i*4+2]; | |
553 | |
554 } | |
536 | 555 |
537 if(sg_exec_tree != NULL) { | 556 if(sg_exec_tree != NULL) { |
538 return; | 557 return; |
539 } | 558 } |
540 } | 559 } |
547 { | 566 { |
548 list->collision_check(screen_w, screen_h, list); | 567 list->collision_check(screen_w, screen_h, list); |
549 | 568 |
550 list->frame++; | 569 list->frame++; |
551 //list = list->next; | 570 //list = list->next; |
552 | 571 |
553 get_matrix(light->matrix, light->angle, light->xyz, camera->matrix); | 572 int light_num = 4; |
554 | 573 for (int i = 0; i < light_num; i++) { |
555 light_vector[0] = 0.0f; | 574 |
556 light_vector[1] = 0.0f; | 575 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); |
557 light_vector[2] = 0.0f; | 576 |
558 light_vector[3] = 1.0f; | 577 light_vector[i*4] = 0.0f; |
559 | 578 light_vector[i*4+1] = 0.0f; |
560 ApplyMatrix(light_vector, light->matrix); | 579 light_vector[i*4+2] = 0.0f; |
561 | 580 light_vector[i*4+3] = 1.0f; |
562 light_vector[0] /= light_vector[2]; | 581 |
563 light_vector[1] /= light_vector[2]; | 582 ApplyMatrix(&light_vector[i*4], light[i]->matrix); |
583 | |
584 light_vector[i*4] /= light_vector[i*4+2]; | |
585 light_vector[i*4+1] /= light_vector[i*4+2]; | |
586 | |
587 } | |
564 | 588 |
565 //sgchange->viewer->light_xyz_stock = getLightVector(); | 589 //sgchange->viewer->light_xyz_stock = getLightVector(); |
566 } | 590 } |
567 | 591 |
568 | 592 |
658 return camera; | 682 return camera; |
659 } | 683 } |
660 | 684 |
661 | 685 |
662 SceneGraphPtr | 686 SceneGraphPtr |
663 SceneGraphRoot::getLight() | 687 SceneGraphRoot::getLight(int id) |
664 { | 688 { |
665 | 689 |
666 return light; | 690 return light[id]; |
667 | 691 |
668 } | 692 } |
669 | 693 |
670 | 694 |
671 float* | 695 float* |