Mercurial > hg > Game > Cerium
view Renderer/DataPack/Test/SpanPack/polygonpack.cpp @ 503:516d5c91d5b4 draft double-linked-task-list
comment
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 11 Oct 2009 19:35:33 +0900 |
parents | f22280772f20 |
children |
line wrap: on
line source
#include <iostream> #include "polygonpack.h" using namespace std; static float calc(float f1, float f2,int i, float base){ float ans; ans = f1/f2*i + base; return ans; } static vertex *vMid1(Vertex *vMid1,Vertex *vMin, Vertex *vMid, Vertex *vMax) { float d,d1; d = (int)vMax->y-(int)vMin->y; d1 = (int)vMid->y - (int)vMin->y; vMid1->tex_x = calc(vMax->tex_x - vMin->tex_x, d, (int)d1 , vMin->tex_x); vMid1->tex_y = calc(vMax->tex_y - vMin->tex_y, d, (int)d1 , vMin->tex_y); vMid1->x = calc(vMax->x - vMin->x, d, (int)d1 , vMin->x); vMid1->y = vMid->y; vMid1->z = calc(vMax->z - vMin->z, d, (int)d1 , vMin->z); printf("x:%f y:%f z:%f tex_x:%f tex_y:%f\n",vMid1->x,vMid1->y,vMid1->z,vMid1->tex_x, vMid1->tex_y); return vMid1; } int Polygon_Pack::create_span(void *wbuf,void *rbuf) { POLYGONPACK *polygon = (POLYGONPACK*)wbuf; SPANPACK *span = (SPANPACK*)rbuf; Vertex *vMin, *vMid, *vMax, *vMid10; Vertex ver; vMid10 = &ver; if(polygon->tri[0].ver1.y <= polygon->tri[0].ver2.y) { if(polygon->tri[0].ver2.y <= polygon->tri[0].ver3.y) { vMin = &polygon->tri[0].ver1; vMid = &polygon->tri[0].ver2; vMax = &polygon->tri[0].ver3; } else if(polygon->tri[0].ver3.y <= polygon->tri[0].ver1.y) { vMin = &polygon->tri[0].ver3; vMid = &polygon->tri[0].ver1; vMax = &polygon->tri[0].ver2; } else { vMin = &polygon->tri[0].ver1; vMid = &polygon->tri[0].ver3; vMax = &polygon->tri[0].ver2; } } else { if(polygon->tri[0].ver1.y <= polygon->tri[0].ver3.y) { vMin = &polygon->tri[0].ver2; vMid = &polygon->tri[0].ver1; vMax = &polygon->tri[0].ver3; } else if(polygon->tri[0].ver3.y <= polygon->tri[0].ver2.y) { vMin = &polygon->tri[0].ver3; vMid = &polygon->tri[0].ver2; vMax = &polygon->tri[0].ver1; } else { vMin = &polygon->tri[0].ver2; vMid = &polygon->tri[0].ver3; vMax = &polygon->tri[0].ver1; } } cout << vMid->y << endl; vMid1(vMid10,vMin,vMid,vMax); half_triangle(polygon->tri[0].tex_addr,polygon->tri[0].tex_width,polygon->tri[0].tex_height,vMin,vMid,vMid10); half_triangle(polygon->tri[0].tex_addr,polygon->tri[0].tex_width,polygon->tri[0].tex_height,vMax,vMid,vMid10); return 0; } void Polygon_Pack::half_triangle(long *tex_addr,long tex_width,long tex_height,Vertex *vMin, Vertex *vMid, Vertex *vMid1) { float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2; float tmp_xpos,tmp_end,tmp_zpos; int i,j; float div_y; float start_z,end_z; float start_tex_x,end_tex_x,start_tex_y,end_tex_y; int x,y,length; int k =0; int l = 1; int start_y = (int)vMid->y; int end_y = (int)vMin->y; if (start_y<end_y) { int i; i=end_y; end_y=start_y; start_y = i; //yの入れ替え k = 1; l = -1; } div_y = start_y - end_y; // > 0 for(i = k; i < div_y+1; i++) { //ここでspanの左端と右端のx,zを求めてる tmp_xpos = calc(vMid1->x - vMin->x ,div_y, i, vMin->x); tmp_end = calc(vMid->x - vMin->x ,div_y, i, vMin->x); tmp_z = calc(vMid1->z - vMin->z ,div_y, i, vMin->z); tmp_zpos = calc(vMid->z - vMin->z ,div_y, i, vMin->z); //printf("x:%f end:%f z:%f zpos:%f\n",tmp_xpos,tmp_end,tmp_z,tmp_zpos); //ここからspanの左端と右端に対応するテクスチャを計算する tmp_tex1 =((i/(div_y)) * vMid1->tex_x) + \ ( ((div_y - i)/(div_y)) * vMin->tex_x); tmp_tex2 =( (i/(div_y)) * vMid->tex_x) + \ ( ((div_y - i)/(div_y)) * vMin->tex_x); tmp_tey1 =( (i/(div_y)) * vMid1->tex_y) + \ ( ((div_y - i)/(div_y)) * vMin->tex_y); tmp_tey2 =( (i/(div_y)) * vMid->tex_y) + \ ( ((div_y - i)/(div_y)) * vMin->tex_y); if(tmp_xpos > tmp_end) { x = (int)tmp_end; y = (int)vMin->y + i*l; length = (int)(tmp_xpos)-(int)(tmp_end)+1; start_z = tmp_zpos; end_z = tmp_z; start_tex_x = tmp_tex2; end_tex_x = tmp_tex1; start_tex_y = tmp_tey2; end_tex_y = tmp_tey1; } else { x = (int)tmp_xpos; y = (int)vMin->y + i*l; length = (int)(tmp_end)-(int)(tmp_xpos)+1; start_z = tmp_z; end_z = tmp_zpos; start_tex_x = tmp_tex1; end_tex_x = tmp_tex2; start_tex_y = tmp_tey1; end_tex_y = tmp_tey2; } printf("x:%d y:%d end:%d z:%f zpos:%f\n",x,y,length,start_z , end_z); printf("start_tex_x:%f end_tex_x:%f start_tex_y:%f end_tex_y:%f\n",start_tex_x,end_tex_x,start_tex_y,end_tex_y); //add(tex_addr,tex_width,tex_height,x,y,length,start_z,end_z,start_tex_x,end_tex_x,start_tex_y,end_tex_y); } }