Mercurial > hg > Members > kono > Cerium
changeset 228:c254a2bd1b34
remove SceneGraph::data, add SceneGraph::coord_xyz, coord_tex, normal
author | gongo@gendarme.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Thu, 12 Feb 2009 16:31:38 +0900 |
parents | d54cbfafcb82 |
children | 401b55a4a4dd |
files | TaskManager/Test/test_render/ChangeLog TaskManager/Test/test_render/SceneGraph.cpp TaskManager/Test/test_render/polygon.cpp TaskManager/Test/test_render/polygon.h TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp TaskManager/Test/test_render/task/create_sgp.cpp TaskManager/Test/test_render/universe.cpp |
diffstat | 7 files changed, 81 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/ChangeLog Wed Feb 11 11:09:39 2009 +0900 +++ b/TaskManager/Test/test_render/ChangeLog Thu Feb 12 16:31:38 2009 +0900 @@ -1,3 +1,25 @@ +2009-02-12 Wataru MIYAGUNI <gongo@cr.ie.u-ryukyu.ac.jp> + + * task/CreatePolygonFromSceneGraph.cpp (CreatePolygonFromSceneGraph::run): fix + 下にあわせる様に + + * SceneGraph.cpp (SceneGraph::SceneGraph, SceneGraph::init) + (SceneGraph::finalize_original): fix + 今まで、Polygon が持つ vertex, normal, texture coordinate ってのが + + --------------------------------------- + data = | vertex | normal | texture | sizeof(data) = size*3 + --------------------------------------- + \ size / \ size / \ size / + + てな感じで、SceneGraph->data の中に 3 つ入ってたわけです。 + これだと、アクセスする時にどれがどれかわからんくなるし、 + ソース読む時に迷う(経験談)ので、data を消して、代わりに + coord_xyz, normal, coord_tex を作りました。 + + * polygon.cpp (Polygon::pickup_coordinate) + (Polygon::pickup_normal, Polygon::pickup_texture): + 2009-02-10 Wataru MIYAGUNI <gongo@cr.ie.u-ryukyu.ac.jp> * Makefile.macosx (depend): fix
--- a/TaskManager/Test/test_render/SceneGraph.cpp Wed Feb 11 11:09:39 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraph.cpp Thu Feb 12 16:31:38 2009 +0900 @@ -143,7 +143,10 @@ name = (char *)xmlGetProp(surface,(xmlChar *)"name"); parent_name = (char *)xmlGetProp(surface,(xmlChar *)"parent"); - data = new float[size*3*3]; + //data = new float[size*3*3]; + coord_xyz = (float*)manager->allocate(sizeof(float)*size*3); + coord_tex = (float*)manager->allocate(sizeof(float)*size*3); + normal = (float*)manager->allocate(sizeof(float)*size*3); get_data(surface->children); @@ -170,7 +173,10 @@ stack_angle[2] = 0.0f; size = 0; - data = NULL; + //data = NULL; + coord_xyz = NULL; + normal = NULL; + coord_tex = NULL; texture_id = -1; move = no_move; @@ -195,7 +201,10 @@ void SceneGraph::finalize_original(void) { - delete [] data; + //delete [] data; + free(coord_xyz); + free(coord_tex); + free(normal); } /**
--- a/TaskManager/Test/test_render/polygon.cpp Wed Feb 11 11:09:39 2009 +0900 +++ b/TaskManager/Test/test_render/polygon.cpp Thu Feb 12 16:31:38 2009 +0900 @@ -181,9 +181,9 @@ { for(int n=0; n<size*3; n+=3) { - cont = pickup_float(cont, data+n); - cont = pickup_float(cont, data+n+1); - cont = pickup_float(cont, data+n+2); + cont = pickup_float(cont, coord_xyz+n); + cont = pickup_float(cont, coord_xyz+n+1); + cont = pickup_float(cont, coord_xyz+n+2); if (cont == NULL) { @@ -194,11 +194,11 @@ void Polygon::pickup_normal(char *cont) { - for(int n=size*3;n<size*6;n+=3) + for (int n = 0; n<size*3; n += 3) { - cont = pickup_float(cont,data+n); - cont = pickup_float(cont,data+n+1); - cont = pickup_float(cont,data+n+2); + cont = pickup_float(cont, normal+n); + cont = pickup_float(cont, normal+n+1); + cont = pickup_float(cont, normal+n+2); if (cont == NULL) { @@ -221,11 +221,11 @@ void Polygon::pickup_texture(char *cont) { - for(int n=size*6; n<size*9; n+=3) + for (int n = 0; n < size*3; n += 3) { - cont = pickup_float(cont,data+n); - cont = pickup_float(cont,data+n+1); - data[n+2] = 1.0; + cont = pickup_float(cont, coord_tex+n); + cont = pickup_float(cont, coord_tex+n+1); + coord_tex[n+2] = 1.0; if (cont == NULL) {
--- a/TaskManager/Test/test_render/polygon.h Wed Feb 11 11:09:39 2009 +0900 +++ b/TaskManager/Test/test_render/polygon.h Thu Feb 12 16:31:38 2009 +0900 @@ -25,10 +25,13 @@ char *name; char *parent_name; - float *data; //"vertex" and "normal" and "texture" - float xyz[4]; // position - float angle[4]; // angle - float c_xyz[4]; // center of rotation + //float *data; //"vertex" and "normal" and "texture" + float *coord_xyz; // vertex coordinate array + float *coord_tex; // texture coordinate array + float *normal; // normal vector array + float xyz[4]; // position + float angle[4]; // angle + float c_xyz[4]; // center of rotation float matrix[16]; float *anim; int texture_id; //texture id number
--- a/TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp Wed Feb 11 11:09:39 2009 +0900 +++ b/TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp Thu Feb 12 16:31:38 2009 +0900 @@ -102,53 +102,51 @@ } TrianglePack *triangle = &pp->tri[pp->info.size++]; - - xyz1[0] = sg->data[(i+0)*3]; - xyz1[1] = sg->data[(i+0)*3+1]; - xyz1[2] = sg->data[(i+0)*3+2]*-1; - xyz1[3] = 1; + + xyz1[0] = sg->coord_xyz[(i+0)*3]; + xyz1[1] = sg->coord_xyz[(i+0)*3+1]; + xyz1[2] = sg->coord_xyz[(i+0)*3+2]*-1.0f; + xyz1[3] = 1.0f; - xyz2[0] = sg->data[(i+1)*3]; - xyz2[1] = sg->data[(i+1)*3+1]; - xyz2[2] = sg->data[(i+1)*3+2]*-1; - xyz2[3] = 1; + xyz2[0] = sg->coord_xyz[(i+1)*3]; + xyz2[1] = sg->coord_xyz[(i+1)*3+1]; + xyz2[2] = sg->coord_xyz[(i+1)*3+2]*-1.0f; + xyz2[3] = 1.0f; - xyz3[0] = sg->data[(i+2)*3]; - xyz3[1] = sg->data[(i+2)*3+1]; - xyz3[2] = sg->data[(i+2)*3+2]*-1; - xyz3[3] = 1; + xyz3[0] = sg->coord_xyz[(i+2)*3]; + xyz3[1] = sg->coord_xyz[(i+2)*3+1]; + xyz3[2] = sg->coord_xyz[(i+2)*3+2]*-1.0f; + xyz3[3] = 1.0f; // sg->matrix = 回転行列*透視変換行列 ApplyMatrix(xyz1, sg->matrix); ApplyMatrix(xyz2, sg->matrix); ApplyMatrix(xyz3, sg->matrix); -#if 1 xyz1[0] /= xyz1[2]; xyz1[1] /= xyz1[2]; xyz2[0] /= xyz2[2]; xyz2[1] /= xyz2[2]; xyz3[0] /= xyz3[2]; xyz3[1] /= xyz3[2]; -#endif triangle->ver1.x = xyz1[0]; triangle->ver1.y = xyz1[1]; triangle->ver1.z = xyz1[2]; - triangle->ver1.tex_x = sg->data[(i+0)*3 + sg->size*6]; - triangle->ver1.tex_y = sg->data[(i+0)*3 + sg->size*6+1]; + triangle->ver1.tex_x = sg->coord_tex[(i+0)*3]; + triangle->ver1.tex_y = sg->coord_tex[(i+0)*3+1]; triangle->ver2.x = xyz2[0]; triangle->ver2.y = xyz2[1]; triangle->ver2.z = xyz2[2]; - triangle->ver2.tex_x = sg->data[(i+1)*3 + sg->size*6]; - triangle->ver2.tex_y = sg->data[(i+1)*3 + sg->size*6+1]; + triangle->ver2.tex_x = sg->coord_tex[(i+1)*3]; + triangle->ver2.tex_y = sg->coord_tex[(i+1)*3+1]; triangle->ver3.x = xyz3[0]; triangle->ver3.y = xyz3[1]; triangle->ver3.z = xyz3[2]; - triangle->ver3.tex_x = sg->data[(i+2)*3 + sg->size*6]; - triangle->ver3.tex_y = sg->data[(i+2)*3 + sg->size*6+1]; + triangle->ver3.tex_x = sg->coord_tex[(i+2)*3]; + triangle->ver3.tex_y = sg->coord_tex[(i+2)*3+1]; triangle->tex_info.addr = sg->texture_info.pixels; triangle->tex_info.width = sg->texture_info.t_w;
--- a/TaskManager/Test/test_render/task/create_sgp.cpp Wed Feb 11 11:09:39 2009 +0900 +++ b/TaskManager/Test/test_render/task/create_sgp.cpp Thu Feb 12 16:31:38 2009 +0900 @@ -62,11 +62,11 @@ * } */ - node->vertex[d] = t->data[i*3]; - node->vertex[d+1] = t->data[i*3+1]; - node->vertex[d+2] = t->data[i*3+2]; - node->texture[tex] = t->data[i*3+t->size*6]; - node->texture[tex+1] = t->data[i*3+t->size*6+1]; + node->vertex[d] = t->coord_xyz[i*3]; + node->vertex[d+1] = t->coord_xyz[i*3+1]; + node->vertex[d+2] = t->coord_xyz[i*3+2]; + node->texture[tex] = t->coord_tex[i*3]; + node->texture[tex+1] = t->coord_tex[i*3+1]; node->size++; }
--- a/TaskManager/Test/test_render/universe.cpp Wed Feb 11 11:09:39 2009 +0900 +++ b/TaskManager/Test/test_render/universe.cpp Thu Feb 12 16:31:38 2009 +0900 @@ -2,8 +2,6 @@ #include "SceneGraphRoot.h" #include "SGList.h" -int moonrem = 0; - static void earth_collision(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree) @@ -20,32 +18,15 @@ moon_move(SceneGraphPtr node, int screen_w, int screen_h) { node->angle[0] += 3.0f; -#if 0 - if (node->angle[0] > 360.0f) { - node->remove(); - //node->angle[0] = 0.0f; - moonrem = 1; - } -#endif } static void earth_move(SceneGraphPtr node, int screen_w, int screen_h) { - return; - node->angle[1] += 1.0f; if (node->angle[1] > 360.0f) { node->angle[1] = 0.0f; -#if 0 - if (moonrem) { - SceneGraphPtr moon = sgroot->createSceneGraph(Moon); - moon->set_move_collision(moon_move, moon_collision); - node->addChild(moon); - moonrem = 0; - } -#endif } node->xyz[0] += node->stack_xyz[0]; @@ -63,7 +44,7 @@ universe_init(void) { SceneGraphPtr earth; - //SceneGraphPtr moon; + SceneGraphPtr moon; sgroot->createFromXMLfile("xml_file/universe.xml"); @@ -72,16 +53,14 @@ // SceneGraph の move と collision を設定 earth->set_move_collision(earth_move, earth_collision); - earth->xyz[0] = 960.0f; - earth->xyz[1] = 540.0f; earth->stack_xyz[0] = 3.0f; earth->stack_xyz[1] = 3.0f; - - //moon = sgroot->createSceneGraph(Moon); - //moon->set_move_collision(moon_move, moon_collision); + + moon = sgroot->createSceneGraph(Moon); + moon->set_move_collision(moon_move, moon_collision); // SceneGraph 同士の親子関係を設定 (今回は 親 earth、子 moon) - //earth->addChild(moon); + earth->addChild(moon); // SceneGraphRoot に、使用する SceneGraph を設定する // このとき、ユーザーが記述した SceneGraph の root を渡す。