NeHe OpenGL Lesson19 – Particle Engine Using Triangle Strips(粒子引擎)

本文介绍了一种简单的粒子引擎,粒子效果在游戏中至关重要,可用于模拟爆炸、水泉、燃烧的星星等。粒子由一组三角形广告牌组成,每个粒子具有位置、运动方向与速度、颜色等属性。文章探讨了粒子初始化、生命周期内更新(包括颜色渐变)、重新激活等关键点,并提出改进方案,如在3D场景中任意位置生成粒子、基于规则生成、沿曲线改变属性等。

screen_shot1-300x238 Here is a simple particle engine. The particle effect is a very important element in game. It could be used simulate an explosion, water fountain, flaming star and so on.
Generally speaking, a particle is a group of triangle billboards.  Each triangle has position, moving direction & speed, moving accelerate direction & speed, gravity, life time, whether active or not, color attributes and so on. During their life time, their color attribute will fade in and fade out.  And those triangles will always face to the view camera no matter how the camera set up.

 

Something Further

This program covers almost all key points of a particle engine. Some thing like initialize the particle triangle attributes, update them during their life time (include fade in & fade out the color), then de-active or re-active them if they run out of their life time. Well, but still some thing more we could improve:
1) The particle engine spawn triangle strip billboards in the fixed z-axes. We could make the particle billboards be spawned at any location in the 3D scene. And at the same time, we will make those triangles face toward the view camera.
2) We could make particle billboards be spawned based on some rules. Like, spawn them in a box, among a sphere, along a circle, cylinder or even a quadrics surface. This will make them more real, more cool.
3) Those attributes that change along the time-line could be linear as this program does. Or even more complicated, how about changing along a curve?
4) More attributes works with more complicated material could be changing along time-line. Like texture coordinates, vertex color, scale size and so on.
5) A better solution to design a particle engine is separate those attributes that need to change as time goes. That means you need to design two vertex array: dynamic one for those vertex attribute that need to change, and a static one for other stuff. This ways is called un-rolled data structure. It is deserved as you strong feel that the particle engine part become the bottle neck of the program. But as the same time, you need to think carefully before you apply this solution into your project. Because this will break object-oriented rule, and make the source code not so easy to understand. This may involved a big change in code, and break the stable version. Think twice! The other way could be reducing the number of the particles.

 

The following code(particle attributes updating) are the core of this particle engine. You could modify them based on your plan here.

particle[loop].x+=particle[loop].xi/(slowdown*1000);// Move On The X Axis By X Speed
particle[loop].y+=particle[loop].yi/(slowdown*1000);// Move On The Y Axis By Y Speed
particle[loop].z+=particle[loop].zi/(slowdown*1000);// Move On The Z Axis By Z Speed
 
particle[loop].xi+=particle[loop].xg;            // Take Pull On X Axis Into Account
particle[loop].yi+=particle[loop].yg;            // Take Pull On Y Axis Into Account
particle[loop].zi+=particle[loop].zg;            // Take Pull On Z Axis Into Account
particle[loop].life-=particle[loop].fade;        // Reduce Particles Life By 'Fade'
 
if (particle[loop].life<0.0f)                    // If Particle Is Burned Out
{
  particle[loop].life=1.0f;                    // Give It New Life
  particle[loop].fade=float(rand()%100)/1000.0f+0.003f;    // Random Fade Value
  particle[loop].x=0.0f;                        // Center On X Axis
  particle[loop].y=0.0f;                        // Center On Y Axis
  particle[loop].z=0.0f;                        // Center On Z Axis
  particle[loop].xi=xspeed+float((rand()%60)-32.0f);    // X Axis Speed And Direction
  particle[loop].yi=yspeed+float((rand()%60)-30.0f);    // Y Axis Speed And Direction
  particle[loop].zi=float((rand()%60)-30.0f);    // Z Axis Speed And Direction
  particle[loop].r=colors[col][0];            // Select Red From Color Table
  particle[loop].g=colors[col][1];            // Select Green From Color Table
  particle[loop].b=colors[col][2];            // Select Blue From Color Table
}

 

The full source code could be downloaded from here.

转载于:https://www.cnblogs.com/open-coder/archive/2012/08/23/2653308.html

内容概要:本文设计了一种基于PLC的全自动洗衣机控制系统内容概要:本文设计了一种,采用三菱FX基于PLC的全自动洗衣机控制系统,采用3U-32MT型PLC作为三菱FX3U核心控制器,替代传统继-32MT电器控制方式,提升了型PLC作为系统的稳定性与自动化核心控制器,替代水平。系统具备传统继电器控制方式高/低水,实现洗衣机工作位选择、柔和过程的自动化控制/标准洗衣模式切换。系统具备高、暂停加衣、低水位选择、手动脱水及和柔和、标准两种蜂鸣提示等功能洗衣模式,支持,通过GX Works2软件编写梯形图程序,实现进洗衣过程中暂停添加水、洗涤、排水衣物,并增加了手动脱水功能和、脱水等工序蜂鸣器提示的自动循环控制功能,提升了使用的,并引入MCGS组便捷性与灵活性态软件实现人机交互界面监控。控制系统通过GX。硬件设计包括 Works2软件进行主电路、PLC接梯形图编程线与关键元,完成了启动、进水器件选型,软件、正反转洗涤部分完成I/O分配、排水、脱、逻辑流程规划水等工序的逻辑及各功能模块梯设计,并实现了大形图编程。循环与小循环的嵌; 适合人群:自动化套控制流程。此外、电气工程及相关,还利用MCGS组态软件构建专业本科学生,具备PL了人机交互C基础知识和梯界面,实现对洗衣机形图编程能力的运行状态的监控与操作。整体设计涵盖了初级工程技术人员。硬件选型、; 使用场景及目标:I/O分配、电路接线、程序逻辑设计及组①掌握PLC在态监控等多个方面家电自动化控制中的应用方法;②学习,体现了PLC在工业自动化控制中的高效全自动洗衣机控制系统的性与可靠性。;软硬件设计流程 适合人群:电气;③实践工程、自动化及相关MCGS组态软件与PLC的专业的本科生、初级通信与联调工程技术人员以及从事;④完成PLC控制系统开发毕业设计或工业的学习者;具备控制类项目开发参考一定PLC基础知识。; 阅读和梯形图建议:建议结合三菱编程能力的人员GX Works2仿真更为适宜。; 使用场景及目标:①应用于环境与MCGS组态平台进行程序高校毕业设计或调试与运行验证课程项目,帮助学生掌握PLC控制系统的设计,重点关注I/O分配逻辑、梯形图与实现方法;②为工业自动化领域互锁机制及循环控制结构的设计中类似家电控制系统的开发提供参考方案;③思路,深入理解PL通过实际案例理解C在实际工程项目PLC在电机中的应用全过程。控制、时间循环、互锁保护、手动干预等方面的应用逻辑。; 阅读建议:建议结合三菱GX Works2编程软件和MCGS组态软件同步实践,重点理解梯形图程序中各环节的时序逻辑与互锁机制,关注I/O分配与硬件接线的对应关系,并尝试在仿真环境中调试程序以加深对全自动洗衣机控制流程的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值