Mercurial > hg > Members > kono > Cerium
changeset 134:92fcce4330f3
CreateSpan で、三角形を二つに割る時、
元々x軸に水平な辺を持っていると、辺に対して half_triangle をかけてしまい
暴走するので、その応急処置。詳しくは CreateSpan::half_triangle
author | gongo@gendarme.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Thu, 27 Nov 2008 16:10:55 +0900 |
parents | 435e0d24db39 |
children | c65aee1528ef |
files | TaskManager/Test/test_render/Makefile.def TaskManager/Test/test_render/task/CreateSpan.cpp TaskManager/Test/test_render/task/DrawSpan.cpp |
diffstat | 3 files changed, 75 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Makefile.def Thu Nov 27 15:08:10 2008 +0900 +++ b/TaskManager/Test/test_render/Makefile.def Thu Nov 27 16:10:55 2008 +0900 @@ -3,15 +3,15 @@ # include/library path # ex: macosx #CERIUM = /Users/gongo/Source/Concurrency/Game_project/Cerium -#CERIUM = /Users/gongo/Source/hg/Cerium +CERIUM = /Users/gongo/Source/hg/Cerium # ex: linux/ps3 -CERIUM = /home/gongo/Cerium +#CERIUM = /home/gongo/Cerium #CERIUM = ../../.. CC = g++ -CFLAGS = -O9 -g -Wall# -DDEBUG +CFLAGS = -O0 -g -Wall# -DDEBUG INCLUDE = -I$(CERIUM)/include/TaskManager -I. LIBS = -L$(CERIUM)/TaskManager
--- a/TaskManager/Test/test_render/task/CreateSpan.cpp Thu Nov 27 15:08:10 2008 +0900 +++ b/TaskManager/Test/test_render/task/CreateSpan.cpp Thu Nov 27 16:10:55 2008 +0900 @@ -77,6 +77,11 @@ v->z = calc(vMax->z - vMin->z, d, d1, vMin->z); } + +/** + * x軸に水平な辺を持つ三角形ポリゴンから、 + * Span を抜き出す + */ void CreateSpan::half_triangle(SpanPackPtr *spackList, int charge_y_top, int charge_y_end, @@ -89,8 +94,38 @@ float start_tex_x, end_tex_x, start_tex_y, end_tex_y; int x, y, length; + /** + * 三角形ポリゴンをx軸に水平に二つに分けようとして + * ある一辺がすでに水平だった場合、つまり + * (環境によっては、back slash が 円マークかも) + * + * |\ + * | \ + * | \ + * ----- + * + * + * 上のようなポリゴンだった場合は、本来なら上の部分の三角形にだけ + * half_triangle の処理をするべきだが、現在の処理だと + * この half_triangle に「上の部分の三角形」と、 + * 「『下の部分の三角形と判断してしまった』直線」が来てしまう。 + * 直線の部分が来ると、calc() で 0 除算とかで、値不定で暴走するので + * 現在はこれで代用。 + * half_triangle 呼ぶ前にこれを判断できれば良いかもしれない。 + * てかこんなんでいいのかよ。。。 + * + */ + if (vMid10->x == vMin->x && vMid10->y == vMin->y) { + return; + } + +#if 0 int start_y = (int)vMid->y; int end_y = (int)vMin->y; +#else + float start_y = vMid->y; + float end_y = vMin->y; +#endif float div_y = start_y - end_y; int k = 0; int l = 1; @@ -103,7 +138,7 @@ l = -1; } - for (int i = k; i < div_y+1; i++) { + for (int i = k; i < (int)div_y+1; i++) { y = (int)vMin->y + i*l; /** @@ -173,7 +208,7 @@ tmp_end = calc(vMid->x - vMin->x ,div_y, i, vMin->x); tmp_z = calc(vMid10->z - vMin->z ,div_y, i, vMin->z); tmp_zpos = calc(vMid->z - vMin->z ,div_y, i, vMin->z); - + tmp_tex1 =((i/(div_y)) * vMid10->tex_x) + ( ((div_y - i)/(div_y)) * vMin->tex_x); tmp_tex2 =( (i/(div_y)) * vMid->tex_x) + @@ -186,7 +221,11 @@ if (tmp_xpos > tmp_end) { x = (int)tmp_end; - length = (int)(tmp_xpos)-(int)(tmp_end)+1; + /** + * +1 は要らない気がする・・・ + */ + //length = (int)(tmp_xpos)-(int)(tmp_end)+1; + length = (int)(tmp_xpos)-(int)(tmp_end); start_z = tmp_zpos; end_z = tmp_z; start_tex_x = tmp_tex2; @@ -195,7 +234,8 @@ end_tex_y = tmp_tey1; } else { x = (int)tmp_xpos; - length = (int)(tmp_end)-(int)(tmp_xpos)+1; + //length = (int)(tmp_end)-(int)(tmp_xpos)+1; + length = (int)(tmp_end)-(int)(tmp_xpos); start_z = tmp_z; end_z = tmp_zpos; start_tex_x = tmp_tex1; @@ -220,6 +260,10 @@ span->tex_x2 = end_tex_x; span->tex_y1 = start_tex_y; span->tex_y2 = end_tex_y; + + // TilePtr の計算 + // tix, tiy (Tile 内での x, y) + // } } @@ -260,6 +304,7 @@ for (int i = 0; i < pp->info.size; i++) { triPack = &pp->tri[i]; + #if 0 make_vertex(triPack, &vMin, &vMid, &vMax); #else @@ -294,7 +339,11 @@ } #endif make_vMid10(vMid10, vMin, vMid, vMax); - + + /** + * ポリゴンを、x軸に水平に分割して二つの三角形を作り、 + * それぞれから Span を求める + */ half_triangle(spackList, charge_y_top, charge_y_end, triPack->tex_addr, triPack->tex_width, triPack->tex_height, vMin, vMid, vMid10);
--- a/TaskManager/Test/test_render/task/DrawSpan.cpp Thu Nov 27 15:08:10 2008 +0900 +++ b/TaskManager/Test/test_render/task/DrawSpan.cpp Thu Nov 27 16:10:55 2008 +0900 @@ -99,11 +99,7 @@ char* DrawSpan::get_pixel(int tx, int ty, void *texture_image) { -#if 0 - return (char*)texture_image+(3*((128)*ty+tx)); -#else - return (char*)texture_image+(4*((8)*ty+tx)); -#endif + return (char*)texture_image+(4*((TEXTURE_SPLIT_PIXEL)*ty+tx)); } Uint32 @@ -118,12 +114,12 @@ void *texture_addr; - int blockX = tx / 8; - int blockY = ty / 8; + int blockX = tx / TEXTURE_SPLIT_PIXEL; + int blockY = ty / TEXTURE_SPLIT_PIXEL; void** addrList = (void**)global_get(TEXTURE2_ID); TilePtr tile; - texture_addr = addrList[blockX + (tw/8)*blockY]; + texture_addr = addrList[blockX + (tw/TEXTURE_SPLIT_PIXEL)*blockY]; /** * get,put ϥ֥(HashȤ)äƥ뤫 @@ -158,7 +154,8 @@ smanager->dma_wait(TEX_LOAD); } - char *p = get_pixel(tx%8, ty%8, tile->pixel); + char *p = get_pixel(tx%TEXTURE_SPLIT_PIXEL, + ty%TEXTURE_SPLIT_PIXEL, tile->pixel); alpha = 255; red = (Uint8) p[0]; @@ -196,7 +193,7 @@ for (int i = 0; i < rangey; i++) { linebuf[i] = (int*)smanager->get_output(i); - linebuf_init(linebuf[i], rangex, 0); + linebuf_init(linebuf[i], rangex, 0xffffff); } bzero(hash_table, sizeof(TilePtr)*hashsize); @@ -217,7 +214,6 @@ for (int t = 0; t < sp->info.size; t++) { span = &sp->span[t]; - int end = span->length_x; Uint32 rgb = 0x00ff00; float tex1 = span->tex_x1; float tex2 = span->tex_x2; @@ -228,6 +224,7 @@ int tex_zpos; int x = span->x; int y = span->y; + int x_len = span->length_x; float z = span->start_z; float zpos = span->end_z; @@ -235,12 +232,12 @@ int localx = getLocalX(x-1); int localy = getLocalY(y-1); - if (end == 1) { + if (x_len == 1) { if (x < rangex_start || rangex_end < x) { continue; } - tex_xpos = (int)((span->tex_height-1) * tex1); - tex_ypos = (int)((span->tex_width-1) * tey1); + tex_xpos = (int)((span->tex_width-1) * tex1); + tex_ypos = (int)((span->tex_height-1) * tey1); tex_zpos = (int)z; if (zpos < zRow[localx + (rangex * localy)]) { @@ -252,18 +249,19 @@ } else { float tex_x, tex_y, tex_z; int js = (x < rangex_start) ? rangex_start - x : 0; - int je = (x + end > rangex_end) ? rangex_end - x : end; + int je = (x + x_len > rangex_end) ? rangex_end - x : x_len; for (int j = js; j <= je; j++) { localx = getLocalX(x-1+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); + tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1); + + tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); + tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-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); + tex_xpos = (int)((span->tex_width-1) * tex_x); + tex_ypos = (int)((span->tex_height-1) * tex_y); if (tex_z < zRow[localx + (rangex*localy)]) { rgb = get_rgb(tex_xpos, tex_ypos, span->tex_width,