《计算机图形学实验》报告
任课教师:钱文华
2016年春季学期
实验:Cohen-Sutherland直线裁剪算法
实验时间:2016年11月3日 实验地点:信息学院2204
实验目的:掌握Cohen-Sutherland
程序代码: #include
int a,b,a1,b1,pp0,pq0,pp1,pq1;
void setPixel(GLint x,GLint y){ }
void init(void){
glClearColor(1.0,1.0,1.0,0.0); glMatrixMode(GL_PROJECTION); glBegin(GL_POINTS); glVertex2i(x,y); glEnd();
直线裁剪算法
}
gluOrtho2D(0.0,200.0,0.0,150.0);
void LineDDA(int x0,int y0,int xEnd,int yEnd){ } //裁剪
int dx = xEnd - x0; int dy = yEnd - y0; int 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); for (k = 0;k x+=xIncrement; y+=yIncrement; setPixel(x,y); class wcPt2D{ }; inline GLint round(const GLfloat a){ } const GLint winLeftBitCode = 0x1; const GLint winRightBitCode = 0x2; const GLint winBottomBitCode = 0x4; const GLint winTopBitCode = 0x8; inline GLint inside(GLint code){ } inline GLint reject(GLint code1,GLint code2){ } inline GLint accept(GLint code1,GLint code2){ } GLubyte encode(wcPt2D pt,wcPt2D winMin,wcPt2D winMax){ return GLint(!(code1|code2)); return GLint(code1&code2); return GLint(!code); return GLint(a+0.5); public: GLfloat x,y; } GLubyte code = 0x00; if(pt.x code = code|winLeftBitCode; if(pt.x>winMax.x) code = code|winRightBitCode; if(pt.y code = code|winBottomBitCode; if(pt.y>winMax.y) code = code|winTopBitCode; return(code); void swapPts(wcPt2D *p1,wcPt2D *p2){ } void swapCodes(GLubyte *c1,GLubyte *c2){ GLubyte tmp; tmp = *c1; *c1 = *c2; *c2 = tmp; wcPt2D tmp; tmp = *p1; *p1 = *p2; *p2 = tmp;