Mercurial > hg > Game > Cerium
changeset 1336:3f95f61faef6 draft
collada file might be readable.
author | e095732 <e095732@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 21 Dec 2011 17:43:20 +0900 |
parents | 8a5f7f54433d |
children | 8b60616fca45 |
files | Renderer/Engine/SceneGraph.cc Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/polygon.cc Renderer/Engine/polygon_pack.h Renderer/Test/SgRootChange.cc Renderer/Test/collada_test/collada_test.cc |
diffstat | 6 files changed, 291 insertions(+), 252 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraph.cc Wed Dec 21 13:47:40 2011 +0900 +++ b/Renderer/Engine/SceneGraph.cc Wed Dec 21 17:43:20 2011 +0900 @@ -622,8 +622,165 @@ } +void Polygon::pickup_coordinate(char *cont) +{ + + // size は頂点の数, count は面の数 + char *tmp_cont = cont; + int count = size / 3; + + for (int i = 0; i < pp_num; i++) { + + TrianglePackPtr tri = pp[i].tri; + // TrianglePack の size のチェック + + int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ; + + //それを構造体に登録 + pp[i].info.size = tri_size; + + + for (int j = 0; j < tri_size; j++) { + + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.x)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.y)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.z)); + + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.x)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.y)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.z)); + + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.x)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.y)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.z)); + + if (tmp_cont == NULL) + { + cout << "Analyzing obj data failed coordinate\n"; + } + + count -= 1; + + } + + } + + if (count != 0) { + printf("miss pickup_coordinate size. diff size = %d\n", count); + } + +} + +void Polygon::pickup_normal(char *cont) +{ + + + // size は頂点の数, count は面の数 + char *tmp_cont = cont; + int count = size / 3; + + for (int i = 0; i < pp_num; i++) { + + TrianglePackPtr tri = pp[i].tri; + // TrianglePack の size のチェック + int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ; + pp[i].info.size = tri_size; + + for (int j = 0; j < tri_size; j++) { + + tmp_cont = pickup_float(tmp_cont, &(tri[j].normal1.x)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].normal1.y)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].normal1.z)); + + tmp_cont = pickup_float(tmp_cont, &(tri[j].normal2.x)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].normal2.y)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].normal2.z)); + + tmp_cont = pickup_float(tmp_cont, &(tri[j].normal3.x)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].normal3.y)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].normal3.z)); + + + if (tmp_cont == NULL) + { + cout << "Analyzing obj data failed coordinate\n"; + } + + count -= 1; + + } + + + } + + if (count != 0) { + printf("miss pickup_normal size. diff size = %d\n", count); + } + +} + +void Polygon::pickup_model(char *cont) +{ + cont = pickup_float(cont,c_xyz); + cont = pickup_float(cont,c_xyz+1); + cont = pickup_float(cont,c_xyz+2); + + if (cont == NULL) + { + cout << "Analyzing obj data failed model\n"; + } +} + +void Polygon::pickup_texture(char *cont) +{ + + char *tmp_cont = cont; + int count = size / 3; + + for (int i = 0; i < pp_num; i++) { + + TrianglePackPtr tri = pp[i].tri; + // TrianglePack の size のチェック + int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ; + pp[i].info.size = tri_size; + + for (int j = 0; j < tri_size; j++) { + + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.tex_x)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.tex_y)); + + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.tex_x)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.tex_y)); + + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.tex_x)); + tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.tex_y)); + + + if (tmp_cont == NULL) + { + cout << "Analyzing obj data failed coordinate\n"; + } + + count -= 1; + + } + + + } + + if (count != 0) { + printf("miss pickup_texture size. diff size = %d\n", count); + } + + + +} + + /* * surface nodeからポリゴンの情報を読み出す 再帰しない + * + * get_data,get_image,makeTapestorys このファイルの外に追い出すのがよい */ void SceneGraph::get_data(TaskManager *manager, xmlNodePtr cur)
--- a/Renderer/Engine/SceneGraphRoot.cc Wed Dec 21 13:47:40 2011 +0900 +++ b/Renderer/Engine/SceneGraphRoot.cc Wed Dec 21 17:43:20 2011 +0900 @@ -304,6 +304,7 @@ } /* compare a with b. Using to compare id */ +/* static int strcmp_a(const char *a, const char *b) { @@ -311,7 +312,6 @@ if (*a) return 0; return a[-1] > b[-1] ? 1:-1; } -/* static float get_point(char *id, int position, LIST_P list) { @@ -395,82 +395,46 @@ int polylist_count; }; -static void -xml_walk(xmlNodePtr cur, struct collada_state *s, LIST_P list) -{ - int in_polylist=0; - - printf("name = %s, child:%s\n", (char *)cur->name, (char *)cur->children); - printf("s->polylist = %d\n",s->polylist); - - if (!xmlStrcmp(cur->name, (xmlChar*)"polylist")) { - - s->polylist_count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count")); - s->polylist=1; - in_polylist=1; - - } else if (!xmlStrcmp(cur->name, (xmlChar*)"vertices")) { +void decode_float_array(xmlNodePtr cur,LIST_P list ){ + + + SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE)); + + char *id = (char*)xmlGetProp(cur, (xmlChar*)"id"); + src->id = (char*)xmlGetProp(cur, (xmlChar*)"id"); + + int count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count")); + src->count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count")); + src->u.array = (float*)malloc(sizeof(float) * src->count); + + char *cont =(char*)xmlNodeGetContent(cur); + //const char *id = get_property("id", cur); + //int count = atoi(get_property("count", cur)); - s->pid = xmlGetProp(cur, (xmlChar*)"id"); - - } else if (!s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) { - - char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic"); - if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"POSITION")) { - s->vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); + /* store float inpoint list */ + for (int i = 0; cont != NULL; i++) { + cont = pickup_float(cont, src->u.array+i); } - } else if (s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) { - char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic"); - - if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"VERTEX")) { - - s->vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); - s->vertex_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); - s->vertex_float = most_match(s->vertices_src+1, list); - - } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"NORMAL")) { - - s->normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); - s->normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); - s->normal_float = most_match(s->normal_src+1, list); - - } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"TEXCOORD")) { + src->next = NULL; + addSource(list, src); + printf("id:%s count:%d cont:%s\n", id, count, cont); +} - s->texcoord_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); - s->texcoord_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); - s->texcoord_float = most_match(s->texcoord_src+1, list); - } - } else if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) { - char *vcont = (char*)xmlNodeGetContent(cur); - - s->vcount = (float*)malloc(sizeof(float)*s->polylist_count); - - for (int i=0; vcont!=NULL; i++) { - /* store vcount list */ - vcont = pickup_float(vcont, s->vcount+i); - } - - } else if (!xmlStrcmp(cur->name, (xmlChar*)"p")) { - - /* only case is nothing input of source="TEXCOORD" */ - +void +decode_points(xmlNodePtr cur, collada_state *s, TaskManager *manager){ char *pcont = (char*)xmlNodeGetContent(cur); int vcsum = 0; - for (int i = 0;i < s->polylist_count;i++){ vcsum += s->vcount[i]; } - s->pcount = (float*)malloc(sizeof(float)*vcsum); - for (int i=0; pcont != NULL; i++) { pcont = pickup_float(pcont, s->pcount+i); } - int vertexp[vcsum]; for (int i = 0;i < vcsum;i++){ vertexp[i]=0; @@ -494,7 +458,6 @@ i++; } } - /* */ for (int i=0; vertexp[i];i++) { if (s->vcount[i] == 4) { for (int j=0; j > s->vcount[i]; j++) { @@ -506,6 +469,60 @@ vertex_table[i] = s->vertex_float->u.array[vertexp[i]]; } } + + int count = vcsum / 3; + SceneGraphPtr sg = new SceneGraph(manager); + sg->pp_num = (count + MAX_SIZE_TRIANGLE - 1) / MAX_SIZE_TRIANGLE; + sg->pp = (PolygonPack*)malloc(sizeof(PolygonPack)*sg->pp_num); + + for (int i = 0;i < sg->pp_num; i++ ){ + PolygonPackPtr pp = sg->pp; + TrianglePackPtr tri = pp[i].tri; + // TrianglePack の size のチェック + int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ; + pp[i].info.size = tri_size; + int k = 0; + int m = 0; + int n = 0; + for (int j = 0; j < tri_size; j++) { + tri[j].normal1.x = normal_table[k++]; + tri[j].normal1.y = normal_table[k++]; + tri[j].normal1.z = normal_table[k++]; + + tri[j].normal2.x = normal_table[k++]; + tri[j].normal2.y = normal_table[k++]; + tri[j].normal2.z = normal_table[k++]; + + tri[j].normal3.x = normal_table[k++]; + tri[j].normal3.y = normal_table[k++]; + tri[j].normal3.z = normal_table[k++]; + + tri[j].ver1.tex_x = texcoord_table[m++]; + tri[j].ver1.tex_y = texcoord_table[m++]; + + tri[j].ver2.tex_x = texcoord_table[m++]; + tri[j].ver2.tex_y = texcoord_table[m++]; + + tri[j].ver3.tex_x = texcoord_table[m++]; + tri[j].ver3.tex_y = texcoord_table[m++]; + + tri[j].ver1.x = vertex_table[n++]; + tri[j].ver1.y = vertex_table[n++]; + tri[j].ver1.z = vertex_table[n++]; + + tri[j].ver2.x = vertex_table[n++]; + tri[j].ver2.y = vertex_table[n++]; + tri[j].ver2.z = vertex_table[n++]; + + tri[j].ver3.x = vertex_table[n++]; + tri[j].ver3.y = vertex_table[n++]; + tri[j].ver3.z = vertex_table[n++]; + + } + + } + sg->c_xyz[0] = sg->c_xyz[1] = sg->c_xyz[2] = 0; + /*TEST*/ for (int i=0; i<vcsum; i++) { printf("vertexp = %d\n", vertexp[i]); @@ -518,36 +535,57 @@ /* got out of polylist */ s->polylist = 0; - in_polylist = 0; - - } else if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) { - - SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE)); - - char *id = (char*)xmlGetProp(cur, (xmlChar*)"id"); - src->id = (char*)xmlGetProp(cur, (xmlChar*)"id"); - - int count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count")); - src->count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count")); - src->u.array = (float*)malloc(sizeof(float) * src->count); - - char *cont =(char*)xmlNodeGetContent(cur); - //const char *id = get_property("id", cur); - //int count = atoi(get_property("count", cur)); - - /* store float inpoint list */ - for (int i = 0; cont != NULL; i++) { - cont = pickup_float(cont, src->u.array+i); - } - - src->next = NULL; - addSource(list, src); - printf("id:%s count:%d cont:%s\n", id, count, cont); } - + + +static void +xml_walk(xmlNodePtr cur, struct collada_state *s, LIST_P list, SceneGraphRoot *root) +{ + int in_polylist=0; + printf("name = %s, child:%s\n", (char *)cur->name, (char *)cur->children); + printf("s->polylist = %d\n",s->polylist); + if (!xmlStrcmp(cur->name, (xmlChar*)"polylist")) { + s->polylist_count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count")); + s->polylist=1; + in_polylist=1; + } else if (!xmlStrcmp(cur->name, (xmlChar*)"vertices")) { + s->pid = xmlGetProp(cur, (xmlChar*)"id"); + } else if (!s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) { + char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic"); + if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"POSITION")) { + s->vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); + } + } else if (s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) { + char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic"); + if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"VERTEX")) { + s->vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); + s->vertex_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); + s->vertex_float = most_match(s->vertices_src+1, list); + } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"NORMAL")) { + s->normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); + s->normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); + s->normal_float = most_match(s->normal_src+1, list); + } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"TEXCOORD")) { + s->texcoord_src = (char*)xmlGetProp(cur, (xmlChar*)"source"); + s->texcoord_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset")); + s->texcoord_float = most_match(s->texcoord_src+1, list); + } + } else if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) { + char *vcont = (char*)xmlNodeGetContent(cur); + s->vcount = (float*)malloc(sizeof(float)*s->polylist_count); + for (int i=0; vcont!=NULL; i++) { + /* store vcount list */ + vcont = pickup_float(vcont, s->vcount+i); + } + } else if (!xmlStrcmp(cur->name, (xmlChar*)"p")) { + decode_points(cur,s,root->tmanager); + in_polylist = 0; + } else if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) { + decode_float_array(cur,list); + } for (cur=cur->children; cur; cur=cur->next){ - xml_walk(cur, s, list); + xml_walk(cur, s, list , root); } } @@ -579,7 +617,7 @@ LIST list; init_list(&list); - xml_walk(cur,&s, &list); + xml_walk(cur,&s, &list,this); }
--- a/Renderer/Engine/polygon.cc Wed Dec 21 13:47:40 2011 +0900 +++ b/Renderer/Engine/polygon.cc Wed Dec 21 17:43:20 2011 +0900 @@ -3,7 +3,6 @@ #include <SDL_opengl.h> #include <SDL_image.h> #include "polygon.h" -#include "xml.h" #include "matrix_calc.h" #include "triangle.h" #include "vertex.h" @@ -45,160 +44,6 @@ } -void Polygon::pickup_coordinate(char *cont) -{ - - // size は頂点の数, count は面の数 - char *tmp_cont = cont; - int count = size / 3; - - for (int i = 0; i < pp_num; i++) { - - TrianglePackPtr tri = pp[i].tri; - // TrianglePack の size のチェック - - int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ; - - //それを構造体に登録 - pp[i].info.size = tri_size; - - - for (int j = 0; j < tri_size; j++) { - - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.x)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.y)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.z)); - - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.x)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.y)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.z)); - - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.x)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.y)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.z)); - - if (tmp_cont == NULL) - { - cout << "Analyzing obj data failed coordinate\n"; - } - - count -= 1; - - } - - } - - if (count != 0) { - printf("miss pickup_coordinate size. diff size = %d\n", count); - } - -} - -void Polygon::pickup_normal(char *cont) -{ - - - // size は頂点の数, count は面の数 - char *tmp_cont = cont; - int count = size / 3; - - for (int i = 0; i < pp_num; i++) { - - TrianglePackPtr tri = pp[i].tri; - // TrianglePack の size のチェック - int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ; - pp[i].info.size = tri_size; - - for (int j = 0; j < tri_size; j++) { - - tmp_cont = pickup_float(tmp_cont, &(tri[j].normal1.x)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].normal1.y)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].normal1.z)); - - tmp_cont = pickup_float(tmp_cont, &(tri[j].normal2.x)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].normal2.y)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].normal2.z)); - - tmp_cont = pickup_float(tmp_cont, &(tri[j].normal3.x)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].normal3.y)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].normal3.z)); - - - if (tmp_cont == NULL) - { - cout << "Analyzing obj data failed coordinate\n"; - } - - count -= 1; - - } - - - } - - if (count != 0) { - printf("miss pickup_normal size. diff size = %d\n", count); - } - -} - -void Polygon::pickup_model(char *cont) -{ - cont = pickup_float(cont,c_xyz); - cont = pickup_float(cont,c_xyz+1); - cont = pickup_float(cont,c_xyz+2); - - if (cont == NULL) - { - cout << "Analyzing obj data failed model\n"; - } -} - -void Polygon::pickup_texture(char *cont) -{ - - char *tmp_cont = cont; - int count = size / 3; - - for (int i = 0; i < pp_num; i++) { - - TrianglePackPtr tri = pp[i].tri; - // TrianglePack の size のチェック - int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ; - pp[i].info.size = tri_size; - - for (int j = 0; j < tri_size; j++) { - - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.tex_x)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.tex_y)); - - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.tex_x)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.tex_y)); - - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.tex_x)); - tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.tex_y)); - - - if (tmp_cont == NULL) - { - cout << "Analyzing obj data failed coordinate\n"; - } - - count -= 1; - - } - - - } - - if (count != 0) { - printf("miss pickup_texture size. diff size = %d\n", count); - } - - - -} - char *get_pixel(int tx, int ty, SDL_Surface *texture_image) { return (char*)texture_image->pixels+(texture_image->format->BytesPerPixel*((texture_image->w)*ty+tx));
--- a/Renderer/Engine/polygon_pack.h Wed Dec 21 13:47:40 2011 +0900 +++ b/Renderer/Engine/polygon_pack.h Wed Dec 21 17:43:20 2011 +0900 @@ -56,8 +56,6 @@ struct POLYGON_info { int size; - int light_pos[3]; - int light_rgb[3]; int span_num; }info; PolygonPack* next;
--- a/Renderer/Test/SgRootChange.cc Wed Dec 21 13:47:40 2011 +0900 +++ b/Renderer/Test/SgRootChange.cc Wed Dec 21 17:43:20 2011 +0900 @@ -50,7 +50,7 @@ } } -static int time = 0; +static int ball_move_time = 0; static void ball_move_idle(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) @@ -60,19 +60,19 @@ if (pad->circle.isPush()) { node->set_move_collision(ball_move_idle2, ball_collision_idle); - time = 0; + ball_move_time = 0; } - time++; + ball_move_time++; - if (time > 90) { + if (ball_move_time > 90) { float w = (float)random(); w = fmodf(w, screen_w - ball_radius*2); node->xyz[0] = w + ball_radius; node->xyz[1] = h0; node->set_move_collision(ball_move, ball_collision); - time = 0; + ball_move_time = 0; } }
--- a/Renderer/Test/collada_test/collada_test.cc Wed Dec 21 13:47:40 2011 +0900 +++ b/Renderer/Test/collada_test/collada_test.cc Wed Dec 21 17:43:20 2011 +0900 @@ -316,6 +316,7 @@ } /*TEST*/ for (int i=0; i<vcsum; i++) { + printf("---------- i = %d ----------------- \n",i); printf("pcount= %f\n", pcount[i]); printf("normal_table= %f\n", normal_table[i]); printf("texcoord_count= %f\n", texcoord_table[i]);