# HG changeset patch # User hiroki@henri.cr.ie.u-ryukyu.ac.jp # Date 1265532772 -32400 # Node ID 987d4cced27974855e218e589da74e3635f1cf40 # Parent 87390c99c90008ce33c2482013ff0bdc4f19b36c# Parent 10a8a80c2ea7dcfc13d99aead9049007b8602e18 merge diff -r 87390c99c900 -r 987d4cced279 Renderer/Engine/SceneGraphRoot.cc --- a/Renderer/Engine/SceneGraphRoot.cc Sun Feb 07 17:43:23 2010 +0900 +++ b/Renderer/Engine/SceneGraphRoot.cc Sun Feb 07 17:52:52 2010 +0900 @@ -25,7 +25,6 @@ sg_src = (SceneGraphPtr*) malloc(sizeof(SceneGraphPtr)*SGLIST_LENGTH); camera = new Camera(w, h, this); - light = new SceneGraph; iterator = new SceneGraphIterator; controller = create_controller(); @@ -41,9 +40,14 @@ //int size = 4; //light_vector = (float*)malloc(sizeof(float)*size); - light->xyz[0] = 0; - light->xyz[1] = 0; - light->xyz[2] = 0; + int light_num = 4; + + for (int i = 0; i < light_num; i++) { + light[i] = new SceneGraph; + light[i]->xyz[0] = 0; + light[i]->xyz[1] = 0; + light[i]->xyz[2] = 0; + } move_finish_flag = 0; // TODO @@ -74,7 +78,10 @@ free(sg_src); delete camera; - delete light; + int light_num = 4; + for (int i = 0; i < light_num; i++) { + delete light[i]; + } delete iterator; delete controller; } @@ -323,61 +330,6 @@ sg_exec_tree = camera->children; } -void -SceneGraphRoot::speExecute(int screen_w, int screen_h, Application *app) -{ - // SceneGraphPtr t = sg_exec_tree; - // SceneGraphPtr cur_parent = camera; - - // 前フレームで描画した SceneGraph は削除 - allRemove(sg_remove_list); - - // 前フレームに作られた SceneGraph は描画用に移行 - // 現フレームでの操作は以下の tree,list には適用されない - sg_draw_tree = sg_exec_tree; - sg_remove_list = sg_available_list; - - // 現フレームで新しく SceneGraph がコピーされるので初期化 - sg_exec_tree = NULL; - sg_available_list = NULL; - - camera->move_execute(screen_w, screen_h); - camera->update(screen_w, screen_h); - - camera->children = NULL; - camera->lastChild = NULL; - - - if(sg_exec_tree != NULL) { - return; - } - - /*removeのflagをもとにtreeを形成*/ - /* spe から送り返されてきた property の配列を見て生成する for()*/ - /* Application内に移動 */ - - // app->property_ope(sg_available_list); - - /* - for (Property *t = (Property *)properties[0]; is_end(t); t++){ - SceneGraphPtr s = app->scenegraph_factory(t); // SceneGraphNode を作る - t->scenegraph = s; // property list には SceneGraphへのポインタが入っている - app->scenegraph_connector(property[0], s); // add する - } - */ - - - - // 現在、allExecute が終わった時点では - // camera->children が User SceneGraph の root になる - - /** - * NULL じゃなかったら、setSceneData が呼ばれてるから - * そっちを次の Scene にする - */ - - sg_exec_tree = camera->children; -} void @@ -415,17 +367,23 @@ list = list->next; } - get_matrix(light->matrix, light->angle, light->xyz, camera->matrix); + int light_num = 4; + for (int i = 0; i < light_num; i++) { - light_vector[0] = 0.0f; - light_vector[1] = 0.0f; - light_vector[2] = 0.0f; - light_vector[3] = 1.0f; + get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); + + light_vector[i*4] = 0.0f; + light_vector[i*4+1] = 0.0f; + light_vector[i*4+2] = 0.0f; + light_vector[i*4+3] = 1.0f; - ApplyMatrix(light_vector, light->matrix); + ApplyMatrix(&light_vector[i*4], light[i]->matrix); + + light_vector[i*4] /= light_vector[i*4+2]; + light_vector[i*4+1] /= light_vector[i*4+2]; - light_vector[0] /= light_vector[2]; - light_vector[1] /= light_vector[2]; + } + if(sg_exec_tree != NULL) { return; @@ -522,17 +480,23 @@ list->frame++; list = list->next; - get_matrix(light->matrix, light->angle, light->xyz, camera->matrix); + + int light_num = 4; + for (int i = 0; i < light_num; i++) { - light_vector[0] = 0.0f; - light_vector[1] = 0.0f; - light_vector[2] = 0.0f; - light_vector[3] = 1.0f; + get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); + + light_vector[i*4] = 0.0f; + light_vector[i*4+1] = 0.0f; + light_vector[i*4+2] = 0.0f; + light_vector[i*4+3] = 1.0f; - ApplyMatrix(light_vector, light->matrix); + ApplyMatrix(&light_vector[i*4], light[i]->matrix); + + light_vector[i*4] /= light_vector[i*4+2]; + light_vector[i*4+1] /= light_vector[i*4+2]; - light_vector[0] /= light_vector[2]; - light_vector[1] /= light_vector[2]; + } if(sg_exec_tree != NULL) { return; @@ -549,18 +513,23 @@ list->frame++; //list = list->next; - - get_matrix(light->matrix, light->angle, light->xyz, camera->matrix); + + int light_num = 4; + for (int i = 0; i < light_num; i++) { - light_vector[0] = 0.0f; - light_vector[1] = 0.0f; - light_vector[2] = 0.0f; - light_vector[3] = 1.0f; + get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); + + light_vector[i*4] = 0.0f; + light_vector[i*4+1] = 0.0f; + light_vector[i*4+2] = 0.0f; + light_vector[i*4+3] = 1.0f; - ApplyMatrix(light_vector, light->matrix); + ApplyMatrix(&light_vector[i*4], light[i]->matrix); + + light_vector[i*4] /= light_vector[i*4+2]; + light_vector[i*4+1] /= light_vector[i*4+2]; - light_vector[0] /= light_vector[2]; - light_vector[1] /= light_vector[2]; + } //sgchange->viewer->light_xyz_stock = getLightVector(); } @@ -660,10 +629,10 @@ SceneGraphPtr -SceneGraphRoot::getLight() +SceneGraphRoot::getLight(int id) { - return light; + return light[id]; } diff -r 87390c99c900 -r 987d4cced279 Renderer/Engine/SceneGraphRoot.h --- a/Renderer/Engine/SceneGraphRoot.h Sun Feb 07 17:43:23 2010 +0900 +++ b/Renderer/Engine/SceneGraphRoot.h Sun Feb 07 17:52:52 2010 +0900 @@ -56,9 +56,11 @@ Camera *camera; // 光源のオブジェクト - SceneGraphPtr light; + SceneGraphPtr light[4]; // 光源の疑似 xml file - float light_vector[4]; + // 光源は4つで決め打ち。 + // 4 * lightnum (4) = 16; + float light_vector[16]; // SceneGraphIterator SceneGraphIteratorPtr iterator; @@ -96,7 +98,7 @@ SceneGraphIteratorPtr getIterator(); SceneGraphIteratorPtr getIterator(SceneGraphPtr list); CameraPtr getCamera(); - SceneGraphPtr getLight(); + SceneGraphPtr getLight(int id); float* getLightVector(); /* Other System API */ diff -r 87390c99c900 -r 987d4cced279 Renderer/Engine/spe/DataLoad.cc --- a/Renderer/Engine/spe/DataLoad.cc Sun Feb 07 17:43:23 2010 +0900 +++ b/Renderer/Engine/spe/DataLoad.cc Sun Feb 07 17:52:52 2010 +0900 @@ -13,7 +13,7 @@ int size = (int)s->get_param(0); int load_id = (int)s->get_param(1); - //printf("size %d",sizeof(float)*length); + //printf("size %d\n",size); s->global_alloc(load_id, size); diff -r 87390c99c900 -r 987d4cced279 Renderer/Engine/spe/DataUpdate.cc --- a/Renderer/Engine/spe/DataUpdate.cc Sun Feb 07 17:43:23 2010 +0900 +++ b/Renderer/Engine/spe/DataUpdate.cc Sun Feb 07 17:52:52 2010 +0900 @@ -15,6 +15,10 @@ int load_id = (int)s->get_param(1); void *global_data = (void*)s->global_get(load_id); + if (size != 64) { + printf("hogehoge\n"); + } + memcpy(global_data,idata,size); return 0; diff -r 87390c99c900 -r 987d4cced279 Renderer/Engine/spe/DrawSpan.cc --- a/Renderer/Engine/spe/DrawSpan.cc Sun Feb 07 17:43:23 2010 +0900 +++ b/Renderer/Engine/spe/DrawSpan.cc Sun Feb 07 17:52:52 2010 +0900 @@ -10,6 +10,7 @@ #include "SchedTask.h" #include "Tapestry.h" #include "SpanPack.h" +#include #if (__LITTLE_ENDIAN__) #define LITTLEENDIAN 1 @@ -55,6 +56,21 @@ SchedTask *smanager,int x, int y, float z, int world_x, int world_y, float world_z); +void +normalize(float *v0, float *v1) +{ + float norm, dnorm; + + norm = sqrt(v1[0]*v1[0] + v1[1]*v1[1] + v1[2]*v1[2]); + if (norm > 0) { + dnorm = 1.0/norm; + v0[0] = v1[0]*dnorm; + v0[1] = v1[1]*dnorm; + v0[2] = v1[2]*dnorm; + v0[3] = v1[3]*dnorm; + } +} + static float innerProduct1(float *v0, float *v1) { @@ -330,7 +346,7 @@ float zpos2 = span->end_z; //spanを右から左に見ていくうちに、zが下がるのか、上がっていくのか。 - float z_inclination = (zpos1 - zpos2) / x_len; + float z_inclination = (zpos2 - zpos1) / x_len; float world_z = zpos2; // Tile 内での座標 @@ -342,7 +358,7 @@ for (int j = je; j >= js; j--) { float tex_x, tex_y, tex_z; - world_z += z_inclination; + world_z -= z_inclination; localx = getLocalX(x-1+j); @@ -392,8 +408,12 @@ int flag; float normal_vector[4] = {normal_x,normal_y,normal_z,0}; // 光のベクトル,きめうちしちゃった。どうにかする - float light_vector[4] = {0,0,-1,0}; + //float light_vector[4] = {0,0,-1,0}; + float light_vector[4]; float inner_product; + float *light_xyz = (float*)smanager->global_get(Light); + + normalize(normal_vector, normal_vector); // 引数で受け取った color の rgb 情報の抜き出し #if LITTLEENDIAN @@ -408,15 +428,46 @@ rgb[0] = (color & 0x000000ff); #endif - // 法線ベクトルと光源ベクトルとの内積をとる - inner_product = innerProduct1(normal_vector,light_vector); - // 内積がマイナスの場合は色がない。 - flag = (inner_product > 0); + int tmp_rgb[3] = {0,0,0}; + int light_num = 4; + for (int i = 0; i < light_num; i++) { + + //printf("light_xyz[%d] %f\n",i*4,light_xyz[i*4]); + //printf("light_xyz[%d] %f\n",i*4+1,light_xyz[i*4+1]); + //printf("light_xyz[%d] %f\n",i*4+2,light_xyz[i*4+2]); + //printf("light_xyz[%d] %f\n",i*4+3fg,light_xyz[i*4+3]); + + light_vector[0] = world_x - light_xyz[i*4]; + light_vector[1] = world_y - light_xyz[i*4+1]; + light_vector[2] = light_xyz[i*4+2] - world_z; + light_vector[3] = light_xyz[i*4+3]; + + normalize(light_vector, light_vector); + + // 法線ベクトルと光源ベクトルとの内積をとる + inner_product = innerProduct1(normal_vector,light_vector); - // 内積を rgb にかけていく - rgb[0] = (unsigned char)(rgb[0]*inner_product*flag); - rgb[1] = (unsigned char)(rgb[1]*inner_product*flag); - rgb[2] = (unsigned char)(rgb[2]*inner_product*flag); + //printf("inner_product %f\n",inner_product); + + // 内積がマイナスの場合は色がない。 + flag = (inner_product > 0); + + // 内積を rgb にかけていく + tmp_rgb[0] += (unsigned char)(rgb[0]*inner_product*flag); + tmp_rgb[1] += (unsigned char)(rgb[1]*inner_product*flag); + tmp_rgb[2] += (unsigned char)(rgb[2]*inner_product*flag); + + } + + int rgb_flag[3]; + for (int i = 0; i < 3; i++) { + rgb_flag[i] = (tmp_rgb[i] > 255); + } + + rgb[0] = tmp_rgb[0]*(1 - rgb_flag[0]) + 255*(rgb_flag[0]); + rgb[1] = tmp_rgb[1]*(1 - rgb_flag[1]) + 255*(rgb_flag[1]); + rgb[2] = tmp_rgb[2]*(1 - rgb_flag[2]) + 255*(rgb_flag[2]); + //計算した rgb を light_rgb にまとめる。 #if LITTLEENDIAN diff -r 87390c99c900 -r 987d4cced279 Renderer/Engine/task/CreatePolygonFromSceneGraph.cc --- a/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc Sun Feb 07 17:43:23 2010 +0900 +++ b/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc Sun Feb 07 17:52:52 2010 +0900 @@ -168,17 +168,20 @@ normal1[0] = sg->normal[(i+0)*3]; normal1[1] = sg->normal[(i+0)*3+1]; normal1[2] = sg->normal[(i+0)*3+2]*-1.0f; - normal1[3] = 1.0f; + //normal1[3] = 1.0f; + normal1[3] = 0.0f; normal2[0] = sg->normal[(i+1)*3]; normal2[1] = sg->normal[(i+1)*3+1]; normal2[2] = sg->normal[(i+1)*3+2]*-1.0f; - normal2[3] = 1.0f; + //normal2[3] = 1.0f; + normal2[3] = 0.0f; normal3[0] = sg->normal[(i+2)*3]; normal3[1] = sg->normal[(i+2)*3+1]; normal3[2] = sg->normal[(i+2)*3+2]*-1.0f; - normal3[3] = 1.0f; + //normal3[3] = 1.0f; + normal3[3] = 0.0f; ApplyNormalMatrix(normal1,sg->real_matrix); ApplyNormalMatrix(normal2,sg->real_matrix); diff -r 87390c99c900 -r 987d4cced279 Renderer/Engine/viewer.cc --- a/Renderer/Engine/viewer.cc Sun Feb 07 17:43:23 2010 +0900 +++ b/Renderer/Engine/viewer.cc Sun Feb 07 17:52:52 2010 +0900 @@ -105,14 +105,17 @@ sgroot = new SceneGraphRoot(this->width, this->height); sgroot->tmanager = manager; - int size = sizeof(float)*4; + int size = sizeof(float)*4*4; //xyz+alfa(4) * light_num(4) + int light_size = size / sizeof(float); light_xyz_stock = (float *)manager->allocate(size); light_xyz = (float *)manager->allocate(size); - light_xyz[0] = 0.0f; - light_xyz[1] = 0.0f; - light_xyz[2] = 0.0f; - light_xyz[3] = 0.0f; + + for (int i = 0; i < light_size ; i++) { + + light_xyz[i] = 0.0f; + + } HTaskPtr data_load; data_load = manager->create_task(DataLoad); @@ -130,7 +133,6 @@ } MainLoop *mainloop = app->init(this, this->width, this->height); - mainloop->mainLoop(); } @@ -470,16 +472,18 @@ //task_next = manager->create_task(Dummy); //task_next->set_post(post2runLoop, (void*)this); - //Light info update + //Light info update HTaskPtr data_update; HTaskPtr data_update_wait; - int size = sizeof(float)*4; + int size = sizeof(float)*4*4; //xyz+alfa(4) * light_num(4) + int light_size = size / sizeof(float); - light_xyz[0] = light_xyz_stock[0]; - light_xyz[1] = light_xyz_stock[1]; - light_xyz[2] = light_xyz_stock[2]; - light_xyz[3] = light_xyz_stock[3]; + for (int i = 0; i < light_size; i++) { + + light_xyz[i] = light_xyz_stock[i]; + + } data_update_wait = manager->create_task(DataUpdate); data_update_wait->add_inData(light_xyz,size); diff -r 87390c99c900 -r 987d4cced279 Renderer/Test/Makefile.macosx --- a/Renderer/Test/Makefile.macosx Sun Feb 07 17:43:23 2010 +0900 +++ b/Renderer/Test/Makefile.macosx Sun Feb 07 17:52:52 2010 +0900 @@ -10,7 +10,7 @@ .cc.o: $(CC) $(CFLAGS) -c $< -o $@ -ALL = ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum property_test send_linda dynamic writer chain_old SgRootChange +ALL = ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum property_test send_linda dynamic writer chain_old SgRootChange oFLAGS=-g -O2 CFLAGt=-g -O2 all: $(ALL) diff -r 87390c99c900 -r 987d4cced279 Renderer/Test/universe.cc --- a/Renderer/Test/universe.cc Sun Feb 07 17:43:23 2010 +0900 +++ b/Renderer/Test/universe.cc Sun Feb 07 17:52:52 2010 +0900 @@ -17,7 +17,7 @@ static void moon_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) { - node->angle[0] += 3.0f; + //node->angle[0] += 3.0f; } @@ -52,9 +52,9 @@ earth = sgroot->createSceneGraph("Earth"); // SceneGraph の move と collision を設定 - earth->set_move_collision(earth_move, earth_collision); - earth->stack_xyz[0] = 3.0f; - earth->stack_xyz[1] = 3.0f; + earth->set_move_collision(moon_move, earth_collision); + earth->xyz[0] = screen_w / 2; + earth->xyz[1] = screen_h / 2; moon = sgroot->createSceneGraph("Moon"); moon->set_move_collision(moon_move, moon_collision);