Mercurial > hg > Game > Cerium
changeset 1351:e51127dbd63c draft
operate directly on matrix. not work yet.
author | Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 15 Jan 2012 23:21:39 +0900 |
parents | b6ee60edacf0 |
children | 57c3b08b76b5 |
files | Renderer/Engine/SceneGraph.cc Renderer/Engine/SceneGraph.h Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/matrix_calc.cc Renderer/Engine/matrix_calc.h Renderer/Engine/polygon.h Renderer/Engine/task/CreatePolygonFromSceneGraph.cc Renderer/Engine/viewer.cc Renderer/Test/universe.cc example/word_count/main.cc |
diffstat | 10 files changed, 96 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraph.cc Tue Jan 10 17:17:13 2012 +0900 +++ b/Renderer/Engine/SceneGraph.cc Sun Jan 15 23:21:39 2012 +0900 @@ -124,21 +124,9 @@ { init(); - - matrix = (float*)manager->allocate(sizeof(float)*16); - texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); - + allocate_init(manager); texture_info->texture_id = -1; - for (int i = 0; i < 16; i++) { - matrix[i] = 0; - } - - for (int i = 0; i < 4; i++) { - matrix[i*4+i] = 1; - } - - finalize = &SceneGraph::finalize_copy; this->name = "NULLPO"; @@ -155,8 +143,7 @@ memcpy(this, orig, sizeof(SceneGraph)); - matrix = (float*)manager->allocate(sizeof(float)*16); - texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); + allocate_init(manager); for (int i = 0; i < 16; i++) { matrix[i] = orig->matrix[i]; @@ -187,9 +174,7 @@ { init(); - - matrix = (float*)manager->allocate(sizeof(float)*16*2); - texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); + allocate_init(manager); texture_info->texture_id = -1; //size : 頂点の数かな @@ -197,13 +182,6 @@ name = (char *)xmlGetProp(surface,(xmlChar *)"name"); parent_name = (char *)xmlGetProp(surface,(xmlChar *)"parent"); - for (int i = 0; i < 16; i++) { - matrix[i] = 0; - } - for (int i = 0; i < 4; i++) { - matrix[i*4+i] = 1; - } - if (size % 3 != 0) { printf("vertex size is error. size %% 3 = %lld\n", size % 3); } @@ -237,21 +215,20 @@ SceneGraph::SceneGraph(TaskManager *manager,const char *font,int pixels,Uint32 color,const char *string_name) { init(); - - this->matrix = (float*)manager->allocate(sizeof(float)*16); - this->texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); + allocate_init(manager); texture_info->texture_id = -1; - - //size : 頂点の数かな - size = 6; - parent_name = NULL; - name = string_name; + for (int i = 0; i < 16; i++) { matrix[i] = 0; } for (int i = 0; i < 4; i++) { matrix[i*4+i] = 1; } + + //size : 頂点の数かな + size = 6; + parent_name = NULL; + name = string_name; if (size % 3 != 0) { printf("vertex size is error. size %% 3 = %lld\n", size % 3); @@ -460,8 +437,28 @@ gid = -1; frame = 0; + } +// spe に渡すために 16アラインメント に allocate をする +void +SceneGraph::allocate_init(TaskManager *manager) +{ + matrix = (float*)manager->allocate(sizeof(float)*16); + out_matrix = (float*)manager->allocate(sizeof(float)*16); + texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); + + for (int i = 0; i < 16; i++) { + matrix[i] = 0; + out_matrix[i] = 0; + } + for (int i = 0; i < 4; i++) { + matrix[i*4+i] = 1; + out_matrix[i*4+i] = 1; + } +} + + SceneGraph::~SceneGraph() { (this->*finalize)(); @@ -1228,9 +1225,9 @@ void SceneGraph::translate(float x, float y, float z) { - this->matrix[3] += x; - this->matrix[4+3] += y; - this->matrix[8+3] += z; + this->matrix[12] += x; + this->matrix[13] += y; + this->matrix[14] += z; } /** @@ -1241,7 +1238,7 @@ void SceneGraph::translateX(float x) { - this->matrix[3] += x; + this->matrix[12] += x; } /** @@ -1252,7 +1249,7 @@ void SceneGraph::translateY(float y) { - this->matrix[4+3] += y; + this->matrix[13] += y; } /** @@ -1263,14 +1260,15 @@ void SceneGraph::translateZ(float z) { - this->matrix[8+3] += z; + this->matrix[14] += z; } void -SceneGraph::angleIt(float *angle) +SceneGraph::angleIt(float xangle, float yangle, float zangle) { float m[16]; float t[4] = {0,0,0,0}; + float angle[4] = {xangle, yangle, zangle, 1}; for(int i=0;i<16;i++) m[i] = matrix[i]; get_matrix(matrix, angle, t, m); }
--- a/Renderer/Engine/SceneGraph.h Tue Jan 10 17:17:13 2012 +0900 +++ b/Renderer/Engine/SceneGraph.h Sun Jan 15 23:21:39 2012 +0900 @@ -87,7 +87,8 @@ // desutroctor で呼ばれる void (SceneGraph::*finalize)(void); - void init(void); + void init(); + void allocate_init(TaskManager *manager); void finalize_original(void); void finalize_copy(void); void move_execute(int screen_w, int screen_h); @@ -118,7 +119,7 @@ void translateY(float y); void translateZ(float z); void scaleIt(float *scale); - void angleIt(float *angle); + void angleIt(float xangle, float yangle, float zangle); void tree_check(void);
--- a/Renderer/Engine/SceneGraphRoot.cc Tue Jan 10 17:17:13 2012 +0900 +++ b/Renderer/Engine/SceneGraphRoot.cc Sun Jan 15 23:21:39 2012 +0900 @@ -873,8 +873,9 @@ * (polygon_vertex) * camera->(s) */ - matrix4x4(camera->matrix, camera->m_view, camera->m_pers); + //matrix4x4(camera->matrix, camera->m_view, camera->m_pers); lightCalc(camera); + copyMatrix(camera->matrix, camera->m_view); copyTree(sg_draw_tree, camera); // 現在、allExecute が終わった時点では @@ -903,7 +904,10 @@ cur_parent->addChild(c); c->frame = t->frame; /*親の回転、座標から、子の回転、座標を算出*/ - get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix); + //get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix); + float m[16]; + for(int i=0;i<16;i++) m[i] = c->matrix[i]; + matrix4x4(c->matrix, m, cur_parent->matrix); }
--- a/Renderer/Engine/matrix_calc.cc Tue Jan 10 17:17:13 2012 +0900 +++ b/Renderer/Engine/matrix_calc.cc Sun Jan 15 23:21:39 2012 +0900 @@ -92,6 +92,15 @@ } +void +copyMatrix(float *m0, float *m1) +{ + for (int i = 0; i < 16; i++) { + m0[i] = m1[i]; + } +} + + /** * ベクトルの正規化 * @@ -166,6 +175,7 @@ */ void matrix4x4(float *xyz, float *xyz1, float *xyz2) //xyz[16] { + for(int t=0; t<16; t+=4) { for(int i=0; i<4; i++)
--- a/Renderer/Engine/matrix_calc.h Tue Jan 10 17:17:13 2012 +0900 +++ b/Renderer/Engine/matrix_calc.h Sun Jan 15 23:21:39 2012 +0900 @@ -25,6 +25,7 @@ float determinant(float *m); void transMatrix(float *m0, float *m1, float *v); void ApplyMatrix(float *v1, float *v2); +void copyMatrix(float *m0, float *m1); void ScaleMatrix(float *m, float v); void ScaleMatrixXYZ(float *m, float sx,float sy, float sz); static inline unsigned long align(unsigned long x,unsigned long alig) { return ((x+(alig-1))&~(alig-1)); }
--- a/Renderer/Engine/polygon.h Tue Jan 10 17:17:13 2012 +0900 +++ b/Renderer/Engine/polygon.h Sun Jan 15 23:21:39 2012 +0900 @@ -15,12 +15,16 @@ const char *name; const char *parent_name; + // SceneGraph から直接操作するmatrix. 操作した matrix は保存しておかないといけない float *matrix; + // matrix に view, perspective, screen 変換をかけたものが入る. SceneGraphから直接操作される matrix は別に必要 + float *out_matrix; texture_list *texture_info; PolygonPackPtr pp; int pp_num; + // ここの xyz, angle はいらなくなる float xyz[4]; // position float angle[4]; // angle float c_xyz[4]; // center of rotation
--- a/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc Tue Jan 10 17:17:13 2012 +0900 +++ b/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc Sun Jan 15 23:21:39 2012 +0900 @@ -107,20 +107,23 @@ //pp, matrix, を受け取る PolygonPackPtr in_pp = (PolygonPackPtr)smanager->get_input(rbuf, 0); // w = world, v = view, p = perspective - float *wvp_matrix = (float*)smanager->get_input(rbuf, 1); - float *m_screen = (float*)smanager->get_input(rbuf, 2); + float *wv_matrix = (float*)smanager->get_input(rbuf, 1); + float *m_pers = (float*)smanager->get_input(rbuf, 2); + float *m_screen = (float*)smanager->get_input(rbuf, 3); float normal_matrix[16]; - for (int i = 0; i<16; i++) normal_matrix[i] = wvp_matrix[i]; + for (int i = 0; i<16; i++) normal_matrix[i] = wv_matrix[i]; normal_matrix[4*0+3] = normal_matrix[4*1+3] = normal_matrix[4*2+3] = 0; normal_matrix[4*3] = normal_matrix[4*3+1] = normal_matrix[4*3+2] = 0; normal_matrix[4*3+3] = 1; - float matrix[16]; // wvpm matrix + float wvp_matrix[16]; // wvp matrix + float matrix[16]; // wvps matrix + matrix4x4(wvp_matrix, wv_matrix, m_pers); matrix4x4(matrix, wvp_matrix, m_screen); - texture_list *tritexinfo = (texture_list*)smanager->get_input(rbuf, 3); + texture_list *tritexinfo = (texture_list*)smanager->get_input(rbuf, 4); PolygonPackPtr next = (PolygonPackPtr)smanager->get_param(0);
--- a/Renderer/Engine/viewer.cc Tue Jan 10 17:17:13 2012 +0900 +++ b/Renderer/Engine/viewer.cc Sun Jan 15 23:21:39 2012 +0900 @@ -481,6 +481,7 @@ create_pp->add_inData(&t->pp[i], sizeof(PolygonPack)); create_pp->add_inData(t->matrix, sizeof(float)*16); + create_pp->add_inData(camera->m_pers, sizeof(float)*16); create_pp->add_inData(camera->m_screen, sizeof(float)*16); create_pp->add_inData(t->texture_info, sizeof(texture_list));
--- a/Renderer/Test/universe.cc Tue Jan 10 17:17:13 2012 +0900 +++ b/Renderer/Test/universe.cc Sun Jan 15 23:21:39 2012 +0900 @@ -17,25 +17,29 @@ static void moon_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) { - node->angle[0] += 3.0f; + //node->stack_angle[0] += 3.0f; + node->angleIt(3, 0, 0); } static void earth_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) { - node->angle[1] += 1.0f; - if (node->angle[1] > 360.0f) { - node->angle[1] = 0.0f; - } + //node->angle[1] += 1.0f; + //node->angleIt(1, 0, 0); + //if (node->angle[1] > 360.0f) { + //node->angle[1] = 0.0f; + //} - node->xyz[0] += node->stack_xyz[0]; - if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) { + //node->xyz[0] += node->stack_xyz[0]; + //node->translateX(node->stack_xyz[0]); + if ((int)node->matrix[12] > screen_w || (int)node->matrix[12] < 0) { node->stack_xyz[0] = -node->stack_xyz[0]; } - node->xyz[1] += node->stack_xyz[1]; - if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) { + //node->xyz[1] += node->stack_xyz[1]; + //node->translateY(node->stack_xyz[1]); + if ((int)node->matrix[13] > screen_h || (int)node->matrix[13] < 0) { node->stack_xyz[1] = -node->stack_xyz[1]; } } @@ -51,23 +55,28 @@ sgroot->OnLightSysSwitch(); SceneGraphPtr light = sgroot->getLight(0); sgroot->OnLightSwitch(0); - light->xyz[0] = screen_w; - light->xyz[1] = screen_h; - light->xyz[2] = 100; + //light->xyz[0] = screen_w; + //light->xyz[1] = screen_h; + //light->xyz[2] = 100; + light->translateX(screen_w); + light->translateY(screen_h); + light->translateZ(100); // SceneGraph ID から SceneGraph を生成する earth = sgroot->createSceneGraph("Earth"); // SceneGraph の move と collision を設定 earth->set_move_collision(earth_move, earth_collision); - earth->xyz[0] = screen_w / 2; - earth->xyz[1] = screen_h / 2; + //earth->xyz[0] = screen_w / 2; + earth->translateX(screen_w / 2); + //earth->xyz[1] = screen_h / 2; + earth->translateY(screen_h / 2); earth->stack_xyz[0] = 3.0f; earth->stack_xyz[1] = 3.0f; moon = sgroot->createSceneGraph("Moon"); moon->set_move_collision(moon_move, moon_collision); - + // SceneGraph 同士の親子関係を設定 (今回は 親 earth、子 moon) earth->addChild(moon);
--- a/example/word_count/main.cc Tue Jan 10 17:17:13 2012 +0900 +++ b/example/word_count/main.cc Sun Jan 15 23:21:39 2012 +0900 @@ -338,7 +338,7 @@ if (w->task_num < w->task_blocks) { // last case - if (w->size >= w->division_size) + while (w->size >= w->division_size) run_tasks(manager,w,w->task_num, w->t_print, w->division_size); // remaining data while (w->size>0)