Mercurial > hg > Game > Cerium
changeset 1340:b6ee60edacf0 draft
merge
author | Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 10 Jan 2012 17:17:13 +0900 |
parents | 035e8c39508c (current diff) 8c098a144c75 (diff) |
children | fed88ab337b4 e51127dbd63c |
files | |
diffstat | 6 files changed, 796 insertions(+), 293 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraph.cc Tue Jan 10 17:15:44 2012 +0900 +++ b/Renderer/Engine/SceneGraph.cc Tue Jan 10 17:17:13 2012 +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 Tue Jan 10 17:15:44 2012 +0900 +++ b/Renderer/Engine/SceneGraphRoot.cc Tue Jan 10 17:17:13 2012 +0900 @@ -24,7 +24,6 @@ sgroot->tmanager = manager; // SGLIST_LENGTH 決め打ちかぁ、動的生成にする場合上限決めておいた方がいいのかな - // sg_src = (SceneGraphPtr*) malloc(sizeof(SceneGraphPtr)*SGLIST_LENGTH); camera = new Camera(w, h, this, sgroot->tmanager); @@ -304,6 +303,7 @@ } /* compare a with b. Using to compare id */ +/* static int strcmp_a(const char *a, const char *b) { @@ -311,7 +311,6 @@ if (*a) return 0; return a[-1] > b[-1] ? 1:-1; } - static float get_point(char *id, int position, LIST_P list) { @@ -327,31 +326,48 @@ } } } - +*/ /** * co */ static SOURCE_P most_match(const char *id , LIST_P list) { - SOURCE_P src,cur; - int tmplength; + SOURCE_P src = NULL; + SOURCE_P cur = NULL;; + int tmplength = 0; int strlength; for (cur=list->first ;cur!=list->end ;cur=cur->next) { - for (strlength=0;id[strlength+1]==cur->id[strlength];strlength++); + for (strlength=0;id[strlength]==cur->id[strlength];strlength++); if (tmplength < strlength) { tmplength = strlength; src = cur; } } + + if (src == NULL){ + fprintf(stderr,"not match"); + } return src; } struct collada_state { - int polylist; + collada_state(){ + polylist = 0; + + vertex_offset = -1; + vertex_count = 0; - const char *polylist_normal; - const char *polylist_vertex; + normal_offset = -1; + normal_count = 0; + + texcoord_offset = -1; + texcoord_count = 0; + + polylist_count = 0; + + } + int polylist; xmlChar *pid; @@ -363,117 +379,26 @@ int normal_offset; int normal_count; + char *texcoord_src; + int texcoord_offset; + int texcoord_count; + float *vcount; float *pcount; - + SOURCE_P normal_float; SOURCE_P vertex_float; + SOURCE_P texcoord_float; char *vertices_src; int polylist_count; - - }; -static void -xml_walk(SceneGraphRoot* self, 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")) { - - 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, 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, 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" */ - - char *pcont = (char*)xmlNodeGetContent(cur); - - s->pcount = (float*)malloc(sizeof(float)*(int)s->polylist_count); - - for (int i=0; pcont != NULL; i++) { - pcont = pickup_float(pcont, s->pcount+i); - } - - int vertexp[s->vertex_count]; - - float *vertex_table = (float*)malloc(sizeof(float)*s->vertex_float->count) ; - float *normal_table = (float*)malloc(sizeof(float)*s->normal_float->count) ; - - /* p separate vertex position and nomal position. */ - for (int i = 0; i < s->polylist_count; i++) { - vertexp[i] = s->pcount[2*i]; - normal_table[i] = s->normal_float->u.array[(int)s->pcount[2*i+1]]; - } - - for (int i=0; vertexp[i];i++) { - if (s->vcount[i] == 4) { - for (int j=0; j > s->vcount[i]; j++) { - vertex_table[i] = s->vertex_float->u.array[vertexp[i]]; - vertex_table[i+3] = s->vertex_float->u.array[vertexp[i+1]]; - i += 2; - } - } - if (s->vcount[i]==3) { - vertex_table[i] = s->vertex_float->u.array[vertexp[i]]; - } - } - for (int i=0; vertex_table; i++) { - printf("normal_table= %f\n", normal_table[i]); - printf("vertex_table= %f\n", vertex_table[i]); - } - - /* got out of polylist */ - s->polylist = 0; - in_polylist = 0; - - } else if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) { - +void decode_float_array(xmlNodePtr cur,LIST_P list ){ + + SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE)); char *id = (char*)xmlGetProp(cur, (xmlChar*)"id"); @@ -481,7 +406,7 @@ 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); + src->u.array = (float*)malloc(sizeof(float)*src->count); char *cont =(char*)xmlNodeGetContent(cur); //const char *id = get_property("id", cur); @@ -495,11 +420,186 @@ src->next = NULL; addSource(list, src); printf("id:%s count:%d cont:%s\n", id, count, cont); +} + + +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); + s->pcount = new float[vcsum]; + for (int i=0; pcont != NULL; i++) { + pcont = pickup_float(pcont, s->pcount+i); + } + int *vertexp; + vertexp = new int[vcsum]; + for (int i=0;i<vcsum;i++){ + vertexp[i]=0; + } + float *vertex_table; + float *normal_table; + float *texcoord_table; + vertex_table = new float[s->vertex_float->count]; + //float *vertex_table = (float*)malloc(sizeof(float)*s->vertex_float->count) ; + normal_table = new float[s->normal_float->count]; + //float *normal_table = (float*)malloc(sizeof(float)*s->normal_float->count) ; + texcoord_table = new float[s->texcoord_float->count]; + //float *texcoord_table = (float*)malloc(sizeof(float)*s->texcoord_float->count) ; + + int limit = vcsum * 2; + if (s->texcoord_offset == 2){ + limit = vcsum * 3; + } + + /* p separate vertex position and nomal position. */ + for (int i=0,j=0; i < limit; i+=2,j++) { + vertexp[j] = s->pcount[i]; + normal_table[j] = s->normal_float->u.array[(int)s->pcount[i+1]]; + if (s->texcoord_offset == 2) { + texcoord_table[j] = s->texcoord_float->u.array[(int)s->pcount[i+2]]; + i++; + } + } + delete s->pcount; + for (int i=0; vertexp[i];i++) { + if (s->vcount[i] == 4) { + for (int j=0; j > s->vcount[i]; j++) { + vertex_table[i] = s->vertex_float->u.array[vertexp[i]]; + vertex_table[i+3] = s->vertex_float->u.array[vertexp[i+1]]; + i += 2; + } + }else if (s->vcount[i]==3) { + vertex_table[i] = s->vertex_float->u.array[vertexp[i]]; + } + } + delete s->vcount; + + 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]); + // printf("vertex_table= %f\n", vertex_table[i]); + } + //free(vertexp); + //free(vertex_table); + //free(normal_table); + //free(texcoord_table); + + delete vertexp; + delete vertex_table; + delete normal_table; + delete texcoord_table; + + /* got out of polylist */ + s->polylist = 0; } - + + +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); + s->vcount = new 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(self, cur, s, list); + xml_walk(cur, s, list , root); } } @@ -512,31 +612,30 @@ void SceneGraphRoot::createFromCOLLADAfile(TaskManager *manager, const char *xmlColladafile) { - /*make parse dom*/ - xmlDocPtr doc; - xmlNodePtr cur; - //,cur_images,cur_effects,cur_geometries,cur_visual_scenes; - //SceneGraphPtr tmp; - - doc = xmlParseFile(xmlColladafile); - cur = xmlDocGetRootElement(doc); + /*make parse dom*/ + xmlDocPtr doc; + xmlNodePtr cur; + //,cur_images,cur_effects,cur_geometries,cur_visual_scenes; + //SceneGraphPtr tmp; + + doc = xmlParseFile(xmlColladafile); + cur = xmlDocGetRootElement(doc); + + if (xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){ + return ; + } - if(xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){ - return ; - } - - /* node analyze */ + /* node analyze */ struct collada_state s; - s.polylist=0; - - for(cur=cur->children; cur; cur=cur->next){ - + for (cur=cur->children; cur; cur=cur->next){ + LIST list; init_list(&list); + xml_walk(cur,&s, &list,this); - xml_walk(this, cur,&s, &list); } - xmlFreeDoc(doc); + + xmlFreeDoc(doc); } void
--- a/Renderer/Engine/polygon.cc Tue Jan 10 17:15:44 2012 +0900 +++ b/Renderer/Engine/polygon.cc Tue Jan 10 17:17:13 2012 +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 Tue Jan 10 17:15:44 2012 +0900 +++ b/Renderer/Engine/polygon_pack.h Tue Jan 10 17:17:13 2012 +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 Tue Jan 10 17:15:44 2012 +0900 +++ b/Renderer/Test/SgRootChange.cc Tue Jan 10 17:17:13 2012 +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; } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Test/collada_test/collada_test.cc Tue Jan 10 17:17:13 2012 +0900 @@ -0,0 +1,404 @@ +#include <stdio.h> +#include <libxml/parser.h> + +typedef struct source { + char *id; + union { + float *array; + char *alias; + }u; + int count; + struct source *next; +} SOURCE; +typedef SOURCE *SOURCE_P; + +typedef struct list { + SOURCE_P first; + SOURCE_P end; +} LIST; +typedef LIST *LIST_P; + +/* add source list */ +static void +addSource(LIST_P list, SOURCE_P src) { + if (list->first == NULL && list->end == NULL) { + list->first = list->end = src; + return; + } + list->end->next = src; + list->end = src; +} + +/* compare a with b. Using to compare id */ +static int +strcmp_a(const char *a, const char *b) +{ + while (*a && *a++ == *b++); + if (*a) return 0; + return a[-1] > b[-1] ? 1:-1; +} +/* +static float +get_point(char *id, int position, LIST_P list) +{ + SOURCE_P cur = list->first; + for (;cur ; cur=cur->next) { + if (!strcmp_a(id, cur->id)) { + if (cur->count == 0) //alias + return get_point(cur->u.alias, position, list); + float *a = cur->u.array; + if (position <= cur->count) { + return a[position]; + } + } + } +} +*/ +/** + * co + */ +static SOURCE_P +most_match(const char *id , LIST_P list) +{ + SOURCE_P src = NULL; + SOURCE_P cur = NULL; + int tmplength = 0; + int strlength; + + for (cur=list->first ;cur!=list->end ;cur=cur->next) { + for (strlength=0;id[strlength]==cur->id[strlength];strlength++); + if (tmplength < strlength) { + tmplength = strlength; + src = cur; + } + } + if ( src == NULL) { + printf("not match list\n"); + } + + return src; +} + +struct collada_state { + collada_state(){ + polylist=0; + vertex_offset=-1; + vertex_count=0; + + normal_offset=-1; + normal_count=0; + + texcoord_offset=-1; + texcoord_count=0; + + polylist_count=0; + } + + int polylist; + + xmlChar *pid; + + char *vertex_src; + int vertex_offset; + int vertex_count; + + char *normal_src; + int normal_offset; + int normal_count; + + char *texcoord_src; + int texcoord_offset; + int texcoord_count; + + float *vcount; + + SOURCE_P normal_float; + SOURCE_P vertex_float; + SOURCE_P texcoord_float; + + char *vertices_src; + int polylist_count; + +}; + +char *skip_to_number(char *cont) +{ + if (cont == NULL) return(NULL); + for (;(*cont < '+' || *cont > '9') && (*cont != '\0');cont++) {} + if (*cont == '\0') + { + fprintf(stderr,"Content data is short\n"); + return(NULL); + } + return(cont); +} + + +char *pickup_float(char *cont, float *index) +{ + int sign=1,exp=1; + float shift=10,val_dec=0,val_int=0; + + cont = skip_to_number(cont); + if (cont == NULL) return(NULL); + + for (;*cont != ' ' && *cont != '\n' && *cont != '\t' && *cont != ',' ;cont++) + { + if (*cont == '-') + { + sign = -1; + } + else if (*cont == '.') + { + shift = 0.1; + } + else if (*cont >= '0' && *cont <= '9') + { + if (shift == 10) + { + val_int *= shift; + val_int += *cont - 48; + } + else + { + val_dec += (*cont - 48) * shift; + shift *= 0.1; + } + } + else if (*cont == 'e' || *cont == 'E') + { + //cont = pickup_exponent(&exp,cont+1); + if (cont == NULL) return(NULL); + } + else if (*cont == '+' || *cont == '/' || *cont == ' ') + { + // ignore + } + + else if (*cont == '\0') + { + // NULL end + + /* ここの条件は collada の仕様に合わせたもの。 + * 自前の blender script から吐き出される xml形式では、 + * 文字の終わりをNULLでは判断せず、エラー処理としていた + * ので必要ではなかった。よって、自前 blender script の + * xml形式の時、途中で NULL が来た場合、エラー処理され + * なくなる。NULL を返すので、呼び出し側で判断する + */ + + *index = sign * (val_int + val_dec) * exp; + return(NULL); + } + else + { + fprintf(stderr,"Pick up float failed : %c(%d)\n",*cont,*cont); + return(NULL); + } + } + + *index = sign * (val_int + val_dec) * exp; + cont++; + return(cont); +} + + + +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")) { + + 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")) { + + char *pcont = (char*)xmlNodeGetContent(cur); + + int vcsum = 0; + for (int i=0; i < s->polylist_count; i++) { + vcsum += s->vcount[i]; + } + + float *pcount = (float*)malloc(sizeof(float)*vcsum); + + for (int i=0; pcont != NULL; i++) { + pcont = pickup_float(pcont, pcount+i); + } + + int vertexp[vcsum]; + + for (int i=0; i<vcsum ;i++) { + vertexp[i]=0; + } + + float *vertex_table = (float*)malloc(sizeof(float)*s->vertex_float->count) ; + float *normal_table = (float*)malloc(sizeof(float)*s->normal_float->count) ; + float *texcoord_table = (float*)malloc(sizeof(float)*s->texcoord_float->count) ; + + int limit = vcsum * 2; + if (s->texcoord_offset == 2){ + limit = vcsum * 3; + } + + /* p separate vertex position and nomal position. */ + for (int i=0, j=0; i < limit; i+=2,j++) { + vertexp[j] = (int)pcount[i]; + normal_table[j] = s->normal_float->u.array[(int)pcount[i+1]]; + if (s->texcoord_offset == 2) { + texcoord_table[j] = s->texcoord_float->u.array[(int)pcount[i+2]]; + i++; + } + } + + for (int i=0; vertexp[i];i++) { + if (s->vcount[i] == 4) { + for (int j=0; j > s->vcount[i]; j++) { + vertex_table[i] = s->vertex_float->u.array[vertexp[i]]; + vertex_table[i+3] = s->vertex_float->u.array[vertexp[i+1]]; + i += 2; + } + } else if (s->vcount[i]==3) { + vertex_table[i] = s->vertex_float->u.array[vertexp[i]]; + } + } + /*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]); + printf("vertexp= %d\n", vertexp[i]); + } + + free(vertex_table); + free(normal_table); + free(texcoord_table); + + /* 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)); + + printf("id:%s count:%d cont:%s\n", id, count, cont); + /* 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); + + } + + for (cur=cur->children; cur; cur=cur->next){ + xml_walk(cur, s, list); + } +} + +void +init_list(LIST_P list) { + list->first = NULL; + list->end = NULL; +} + + +int main(int argc, char *argv[]) { + + const char *xmlColladafile = argv[1]; + + /*make parse dom*/ + xmlDocPtr doc; + xmlNodePtr cur; + //,cur_images,cur_effects,cur_geometries,cur_visual_scenes; + //SceneGraphPtr tmp; + + doc = xmlParseFile(xmlColladafile); + cur = xmlDocGetRootElement(doc); + + if(xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){ + return 0; + } + + /* node analyze */ + struct collada_state s; + + LIST list; + + for(cur=cur->children; cur; cur=cur->next){ + init_list(&list); + xml_walk(cur,&s, &list); + } + + //printlist(list); + xmlFreeDoc(doc); + + return 0; + +}