Skip to content

Particle System

Anton Åsbrink edited this page Feb 15, 2019 · 12 revisions

All particles are held by their respective emitters. Any particle spawned will start with selected values by the emitter.

Creating and linking emitter

Create an emitter object were relevant and link it to the particleManager

renderer.pushParticleManager(&ParticleManager)

ParticleEmitter emitter;
ParticleManager.addEmitter(&emitter);

Running emitter(s)

All updating of emitters and particles are done by calling particle managers update and should be done every logic frame. Emitters can be activated by calling "playEmitter(float)" giving it a duration you want it to be active. By giving it 0 as a duration it will start looping emission.

logicUpdate() {
ParticleManager.update(dt);
}

......

emitter.playEmitter(0.1f) //Will fire particles for 0.1 seconds
emitter.playEmitter(0) // Will fire particles indefinitely

Emitter properties

Emitters start with some default properties but can be changed by calling appropiate functions. Values shown in example are the default values.

emitter.setPosition(glm::vec3(0.0f, 0.0f, 0.0f)) //This is emitter and particle start position
emitter.setVelocity(glm::vec3(0.0f, 0.0f, 0.0f)) //This is how fast particles exit emitter
emitter.setAcceleration(glm::vec3(0.0f, 0.0f, 0.0f)) //How fast particles accelerate over its life
emitter.setMaxParticle(100) //Maximum amount of particles for emitter
emitter.setSpawnRate(10) //How many particles are spawned per second
emitter.setLifeTime(10.0f) //How long the particles are alive, if it is a indefinitely emitter then this should be MaxParticle/SpawnRate
emitter.setStartColour(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)) //What colour particles start as. Overrides setEndColour
emitter.setEndColour(glm::Vec4(1.0f, 1.0f, 1.0f, 1.0f)) //What colour particles will be at their end of life. setStartColour overwrites endColour and should changing colour be used then this function should be called after setStartColour
emitter.setScale(1.0f) //How big the particles start as
emitter.setScaleChange(1.0f) //How much particles change per second. 0.9f to reduce scale by 10% per second and 1.1f to increase scale by 10%
emitter.setSpread(0.0f) //How much velocity will randomly modify in all directions

Clone this wiki locally