In this lab we will be checking out particle systems, This lab will be roughly based on the “The Ogre 3D Startup Sequence” from the book “Ogre 3D 1.7 - Beginner's Guide” by Felix Kerger, Chapter 10.
Discussion thread for this lab is here: Lab 8 Discussion Thread
You will have to create the folder ParticleSystems
where your application can see it. and add the folder into your resource file like you have done in previous labs.
You can use your own project or start fresh with the base application code
// Create a particle system Ogre::ParticleSystem* partSystem = _sceneManager->createParticleSystem("smoke", "Examples/Smoke"); // Attach the particle system to Sinbad _SinbadNode->attachObject(partSystem);
*.particle
files so create a file MyParticleSystem.particle
in your ParticleSystems folder.particle_system MySmoke1 { // Make the particles use the "Examples/Smoke" material, and be 10x10 units large. material Examples/Smoke particle_width 10 particle_height 10 // Make the emitter limit the emitter to have at maximum 500 particles active. // And set the particle type as point, which always faces the camera. quota 500 billboard_type point // Make the emitters origin a point. emitter Point { // Make the emitter emit 3 particles per second. emission_rate 3 // Emitt the particles in the given direction, at a velocity of 20 units per second. direction 1 0 0 velocity 20 } }
// This will be the range of angle variation the particles will be fired at. angle 30 // Destroy the particle after 10 seconds. time_to_live 10 // Colour the particles red with a fully opaque alpha value. colour 1 0 0 1
// Destroy the particle after 1 to 4 seconds. time_to_live_min 1 time_to_live_max 10 // Colour the particles linearly interpolated from red to blue. colour_range_start 1 0 0 colour_range_end 0 0 1
emission_rate, direction and velocity
. And we will now modify the behaviour of the emitter, giving it a emission duration and restart delay. Lets make it emit particles for 1 second and then stop for one second before starting again. // Emit particles for 1 second at a time with a 1 second interval. duration 1 repeat_delay 1
emission rate, velocity and direction
. And set the time_to_live 10
. See: Affector Reference.affector Scaler { rate 10 }
// This affector will add the following values to the colour of the particles each second.þ affector ColourFader { red 0.0 green -0.25 blue -0.25 }
Color fader has some additional functionality, like changing the color in two stages.
// This affector will add the following values to the colour of the particles each second. // Notice the suffix of the ColorFader(2), that is important. affector ColourFader2 { // Notice the suffix here also, red(1) this indicates the color change per second for state 1 red1 0.0 green1 -1 blue1 -1 // Set the second state when the particle has 2 second left to live. state_change 2 // And here is has the suffix 2, which in turn sets the change per second for state 2 red2 0 green2 +1 blue2 +1 // This is all works for the alpha channel to of course. alpha2 -1 }
time# scale
, and colours are given in the form colour# r g b a
. Lets create a jolly little stream: // ColourInterpolators can have up to 6 colour intervals indexed 0 to 5. affector ColourInterpolator { time0 0 colour0 1 0 0 0 time1 0.195 colour1 1 1 0 1 time2 0.39 colour2 0 1 1 1 time3 0.585 colour3 0 0 1 1 time4 0.78 colour4 1 0 1 1 time5 1 colour5 0 1 0 0 }
Note: You have to define the default colour as colour 1 0 0 0
in the point_emitter block to eliminate the stuttering when the particles spawn. Just remember to remove that for the next step.
// This will make the particles fly around like they have no tomorrow. affector DirectionRandomiser { // This indicates the magnitude of the random choices the particle makes. randomness 1000 // Scope governs the chance that a given particle takes a random direction change scale from 0..1 ~ 0-100% scope 1 // Here you can indicate if the particle should randomize its velocity or not. <true|false> keep_velocity true }
This could be useful for a pile of fireworks catching fire?, or a swarm of mosquitoes.
// Deflector planes bounce the particles of the given plane. affector DeflectorPlane { //The point of the plane, note: the plane is infinite plane_point 10 0 0 // The normal vector of the plane, the direction of the particles will be mirror around this normal. plane_normal -0.7 0.7 0 // The amount of velocity the particles retain after the collision. bounce 1.0 } // You can provide more than one plane. affector DeflectorPlane { plane_point 10 15 0 plane_normal -0.7 -0.7 0 bounce 1.0 }
Das Bonus von GEDE!
// Attach a sword to Sinbads right hand. // Create the sword entity. Ogre::Entity* sword = _sceneManager->createEntity("Sword.mesh"); // Attach the sword to Sinbads right hand. _SinbadEnt->attachObjectToBone("Handle.R", sword); // Clasp Sinbads hands around the hilt of the sword. _SinbadEnt->getAnimationState("HandsClosed")->setEnabled(true);
// Use this as a base for your fireworks :) particle_system Fireworks { // Make the particles use the "Examples/Flare" material, and be 1x1 units large. material Examples/Flare particle_width 1 particle_height 1 // Make the emitter limit the emitter to have at maximum 2000 particles active. // And set the particle type as point, which always faces the camera. quota 2000 billboard_type point // The maximum amount of emitter emitters emit_emitter_quota 10 // Make the emitters origin a Point. emitter Point { // tell the particles to emitt the "bomb emitter" described below emit_emitter bomb // Fire one firework per second emission_rate 1 // Make the particles go up. direction 0 1 0 velocity 70 time_to_live 2 } // The emitter emitted by the particles above emitter Point { // Name the emitter to match the name in the emit_emitter block name bomb // Configure the explosion. emission_rate 200 velocity 30 // How long should the firework emit duration_min 0.1 duration_max 0.2 // This is used to make sure the particles in the emitter emitter dont fire while the particle is in mid flight. repeat_delay_min 1 repeat_delay_max 1.9 time_to_live_min 0.3 time_to_live_max 0.4 } // Add some pseudo gravity. affector LinearForce { force_vector 0 -50 0 } }
Note: Affectors affect both the emitter and the emitter emitter :)
Upload your commented source files into Lab8 in MySchool (zip them up if more than one). The lab projects will not be graded, but their completion counts towards your participation grade.