# HG changeset patch # User admin@mcbk.cr.ie.u-ryukyu.ac.jp # Date 1247209575 -32400 # Node ID 51ffd144f62c4e9b15cbcfe8423eff173a72f448 # Parent d6338bb6db87e19458ed4fec2cf5fd6c9ed72504 fix hash_regist diff -r d6338bb6db87 -r 51ffd144f62c TaskManager/Test/test_render/SceneGraph.cpp --- a/TaskManager/Test/test_render/SceneGraph.cpp Thu Jul 09 17:59:44 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraph.cpp Fri Jul 10 16:06:15 2009 +0900 @@ -18,9 +18,6 @@ static TextureHash texture_hash; struct texture_list list[TABLE_SIZE]; -// TextureHash.cpp -extern int id_count; - extern int decode(char *cont, FILE *outfile); static void @@ -28,7 +25,7 @@ static void no_collision(SceneGraphPtr self, int screen_w, int screen_h, - SceneGraphPtr tree) {} + SceneGraphPtr tree) {} /** * 事前に計算したテクスチャの最大縮小率 scale まで、 @@ -64,33 +61,33 @@ */ static uint32* makeTapestry(int tex_w, int tex_h, uint32 *tex_src, - int all_pixel_num, int scale_cnt) + int all_pixel_num, int scale_cnt) { uint32 *tex_dest; int t = 0; int diff = TEXTURE_SPLIT_PIXEL; int p_diff = 1; - + tex_dest = (uint32*)manager->allocate(sizeof(int)*all_pixel_num); while (scale_cnt) { - for (int y = 0; y < tex_h; y += diff) { - for (int x = 0; x < tex_w; x += diff) { - for (int j = 0; j < diff; j += p_diff) { - for (int i = 0; i < diff; i += p_diff) { - tex_dest[t++] - = tex_src[(x+i) + tex_w*(y+j)]; - } - } - } - } - - diff <<= 1; - p_diff <<= 1; - scale_cnt >>= 1; + for (int y = 0; y < tex_h; y += diff) { + for (int x = 0; x < tex_w; x += diff) { + for (int j = 0; j < diff; j += p_diff) { + for (int i = 0; i < diff; i += p_diff) { + tex_dest[t++] + = tex_src[(x+i) + tex_w*(y+j)]; + } + } + } + } + + diff <<= 1; + p_diff <<= 1; + scale_cnt >>= 1; } - + return tex_dest; } @@ -130,7 +127,7 @@ finalize = &SceneGraph::finalize_copy; - frame = 0; + frame = 0; } @@ -229,14 +226,14 @@ { /* childrenのリストの最後に加える (brother として)*/ if (this->lastChild != NULL) { - SceneGraphPtr last = this->lastChild; - last->brother = child; + SceneGraphPtr last = this->lastChild; + last->brother = child; } this->lastChild = child; if (this->children == NULL) { - this->children = child; + this->children = child; } child->parent = this; @@ -255,10 +252,10 @@ SceneGraph::addBrother(SceneGraphPtr bro) { if (this->parent) { - parent->addChild(bro); + parent->addChild(bro); } else { - fprintf(stderr, "error : SceneGraph::%s : %s doesn't have parent\n", - __FUNCTION__, this->name); + fprintf(stderr, "error : SceneGraph::%s : %s doesn't have parent\n", + __FUNCTION__, this->name); } return bro; @@ -276,8 +273,8 @@ /* 子供から再帰的に探す */ for(tmp = this->children; tmp; tmp = tmp->next) { - if ((result=tmp->searchSceneGraph(name)) != NULL) - return result; + if ((result=tmp->searchSceneGraph(name)) != NULL) + return result; } /* 無かったら NULL. */ @@ -291,37 +288,37 @@ while(t) { - cout << "my_name : " << t->name << endl; - if(t->children != NULL) - { - cout << "--move children : " << t->children->name << endl; - t = t->children; - } - else if(t->brother != NULL) - { - cout << "--move brother : " << t->brother->name << endl; - t = t->brother; - } - else - { - while(t) - { - if(t->brother != NULL) - { - cout << "--move brother : " << t->brother->name << endl; - t = t->brother; - break; - } - else - { - if(t->parent) - { - cout << "--move parent : " << t->parent->name << endl; - } - t = t->parent; - } - } - } + cout << "my_name : " << t->name << endl; + if(t->children != NULL) + { + cout << "--move children : " << t->children->name << endl; + t = t->children; + } + else if(t->brother != NULL) + { + cout << "--move brother : " << t->brother->name << endl; + t = t->brother; + } + else + { + while(t) + { + if(t->brother != NULL) + { + cout << "--move brother : " << t->brother->name << endl; + t = t->brother; + break; + } + else + { + if(t->parent) + { + cout << "--move parent : " << t->parent->name << endl; + } + t = t->parent; + } + } + } } } @@ -334,11 +331,11 @@ cout << "parent_name = " << parent_name << endl; if (parent != NULL) { - cout << "parent->name = " << parent->name << endl; + cout << "parent->name = " << parent->name << endl; } if (children != NULL) { - cout << "children->name = " << children->name << endl; + cout << "children->name = " << children->name << endl; } } @@ -348,40 +345,41 @@ */ void SceneGraph::get_data(xmlNodePtr cur) -{ +{ //char *image_name; for(;cur;cur=cur->next) { - if(!xmlStrcmp(cur->name,(xmlChar*)"coordinate")) + if(!xmlStrcmp(cur->name,(xmlChar*)"coordinate")) { - char *cont = (char *)xmlNodeGetContent(cur); - pickup_coordinate(cont); + char *cont = (char *)xmlNodeGetContent(cur); + pickup_coordinate(cont); } - else if(!xmlStrcmp(cur->name,(xmlChar*)"normal")) + else if(!xmlStrcmp(cur->name,(xmlChar*)"normal")) { - char *cont = (char *)xmlNodeGetContent(cur); - pickup_normal(cont); + char *cont = (char *)xmlNodeGetContent(cur); + pickup_normal(cont); } - else if(!xmlStrcmp(cur->name,(xmlChar*)"model")) + else if(!xmlStrcmp(cur->name,(xmlChar*)"model")) { - char *cont = (char *)xmlNodeGetContent(cur); - pickup_model(cont); + char *cont = (char *)xmlNodeGetContent(cur); + pickup_model(cont); } - else if(!xmlStrcmp(cur->name,(xmlChar*)"texture")) + else if(!xmlStrcmp(cur->name,(xmlChar*)"texture")) { - char *cont = (char *)xmlNodeGetContent(cur); - pickup_texture(cont); - } - else if(!xmlStrcmp(cur->name,(xmlChar*)"imageflag")) + char *cont = (char *)xmlNodeGetContent(cur); + pickup_texture(cont); + } + else if(!xmlStrcmp(cur->name,(xmlChar*)"imageflag")) { - char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); - texture_hash.hash_regist(filename); - } - else if(!xmlStrcmp(cur->name,(xmlChar*)"image")) + int id; + char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); + texture_hash.hash_regist(filename, id); + } + else if(!xmlStrcmp(cur->name,(xmlChar*)"image")) { - get_image(cur); - } + get_image(cur); + } } } @@ -390,77 +388,77 @@ { int fd = mkstemp(image_name); FILE *outfile = fdopen(fd, "wb"); - + if (NULL == outfile) { - cout << "error open file\n"; - return 0; + cout << "error open file\n"; + return 0; } - + char *cont = (char *)xmlNodeGetContent(cur); //decode(cont, image_name); decode(cont, outfile); fclose(outfile); - + /** * image を 32bit(RGBA) に変換する */ SDL_Surface *texture_image = IMG_Load(image_name); SDL_Surface *tmpImage - = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w, - texture_image->h, 32, redMask, - greenMask, blueMask, alphaMask); + = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w, + texture_image->h, 32, redMask, + greenMask, blueMask, alphaMask); SDL_Surface *converted; converted = SDL_ConvertSurface(texture_image, tmpImage->format, - SDL_HWSURFACE); + SDL_HWSURFACE); if (converted != NULL) { - SDL_FreeSurface(texture_image); - texture_image = converted; + SDL_FreeSurface(texture_image); + texture_image = converted; } - + return texture_image; } int -SceneGraph::makeTapestries(SDL_Surface *texture_image) { - uint32 *tapestry; - int scale = 1; - int tex_w = texture_image->w; - int tex_h = texture_image->h; - int all_pixel_num = 0; +SceneGraph::makeTapestries(SDL_Surface *texture_image, int id) { + uint32 *tapestry; + int scale = 1; + int tex_w = texture_image->w; + int tex_h = texture_image->h; + int all_pixel_num = 0; - /** - * テクスチャの w or h が 8 pixel で分割できる間、 - * 1/2 の縮小画像を作る。 - * ここでは、最大の scale (1/scale) を見つける - * - * (ex) - * (128,128) => 64,64 : 32,32: 16,16 : 8,8 - * scale = 16 - * (128, 64) => 64,32 : 32,16: 16,8 - * scale = 8 - */ - while (tex_w % TEXTURE_SPLIT_PIXEL == 0 && - tex_h % TEXTURE_SPLIT_PIXEL == 0) { - all_pixel_num += tex_w*tex_h; - tex_w >>= 1; /* tex_w /= 2 */ - tex_h >>= 1; - scale <<= 1; /* scale *= 2 */ - } + /** + * テクスチャの w or h が 8 pixel で分割できる間、 + * 1/2 の縮小画像を作る。 + * ここでは、最大の scale (1/scale) を見つける + * + * (ex) + * (128,128) => 64,64 : 32,32: 16,16 : 8,8 + * scale = 16 + * (128, 64) => 64,32 : 32,16: 16,8 + * scale = 8 + */ + while (tex_w % TEXTURE_SPLIT_PIXEL == 0 && + tex_h % TEXTURE_SPLIT_PIXEL == 0) { + all_pixel_num += tex_w*tex_h; + tex_w >>= 1; /* tex_w /= 2 */ + tex_h >>= 1; + scale <<= 1; /* scale *= 2 */ + } - scale >>= 1; + scale >>= 1; - tapestry = makeTapestry(texture_image->w, texture_image->h, - (uint32*)texture_image->pixels, - all_pixel_num, scale); + tapestry = makeTapestry(texture_image->w, texture_image->h, + (uint32*)texture_image->pixels, + all_pixel_num, scale); - list[id_count-1].t_w = texture_image->w; - list[id_count-1].t_h = texture_image->h; - list[id_count-1].pixels_orig = (Uint32*)texture_image->pixels; - list[id_count-1].pixels = tapestry; - list[id_count-1].scale_max = scale; - - return id_count-1; + list[id].t_w = texture_image->w; + list[id].t_h = texture_image->h; + list[id].pixels_orig = (Uint32*)texture_image->pixels; + list[id].pixels = tapestry; + list[id].scale_max = scale; + + return id; } void @@ -470,36 +468,36 @@ char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); if (filename == NULL || filename[0] == 0) { - return; + return; } /** * image_name を既に Load していれば何もしない */ - int tex_id = texture_hash.hash_regist(filename); - if (tex_id < 0) { + int tex_id; + if (!texture_hash.hash_regist(filename, tex_id)) { + + SDL_Surface *texture_image = load_decode_image(image_name, cur); - SDL_Surface *texture_image = load_decode_image(image_name, cur); - - texture_id = makeTapestries(texture_image); - - if (unlink(image_name)) { - cout << "unlink error\n"; - } + texture_id = makeTapestries(texture_image, tex_id); + + if (unlink(image_name)) { + cout << "unlink error\n"; + } } else { - /** - * 以前に Load されている Texture を共用 - */ - texture_id = tex_id; + /** + * 以前に Load されている Texture を共用 + */ + texture_id = tex_id; } - - // こんなことすると list[] のいみあるのかなーと - // 微妙に思う、自分で書き換えた感想 by gongo - texture_info.t_w = list[texture_id].t_w; - texture_info.t_h = list[texture_id].t_h;; - texture_info.pixels_orig = list[texture_id].pixels_orig; - texture_info.pixels = list[texture_id].pixels; - texture_info.scale_max = list[texture_id].scale_max; + + // こんなことすると list[] のいみあるのかなーと + // 微妙に思う、自分で書き換えた感想 by gongo + texture_info.t_w = list[texture_id].t_w; + texture_info.t_h = list[texture_id].t_h;; + texture_info.pixels_orig = list[texture_id].pixels_orig; + texture_info.pixels = list[texture_id].pixels; + texture_info.scale_max = list[texture_id].scale_max; } @@ -512,11 +510,11 @@ //delete [] n->data; if (next) { - while (n) { - m = n->next; - delete n; - n = m; - } + while (n) { + m = n->next; + delete n; + n = m; + } } } @@ -539,42 +537,42 @@ SceneGraphPtr t = top; while (t) { - t->move_execute(screen_w, screen_h); - t->collision_check(screen_w, screen_h, top); + t->move_execute(screen_w, screen_h); + t->collision_check(screen_w, screen_h, top); - t->frame++; + t->frame++; - if (t->parent != NULL) { - get_matrix(t->matrix, t->angle, t->xyz, t->parent->matrix); - } else { - get_matrix(t->matrix, t->angle, t->xyz, NULL); - } + if (t->parent != NULL) { + get_matrix(t->matrix, t->angle, t->xyz, t->parent->matrix); + } else { + get_matrix(t->matrix, t->angle, t->xyz, NULL); + } - if (t->children != NULL) { - t = t->children; - } else if (t->brother != NULL) { - t = t->brother; - } else { - while (t) { - if (t->brother != NULL) { - t = t->brother; - break; - } else { - if (t->parent == NULL) { - t = NULL; - break; - } else { - t = t->parent; - } - } - } - } + if (t->children != NULL) { + t = t->children; + } else if (t->brother != NULL) { + t = t->brother; + } else { + while (t) { + if (t->brother != NULL) { + t = t->brother; + break; + } else { + if (t->parent == NULL) { + t = NULL; + break; + } else { + t = t->parent; + } + } + } + } } } void SceneGraph::set_move_collision(SceneGraphPtr node, move_func new_move, - collision_func new_collision) + collision_func new_collision) { node->move = new_move; node->collision = new_collision; @@ -582,7 +580,7 @@ void SceneGraph::set_move_collision(move_func new_move, - collision_func new_collision) + collision_func new_collision) { this->move = new_move; this->collision = new_collision; @@ -593,10 +591,10 @@ { /* next のリストの最後に加える */ if (this->next != NULL) { - SceneGraphPtr tmp = this->last; - tmp->next = next; + SceneGraphPtr tmp = this->last; + tmp->next = next; } else { - this->next = next; + this->next = next; } this->last = next; @@ -633,7 +631,7 @@ /** * tree から node を削除する - * + * * @param tree SceneGraphTree * @return node削除後の SceneGraphTree */ @@ -645,38 +643,38 @@ SceneGraphPtr ret = tree; if (parent) { - SceneGraphPtr brother = parent->children; - SceneGraphPtr p, p1 = NULL; + SceneGraphPtr brother = parent->children; + SceneGraphPtr p, p1 = NULL; - p = brother; - if (p) { - if (p == node) { - parent->children = NULL; - parent->lastChild = NULL; - } else { - p1 = p->brother; + p = brother; + if (p) { + if (p == node) { + parent->children = NULL; + parent->lastChild = NULL; + } else { + p1 = p->brother; + + while (p1 && p1 != node) { + p1 = p1->brother; + p = p->brother; + } - while (p1 && p1 != node) { - p1 = p1->brother; - p = p->brother; - } - - if (p1) { - p->brother = p1->brother; + if (p1) { + p->brother = p1->brother; - // node が最後尾なら、lastChild を変更 - if (parent->lastChild == p1) { - parent->lastChild = p; - } - } else { - // Can't find remove node - } - } - } + // node が最後尾なら、lastChild を変更 + if (parent->lastChild == p1) { + parent->lastChild = p; + } + } else { + // Can't find remove node + } + } + } } else { - // 親が居ない = tree root なので - // NULL を返す - ret = NULL; + // 親が居ない = tree root なので + // NULL を返す + ret = NULL; } return ret; @@ -684,7 +682,7 @@ /** * list から node を削除する - * + * * @param list SceneGraphList * @return node削除後の SceneGraphList */ @@ -695,15 +693,15 @@ SceneGraphPtr prev = node->prev; SceneGraphPtr next = node->next; SceneGraphPtr ret = list; - + if (prev) { - prev->next = next; + prev->next = next; } else { - ret = next; + ret = next; } if (next) { - next->prev = prev; + next->prev = prev; } return ret; diff -r d6338bb6db87 -r 51ffd144f62c TaskManager/Test/test_render/SceneGraph.h --- a/TaskManager/Test/test_render/SceneGraph.h Thu Jul 09 17:59:44 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraph.h Fri Jul 10 16:06:15 2009 +0900 @@ -13,7 +13,7 @@ typedef void (*move_func)(SceneGraph* node, int screen_w, int screen_h); typedef void (*collision_func)(SceneGraph* node, int screen_w, int screen_h, - SceneGraph* tree); + SceneGraph* tree); typedef SceneGraph* SceneGraphPtr; class SceneGraph : public Polygon { @@ -75,13 +75,13 @@ SceneGraphPtr clone(void *buf); SceneGraphPtr searchSceneGraph(const char *name); void set_move_collision(SceneGraphPtr node, - move_func new_move, collision_func new_collision); + move_func new_move, collision_func new_collision); void set_move_collision(move_func new_move, collision_func new_collision); void remove(void); SceneGraphPtr realRemoveFromTree(SceneGraphPtr tree); SceneGraphPtr realRemoveFromList(SceneGraphPtr list); int isRemoved(void); - + static SceneGraphPtr createSceneGraph(int id); void translate(float x, float y, float z); @@ -96,7 +96,7 @@ void delete_data(void); SDL_Surface* load_decode_image(char *image_name, xmlNodePtr cur); - int makeTapestries(SDL_Surface *texture_image); + int makeTapestries(SDL_Surface *texture_image, int id); void get_image(xmlNodePtr cur); }; diff -r d6338bb6db87 -r 51ffd144f62c TaskManager/Test/test_render/TextureHash.cpp --- a/TaskManager/Test/test_render/TextureHash.cpp Thu Jul 09 17:59:44 2009 +0900 +++ b/TaskManager/Test/test_render/TextureHash.cpp Fri Jul 10 16:06:15 2009 +0900 @@ -2,15 +2,15 @@ #include #include "TextureHash.h" -int id_count; +static int id_count; TextureHash::TextureHash(void) { table = (hashtable*)malloc(sizeof(hashtable)*TABLE_SIZE); for (int i = 0; i < TABLE_SIZE; i++) { - table[i].tx_id = -1; - table[i].key = NULL; + table[i].tx_id = -1; + table[i].key = NULL; } } @@ -26,26 +26,28 @@ int value = 0; for (int i = 0; key[i]; i++) { - value += key[i]*(i+1)*17+1; + value += key[i]*(i+1)*17+1; } return value%TABLE_SIZE; } int -TextureHash::hash_regist(const char* key) +TextureHash::hash_regist(const char* key, int &id) { int hash = hash_function(key); - + for (int i = 0; ; i++) { - if (table[hash].tx_id == -1) { - table[hash].key = (char*)key; - table[hash].tx_id = id_count++; - return -1; - } else if (strcmp(key, table[hash].key) == 0 - && table[hash].tx_id != -1){ - return table[hash].tx_id; - } - hash = ((37*hash)^(11*i)) % TABLE_SIZE; + if (table[hash].tx_id == -1) { + table[hash].key = (char*)key; + id = id_count++; + return 0; + + } else if (strcmp(key, table[hash].key) == 0 + && table[hash].tx_id != -1){ + id = table[hash].tx_id; + return 1; + } + hash = ((37*hash)^(11*i)) % TABLE_SIZE; } } diff -r d6338bb6db87 -r 51ffd144f62c TaskManager/Test/test_render/TextureHash.h --- a/TaskManager/Test/test_render/TextureHash.h Thu Jul 09 17:59:44 2009 +0900 +++ b/TaskManager/Test/test_render/TextureHash.h Fri Jul 10 16:06:15 2009 +0900 @@ -14,8 +14,8 @@ TextureHash(void); ~TextureHash(void); - int hash_function(const char*); - int hash_regist(const char*); + int hash_function(const char* image_name); + int hash_regist(const char* image_name, int &tx_id); }; #endif diff -r d6338bb6db87 -r 51ffd144f62c TaskManager/Test/test_render/polygon.cpp --- a/TaskManager/Test/test_render/polygon.cpp Thu Jul 09 17:59:44 2009 +0900 +++ b/TaskManager/Test/test_render/polygon.cpp Fri Jul 10 16:06:15 2009 +0900 @@ -18,8 +18,6 @@ extern int decode(char *cont, FILE *outfile); -//SDL_Surface* Polygon::texture_image; - Polygon::Polygon(void) { xyz[0] = 0; @@ -36,7 +34,7 @@ angle[3] = 1; for (int i = 0; i < 16; i++) { - matrix[i] = 0; + matrix[i] = 0; } } @@ -57,7 +55,7 @@ angle[3] = 1; for (int i = 0; i < 16; i++) { - matrix[i] = 0; + matrix[i] = 0; } } @@ -69,43 +67,43 @@ /***SceneGraphUpdate***/ //sgp_update(); for (int i = 0; i < sgp->info.size; i++) { - SceneGraphNode node = sgp->node[i]; + SceneGraphNode node = sgp->node[i]; - /***draw***/ - int n,nt; - for(n=0,nt=0; nviewer = viewer; - span->p = this; - span->create_span(tri,texture_image); - delete ver1; - delete ver2; - delete ver3; - delete tri; - delete span; - } + Triangle *tri = new Triangle(ver1,ver2,ver3); + Span_c *span = new Span_c(); + span->viewer = viewer; + span->p = this; + span->create_span(tri,texture_image); + delete ver1; + delete ver2; + delete ver3; + delete tri; + delete span; + } } } @@ -114,20 +112,20 @@ { for(int n=0; ninfo.size; n++) { - Vertex *ver1 = new Vertex(pp->tri[n].ver1.x,pp->tri[n].ver1.y,pp->tri[n].ver1.z,pp->tri[n].ver1.tex_x,pp->tri[n].ver1.tex_y); - Vertex *ver2 = new Vertex(pp->tri[n].ver2.x,pp->tri[n].ver2.y,pp->tri[n].ver2.z,pp->tri[n].ver2.tex_x,pp->tri[n].ver2.tex_y); - Vertex *ver3 = new Vertex(pp->tri[n].ver3.x,pp->tri[n].ver3.y,pp->tri[n].ver3.z,pp->tri[n].ver3.tex_x,pp->tri[n].ver3.tex_y); + Vertex *ver1 = new Vertex(pp->tri[n].ver1.x,pp->tri[n].ver1.y,pp->tri[n].ver1.z,pp->tri[n].ver1.tex_x,pp->tri[n].ver1.tex_y); + Vertex *ver2 = new Vertex(pp->tri[n].ver2.x,pp->tri[n].ver2.y,pp->tri[n].ver2.z,pp->tri[n].ver2.tex_x,pp->tri[n].ver2.tex_y); + Vertex *ver3 = new Vertex(pp->tri[n].ver3.x,pp->tri[n].ver3.y,pp->tri[n].ver3.z,pp->tri[n].ver3.tex_x,pp->tri[n].ver3.tex_y); - Triangle *tri = new Triangle(ver1,ver2,ver3); - Span_c *span = new Span_c(); - span->viewer = viewer; - span->p = this; - span->create_span(tri,texture_image); - delete ver1; - delete ver2; - delete ver3; - delete tri; - delete span; + Triangle *tri = new Triangle(ver1,ver2,ver3); + Span_c *span = new Span_c(); + span->viewer = viewer; + span->p = this; + span->create_span(tri,texture_image); + delete ver1; + delete ver2; + delete ver3; + delete tri; + delete span; } } @@ -136,42 +134,42 @@ Span *span; for (int n = 0; n < sp->info.size; n++) { - span = &sp->span[n]; + span = &sp->span[n]; - //int x = span->x; - //int y = span->y; - float z = span->start_z; - int end = span->length_x; - float zpos = span->end_z; - float tex1 = span->tex_x1; - float tex2 = span->tex_x2; - float tey1 = span->tex_y1; - float tey2 = span->tex_y2; - Uint32 rgb; - int tex_xpos; - int tex_ypos; - int tex_zpos; - float tex_x, tex_y, tex_z; + //int x = span->x; + //int y = span->y; + float z = span->start_z; + int end = span->length_x; + float zpos = span->end_z; + float tex1 = span->tex_x1; + float tex2 = span->tex_x2; + float tey1 = span->tex_y1; + float tey2 = span->tex_y2; + Uint32 rgb; + int tex_xpos; + int tex_ypos; + int tex_zpos; + float tex_x, tex_y, tex_z; - if (end == 1) { - tex_xpos = (int)((span->tex_height-1) * tex1); - tex_ypos = (int)((span->tex_width-1) * tey1); - tex_zpos = (int)z; - rgb = get_rgb(tex_xpos, tex_ypos); - //viewer->write_pixel(x, y, zpos, rgb); - } else { - for (int j = 0; j < end; j++) { - tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1); - tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1); - tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1); - if (tex_x > 1) tex_x = 1; - if (tex_y > 1) tex_y = 1; - tex_xpos = (int)((span->tex_height-1) * tex_x); - tex_ypos = (int)((span->tex_width-1) * tex_y); - rgb = get_rgb(tex_xpos,tex_ypos); - //viewer->write_pixel(j + x, y, tex_z, rgb); - } - } + if (end == 1) { + tex_xpos = (int)((span->tex_height-1) * tex1); + tex_ypos = (int)((span->tex_width-1) * tey1); + tex_zpos = (int)z; + rgb = get_rgb(tex_xpos, tex_ypos); + //viewer->write_pixel(x, y, zpos, rgb); + } else { + for (int j = 0; j < end; j++) { + tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1); + tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1); + tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1); + if (tex_x > 1) tex_x = 1; + if (tex_y > 1) tex_y = 1; + tex_xpos = (int)((span->tex_height-1) * tex_x); + tex_ypos = (int)((span->tex_width-1) * tex_y); + rgb = get_rgb(tex_xpos,tex_ypos); + //viewer->write_pixel(j + x, y, tex_z, rgb); + } + } } } @@ -181,14 +179,14 @@ { for(int n=0; nformat; if (tx<0) tx = 0; @@ -278,17 +276,17 @@ //printf("pixel = %d\n", pixel); //printf("pixel %x bpp = %d ",p, fmt->BytesPerPixel); //SDL_UnlockSurface(texture_image); - + temp = pixel&fmt->Rmask; temp = temp>>fmt->Rshift; temp = temp<Rloss; red = (Uint8)temp; - + temp = pixel&fmt->Gmask; temp = temp>>fmt->Gshift; temp = temp<Gloss; green = (Uint8)temp; - + temp = pixel&fmt->Bmask; temp = temp>>fmt->Bshift; temp = temp<Bloss; @@ -297,8 +295,8 @@ blue = (Uint8) p[0]; green = (Uint8) p[1]; red = (Uint8) p[2]; - - //printf("tx = %d ty = %d ", tx,ty); + + //printf("tx = %d ty = %d ", tx,ty); //printf("pixel color => R: %d, G: %d, B: %d\n", red, green, blue); SDL_PixelFormat *pf = NULL; diff -r d6338bb6db87 -r 51ffd144f62c TaskManager/Test/test_render/polygon.h --- a/TaskManager/Test/test_render/polygon.h Thu Jul 09 17:59:44 2009 +0900 +++ b/TaskManager/Test/test_render/polygon.h Fri Jul 10 16:06:15 2009 +0900 @@ -36,7 +36,7 @@ float *anim; int texture_id; //texture id number struct texture_list texture_info; - + SDL_Surface* texture_image; Polygon(void);