欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > DOC文档下载  

    图形学综合实验.doc

    • 资源ID:2888222       资源大小:4.92MB        全文页数:38页
    • 资源格式: DOC        下载积分:8金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要8金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    图形学综合实验.doc

    期末时上交的图形学实验报告,虽然只得了良,但用心去做了,供大家参考(实验报告+源程序+图片素材): 数学与计算机科学学院实验报告计算机图形综合实验程序名称:Fantasy Solar System程序设计者:*学 号:*所在学院、班级:数学与计算机科学(软件)学院08级综合班电子邮件:fzu_xxs2010指导教师:*完稿日期:二 一 一 年 六 月 十四 日Ø 实验名称:太阳系的模拟Ø 实验内容:1、绘制太阳系8大行星2、显示行星的运动轨道;3、实现8大行星、太空等的纹理映射;4、实现各大行星的公转和自转;5、设置合适的灯光,模拟太阳、月亮、地球、星星等光照效果;6、通过控制摄像机的漫游与环视,实现太阳系的漫游;7、显示各行星的简介资料;8、利用融合、雾化等方法,增强太空的真实感效果;9、设计合理、友好的交互界面。通过鼠标、键盘(包括功能键、组合键)、菜单等,控制各种参数的变化。比如:(1)行星的运转速度、运动轨迹显示的开关;(2)灯光的开启、位置、颜色以及材质;(3)漫游的方向控制;(4)雾化、融合效果的控制。10、其它功能(自定,选做)。Ø 实验环境1.软件环境:(1)操作系统:Windows 7 (2)编译器:Microsoft Visual Studio 20082.硬件环境:(1)主板:技嘉 GA-MA785GT-UT3H (2)CPU:AMD Athlon(tm) II ×4 630 Processor (3)内存:Kingston DDR3,2G(4)硬盘:SATA 500G(5)屏幕分辨率:1024×768Ø 实验方案与程序设计1.设置初始化函数init()实现对自转、公转速度的初始,字符显示列表的初始,深度信息的设置,视见体的初始,投影矩阵的设置,以及灯光、纹理、材质的设置。2.显示回调函数myDisplay()实现对场景的总体绘制:通过myFog()实现雾化;draw_back_ground()实现背景绘制;draw_path()实现轨道绘制;draw_planet()实现星球的绘制;show_info()则实现了星体信息的显示。3.通过键盘回调函数、功能键回调函数和右键菜单更改各个参数以实现多种特殊效果,如漫游、星体的单独显示、雾的颜色和浓度的更改、自转和公转的速度设置、灯光的开户关闭和颜色的设置、重置场景以及退出程序等。4.详细信息见程序代码及注释。Ø 实验结果与分析(包括功能说明、操作说明)1.通过f键开启和关闭雾化效果;2.通过l(字母L)键开启和关闭太阳光源;3.通过r键重置场景;4.通过q键退出程序;5.通过数字键0到9实现各星体的单独显示和全部显示;6.当单独显示某一星体时,可通过w,s键加快或减缓该星体的自转速度,通过a,d键加快或减缓该星体的公转速度;7.通过z,x,c,v键移动视点的焦点;8.通过四个方向键和Page Up,Page Down键移动视点的坐标;9.单击右键弹出右键菜单,各菜单项说明如下:u Path: show moving path表示显示运动轨迹和坐标轴,hide moving path表示隐藏运动轨迹和坐标轴u Rotation:start rotation表示开启自转,stop rotation表示停止自转u Revolution:start revolution表示开启公转,stop revolution表示停止公转u Fog Density: 设置雾的浓度,thin表示小雾,medium表示普通雾,thick大雾u Fog Color:设置雾的颜色(灰色、红色、蓝色、绿色)u Sun Light Color:设置太阳光的颜色,四个可选项依次为白色、红色、绿色、蓝色Ø 实验中遇到的问题及解决方法1.Q:生成的可执行文件在其它计算机上不能运行。S:首先是犯了一个低级错误,就是生成可执行文件时没将debug改为release;其次在没有安装opengl库文件的机子上,是没有glut32.dll的,所以要将可执行文件和glut32.dll一起拷贝到其它计算机上。2.Q:处理纹理的函数auxDIBImageLoadW在生成可执行文件时出错,提示信息为error C2664: “auxDIBImageLoadW”: 不能将参数 1 从“char *”转换为“LPCWSTR”。 S: 这是由于VS2008默认使用Unicode字符,LPCWSTR即是Unicode字符的一种。解决方法为更改工程的属性:项目->Fantasy Solar System属性->配置属性->常规,在其中的字符集选项中把“使用Unicode字符集”更改为“未设置”。3.Q:在实验室的机子上,星体的贴图无法正常显示,出现时隐时现的情况,同时灯光也随之出错。S:视见体的前截面的值设得太小了,将其从0.01改为10,问题解决。之所以在自己宿舍的计算机上可以显示,可能原因是计算能力相对机房的机子强一些故可处理的精度更高一些。4.Q: 在加入了键盘回调函数之后,字符无法正常显示。S: 原因是键盘回调函数本身会将从键盘输入的字符读入程序中,从而使显示字符列表的初始化失败。解决方案为在键盘事件发生前调用传递空串给显示字符函数进行字符显示列表的初始化。5.Q: 启用雾化效果时,显示结果为一大片不透明灰色。S: 最后发现是雾化的起始位置和结束位置问题,将起始和结束位置设为与视见体初始相同,问题解决。同时雾化效果必须有灯光的配合。 Ø 实验心得(自我评价)与建议这个Solar System写得好累,1081行的代码敲得都憔悴了。实验提交时限又正好赶上考试,所以上交时间有些迟。虽然有理论课作为基础,但实践时发现各种矩阵之间的相互影响有时搞得程序跑出来的结果莫名其妙,许多次不得不重写所有代码,先后经历了好几个版本的修改。总结前期失败的原因,主要是程序的结构不够清晰,各功能的实现相互交叉,导致耦合度过高,引起许多隐含错误。后面学乖了,首先设计整体的框架,抽象出各个相对独立的部件,再在这些部件内实现功能。同时在启用纹理绘制完对象后立即关闭纹理,以减少潜在的对其它矩阵的影响。这种方式写出来的代码条理清楚,思路清晰则易于查错,经过注释方面的美化之后,不得不说其实挺漂亮的。虽然最终实现的效果没有那么炫丽,但在完成实验的过程中学到了许多理论课上所没有的知识。有时出现的错误自己觉得是毫无道理的,求助Google无果后,自己只能一步一步地调试,一行一行地注释,一个变量一个变量地修改参数,一个位置一个位置地安放函数。最终的结果是错误不是没有道理的,而是自己本身考虑事情不够全面。错误不单是代码方面的,还有自己逻辑上的和系统编译方面等,有些还是openGL自身固有的。面对Bug调试很久没有解决,有时会相当沮丧,甚至觉得自己根本没有能力解决。但静下心来认真查资料,问题是会逐渐明朗化的,所以对自己要有信心。写完这个代码,终于可以脸不红心不跳地说自己已经完成openGL编程入门了。附录一(源程序):/* File: Fantasy Solar System.cpp* Version: 4.0 aleph* Compiler: Visual Studio 2008* Author: s030802435* E-mail: fzu_xxs2010* Function: This is an OpenGL program to imitate solar system* Usage:* #1.Press the key 'f' to turn on or turn off the fog* #2.Press the key 'l' to turn on or turn off the sun light* #3.Press the key 'r' to reset the scene* #4.Press the key 'q' to exit the program.* #5.Press the number button to show planet alone:* 0: show all planet* 1: show Sun* 2: show Mercury* 3: show Venus* 4: show Earth and Moon* 5: show Mars* 6: show Jupiter* 7: show Saturn* 8: show Uranus* 9: show Neptune* #6.When you show planet alone, you can change the speed of rotation and revolution:*Press 'w' to increase the speed of rotation*Press 's' to decrease the speed of rotation*Press 'd' to increase the speed of revolution*Press 'a' to decrease the speed of revolution* #7.Press 'z', 'x', 'c' or 'v' to move the focus of view*'z'-left 'x'-right 'c'-up 'v'-down* #8.the position of view point can be changed by:*up-arrow: towards near*down-arrow: towards far*left-arrow: towards left*right-arrow: towards right*Page Up key: towards upside*Page Down key: towards downside* #9.Click right button to pop the main menu:*Path: show path or not*Rotation: start or stop rotation *Revolution: start or stop revolution*Fog Density: set the density of fog(thin, medium or thick)*Fog Color: set the color of fog(grey, red, blue or green)*Sun Light Color: set the color of sun light(white, red, green or blue)* Attention: You should set your project don't use Unicode characters* Last modify: 2011-6-14*/* Head File*/#include<GL/glut.h>#include<stdio.h>#include<stdlib.h>#include<windows.h>#include<math.h>#include<glaux.h>/ If fail to find this head file, please try "GL/glaux.h"/* Macro*/#pragma comment(lib,"opengl32.lib")#pragma comment(lib,"glu32.lib")#pragma comment(lib,"glaux.lib")#pragma comment(lib,"GLUT32.LIB")#define TRUE 1#define FALSE 0#define PIE 3.1415926#define MAXTEXTURE 11#define width 1024#define height 512#define MAX_CHAR 128/* Static Global Var*/static GLint show_back_ground=TRUE; / show the background bitmapstatic GLuint textureMAXTEXTURE; / the array of texturesstatic GLint cnt=0; / the index of the texturesstatic GLuint isFirstCall = TRUE; / first call character display liststatic GLuint lists; / character display listsstatic GLfloat lookx=0.0,looky=100.0,lookz=300.0; / coordinate of viewportstatic GLfloat look_x=0.0,look_y=0.0,look_z=0.0; / focus point of viewportstatic GLint show_planet = 0; / choose the planet to showstatic GLint show_path = TRUE; / show the path of planet movingstatic GLfloat myTime,myTime_2; / the computer system timestatic GLint rotation_speed9; / adjust the rotation speed of Earthstatic GLint revolution_speed9; / adjust the revolution speed of Earthstatic GLint stop_rotation=FALSE; / stop rotation of planetsstatic GLint stop_revolution=FALSE; / stop revolution of planetsstatic GLfloat sun_ambient = 1.0 , 0.9 , 0.9 , 0.1 ; / ambient part of sun lightstatic GLfloat sun_diffuse = 1.0 , 0.9 , 0.9 , 1.0 ; / diffuse part of sun lightstatic GLfloat sun_specular = 1.0 , 0.9 , 0.9 , 1.0 ; / specular part of sun lightstatic GLfloat sun_position = 0.0 , 0.0 , 0.0 , 1.0 ; / the position of sun lightstatic GLfloat globel_ambient = 0.3 , 0.3 , 0.3 , 1.0 ; / globel lightstatic GLfloat sun_self_emission = 0.8 , 0.8 , 0.8 , 1.0 ; / the surface light of sunstatic GLfloat planet_ambient = 0.01 , 0.01 , 0.01 , 1.0 ; / ambient part of planet surfacestatic GLfloat planet_diffuse = 0.7 , 0.7 , 0.7 , 1.0 ; / diffuse part of planet surfacestatic GLfloat planet_specular = 0.5 , 0.5 , 0.5 , 0.5 ; / specular part of planet surfacestatic GLfloat planet_self_emission = 0.2 , 0.2 , 0.2 , 1.0; / the surface light of planet surfacestatic GLfloat planet_high_light = 120.0; / highlights coefficient of planetstatic GLint sun_light_on = TRUE; / the state of sun lightstatic GLint set_fog = TRUE; / start fog effect or notstatic GLfloat fog_density = 10.0; / the density of fogstatic GLfloat fog_color4 = 0.5f,0.5f,0.5f,1.0f; / the color of fogstatic GLUquadricObj* g_text= gluNewQuadric(); / achieve texture by quadric object /* Function*/*-*/* open bitmap file */*-*/AUX_RGBImageRec *LoadImage(char *Filename) FILE *File=NULL;if(!Filename) return NULL;File = fopen(Filename,"r");if(File) fclose(File);return auxDIBImageLoad(Filename);return NULL;/*-*/* load textures */*-*/int LoadGLTextures(char *Filename) GLint Status=FALSE; AUX_RGBImageRec *TextureImage1; memset(TextureImage,0,sizeof(void *)*1); if (TextureImage0=LoadImage(Filename) Status=TRUE; glGenTextures(1, &texturecnt); glBindTexture(GL_TEXTURE_2D, texturecnt+); glPixelStorei(GL_UNPACK_ALIGNMENT,1); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage0->sizeX,TextureImage0->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,TextureImage0->data); if (TextureImage0) if (TextureImage0->data) free(TextureImage0->data); free(TextureImage0); return Status; /*-*/* load the textures which will be used */*-*/int InitTexture() if( !LoadGLTextures("Image/space.bmp") printf("Fail to load Image/space.bmpn"); return -1; if( !LoadGLTextures("Image/sun.bmp")printf("Fail to load Image/sun.bmpn");return -1;if( !LoadGLTextures("Image/mercury.bmp")printf("Fail to load Image/mercury.bmpn");return -1;if( !LoadGLTextures("Image/venus.bmp")printf("Fail to load Image/venus.bmpn");return -1;if( !LoadGLTextures("Image/earth.bmp")printf("Fail to load Image/earth.bmpn");return -1;if( !LoadGLTextures("Image/moon.bmp")printf("Fail to load Image/moon.bmpn");return -1;if( !LoadGLTextures("Image/mars.bmp")printf("Fail to load Image/mars.bmpn");return -1;if( !LoadGLTextures("Image/jupiter.bmp")printf("Fail to load Image/jupiter.bmpn");return -1;if( !LoadGLTextures("Image/saturn.bmp")printf("Fail to load Image/saturn.bmpn");return -1;if( !LoadGLTextures("Image/uranus.bmp")printf("Fail to load Image/uranus.bmpn");return -1;if( !LoadGLTextures("Image/neptune.bmp")printf("Fail to load Image/neptune.bmpn");return -1;/else printf("success load all the bitmapsn"); return TRUE; /*-*/* Display strings */*-*/void drawString(const char* str) if( isFirstCall ) isFirstCall = FALSE; lists = glGenLists(MAX_CHAR); wglUseFontBitmaps(wglGetCurrentDC(), 0, MAX_CHAR, lists); for(; *str!='0' +str) glCallList(lists + *str);/*-*/* Display information about the planet */*-*/void show_info(char* str)glMatrixMode(GL_MODELVIEW);glDisable(GL_LIGHTING);glColor3f(1.0,0.1,0.0); glPushMatrix();glRasterPos2f(-200.0f, 100.0f);drawString(str);glEnable(GL_LIGHTING);glColor3f(1.0,1.0,1.0);glPopMatrix();/*-*/* draw fog */*-*/void myFog()glFogi(GL_FOG_MODE,GL_LINEAR);glFogfv(GL_FOG_COLOR,fog_color);glFogf(GL_FOG_DENSITY,fog_density);glHint(GL_FOG_HINT,GL_DONT_CARE); glFogf(GL_FOG_START,300.0f);glFogf(GL_FOG_END,-300.0f);/*-*/* initialization */*-*/bool init()glClearColor(0.0,0.0,0.0,1.0);show_info("");rotation_speed0=27;rotation_speed1=58;rotation_speed2=243;rotation_speed3=1;rotation_speed4=1;rotation_speed5=10;rotation_speed6=11;rotation_speed7=8;rotation_speed8=8;revolution_speed0=0;revolution_speed1=88;revolution_speed2=225;revolution_speed3=365;revolution_speed4=686;revolution_speed5=100;revolution_speed6=129;revolution_speed7=500;revolution_speed8=550;glDepthFunc(GL_LEQUAL);glClearDepth(1.0f);glEnable(GL_DEPTH_TEST);glShadeModel(GL_SMOOTH);gluLookAt (lookx, looky, lookz, look_x, look_y, look_z, 0.0, 1.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,(GLfloat)(width)/(GLfloat)(height),10,100000); glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);glEnable(GL_TEXTURE_2D);gluQuadricTexture(g_text,GL_TRUE); InitTexture(); glEnable(GL_LIGHTING);glEnable(GL_LIGHT0); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE , GL_FALSE);

    注意事项

    本文(图形学综合实验.doc)为本站会员(文库蛋蛋多)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开