Extending The Default Particle Classes

Top  Previous  Next

If you want to use one of the default particle system classes, but find that its corresponding particle class doesn't have all of the particle properties you require, you can create a new particle class that inherits from the default particle system's particle class.  When creating the new particle class be sure to override the Reset() and CopyFrom() functions properly.  Below is an example of how to extend the default quad particle class to add a Temperature property:


class TemperatureParticle : DefaultQuadParticle


       public float Temperature;


       public override void Reset()



               Temperature = 0.0f;



       public override void CopyFrom(DPSFParticle ParticleToCopy)


           // Cast the Particle to the type it really is

          TemperatureParticle cParticleToCopy = (TemperatureParticle)ParticleToCopy;



           Temperature = cParticleToCopy.Temperature;




Once you have the new particle class created, instead of having your particle system inherit from the Default particle system class, have it inherit from the DPSF Default particle system class, as these allow you to specify the particle class and vertex structure you want the default particle system class to use.  Below is an example of how to declare a particle system class that inherits from the default point sprite particle system and uses the new TemperatureParticle particle class:


class TemperatureParticleSystem : DPSFDefaultQuadParticleSystem<TemperatureParticle, DefaultQuadParticleVertex>



For more examples of extending the default particle classes, see the Box and Image particle systems' source code included in DPSF Demo.


If you also wish to use custom shaders, you may also create a new particle vertex structure and override the UpdateVertexProperties() function to copy a particle's drawable properties into the vertex buffer.