|
|

楼主 |
发表于 2009-6-18 15:56:00
|
显示全部楼层
Re:请教DirectDraw图形程序的窗口比例问题!
算法应该是没问题的
我是照着书上写下来的
在非宽屏电脑运行是正常的
代码在这里
/****************************************画图函数********************************************/
void Graphic: ine(NUMTYPE x1,NUMTYPE y1,NUMTYPE x2,NUMTYPE y2,DWORD color)
{
NUMTYPE dx,dy,x_inc,y_inc,error,index,x=x1,y=y1;
dx=x2-x1;
dy=y2-y1;
if(dx>=0) x_inc=1;
else
{
x_inc=-1;
dx=-dx;
}
if(dy>=0) y_inc=1;
else
{
y_inc=-1;
dy=-dy;
}
if(dx>=dy)
{
error=2*dy-dx;
for(index=0;index<=dx;index++)
{
video_buffer[(int)x+(int)y*lpitch] = color;
x+=x_inc;
if(error>=0)
{
y+=y_inc;
error+=2*dy-2*dx;
}
else error=error+2*dy;
}
}
else
{
error=2*dx-dy;
for(index=0;index<=dy;index++)
{
video_buffer[(int)x+(int)y*lpitch] = color;
y+=y_inc;
if(error>=0)
{
error+=2*dx-2*dy;
x+=x_inc;
}
else error+=2*dx;
}
}
} // Line
void Graphic::Circle(NUMTYPE xc,NUMTYPE yc,NUMTYPE r,DWORD color)
{
NUMTYPE x=0,y=r;
NUMTYPE e=2*(1-r);
NUMTYPE d;
while(y>=0)
{
video_buffer[(int)(x+xc)+(int)(y+yc)*lpitch] = color;
video_buffer[(int)(-x+xc)+(int)(y+yc)*lpitch] = color;
video_buffer[(int)(x+xc)+(int)(-y+yc)*lpitch] = color;
video_buffer[(int)(-x+xc)+(int)(-y+yc)*lpitch] = color;
if(e<0)
{
d=2*e+2*y-1;
if(d<=0)
{
x=x+1; e=e+2*x+1;
}
else
{
x=x+1; y=y-1; e=e+2*x-2*y+2;
}
}
else if(e>0)
{
d=2*e-2*x-1;
if(d<=0)
{
x=x+1; y=y-1; e=e+2*x-2*y+2;
}
else
{
y=y-1; e=e-2*y+1;
}
}
else if(e==0)
{
x=x+1; y=y-1; e=e+2*x-2*y+2;
}
}
} |
|