///DDA画直线
#include <cstdio>
using namespace std;
void Line(int x1, int y1, int x2, int y2, int color)
{
CDC *pDC = GetDC();///获取图形设备环境
float t, x, y, step;
step = 1.0/(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
for(t=0.0; t<=1.0; t=t+step)
{
x = x1 + t*(x2-x1);
y = y1 + t*(y2-y1);
pDC->SetPixel(x,y, color);
}
}
void DDA(int x1,int y1,int x2,int y2,int color)
{
CDC *pDC=GetDC();
float t,x,y,step;
step=1.0/((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
for(t=0.0; t<=1.0; t+=step)
{
x=x1+t*(x2-x1);
y=y1+t*(y2-y1);
PDC->SetPiexl(x,y,color);
}
}
计算机图形学画图代码总结
最新推荐文章于 2024-06-04 09:17:58 发布