计算机图形学中关于画图的代码总结
发布时间
阅读量:
阅读量
///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
全部评论 (0)
还没有任何评论哟~
