Abstract class defining the interface to be implemented by particle emitters.
Particle emitters are the sources of particles in a particle system. This class defines the ParticleEmitter interface, and provides a basic implementation for tasks which most emitters will do (these are of course overridable). Particle emitters can be grouped into types, e.g. 'point' emitters, 'box' emitters etc; each type will create particles with a different starting point, direction and velocity (although within the types you can configure the ranges of these parameters).

Because there are so many types of emitters you could use, the engine chooses not to dictate the available types. It comes with some in-built, but allows plugins or games to extend the emitter types available. This is done by subclassing ParticleEmitter to have the appropriate emission behavior you want, and also creating a subclass of ParticleEmitterFactory which is responsible for creating instances of your new emitter type. You register this factory with the ParticleSystemManager using AddEmitterFactory, and from then on emitters of this type can be created either from code or through XML particle scripts by naming the type.

This same approach is used for ParticleAffectors (which modify existing particles per frame). This means that the engine is particularly flexible when it comes to creating particle system effects, with literally infinite combinations of emitter and affector types, and parameters within those types.

Inheritance: IConfigurable
Ejemplo n.º 1
0
			/// <see cref="Translator.Translate"/>
			public override void Translate( ScriptCompiler compiler, AbstractNode node )
			{
				ObjectAbstractNode obj = (ObjectAbstractNode)node;

				// Must have a type as the first value
				if ( obj.Values.Count == 0 )
				{
					compiler.AddError( CompileErrorCode.StringExpected, obj.File, obj.Line );
					return;
				}

				string type = string.Empty;
				if ( !getString( obj.Values[ 0 ], out type ) )
				{
					compiler.AddError( CompileErrorCode.InvalidParameters, obj.File, obj.Line );
					return;
				}

				ParticleSystem system = (ParticleSystem)obj.Parent.Context;
				_Emitter = system.AddEmitter( type );

				foreach ( AbstractNode i in obj.Children )
				{
					if ( i is PropertyAbstractNode )
					{
						PropertyAbstractNode prop = (PropertyAbstractNode)i;
						string value = string.Empty;

						// Glob the values together
						foreach ( AbstractNode it in prop.Values )
						{
							if ( it is AtomAbstractNode )
							{
								if ( string.IsNullOrEmpty( value ) )
									value = ( (AtomAbstractNode)it ).Value;
								else
									value = value + " " + ( (AtomAbstractNode)it ).Value;
							}
							else
							{
								compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
								break;
							}
						}

						if ( !_Emitter.SetParam( prop.Name, value ) )
						{
							compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
						}
					}
					else
					{
						_processNode( compiler, i );
					}
				}
			}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="emitter"></param>
        public virtual void CopyTo(ParticleEmitter emitter)
        {
            // loop through all registered commands and copy from this instance to the target instance
            foreach(DictionaryEntry entry in commandTable) {
                string name = (string)entry.Key;

                // get the value of the param from this instance
                string val = ((ICommand)entry.Value).Get(this);

                // set the param on the target instance
                emitter.SetParam(name, val);
            }
        }
Ejemplo n.º 3
0
		/// <summary>
		///
		/// </summary>
		/// <param name="emitter"></param>
		public virtual void CopyTo( ParticleEmitter emitter )
		{
			// loop through all registered commands and copy from this instance to the target instance
			foreach ( string key in commandTable.Keys )
			{
				// get the value of the param from this instance
				string val = ( (IPropertyCommand)commandTable[ key ] ).Get( this );

				// set the param on the target instance
				emitter.SetParam( key, val );
			}
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="line"></param>
        /// <param name="emitter"></param>
        private void ParseEmitterAttrib(string line, ParticleEmitter emitter)
        {
            string[] values = line.Split(new char[] {' '}, 2);

            if(!(emitter.SetParam(values[0], values[1]))) {
                ParseHelper.LogParserError(values[0], emitter.Type, "Command not found.");
            }
        }
Ejemplo n.º 5
0
		// Just override the mandatory create scene method
		public override void CreateScene()
		{
			RAND = new Random( 0 ); // najak: use a time-based seed
			GuiMgr = OverlayManager.Instance.Elements;
			scene.AmbientLight = new ColorEx( 0.75f, 0.75f, 0.75f ); // default Ambient Light
			// Customize Controls - speed up camera and slow down the input update rate
			this.camSpeed = 5.0f;
			inputInterval = inputTimer = 0.02f;

			// Create water mesh and entity, and attach to sceneNode
			waterMesh = new WaterMesh( "WaterMesh", PLANE_SIZE, CMPLX );
			waterEntity = scene.CreateEntity( "WaterEntity", "WaterMesh" );
			SceneNode waterNode = scene.RootSceneNode.CreateChildSceneNode();
			waterNode.AttachObject( waterEntity );

			// Add Ogre head, give it it's own node
			headNode = waterNode.CreateChildSceneNode();
			Entity ent = scene.CreateEntity( "head", "ogrehead.mesh" );
			headNode.AttachObject( ent );

			// Create the camera node, set its position & attach camera
			camera.Yaw( -45f );
			camera.Move( new Vector3( 1500f, 700f, PLANE_SIZE + 700f ) );
			camera.LookAt( new Vector3( PLANE_SIZE / 2f, 300f, PLANE_SIZE / 2f ) );
			camera.SetAutoTracking( false, headNode ); // Autotrack the head, but it isn't working right

			//scene.SetFog(FogMode.Exp, ColorEx.White, 0.000020f); // add Fog for fun, cuz we can

			// show overlay
			waterOverlay = OverlayManager.Instance.GetByName( "Example/WaterOverlay" );
			waterOverlay.Show();

			// Create Rain Emitter, but default Rain to OFF
			particleSystem = ParticleSystemManager.Instance.CreateSystem( "rain", "Examples/Water/Rain" );
			particleEmitter = particleSystem.GetEmitter( 0 );
			particleEmitter.EmissionRate = 0f;

			// Attach Rain Emitter to SceneNode, and place it 3000f above the water surface
			SceneNode rNode = scene.RootSceneNode.CreateChildSceneNode();
			rNode.Translate( new Vector3( PLANE_SIZE / 2.0f, 3000, PLANE_SIZE / 2.0f ) );
			rNode.AttachObject( particleSystem );
			particleSystem.FastForward( 20 ); // Fastforward rain to make it look natural

			// It can't be set in .particle file, and we need it ;)
			//particleSystem.Origin = BillboardOrigin.BottomCenter;

			// Set Lighting
			lightNode = scene.RootSceneNode.CreateChildSceneNode();
			lightSet = scene.CreateBillboardSet( "Lights", 20 );
			lightSet.MaterialName = "Particles/Flare";
			lightNode.AttachObject( lightSet );
			SetLighting( "Ambient" ); // Add Lights - added by Najak to show lighted Water conditions - cool!

			#region STUBBED LIGHT ANIMATION
			// Create a new animation state to track this
			// TODO: Light Animation not working.
			//this.animState = scene.CreateAnimationState("WaterLight");
			//this.animState.Time = 0f;
			//this.animState.IsEnabled = false;

			// set up spline animation of light node.  Create random Spline
			Animation anim = scene.CreateAnimation( "WaterLight", 20 );
			AnimationTrack track = anim.CreateNodeTrack( 0, this.lightNode );
			TransformKeyFrame key = (TransformKeyFrame)track.CreateKeyFrame( 0 );
			for ( int ff = 1; ff <= 19; ff++ )
			{
				key = (TransformKeyFrame)track.CreateKeyFrame( ff );
				Random rand = new Random( 0 );
				Vector3 lpos = new Vector3(
					(float)rand.NextDouble() % (int)PLANE_SIZE, //- PLANE_SIZE/2,
					(float)rand.NextDouble() % 300 + 100,
					(float)rand.NextDouble() % (int)PLANE_SIZE ); //- PLANE_SIZE/2
				key.Translate = lpos;
			}
			key = (TransformKeyFrame)track.CreateKeyFrame( 20 );
			#endregion STUBBED LIGHT ANIMATION

			// Initialize the Materials/Demo
			UpdateMaterial();
			UpdateInfoParamC();
			UpdateInfoParamD();
			UpdateInfoParamU();
			UpdateInfoParamT();
			UpdateInfoNormals();
			UpdateInfoHeadDepth();
			UpdateInfoSkyBox();
			UpdateInfoHeadSpeed();
			UpdateInfoLights();
			UpdateInfoTracking();

			// Init Head Animation:  Load adds[] elements - Ogre head animation
			adds[ 0 ] = 0.3f;
			adds[ 1 ] = -1.6f;
			adds[ 2 ] = 1.1f;
			adds[ 3 ] = 0.5f;
			sines[ 0 ] = 0;
			sines[ 1 ] = 100;
			sines[ 2 ] = 200;
			sines[ 3 ] = 300;

		} // end CreateScene()
Ejemplo n.º 6
0
			public ParticleEmitterTranslator()
				: base()
			{
				_Emitter = null;
			}
Ejemplo n.º 7
0
		/// <summary>
		///		Destroys the emitter referenced by the parameter.
		/// </summary>
		/// <param name="emitter"></param>
		public virtual void Destroy( ParticleEmitter emitter )
		{
			// remove the emitter from the list
			this.emitterList.Remove( emitter );
		}