




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验八:粒子系统姓名:班级:数字媒体与技术11(1)学号:2011329700132一、实验目的掌握粒子系统的的原理,熟悉Ogre中粒子系统的结构和使用方法.二、实验仪器Visual Studio 2005三、实验原理及过程/利用Ogre实现一个粒子系统效果,并描述程序实现时的思路包括对每个调用的API以及脚本进行详细说明粒子是用四边形来表示的。它有长宽,和其方向,有数量和材质,还有重量。这些属性封在粒子属性变换器(Affector)中,Affector中包含颜色衰退变换器(ColourFaderAffector)和线形影响变换器(LinearForceAffector)。粒子的产生由粒子发生器(Emmiter)产生。它包含有盒状粒子发生器(BoxEmmitter)和点状粒子发生器( PointEmmiter),由这些组成粒子脚本文件,以.particle为其扩展名。点状粒子发生器随机地从单一的点发射粒子;盒状粒子发生器随机的从一个区域发射粒子。通过创建Plugins你可以向ogre里增加一个新的发射器。当前ogre只支持点状粒子发生器和盒状粒子发射器。当粒子发生器不停的喷发出大量粒子时,就可以形成烟、火和爆炸等效果。 粒子系统结构图:粒子系统脚本OGRE提供了粒子系统脚本语言,可以在脚本中设置粒子的各种属性,而不用重新编译程序。这样给使用者带来了方便。需要注意的粒子系统脚本文件有自己的语法,类似C+:注释用“/”,用“ ”来区分界限。但不支持在代码后跟注释。粒子系统在脚本中是以模板的形式定义的,你可以在程序运行期创建多个实例。 载入粒子脚本粒子系统脚本是在系统初始化的时候载入的,缺省情况下系统在公共资源路径(Root:addResourceLocation函数指定)下查找所有扩展名为“.particle”的文件并解析它们。如果你想指定其它扩展名可使用ParticleSystemManager:getSingleton().parseAllSources方法,如果想解析单个的粒子系统脚本文件可使用ParticleSystemManager:getSingleton().parseScript方法。一旦粒子系统脚本被载入,你可以使用ParticleSystemManager:getSingleton().createSystem()方法来创建一个实例化的粒子系统,该方法接收两个参数,一个该粒子系统的名称,而另外一个参数是要参照的模板名称(也就是脚本中定义过的模板名称。格式可以在一个脚本文件中定义多个粒子系统模板。以下是一个典型的粒子脚本,该脚本包含三个粒子系统模板,它被用于OGRE的粒子DEMO中,你可以运行该DEMO来查看实际效果。当然你也可以修改这些属性来改变效果。 / 粒子系统模板名/ Exudes greeny particles which float upwardsExamples/GreenyNimbus/ 粒子的Materialmaterial Examples/Flare/ 粒子的宽度particle_width 30/ 粒子的高度particle_height 30/ 粒子的裁剪模式:整体包围盒裁剪或单个粒子裁剪。cull_each false/ 粒子数目quota 10000/ 公告板的类型:point指代表粒子的四边形总是面向摄像机。billboard_type point/ 盒状粒子发射器emitter Box/ 粒子发射时偏离direction的最大角度angle 30/ 发射速率(个/秒)emission_rate 30/ 粒子生存时间(秒)time_to_live 50/ 粒子的发射方向direction 0 1 0/ 速率velocity 10/ 颜色起始值colour_range_start 1 1 0/ 颜色结束值(在起始值和结束值之间取随机数)colour_range_end 0.3 1 0.3/ 定义粒子发射器BOX的大小width 60height 60depth 60/ LinearForce:对运动中的粒子的加上一个外力,影响其运动轨迹。/ Make em float upwardsaffector LinearForce/ 指定外力的影响(用向量表示)force_vector 0 100 0/ add:粒子的运动向量加上外力的向量。效果:匀加速运动。force_application add/ ColourFader:影响粒子中的颜色/ Faderaffector ColourFader/ 每秒衰减0.25red -0.25green -0.25blue -0.25/ A sparkly purple fountainExamples/PurpleFountainmaterial Examples/Flare2particle_width 20particle_height 20cull_each falsequota 10000billboard_type oriented_self/ Area emitteremitter Pointangle 15emission_rate 75time_to_live 3direction 0 1 0velocity_min 250velocity_max 300/颜色变换上下限colour_range_start 0 0 0colour_range_end 1 1 1/ Gravityaffector LinearForceforce_vector 0 -100 0force_application add/ Faderaffector ColourFaderred -0.25green -0.25blue -0.25/ A downpourExamples/Rainmaterial Examples/Dropletparticle_width 50particle_height 100cull_each truequota 10000/ Make common direction straight down (faster than self oriented)billboard_type oriented_commoncommon_direction 0 -1 0/ Area emitteremitter Boxangle 0emission_rate 100time_to_live 5direction 0 -1 0velocity 50colour_range_start 0.3 1 0.3colour_range_end 0.7 1 0.7width 1000height 1000depth 0/ Gravityaffector LinearForceforce_vector 0 -200 0force_application add脚本中的每一个粒子系统模板都必须有一个名字,且必须是在“”前的第一行。这个名称必须是唯一的。名字中可以包含“/”来构成路径,但OGRE引擎只把它当成字符串看待,并不真正来分析这个路径,它仅仅方便程序员来区分层次。一个粒子系统可以设置一些上层属性,如:quota 表示允许的最大粒子个数。除了基本属性外,还必须在一个粒子系统模板内嵌套定义发射器Emitters和属性变换器affectors。它们内部的属性与它们的类型有关。四、实验结果五、实验心得六、主要代码#include ProceduralManualObject.h#include OgreRenderToVertexBuffer.h#include RandomTools.h#include SamplePlugin.h#include SdkSample.husing namespace Ogre;using namespace OgreBites;/#define LOG_GENERATED_BUFFERVector3 GRAVITY_VECTOR = Vector3(0, -9.8, 0);Real demoTime = 0;ProceduralManualObject* particleSystem;#ifdef LOG_GENERATED_BUFFERstruct FireworkParticle float pos3;float timer;float type;float vel3;#endifclass _OgreSampleClassExport Sample_ParticleGS : public SdkSamplepublic: Sample_ParticleGS() mInfoTitle = Particle Effects (GPU);mInfoDescription = A demo of GPU-accelerated particle systems using geometry shaders and render to vertex buffers.;mInfoThumbnail = thumb_particlegs.png;mInfoCategory = Effects; protected:ProceduralManualObject* createProceduralParticleSystem()particleSystem = static_cast(mSceneMgr-createMovableObject(ParticleGSEntity, ProceduralManualObjectFactory:FACTORY_TYPE_NAME);particleSystem-setMaterial(Ogre/ParticleGS/Display);/Generate the geometry that will seed the particle systemManualObject* particleSystemSeed = mSceneMgr-createManualObject(ParticleSeed);/This needs to be the initial launcher particleparticleSystemSeed-begin(Ogre/ParticleGS/Display, RenderOperation:OT_POINT_LIST);particleSystemSeed-position(0,0,0); /PositionparticleSystemSeed-textureCoord(1); /TimerparticleSystemSeed-textureCoord(0); /TypeparticleSystemSeed-textureCoord(0,0,0); /VelocityparticleSystemSeed-end();/Generate the RenderToBufferObjectRenderToVertexBufferSharedPtr r2vbObject = HardwareBufferManager:getSingleton().createRenderToVertexBuffer();r2vbObject-setRenderToBufferMaterialName(Ogre/ParticleGS/Generate);/Apply the random textureTexturePtr randomTexture = RandomTools:generateRandomVelocityTexture();r2vbObject-getRenderToBufferMaterial()-getTechnique(0)-getPass(0)-getTextureUnitState(RandomTexture)-setTextureName(randomTexture-getName(), randomTexture-getTextureType();r2vbObject-setOperationType(RenderOperation:OT_POINT_LIST);r2vbObject-setMaxVertexCount(16000);r2vbObject-setResetsEveryUpdate(false);VertexDeclaration* vertexDecl = r2vbObject-getVertexDeclaration();size_t offset = 0;offset += vertexDecl-addElement(0, offset, VET_FLOAT3, VES_POSITION).getSize(); /Positionoffset += vertexDecl-addElement(0, offset, VET_FLOAT1, VES_TEXTURE_COORDINATES, 0).getSize(); /Timeroffset += vertexDecl-addElement(0, offset, VET_FLOAT1, VES_TEXTURE_COORDINATES, 1).getSize(); /Typeoffset += vertexDecl-addElement(0, offset, VET_FLOAT3, VES_TEXTURE_COORDINATES, 2).getSize(); /Velocity/Bind the two togetherparticleSystem-setRenderToVertexBuffer(r2vbObject);particleSystem-setManualObject(particleSystemSeed);/Set boundsAxisAlignedBox aabb;aabb.setMinimum(-100,-100,-100);aabb.setMaximum(100,100,100);particleSystem-setBoundingBox(aabb);return particleSystem; void setupContent(void) / Check capabilitiesconst RenderSystemCapabilities* caps = Root:getSingleton().getRenderSystem()-getCapabilities(); if (!caps-hasCapability(RSC_GEOMETRY_PROGRAM) OGRE_EXCEPT(Exception:ERR_NOT_IMPLEMENTED, Your render system / hardware does not support geometry programs, so cannot run this demo. Sorry!, Sample_ParticleGS:createScene); if (!caps-hasCapability(RSC_HWRENDER_TO_VERTEX_BUFFER) OGRE_EXCEPT(Exception:ERR_NOT_IMPLEMENTED, Your render system / hardware does not support render to vertex buffers, so cannot run this demo. Sorry!, Sample_ParticleGS:createScene); static bool firstTime = true;if (firstTime)Root:getSingleton().addMovableObjectFactory(new ProceduralManualObjectFactory);firstTime = false;ProceduralManualObject* particleSystem = createProceduralParticleSystem();mSceneMgr-getRootSceneNode()-createChildSceneNode()-attachObject(particleSystem);/mSceneMgr-getRootSceneNode()-createChildSceneNode()-attachObject(particleSystem-getManualObject();mCamera-setPosition(0,35,-100);mCamera-lookAt(0,35,0);/Add an ogre head to the sceneSceneNode* ogreHeadSN = mSceneMgr-getRootSceneNode()-createChildSceneNode();Entity *ogreHead = mSceneMgr-createEntity(head, ogrehead.mesh); ogreHeadSN-scale(0.1,0.1,0.1);ogreHeadSN-yaw(Degree(180);ogreHeadSN-attachObject(ogreHead);/Add a plane to the scenePlane plane;plane.normal = Vector3:UNIT_Y;plane.d = 100;MeshManager:getSingleton().createPlane(Myplane,ResourceGroupManager:DEFAULT_RESOURCE_GROUP_NAME, plane,1500,1500,20,20,true,1,60,60,Vector3:UNIT_Z);Entity* pPlaneEnt = mSceneMgr-createEntity( plane, Myplane );pPlaneEnt-setMaterialName(Examples/Rockwall);pPlaneEnt-setCastShadows(false);mSceneMgr-getRootSceneNode()-createChildSceneNode(Vector3(0,95,0)-attachObject(pPlaneEnt); bool frameStarted(const FrameEvent& evt) /Set shader parametersGpuProgramParametersSharedPtr geomParams = particleSystem-getRenderToVertexBuffer()-getRenderToBufferMaterial()-getTechnique(0)-getPass(0)-getGeometryProgramParameters();geomParams-setNamedConstant(elapsedTime, evt.timeSinceLastFrame);demoTime += evt.timeSinceLastFrame;geomParams-setNamedConstant(globalTime, demoTime);geomParams-setNamedConstant(frameGravity, GRAVITY_VECTOR * evt.timeSinceLastFrame);return SdkSample:frameStarted(evt); #ifdef LOG_GENERATED_BUFFERbool frameEnded(const FrameEvent& evt) /This will only work if the vertex buffer usage is dynamic (see R2VB implementation)LogManager:getSingleton().getDefaultLog()-stream() Particle system for frame getRenderToVer
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 骨科病房护理要点与实践
- 牵引术护理要点
- 生产管理:运作战略管理
- 2025届广东汕尾甲子镇瀛江学校八年级数学第二学期期末联考模拟试题含解析
- 血液臭氧治疗
- 重症护理核心理念与实务
- 手写护理文书标准化管理
- 高一新生住宿管理规范与实施策略
- 与法律有关的职业考试题及答案
- 经典诵读活动总结模版
- 电费优化与节约的管理方法及其应用分析报告
- 彩钢板围挡搭设施工方案
- 山东2025年山东省烟草专卖局(公司)高校毕业生招聘208人笔试历年参考题库附带答案详解
- 船舶工程设备租赁保障措施
- 焊工(初级)实操理论考试1000题及答案
- 《人工智能在财务稽查领域中的应用》
- 统编版五年级语文水浒传整本书阅读交流课 公开课一等奖创新教学设计
- 2025年小学生入队的试题及答案
- 武汉2025届高中毕业生二月调研考试数学试题及答案
- 工程造价咨询项目委托合同
- 基于嵌入式STM32模块的多功能电子秤设计16000字论文
评论
0/150
提交评论