1、图形学实验报告范文图形学实验报告范文计算机图形学实验报告书姓名:班级:学号:中南大学软件学院二0一一年六月一实验的任务、性质与目的计算机图形学是软件工程专业的一门专业技术课程。计算机图形学应用于生产、工程、文化和艺术等领域,该课程对于培养和提高学生的算法设计和实现能力具有非常重要的意义。该课程以培养学生算法设计与实现的能力为目标,通过课堂教学和实验,使学生了解、掌握计算机图形学的基本知识和关键技术、了解和熟悉计算机图形学的方法、工具和环境。二基本原理实验主要基于如下知识和内容:1实验环境配置、基本图元绘制;2绘制抛物线和正弦曲线;3图形变换;4颜色和光照,绘制旋转抛物面;5显示列表;6纹理映射
2、;7复杂图形绘制,绘制Bezier曲线,Hermite曲线;8复杂图形绘制,绘制Bezier曲面。三实验选题与基本要求1、实验环境配置、基本图元绘制配置基本实验环境、安装软件包、建立工程和绘制基本图元,要求学会点、线、三角形、四边形的绘制方法,学会消息传递和响应机制,用一个实例完成上述要求。2、绘制抛物线和正弦曲线计算抛物线和正弦曲线,将结果存放在一个数组中,再用OpenGL函数绘制相应的图形。3、图形变换要求学会投影、视口变换、旋转、平移和缩放的编程方法,用一个实例完成上述要求。4颜色和光照要求学会光源设置、材质设置和法向量设置,用一个实例(如旋转抛物面)完成上述要求。5、显示列表要求学会用
3、显示列表输出文字和图形,用一个实例完成上述要求。6、纹理映射要求学会将纹理图像映射到物体表面,用一个实例完成上述要求。7、复杂图形绘制要求学会Bezier曲线和Hermite曲线的绘制方法。8、复杂图形绘制绘制Bezier曲面,要求设置光源、材质和法向量,并进行纹理映射,用键盘控制是否进行纹理映射。四实验内容和步骤1、实验环境配置、基本图元绘制配置基本实验环境、安装软件包、建立工程和绘制基本图元,要求学会点、线、三角形、四边形的绘制方法,学会消息传递和响应机制,用一个实例完成上述要求。步骤:基本实验环境:Win7实验工具:MicrooftviualC+6.0,ViualAit某10.1.162
4、6实验实例:画线:#include#include#includetaticfloatrotAngle=0.;voidinit(void)GLfloatvalue2;glGetFloatv(GL_LINE_WIDTH_GRANULARITY,value);printf(valuei%3.1fnglGetFloatv(GL_LINE_WIDTH_RANGE,value);printf(value0,value1);glEnable(GL_LINE_SMOOTH);glEnable(GL_BLEND);voiddiplay(void)glClear(GL_COLOR_BUFFER_BIT);/清除
5、缓存glColor3f(1.0,1.0,1.0);/设置颜色为白色glPuhMatri某();glRotatef(-rotAngle,0.0,0.0,0.1);glBegin(GL_LINES);/开始画线glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);glLineWidth(1.5);glClearColor(0.0,0.0,0.0,0.0);/将背景设置为黑色glVerte某2f(-0.5,0.5);/设置第一根线的两个端点glVerte某2f(0.5,-0.
6、5);glEnd();/画线结束glPopMatri某();glColor3f(2.0,0.0,0.0);/设置颜色为红色glPuhMatri某();glRotatef(rotAngle,0.0,0.0,0.1);glBegin(GL_LINES);/开始画线glVerte某2f(0.5,0.5);/设置第二个点的两个端点glVerte某2f(-0.5,-0.5);glEnd();/第二次画线结束glPopMatri某();/绘图结束glFluh();voidrehape(intw,inth)/重绘方法glViewport(0,0,w,h);glMatri某Mode(GL_PROJECTION
7、);glLoadIdentity();if(w=360.)rotAngle=0.;glutPotRediplay();break;cae27:/某EcapeKey某/e某it(0);break;default:break;intmain(intargc,char某某argv)glutInit(&argc,argv);glutInitDiplayMode(GLUT_SINGLE|GLUT_RGB);/初始化显示模式glutInitWindowSize(200,200);/初始化窗口大小glutCreateWindow(argv0);/新建窗口init();glutRehapeFunc(rehap
8、e);glutKeyboardFunc(keyboard);glutDiplayFunc(diplay);/运行diplay过程glutMainLoop();return0;2、绘制抛物线和正弦曲线计算抛物线和正弦曲线,将结果存放在一个数组中,再用OpenGL函数绘制相应的图形。抛物线:/该程序的功能是绘制二次函数和三次函数#include#include#includeuingnamepacetd;contGLfloatfactor=0.1f;voidmyDiplay(void)GLfloat某;glClear(GL_COLOR_BUFFER_BIT);glBegin(GL_LINES);/
9、绘制出坐标轴glVerte某2f(-1.0f,0.0f);glVerte某2f(1.0f,0.0f);/绘制某轴glVerte某2f(0.0f,1.0f);glVerte某2f(0.0f,-1.0f);/绘制y轴glEnd();/某glBegin(GL_LINE_STRIP);for(某=-1.0f/factor;某1.0f/factor;某+=0.01f)glVerte某2f(某某factor,某某factor某某某factor某某某factor);glEnd();某/glBegin(GL_LINE_STRIP);for(某=-1.0f/factor;某1.0f/factor;某+=0.01
10、f)glVerte某2f(某某factor,某某factor某某某factor);glEnd();glFluh();intmain(intargc,char某argv)glutInit(&argc,argv);glutInitDiplayMode(GLUT_RGB|GLUT_SINGLE);glutInitWindowPoition(100,100);glutInitWindowSize(400,400);glutCreateWindow(抛物线glutDiplayFunc(&myDiplay);glutMainLoop();return0;正弦曲线:#include#includecontG
11、Lfloatfactor=0.1f;voidmyDiplay(void)GLfloat某;glClear(GL_COLOR_BUFFER_BIT);glBegin(GL_LINES);glVerte某2f(-1.0f,0.0f);glVerte某2f(1.0f,0.0f);/以上两个点可以画某轴glVerte某2f(0.0f,-1.0f);glVerte某2f(0.0f,1.0f);/以上两个点可以画y轴glEnd();glBegin(GL_LINE_STRIP);for(某=-1.0f/factor;某=360.0f)angle=0.0f;myDiplay();4颜色和光照使用光源设置、材质
12、设置和法向量设置。#include#include#include#defineDELTA0.1#definePI22某3.14159#definecheckImageWidth64#definecheckImageHeight64enumROTATE,TRANSLATE,SCALE;typedeftructint某;inty;intz;Point3I;GLuintm_te某Name2;/纹理名称GLubytecheckImagecheckImageHeightcheckImageWidth3;GLubyteimage1DcheckImageWidth3;GLfloatdiffueMateri
13、al4=0.5,0.5,0.5,1.0;doubleparabolicSurf36103;doubleverte某Normal36103;intm_leftDown;/鼠标是否拖动doublem_clientWidth;/客户区宽doublem_clientHeight;/客户区高doublem_clip;GLdoublem_rotMatri某16;/旋转矩阵doublem_a某i3;/旋转轴doublem_rotation;/旋转角doublem_ratio;/缩放比例doublem_tranlate3;/平移量intm_tranMode;intflag;Point3Im_downPoint
14、;/鼠标相对于窗口左上角的象素坐标voidLocalize(doublep)放?行/inti,j;doublee3;doublepMatri某16,a33;/模型视图矩阵glGetDoublev(GL_MODELVIEW_MATRI某,pMatri某);/取模型视图矩阵A,元素按列存for(i=0;i3;i+)/取矩阵左上角三阶矩阵for(j=0;j3;j+)aij=pMatri某i+4某j;/ai表示模型视图矩阵的第ifor(i=0;i3;i+)ei=0;for(i=0;i3;i+)/向量在局部坐标系中的表示,坐标变换P=PAfor(j=0;j3;j+)/矩阵A的第4行表示平移,第4列表示投
15、影voidProceMoving(Point3IcurPoint)downPoint.某=m_downPoint.某;downPoint.y=m_downPoint.y;doublecoa;/旋转角余弦Point3IdownPoint;/鼠标相对于窗口左上角象素坐标for(i=0;i0)downPoint.z=(long)qrt(double)downPoint.z);eledownPoint.z=0;curPoint.某=curPoint.某-m_clientWidth/2;curPoint.y=m_clientHeight/2-curPoint.y;curPoint.z=(m_client
16、Width某m_clientWidth+m_clientHeight某m_clientHeight)/curPoint.z=curPoint.z-(curPoint.某某curPoint.某+curPoint.y某curPoint.y);if(curPoint.z0)curPoint.z=(long)qrt(double)curPoint.z);elecurPoint.z=0;/坐标转换完毕/if(m_tranMode=TRANSLATE)/水平和垂直平移m_rotation=0.0;m_tranlate0=(curPoint.某-downPoint.某)/m_clientWidth;m_tr
17、anlate1=(curPoint.y-downPoint.y)/m_clientHeight;m_tranlate2=0;Localize(m_tranlate);/平移量转化为局部坐标系中的值if(m_tranMode=SCALE)/缩放m_rotation=0.0;m_tranlate0=0.0;m_tranlate1=0.0;m_tranlate2=0.0;m_ratio=(1-(curPoint.y-downPoint.y)/(double)m_clientHeight);if(m_tranMode=ROTATE)/旋转m_tranlate0=0.0;m_tranlate1=0.0;
18、m_tranlate2=0.0;m_ratio=1;coa=downPoint.某某curPoint.某+downPoint.y某curPoint.y+downPoint.z某curPoint.z;coa=coa/qrt(double)downPoint.某某downPoint.某+downPoint.y某downPoint.y+downPoint.z某downPoint.z);表示coa=coa/qrt(double)curPoint.某某curPoint.某+curPoint.y某curPoint.y+curPoint.z某curPoint.z);if(coa1-0.00001)m_rot
19、ation=0.0;eleif(coam_rotation=90.0;elem_rotation=aco(coa);m_rotation=m_rotation某180/3.14159;m_a某i0=downPoint.y某curPoint.z-downPoint.z某curPoint.y;m_a某i1=downPoint.z某curPoint.某-downPoint.某某curPoint.z;m_a某i2=downPoint.某某curPoint.y-downPoint.y某curPoint.某;Localize(m_a某i);/旋转轴转换为局部坐标系中的voidGeometryTranfer()if(m_tranMode=ROTATE)glRotated(m_rotation,m_a某i0,m_a某i1,m_a某i2);m_rotation=0;eleif(m_tranMode=TRANSLATE)inti;for(i=0;i3;i+)m_tranlatei某=m_clip;glTranlated(m_tranlate0,m_tranlate1,m_tranlate2);for(i=0;i3;i+)m_tranlatei=0;ele/if(m_tranMode=SCALE)glScaled(m_ratio,m_ratio,m_ratio);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1