Axiom.ParticleFX.ColorImageAffector.AffectParticles C# (CSharp) Method

AffectParticles() public method

public AffectParticles ( ParticleSystem system, float timeElapsed ) : void
system ParticleSystem
timeElapsed float
return void
		public override void AffectParticles( ParticleSystem system, float timeElapsed )
		{
			if ( !colorImageLoaded )
			{
				loadImage();
			}

			int width = colorImage.Width - 1;
			float height = colorImage.Height - 1;

			// loop through the particles
			for ( int i = 0; i < system.Particles.Count; i++ )
			{
				Particle p = (Particle)system.Particles[ i ];

				// life_time, float_index, index and position are CONST in OGRE, but errors here

				// We do not have the concept of a total time to live!
				float life_time = p.totalTimeToLive;
				float particle_time = 1.0f - ( p.timeToLive / life_time );

				if ( particle_time > 1.0f )
				{
					particle_time = 1.0f;
				}
				if ( particle_time < 0.0f )
				{
					particle_time = 0.0f;
				}

				float float_index = particle_time * width;
				int index = (int)float_index;
				int position = index * 4;

				if ( index <= 0 )
				{
					p.Color = colorImage.GetColorAt( 0, 0, 0 );
				}
					else if ( index >= width )
				{
					p.Color = colorImage.GetColorAt( width, 0, 0 );
				}
				else
				{
					// fract, to_color and from_color are CONST in OGRE, but errors here
					float fract = float_index - (float)index;
					float toColor = fract;
					float fromColor = (1 - toColor );

					ColorEx from = colorImage.GetColorAt( index, 0, 0 ),
							to = colorImage.GetColorAt( index + 1, 0, 0 );

					p.Color.r = ( from.r * fromColor ) + ( to.r * toColor );
					p.Color.g = ( from.g * fromColor ) + ( to.g * toColor );
					p.Color.b = ( from.b * fromColor ) + ( to.b * toColor );
					p.Color.a = ( from.a * fromColor ) + ( to.a * toColor );
				}
			}

		}