//The function called each time we need to emit something. //It takes as argument "now" which represent the actual time, //"timeSinceLastCall" which represent... you know what //And an "out" argument (which means that IT MUST BE INITIALIZED INTO THIS FUNCTION), //"Particles" which represents every newly created particle. public void Emit(uint now, uint timeSinceLastCall, out Particle[] Particles) { //YOU ALWAYS MUST INITIALIZE Particles Particles = new Particle[0]; if (now - lastParticleCreation < 100) return; Particles = new Particle[36]; lastParticleCreation = now; //A little offset for the particles to go up and down. Vector3D offset = new Vector3D(0, NewMath.FCos(now) / 10f, 0); //For every particle in our array for (int i = 0; i < 36; i++) { double angle = (Math.PI * 10 * i) / 180.0; //We create the particle Particles[i] = new Particle(); //We set the postion as null... Particles[i].Position = new Vector3D(0, 0, 0); //Particle.Vector represents the direction and speed of the particle. //As you may have seen, I love cosines and sinus and here again I used //it to create a "circle" effect Particles[i].Vector = new Vector3D((float)Math.Cos(angle) / 5f, 0, NewMath.FSin(angle) / 5f) + offset; //Start Vector is the same as the vector... It is useless here but serves for the affector. Particles[i].StartVector = Particles[0].Vector; //Start Time is now and End Time is now + 10 seconds Particles[i].StartTime = now; Particles[i].EndTime = now + 10000; //Color is White and again Start Color is the same... For the same reason as Start Vector ! Particles[i].Color = Color.From(0, _rand.Next(255), _rand.Next(255), _rand.Next(255)); ; Particles[i].StartColor = Particles[0].Color; } }
public void Affect(uint now, Particle[] Particles) { if (now - lastParticleAffect < 200) return; lastParticleAffect = now; //Our color changes every second... Again cosines and sinuses ! Color col = new Color(0, (int)(Math.Cos(now) * 255), (int)(Math.Sin(now) + Math.Cos(now) * 255 / 2), (int)(Math.Sin(now) * 255)); //Here it is very heavy on big particle systems. foreach (Particle part in Particles) //We set the color part.Color = col; }
public void AddAffector(IParticleAffector aff) { OnNativeAffect del = delegate(uint now, IntPtr[] Particles, int count) { Particle[] array = new Particle[count]; for (int i = 0; i < array.Length; i++) array[i] = (Particle)NativeElement.GetObject((IntPtr)Particles[i], typeof(Particle)); aff.Affect(now, array); for (int i = 0; i < array.Length; i++) array[i].Dispose(); array = null; }; AntiGC.Add(del); Particle_AddAffectorA(_raw, del); }