Introduction to Game Programming with C++ (Wordware Game Developers Library)

19.8 Particle Systems

A particle system is a collection of related particles. In this sense, a particle is a small item or object such as a grain of sand, a raindrop, or a snowflake. A particle system is therefore an organized group of objects that not only maintains a list of particles, but controls their behavior and movement. It logically follows then, that a particle system allows the creation of rain, snow, fog, magic dust, and many other effects.

In OGRE, particle systems can be thought of as a collection of billboards, where each billboard is a particle. As mentioned, a billboard is a flat rectangular mesh textured with an image, and this mesh will always face the camera. Specifically, an OGRE particle system has the following properties:

19.8.1 Scripted Particle Systems

In OGRE, particle systems are defined in scripts, much like material scripts. There are specified keywords to define emitters, behavior controllers, particle properties, and so on. And, at run time, the particle system class loads and manages particle systems created from scripts. For information on the finer points of particle systems, consult the OGRE manual. For an example of their general use in an application, consider the following particle script:

// Exudes greeny particles that float upward Examples/GreenyNimbus { material Examples/FlarePointSprite point_rendering true // point rendering means size is controlled by material // provide fallback sizes for hardware that doesn't support point sprite particle_width 30 particle_height 30 cull_each false cull_each false quota 10000 billboard_type point // Area emitter emitter Box { angle 30 emission_rate 30 time_to_live 5 direction 0 1 0 velocity 0 colour_range_start 1 1 0 colour_range_end 0.3 1 0.3 width 60 height 60 depth 60 } // Make 'em float upward affector LinearForce { force_vector 0 100 0 force_application add } // Fader affector ColourFader { red -0.25 green -0.25 blue -0.25 } }

Note 

Notice how this script refers to material Examples/FlarePoint-Sprite by name. This material is defined in a separate material script shown below.

material Examples/FlarePointSprite { technique { pass { lighting off scene_blend add depth_write off point_sprites on point_size 2 point_size_attenuation on texture_unit { texture flare.png } } } }

19.8.2 Loading Particle Systems

Figure 19.2

Once a particle system is defined in script form, it can then be loaded into OGRE using a particle system class. This can be created using the createParticleSystem method of the scene manager. Once created, the particle system exists in memory but, like newly created entities, it is not added to the scene hierarchy. This is achieved by the usual node create and attach methods. Consider the following:

ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("Nimbus", "Examples/GreenyNimbus"); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pSys1);

Категории