- 1、本文档共4页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
计算机图形学源程序
#include CGmain.h
void setPixel(GLint x, GLint y)
{
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_POINTS);
glVertex2i(x, y);
glEnd();
}
int roundInt(const float a)
{
return int(a+0.5);
}
int sqr(int x)
{
return x*x;
}
void lineDDA2(int x0, int y0, int xEnd, int yEnd)
{
int x;
float dx, dy, k, y;
dx = xEnd - x0;
dy = yEnd - y0;
k = dy / dx;
y = y0;
for (x = x0; x = xEnd; x++)
{
setPixel(x, roundInt(y));
y = y + k;
}
}
void lineDDA(int x0, int y0, int xEnd, int yEnd)
{
int dx = xEnd-x0, dy = yEnd - y0, steps, k;
float xIncrement, yIncrement, x = x0, y = y0;
if(abs(dx)abs(dy))
steps = abs(dx);
else
steps = abs(dy);
xIncrement = float(dx)/float(steps);
yIncrement = float(dy)/float(steps);
setPixel(roundInt(x),roundInt(y));
for(k = 0; ksteps;k++)
{
x += xIncrement;
y += yIncrement;
setPixel(roundInt(x), roundInt(y));
//printf(%d,%d\n,roundInt(x),roundInt(y));
}
//printf(%d\n,k);
}
void lineBresenham(int x0, int y0, int xEnd, int yEnd){
int dx = abs(xEnd - x0), dy = abs(yEnd - y0);
int p = 2 * dy - dx;
int twoDy = 2 *dy, twoDyMinusDx = 2 * (dy - dx);
int x, y;
if(x0 xEnd){
x = xEnd;
y = yEnd;
xEnd = x0;
}
else{
x = x0;
y = y0;
}
setPixel(x, y);
while(x xEnd){
x++;
if(p0)
p += twoDy;
else{
y++;
p += twoDyMinusDx;
}
setPixel(x, y);
}
}
void circleMidpoint(GLint xc, GLint yc, GLint radius)
{
int x,y,r=radius;
float d;
x=0+xc;y=r+yc;d=1.25-r;
setPixel(x,y);
setPixel(y,x);
setPixel(y,-x);
setPixel(x,-y);
setPixel(-x,-y);
setPixel(-y,-x);
setPixel(-y,x);
setPixel(-x,y);
while(x-xcy-yc)
{
if(d0)
{
d+=2*x+3;
x++;
}
else
{
d+=2*(x-y)+5;
x++;
y--;
}
setPixel(x,y);
setPixel(y,x);
setPixel(y,-x);
setPixel(x,-y);
setPixel(-x,-y);
setPixel(-y,-x);
setPixel(-y,x);
setPixel(-x,y);
}
}
void MidpointEllipse(int a,int b)
{
int x,y;
float d1,d2;
x=0;y=b;
d1=b*b+a*a*(-b+0.25);
setPixel(x,y);
文档评论(0)