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

    多媒体技术实验报告.doc

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

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

    多媒体技术实验报告.doc

    1q实验 粒子系统讲授时数:0.5学时。一、 实验类型研究创新型实验 二、 实验目的Ø 通过本实验让学生熟练掌握三维图形程序编写,掌握粒子系统的设计与实现,加深对粒子系统的认识。Ø 本实验要实现一个基于粒子系统的烟花效果模拟。粒子系统包括:粒子初始化、粒子状态控制、粒子的绘制。Ø 实现本系统实现之后,学生可以在此基础上进行扩展,例如模拟喷泉效果。喷泉效果的实现包括:粒子颜色保持蓝色,粒子运动受到重力作用。三、 实验要求Ø 三维图形绘制工程配置和环境设置。Ø 粒子系统设计,实现粒子系统的数据结构和管理的设计模式。Ø 各个粒子位置、颜色计算。Ø 粒子的绘制。Ø 提交程序使用手册(可简单到为一个readme文件)。四、 实验内容利用OpenGL实现一个粒子系统,模拟烟花效果。五、 开设方式小组实验。六、 学时数8学时。七、 参考资料1 VC+编程指南,2 NeHe OpenGL框架程序3 OpenGL SDK下载http:/www.opengl.org/八、 实验后记电 子 科 技 大 学实 验 报 告学生姓名: 学 号: 指导教师:实验地点: 实验时间:一、实验室名称:计算机学院软件实验室二、实验项目名称:粒子系统三、实验学时:8学时四、实验原理粒子系统在计算机动画中被广泛用于模拟爆炸、喷泉、流星等效果。在本实验中,粒子系统被用来模拟不断喷射的烟花。实现粒子系统包括:(1)粒子初始化。(2)粒子运动和颜色模拟。(3)粒子生命周期模拟。粒子的初始化给所有的粒子的位置、速度、生命和衰减周期赋值;运动和颜色模拟是计算粒子的速度、位置在每一时间步长之后变化的值;粒子的生命周期模拟是在粒子生命完结之后重新初始化该粒子。为了实现这样的效果,粒子应该具有以下属性:(1)boolactive;粒子的活动状态,为true时,才模拟粒子。(2)floatlife;粒子的生命值,在模拟过程中不断减少,如果为0就重新初始化粒子。(3)floatfade;粒子的生命值减少的速度。(4)floatr;粒子颜色R分量。(5)floatg;粒子颜色G分量。(6)floatb;粒子颜色B分量。(7)floatx;粒子位置X分量。(8)floaty;粒子位置Y分量。(9)floatz;粒子位置Z分量。(10)floatxi;粒子速度X分量。(11)floatyi;粒子速度Y分量。(12)floatzi;粒子速度Z分量。(13)floatxg;粒子加速度X分量。(14)floatyg;粒子加速度X分量。(15)floatzg;粒子加速度X分量。在具体的模拟过程中,需要创建一个数组叫particle数组存MAX_PARTICLES个元素。也就是说我们创建1000(MAX_PARTICLES)个粒子,存储空间为每个粒子提供相应的信息。使用光滑的阴影,清除背景为黑色,关闭深度测试,绑定并映射纹理。启用映射位图后我们选择粒子纹理。唯一的改变就是禁用深度测试和初始化粒子。并且创建一个循环loop.这个环将会更新每一个粒子。每次循环时首先检查粒子是否活跃。如果不活跃,则不被更新。在这个程序中,它们始终活跃。五、实验目的本实验要实现粒子系统。粒子系统包括以下模块:粒子初始化;位置、速度、颜色实时计算;生命周期控制。基本系统实现之后,可以在此基础上扩展为喷泉效果。实现喷泉效果需要一下几个模块:(1)粒子水平方向的随机初速度。(2)粒子运动模拟。(3)位置低于地面,重新初始化。六、实验内容利用OpenGL实现一个粒子系统。七、实验器材(设备、元器件)1. 操作系统:Windows XP2. 开发工具:VC2005,OpenGL库3. 普通PC即可八、实验步骤(1) 创建工程启动VC+2005,选择菜单中的“文件”->“新建”->“项目”。在弹出的对话框中,左边的“项目类型”框中,选择“Visual C+”,在右边框中,选择“Win32项目”。在对话框下边,选择工程文件存放目录及输入名称,如Particle,单击“确定”。在“Win32应用程序向导”中单击“下一步”,在“应用程序类型”中选择“windows应用程序”;在“附加选项”中选择“空项目”。点击“完成”。(2) 设置此工程所需的OpenGL库选择菜单中的“项目”->“属性”。在弹出的“Particle属性页”对话框中,展开“链接器”选择“输入”。选择右边框中的“附加依赖项”,单击最右端的“”小按钮,弹出“附加依赖项”对话框,输入“OPENGL32.lib GLUT.lib GLAUX.lib GLU32.lib”(注意,输入双引号中的内容,各个库用空格分开;否则会出现链接错误。如果编译时提示找不到以上的lib文件,把“链接器->常规->附加库目录”选择为OpenGL SDK所在目录,或者从OPENGL SDK中把这几个lib文件放到Microsoft Visual Studio 8VClib)。“配置属性->常规->字符集”设置为“未设置”。“C/C+->预编译头->创建/使用预编译头”设置为“不使用预编译头”。单击“确定”结束。项目属性设置完成。(3) 在工程项目中添加源文件在“解决方案资源管理器”中,选中Particle项目下的“源文件”筛选器。右键点击后选择“添加”,然后选择新建项。在“添加新项”的窗口中选择“C+文件(.cpp)”模板,并命名为main.cpp。(4) 录入源程序程序使用到了资源文件“Particle.bmp”作为粒子的贴图,该文件如下:图1 Particle.bmp将该文件保存在工程目录“ParticleData”目录下。将源程序写入到工程中。新建好main.cpp文件后,将代码写入该文件。参考源代码如下:Main.cpp#include <windows.h>/ Header File For Windows#include <stdio.h>/ Header File For Standard Input/Output#include <glgl.h>/ Header File For The OpenGL32 Library#include <glglu.h>/ Header File For The GLu32 Library#include <glglaux.h>/ Header File For The Glaux Library#defineMAX_PARTICLES1000/ Number Of Particles To CreateHDChDC=NULL;/ Private GDI Device ContextHGLRChRC=NULL;/ Permanent Rendering ContextHWNDhWnd=NULL;/ Holds Our Window HandleHINSTANCEhInstance;/ Holds The Instance Of The Applicationboolkeys256;/ Array Used For The Keyboard Routineboolactive=TRUE;/ Window Active Flag Set To TRUE By Defaultboolfullscreen=TRUE;/ Fullscreen Flag Set To Fullscreen Mode By Defaultboolrainbow=true;/ Rainbow Mode?boolsp;/ Spacebar Pressed?boolrp;/ Enter Key Pressed?floatslowdown=2.0f;/ Slow Down Particlesfloatxspeed;/ Base X Speed (To Allow Keyboard Direction Of Tail)floatyspeed;/ Base Y Speed (To Allow Keyboard Direction Of Tail)floatzoom=-40.0f;/ Used To Zoom OutGLuintloop;/ Misc Loop VariableGLuintcol;/ Current Color SelectionGLuintdelay;/ Rainbow Effect DelayGLuinttexture1;/ Storage For Our Particle Texturetypedef struct/ Create A Structure For Particleboolactive;/ Active (Yes/No)floatlife;/ Particle Lifefloatfade;/ Fade Speedfloatr;/ Red Valuefloatg;/ Green Valuefloatb;/ Blue Valuefloatx;/ X Positionfloaty;/ Y Positionfloatz;/ Z Positionfloatxi;/ X Directionfloatyi;/ Y Directionfloatzi;/ Z Directionfloatxg;/ X Gravityfloatyg;/ Y Gravityfloatzg;/ Z Gravityparticles;/ Particles Structureparticles particleMAX_PARTICLES;/ Particle Array (Room For Particle Info)static GLfloat colors123=/ Rainbow Of Colors1.0f,0.5f,0.5f,1.0f,0.75f,0.5f,1.0f,1.0f,0.5f,0.75f,1.0f,0.5f,0.5f,1.0f,0.5f,0.5f,1.0f,0.75f,0.5f,1.0f,1.0f,0.5f,0.75f,1.0f,0.5f,0.5f,1.0f,0.75f,0.5f,1.0f,1.0f,0.5f,1.0f,1.0f,0.5f,0.75f;LRESULTCALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);/ Declaration For WndProcAUX_RGBImageRec *LoadBMP(char *Filename)/ Loads A Bitmap Image FILE *File=NULL;/ File Handle if (!Filename)/ Make Sure A Filename Was Given return NULL;/ If Not Return NULL File=fopen(Filename,"r");/ Check To See If The File Exists if (File)/ Does The File Exist? fclose(File);/ Close The Handlereturn auxDIBImageLoad(Filename);/ Load The Bitmap And Return A Pointer return NULL;/ If Load Failed Return NULLint LoadGLTextures()/ Load Bitmap And Convert To A Texture int Status=FALSE;/ Status Indicator AUX_RGBImageRec *TextureImage1;/ Create Storage Space For The Textures memset(TextureImage,0,sizeof(void *)*1);/ Set The Pointer To NULL if (TextureImage0=LoadBMP("Data/Particle.bmp")/ Load Particle Texture Status=TRUE;/ Set The Status To TRUEglGenTextures(1, &texture0);/ Create One TextureglBindTexture(GL_TEXTURE_2D, texture0);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage0->sizeX, TextureImage0->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage0->data); if (TextureImage0)/ If Texture Existsif (TextureImage0->data)/ If Texture Image Existsfree(TextureImage0->data);/ Free The Texture Image Memoryfree(TextureImage0);/ Free The Image Structure return Status;/ Return The StatusGLvoid ReSizeGLScene(GLsizei width, GLsizei height)/ Resize And Initialize The GL Windowif (height=0)/ Prevent A Divide By Zero Byheight=1;/ Making Height Equal OneglViewport(0,0,width,height);/ Reset The Current ViewportglMatrixMode(GL_PROJECTION);/ Select The Projection MatrixglLoadIdentity();/ Reset The Projection Matrix/ Calculate The Aspect Ratio Of The WindowgluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,200.0f);glMatrixMode(GL_MODELVIEW);/ Select The Modelview MatrixglLoadIdentity();/ Reset The Modelview Matrixint InitGL(GLvoid)/ All Setup For OpenGL Goes Hereif (!LoadGLTextures()/ Jump To Texture Loading Routinereturn FALSE;/ If Texture Didn't Load Return FALSEglShadeModel(GL_SMOOTH);/ Enable Smooth ShadingglClearColor(0.0f,0.0f,0.0f,0.0f);/ Black BackgroundglClearDepth(1.0f);/ Depth Buffer SetupglDisable(GL_DEPTH_TEST);/ Disable Depth TestingglEnable(GL_BLEND);/ Enable BlendingglBlendFunc(GL_SRC_ALPHA,GL_ONE);/ Type Of Blending To PerformglHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);/ Really Nice Perspective CalculationsglHint(GL_POINT_SMOOTH_HINT,GL_NICEST);/ Really Nice Point SmoothingglEnable(GL_TEXTURE_2D);/ Enable Texture MappingglBindTexture(GL_TEXTURE_2D,texture0);/ Select Our Texturefor (loop=0;loop<MAX_PARTICLES;loop+)/ Initials All The Texturesparticleloop.active=true;/ Make All The Particles Activeparticleloop.life=1.0f;/ Give All The Particles Full Lifeparticleloop.fade=float(rand()%100)/1000.0f+0.003f;/ Random Fade Speedparticleloop.r=colorsloop*(12/MAX_PARTICLES)0;/ Select Red Rainbow Colorparticleloop.g=colorsloop*(12/MAX_PARTICLES)1;/ Select Red Rainbow Colorparticleloop.b=colorsloop*(12/MAX_PARTICLES)2;/ Select Red Rainbow Colorparticleloop.xi=float(rand()%50)-26.0f)*10.0f;/ Random Speed On X Axisparticleloop.yi=float(rand()%50)-25.0f)*10.0f;/ Random Speed On Y Axisparticleloop.zi=float(rand()%50)-25.0f)*10.0f;/ Random Speed On Z Axisparticleloop.xg=0.0f;/ Set Horizontal Pull To Zeroparticleloop.yg=-0.8f;/ Set Vertical Pull Downwardparticleloop.zg=0.0f;/ Set Pull On Z Axis To Zeroreturn TRUE;/ Initialization Went OKint DrawGLScene(GLvoid)/ Here's Where We Do All The DrawingglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);/ Clear Screen And Depth BufferglLoadIdentity();/ Reset The ModelView Matrixfor (loop=0;loop<MAX_PARTICLES;loop+)/ Loop Through All The Particlesif (particleloop.active)/ If The Particle Is Activefloat x=particleloop.x;/ Grab Our Particle X Positionfloat y=particleloop.y;/ Grab Our Particle Y Positionfloat z=particleloop.z+zoom;/ Particle Z Pos + Zoom/ Draw The Particle Using Our RGB Values, Fade The Particle Based On It's LifeglColor4f(particleloop.r,particleloop.g,particleloop.b,particleloop.life);glBegin(GL_TRIANGLE_STRIP);/ Build Quad From A Triangle Strip glTexCoord2d(1,1); glVertex3f(x+0.5f,y+0.5f,z); / Top RightglTexCoord2d(0,1); glVertex3f(x-0.5f,y+0.5f,z); / Top LeftglTexCoord2d(1,0); glVertex3f(x+0.5f,y-0.5f,z); / Bottom RightglTexCoord2d(0,0); glVertex3f(x-0.5f,y-0.5f,z); / Bottom LeftglEnd();/ Done Building Triangle Stripparticleloop.x+=particleloop.xi/(slowdown*1000);/ Move On The X Axis By X Speedparticleloop.y+=particleloop.yi/(slowdown*1000);/ Move On The Y Axis By Y Speedparticleloop.z+=particleloop.zi/(slowdown*1000);/ Move On The Z Axis By Z Speedparticleloop.xi+=particleloop.xg;/ Take Pull On X Axis Into Accountparticleloop.yi+=particleloop.yg;/ Take Pull On Y Axis Into Accountparticleloop.zi+=particleloop.zg;/ Take Pull On Z Axis Into Accountparticleloop.life-=particleloop.fade;/ Reduce Particles Life By 'Fade'if (particleloop.life<0.0f)/ If Particle Is Burned Outparticleloop.life=1.0f;/ Give It New Lifeparticleloop.fade=float(rand()%100)/1000.0f+0.003f;/ Random Fade Valueparticleloop.x=0.0f;/ Center On X Axisparticleloop.y=0.0f;/ Center On Y Axisparticleloop.z=0.0f;/ Center On Z Axisparticleloop.xi=xspeed+float(rand()%60)-32.0f);/ X Axis Speed And Directionparticleloop.yi=yspeed+float(rand()%60)-30.0f);/ Y Axis Speed And Directionparticleloop.zi=float(rand()%60)-30.0f);/ Z Axis Speed And Directionparticleloop.r=colorscol0;/ Select Red From Color Tableparticleloop.g=colorscol1;/ Select Green From Color Tableparticleloop.b=colorscol2;/ Select Blue From Color Table/ If Number Pad 8 And Y Gravity Is Less Than 1.5 Increase Pull Upwardsif (keysVK_NUMPAD8 && (particleloop.yg<1.5f) particleloop.yg+=0.01f;/ If Number Pad 2 And Y Gravity Is Greater Than -1.5 Increase Pull Downwardsif (keysVK_NUMPAD2 && (particleloop.yg>-1.5f) particleloop.yg-=0.01f;/ If Number Pad 6 And X Gravity Is Less Than 1.5 Increase Pull Rightif (keysVK_NUMPAD6 && (particleloop.xg<1.5f) particleloop.xg+=0.01f;/ If Number Pad 4 And X Gravity Is Greater Than -1.5 Increase Pull Leftif (keysVK_NUMPAD4 && (particleloop.xg>-1.5f) particleloop.xg-=0.01f;if (keysVK_TAB)/ Tab Key Causes A Burstparticleloop.x=0.0f;/ Center On X Axisparticleloop.y=0.0f;/ Center On Y Axisparticleloop.z=0.0f;/ Center On Z Axisparticleloop.xi=float(rand()%50)-26.0f)*10.0f;/ Random Speed On X Axisparticleloop.yi=float(rand()%50)-25.0f)*10.0f;/ Random Speed On Y Axisparticleloop.zi=float(rand()%50)-25.0f)*10.0f;/ Random Speed On Z Axis return TRUE;/ Everything Went OKGLvoid KillGLWindow(GLvoid)/ Properly Kill The Windowif (fullscreen)/ Are We In Fullscreen Mode?ChangeDisplaySettings(NULL,0);/ If So Switch Back To The DesktopShowCursor(TRUE);/ Show Mouse Pointerif (hRC)/ Do We Have A Rendering Context?if (!wglMakeCurrent(NULL,NULL)/ Are We Able To Release The DC And RC Contexts?MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);if (!wglDeleteContext(hRC)/ Are We Able To Delete The RC?MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);hRC=NULL;/ Set RC To NULLif (hDC && !ReleaseDC(hWnd,hDC)/ Are We Able To Release The DCMessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);hDC=NULL;/ Set DC To NULLif (hWnd && !DestroyWindow(hWnd)/ Are We Able To Destroy The Window?MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);hWnd=NULL;/ Set hWnd To NULLif (!UnregisterClass("OpenGL",hInstance)/ Are We Able To Unregister ClassMessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);hInstance=NULL;/ Set hInstance To NULL/*This Code Creates Our OpenGL Window. Parameters Are:* *title- Title To Appear At The Top Of The Window* *width- Width Of The GL Window Or Fullscreen Mode* *height- Height Of The GL Window Or Fullscreen Mode* *bits- Number Of Bits To Use For Color (8/16/24/32)* *fullscreenflag- Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE)*

    注意事项

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

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




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开