《图形学实验图形剪裁》由会员分享,可在线阅读,更多相关《图形学实验图形剪裁(6页珍藏版)》请在金锄头文库上搜索。
1、实实 验验 报报 告告课课 程程计算机图形学实验项目实验项目图形剪裁成成 绩绩专业班级专业班级软件工程 08 级学学 号号0805020337批阅日期批阅日期姓姓 名名实验日期实验日期2011.12.29指导教师指导教师一一【实验目的实验目的】1.编程实现用鼠标绘制线段和矩形,并实现剪裁的功能2.实现计算机系统的交互功能,掌握基本的图形剪裁的思路4.掌握开发环境,及相关类库和工具的使用二二【实验内容实验内容】根据已提供的程序框架及思路,完成系统的开发,要求运用图形剪裁算法实现功能,系统健壮, 实现人机交互。三三【实验过程实验过程】本次实验我采用了 glut 的框架,源代码如下:#include
2、 #include #include class wcPt2D public: float x,y; int w=1024,h=768,flag=1; inthh=h; wcPt2D point1512; wcPt2D point2512; wcPt2D temporary; wcPt2D glRectf1; wcPt2D glRectf2; int i=0; bool first=true; bool second=true;void Reshape(int w, int h) glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport
3、(0, 0, w, h); gluOrtho2D(0, w, 0, h); void Display() glClearColor(1.0,1.0,1.0,1.0); glClear(GL_COLOR_BUFFER_BIT); glLineWidth(2.0); if(flag=1) if(first) Drawtemporaryline(); else Drawtrueline(); first=!first; else if(flag=2) if(second) DrawtemporaryglRectf(); else DrawtrueglRectf(); flag=1; first=tr
4、ue; second=true; for(int j=0;jglRectf2.x) a=glRectf1.x; glRectf1.x=glRectf2.x; glRectf2.x=a; if(glRectf1.yglRectf2.y) a=glRectf1.y; glRectf1.y=glRectf2.y; glRectf2.y=a; for(int j=0;j*u2) retVal=false; else if(r*u1) *u1 = r; else if(p 0.0) r=q/p; if(r0.0) p1.x+=u1*dx; p1.y+=u1*dy; glBegin(GL_LINES);
5、glColor3f(0.0,0.0,0.0); glVertex3f(p1.x,p1.y,0.0); glVertex3f(p2.x,p2.y,0.0); glEnd(); int main(intargc, char* argv) glutInit( glutInitWindowPosition(0, 0); glutInitWindowSize(w,h); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutCreateWindow(“liangbarskey“); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glutDisplayFunc(Display); glutKeyboardFunc(Keyboard); glutReshapeFunc(Reshape); glutMotionFunc(mymotion); glutMouseFunc(mymouse); glutMainLoop(); return 0; 实验截图: