19.8 Particle Systems


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:

  • A particle system maintains a list of particles, and particles are implemented as billboards. Each particle system will have a quota of billboards, which is the maximum number of particles it may have at any one time.

  • The particle system specifies particle properties.

    Each particle in the system needs a size in terms of width and height, and needs a position in 3D space. Furthermore, it needs a texture and color to define its appearance. Also, each particle needs a lifetime, which is a specified period of time in which the particle exists. For example, rain falls from the sky and hits the ground. As it hits the ground, the drop vanishes and more rain falls from the sky. Thus, in this example, a particle lifetime is the period in which the drop falls from the sky and hits the ground, after which the particle expires and the particle system may generate more particles to fall from the sky.

  • Each particle system needs an emitter. This is a point or specified box in 3D space where new particles are generated at a specified rate. For a rain particle system, the emitter will be an appropriately sized box situated in the sky.

  • Finally, a particle system needs a behavior controller that defines how the particles are affected over time. Specifically, it defines how particles move and how they behave. It controls, for example, how raindrops are affected by gravity and fall from the sky to the ground, and whether any drops have their trajectory changed by wind, hail, the sea, or any other factors.

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

image from book
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); 




Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

Similar book on Amazon
Beginning C++ Through Game Programming
Beginning C++ Through Game Programming
Beginning Game Programming
Beginning Game Programming
The Ultimate Guide to Video Game Writing and Design
The Ultimate Guide to Video Game Writing and Design

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net