void drawedge
(int x1,int y1,float u1,float v1,int x2,int y2,float u2,float v2)
Now we also need some new edges declared. Let these be uedge[200][2] and vedge[200][2]. These edges we fill with the u and v slope values, like we did with the other fillers, but only with x and z edge. Remember we still need the x edge, since we still have to know where the faces edges are, since u and v edge only declares where the edges are on the texturemap, not on the screen. This is important to remember. Now, how would this look as a routine?
Теперь мы также нуждаемся в некоторых новых объявленных краях. Пусть это будут uedge [200] [2] и vedge [200] [2]. Эти края, мы заполним u и v значениями наклона, как это мы делали с другими заполнениями но только с краем z и x. Не забудьте, что мы все еще нуждаемся в крае x, так как мы все еще должны знать, где края плоскостей, поскольку u и v край только декларируют, где края находятся на текстуре, но не на экране. Это важно помнить. Теперь, как это смотрело бы в подпрограмме?
void drawedge
(int x1,int y1,float u1,float v1,int x2,int y2,float u2,float v2)
{
int side = 0;
float temp = x1;
float xslope;
float uslope;
float vslope;
if (y1 >= y2)
{
side = 1;
x1 = x2;
x2 = temp;
temp = y1;
y1 = y2;
y2 = temp;
temp = u1;
u1 = u2;
u2 = temp;
temp = v1;
v1 = v2;
v2 = temp;
}
if (y2-y1==0)
{
xslope = (x2-x1);
uslope = (u2-u1);
vslope = (v2-v1);
}
else
{
xslope = (x2-x1)/(y2-y1);
uslope = (u2-u1)/(y2-y1);
vslope = (v2-v1)/(y2-y1);
}
for (y=y1;y<=y2;y++)
{
xedge[y][side] = x1;
x1 += xslope;
uedge[y][side] = u1;
u1 += uslope;
vedge[y][side] = v1;
v1 += vslope;
}
}
Okay, now we have filled our U and V edges with values, but we also need to draw the lines. What we basicly need to do, is to draw from xedge[200][0] to xedge[200][1] with texture[mapx+mapy*256] as pixel. Mapx and mapy we give the value u and vedge[200][0], and then calculate another two slopes, that is u and v slope. Now, our hline routine have to be changed too, but in this case, lets move the hline into our main procedure. There no reason why this should be outside the main procedure. Now, lets see how the entire routine would look like:
Отлично, теперь мы заполнили наши U и V края значениями, но мы также должны рисовать линии. Что мы просто должны делать, так это рисовать из xedge [200] [0] к xedge [200] [1] с texture [mapx + mapy*256] как пиксел. Mapx и mapy мы возьмем как значения u и vedge [200] [0], и затем вычисляем другие два наклона, которые является u и v наклонами. Теперь, наша hline подпрограмма должна быть изменена также, но в этом случае, давайте поместим hline в нашу основную процедуру. Нет никакой причины, почему она должно иметься снаружи основной процедуры. Теперь, давайте посмотрим, как вся подпрограмма выглядела бы:
void drawedge
(int x1,int y1,float u1,float v1,int x2,int y2,float u2,float v2)
{
int side = 0;
float temp = x1;
float xslope;
float uslope;
float vslope;
if (y1 >= y2)
{
side = 1;
x1 = x2;
x2 = temp;
temp = y1;
y1 = y2;
y2 = temp;
temp = u1;
u1 = u2;
u2 = temp;
temp = v1;
v1 = v2;
v2 = temp;
}
if (y2-y1==0)
{
xslope = (x2-x1);
uslope = (u2-u1);
vslope = (v2-v1);
}
else
{
xslope = (x2-x1)/(y2-y1);
uslope = (u2-u1)/(y2-y1);
vslope = (v2-v1)/(y2-y1);
}
for (y=y1;y<=y2;y++)
{
xedge[y][side] = x1;
x1 += xslope;
uedge[y][side] = u1;
u1 += uslope;
vedge[y][side] = v1;
v1 += vslope;
}
}
void texturepoly(int x1,int y1,float u1,float v1,
int x2,int y2,float u2,float v2,
int x3,int y3,float u3,float v3)
{
int minx,maxx;
int i;
float mapx, mapy;
float uslope,vslope;
float temp;
int x;
int xpos1,xpos2;
texturedrawedge(x1,y1,u1,v1,x2,y2,u2,v2);
texturedrawedge(x2,y2,u2,v2,x3,y3,u3,v3);
texturedrawedge(x3,y3,u3,v3,x1,y1,u1,v1);
miny=y1;
if (miny > y2)
miny=y2;
if (miny > y3)
miny=y3;
maxy=y1;
if (maxy < y2)
maxy=y2;
if (maxy < y3)
maxy=y3;
minx=x1;
if (minx > x2)
minx=x2;
if (minx > x3)
minx=x3;
maxx=x1;
if (maxx < x2)
maxx=x2;
if (maxx < x3)
maxx=x3;
for (y=miny;y<=maxy;y++)
{
if (xedge[y][1]-xedge[y][0] != 0)
{
uslope = (uedge[y][1]-uedge[y][0])/(xedge[y][1]-xedge[y][0]);
vslope = (vedge[y][1]-vedge[y][0])/(xedge[y][1]-xedge[y][0]);
}
else
{
uslope = (uedge[y][1]-uedge[y][0]);
vslope = (vedge[y][1]-vedge[y][0]);
}
mapxf=uedge[y][0];
mapyf=vedge[y][0];
for (x=xedge[y][0];x<=xedge[y][1];x++)
{
BufPixel(x,y,texture[(mapx)+(mapy<<8)]);
mapx += uslope;
mapy += vslope;
}
}
}
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.