ImageVerifierCode 换一换
格式:DOCX , 页数:32 ,大小:306.58KB ,
资源ID:3608593      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3608593.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(南昌大学图形学实验报告完整版.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

南昌大学图形学实验报告完整版.docx

1、南昌大学图形学实验报告完整版实验一一、实验项目名称 熟悉opengl环境二、实验目的 1、掌握在利用OpenGL图形库进行图形程序设计的基本方法。 2、掌握Windows环境下的消息处理方法。 3、理解OpenGL运行机制。三、实验基本原理和内容 使用opengl绘制一个图形四、主要仪器设备及耗材PC机一台,win7 VC+6.0环境五、实验步骤1、打开VC+6.02、新建工程,键入代码3、记录结果六、实验数据及处理结果7、思考讨论题或体会或对改进实验的建议 通过第一次实验体会到opengl的魅力8、参考资料:计算机图形学(第三版)Donald Hearn 电子工业出版社 九、源代码#incl

2、udeusing namespace std;#include #include const int n = 1000;const GLfloat R = 0.5f;const GLfloat Pi = 3.1415926536f;void DrawCircle() int i; GLfloat x,y; glBegin(GL_LINE_LOOP); for(i=0; in; +i) x=R*cos(2*Pi/n*i)*(1-cos(2*Pi/n*i); y=R*sin(2*Pi/n*i)*(1-cos(2*Pi/n*i); glVertex2f(y, x+0.2f); glEnd(); gl

3、Flush();void myDisplay() glClear(GL_COLOR_BUFFER_BIT); DrawCircle();void init (void) glClearColor(1.0f,1.0f, 1.0f,0.0f); glMatrixMode (GL_PROJECTION); gluOrtho2D(-400.0,400.0,-400.0,400.0); glMatrixMode(GL_MODELVIEW); int main(int argc, char *argv) glutInit(&argc, argv); glutInitDisplayMode(GLUT_SIN

4、GLE | GLUT_RGB); glutInitWindowPosition(100, 100); glutInitWindowSize(500, 500); glutCreateWindow(心形); /init(); glutDisplayFunc(myDisplay); glutMainLoop(); return 0;实验二一、实验项目名称 任意斜率直线和中点画圆二、实验目的 理解DDA直线算法和中点画圆算法三、实验基本原理和内容 四、主要仪器设备及耗材PC机一台,win7 VC+6.0环境五、实验步骤六、实验数据及处理结果7、思考讨论题或体会或对改进实验的建议画线的核心是通过算法来

5、调整直线的生成方式,这只是其中一种方式八、参考资料:计算机图形学(第三版)Donald Hearn 电子工业出版社 附源码:1:任意直线斜率#include#include#includeusing namespace std;static float m=0;float x,y;void init(void) glClearColor(1.0,1.0,1.0,0); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0,200.0,0.0,150.0);void line() glClear(GL_COLOR_BUFFER_BIT); glColor3f(1

6、.0,0.0,0.0); if(fabs(m)=0) glBegin(GL_LINES); glVertex2i(18,70); glVertex2i(300,70); glEnd(); else if(fabs(m)=1) glBegin(GL_POINTS); x=70; y=70; for(int i=0;i=1000;i+) glVertex2f(x,y); x+=0.1; y=y+m*0.1; glEnd(); else glBegin(GL_POINTS); x=70; y=70; for(int i=0;i=1000;i+) glVertex2f(x,y); y+=0.1; x=

7、x+0.1/m; glEnd(); glFlush();void main(int argc,char *argv)coutm; glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowPosition(50,100); glutInitWindowSize(400,300); glutCreateWindow(任意斜率的直线); init(); glutDisplayFunc(line); glutMainLoop();2:中点画圆#includeusing namespace std;#i

8、nclude #include const int n = 1000;const GLfloat R = 0.5f;const GLfloat Pi = 3.1415926536f;/以下为一般圆生成算法,不采纳/*void DrawCircle() int i; glBegin(GL_LINE_LOOP); for(i=0; in; +i) glVertex2f(R*cos(2*Pi/n*i), R*sin(2*Pi/n*i); glEnd(); glFlush();void myDisplay() glClear(GL_COLOR_BUFFER_BIT); DrawCircle();*/以

9、下代码为中点画圆算法class screenPtprivate:GLint x,y;public: sceenPt()x=y=0; void setCoords(GLint xcoordValue,GLint ycoordValue) x=xcoordValue; y=ycoordValue; GLint getx() constreturn x; GLint gety() constreturn y; void incrementx()x+; void decrementy()y-;void setPixel(GLint xcoord,GLint ycoord) /glClear(GL_CO

10、LOR_BUFFER_BIT); /glColor3f (1.0,0.0,0.0); glBegin(GL_POINTS); glVertex2i(xcoord,ycoord); glEnd(); /glRectf(-0.5f, -0.5f, 0.5f, 0.5f);void circleMidpoint(GLint xc,GLint yc,GLint radius) screenPt circPt; GLint p=1-radius; circPt.setCoords(0,radius); void circlePlotPoints(GLint ,GLint ,screenPt); circ

11、lePlotPoints(xc,yc,circPt); while(circPt.getx()circPt.gety() circPt.incrementx(); if(p0) p+=2*circPt.getx()+1; else circPt.decrementy(); p+=2*(circPt.getx()-circPt.gety()+1; circlePlotPoints(xc,yc,circPt); void circlePlotPoints(GLint xc,GLint yc,screenPt circPt) setPixel(xc+circPt.getx(),yc+circPt.g

12、ety();/1 setPixel(xc-circPt.getx(),yc+circPt.gety(); setPixel(xc+circPt.getx(),yc-circPt.gety(); setPixel(xc-circPt.getx(),yc-circPt.gety(); setPixel(xc+circPt.gety(),yc+circPt.getx();/5 setPixel(xc-circPt.gety(),yc+circPt.getx(); setPixel(xc+circPt.gety(),yc-circPt.getx(); setPixel(xc-circPt.gety()

13、,yc-circPt.getx();void myDisplay() glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f,0.0f,0.0f); glViewport(0,0,400,400); circleMidpoint(0,0,360); glFlush();void init (void) glClearColor(1.0f,1.0f, 1.0f,0.0f); glMatrixMode (GL_PROJECTION); gluOrtho2D(-400.0,400.0,-400.0,400.0); glMatrixMode(GL_MODELVIEW)

14、;int main(int argc, char *argv) glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(100, 100); glutInitWindowSize(500, 500); glutCreateWindow(画一个圆); init(); glutDisplayFunc(&myDisplay); glutMainLoop(); return 0;实验三一、实验项目名称直线裁剪算法二、实验目的 掌握Sutherland-Cohen 或Liang-

15、Barsky 直线裁剪算法3、实验基本原理和内容4、四、主要仪器设备及耗材PC机一台,win7 VC+6.0环境五、实验步骤六、实验数据及处理结果 7、思考讨论题或体会或对改进实验的建议剪裁的时候要注意视点的位置,以及剪裁点的设置八、参考资料:计算机图形学(第三版)Donald Hearn 电子工业出版社 附源码:/*#include class wcPt2Dprivate: GLfloat x,y;public: wcPt3D() x=0.0; y=0.0; setCoords(GLfloat xCoord,GLfloat yCoord) x=xCoord; y=yCoord; GLfloa

16、t getx() const return x; GLfloat gety() const return y; ;inline GLint round(const GLfloat a) return GLint(a+0.5);GLint clipTest(GLfloat p,GLfloat q,GLfloat *u1,GLfloat *u2) GLfloat r; GLint returnValue=true; if(p*u2) returnValue=false; else if(r*u1) *u1=r; else if(p0.0) r=q/p; if(r*u1) returnValue=f

17、alse; else if(r*u2) *u2=r; else if(q0.0) returnValue=false; return returnValue;void lineClipLiangBarsk(wcPt2D winMin,wcPt2D winMax,wcPt2D p1,wcPt2D p2) GLfloat u1=0.0,u2=1.0,dx=p2.getx()-p1.getx(),dy; if(clipTest(-dx,p1.getx()-winMin.getx(),&u1,&u2) dy=p2.gety()-p1.gety(); if(clipTest(-dy,p1.gety()-

18、winMin.gety(),&u1,&u2) if(clipTest(dy,winMax.gety()-p1.gety(),&u1,&u2) if(u20.0) p1.setCoords(p1.getx()+u1*dx,p1.gety()+u1*dy); lineBres(round(p1.getx(),round(p1.gety(),round(p2.getx(),round(p2.gety); void myDisplay(void)glClear(GL_COLOR_BUFFER_BIT); glColor3f (1.0,0.0,0.0); glBegin (GL_LINES); glVe

19、rtex2i (180,15); glVertex2i (10,145); glEnd();glRectf(-0.5f, -0.5f, 0.5f, 0.5f);glFlush(); void init (void) glClearColor(1.0 ,1.0, 1.0,0.0); glMatrixMode (GL_PROJECTION); gluOrtho2D(0.0,200.0,0.0,150.0);int main(int argc, char *argv) glutInit(&argc, argv);glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);

20、glutInitWindowPosition(50, 100);glutInitWindowSize(400,300);glutCreateWindow(OpenGL);init ();glutDisplayFunc(&myDisplay);glutMainLoop();return 0;*/*利用VC+OpenGL实现直线的编码裁剪算法,在屏幕上用一个封闭矩形裁剪任意一条直线。#include #include int flag;void setPixel(GLint x,GLint y) glBegin(GL_POINTS); glVertex2i(x, y); glEnd(); /* B

21、resenham line-drawing procedure for |m| xEnd) x = xEnd; y = yEnd; xEnd = x0; else x = x0; y = y0; setPixel (x, y);while (x xEnd) x+; if (p 0) p += twoDy; else y+; p += twoDyMinusDx; setPixel (x, y); /*/以下未变,见课本P264/*class wcPt2D public: GLfloat x, y;inline GLint round (const GLfloat a) return GLint

22、(a + 0.5); /* Define a four-bit code for each of the outside regions of a * rectangular clipping window.const GLint winLeftBitCode = 0x1;const GLint winRightBitCode = 0x2;const GLint winBottomBitCode = 0x4;const GLint winTopBitCode = 0x8;/* A bit-mask region code is also assigned to each endpoint of

23、 an input * line segment, according to its position relative to the four edges of * an input rectangular clip window. * * An endpoint with a region-code value of 0000 is inside the clipping * window, otherwise it is outside at least one clipping boundary. If * the or operation for the two endpoint c

24、odes produces a value of * false, the entire line defined by these two endpoints is saved * (accepted). If the and operation between two endpoint codes is * true, the line is completely outside the clipping window, and it is * eliminated (rejected) from further processing. */inline GLint inside (GLi

25、nt code) return GLint (!code); inline GLint reject (GLint code1, GLint code2) return GLint (code1 & code2); inline GLint accept (GLint code1, GLint code2) return GLint (!(code1 | code2); GLubyte encode (wcPt2D pt, wcPt2D winMin, wcPt2D winMax) GLubyte code = 0x00;if (pt.x winMax.x) code = code | win

26、RightBitCode; if (pt.y winMax.y) code = code | winTopBitCode; return (code);void swapPts (wcPt2D * p1, wcPt2D * p2) wcPt2D tmp;tmp = *p1; *p1 = *p2; *p2 = tmp;void swapCodes (GLubyte * c1, GLubyte * c2) GLubyte tmp;tmp = *c1; *c1 = *c2; *c2 = tmp;void lineClipCohSuth (wcPt2D winMin, wcPt2D winMax, wcPt2D p1, wcPt2D p2) GLubyte code1, code2; GLint done = false, plotLine = false;GLfloat m; while (!done) code1 = encode (p1, winMin, winMax); code2 = encode (p2, winMin, winMax); if (accept (code1, code2) done = tru

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1