/// <summary> /// Creates a new particleEmitter /// </summary> /// <param name="repeat">Should the emitter stay active and keep emitting particles after the max amount of particles have been emitted</param> /// <param name="maxParticles">Max amount of particles</param> /// <param name="emitLocation">The location to emit from</param> /// <param name="direction">The velocity of the particles</param> /// <param name="particleSpeed">The speed of the particles</param> /// <param name="maxAngle">The angle based on the velocity the particles can be emitted from</param> /// <param name="particleLifeTime">Lifetime of particles in seconds</param> /// <param name="particleScale">Size of particles </param> /// <param name="particleShape">Particle shape</param> /// <param name="startColor">Starting particle color</param> /// <param name="autoStart">Should the emitter start immediatly</param> /// <param name="emitType">The type of the emitter</param> /// <param name="endColor">The color of the particle at the end</param> public ParticleEmitter(bool autoStart, bool repeat, int maxParticles, Vector2 emitLocation, Vector2 direction, float particleSpeed, float maxAngle, float particleLifeTime, float particleScale, ParticleShape particleShape, EmitType emitType, Color startColor, Color endColor) { this.repeat = repeat; this.maxParticles = maxParticles; this.Position = emitLocation; this.ParticleDirection = direction; this.particleSpeed = particleSpeed; this.maxAngle = maxAngle; this.particleLifeTime = particleLifeTime; this.particleScale = particleScale; this.particleShape = particleShape; this.emitType = emitType; this.startColor = startColor; this.endColor = endColor; this.Paused = !autoStart; random = new Random(); if (repeat == false) { emitterLifeTime = particleLifeTime; } particleTexture = ParticleSystem.Instance.GetTexture(particleShape); ParticleSystem.Instance.AddEmitter(this); }
public Texture2D GetTexture(ParticleShape particleShape) { if (!textures.ContainsKey(particleShape)) { throw new ArgumentException("Shape doesnt exist in our dictionary"); } return(textures[particleShape]); }
public Particle(int Dim, int HistoryLength, double[] startPos = null, double startAngl = 0.0, ParticleShape shape = ParticleShape.spherical) { m_Dim = Dim; m_HistoryLength = HistoryLength; m_shape = shape; #region Particle history // ============================= for (int i = 0; i < HistoryLength; i++) { currentPos_P.Add(new double[Dim]); currentAng_P.Add(new double()); vel_P.Add(new double[Dim]); rot_P.Add(new double()); forces_P.Add(new double[Dim]); torque_P.Add(new double()); } #endregion #region Initial values // ============================= if (startPos == null) { if (Dim == 2) { startPos = new double[] { 0.0, 0.0 }; } else { startPos = new double[] { 0.0, 0.0, 0.0 }; } } currentPos_P[0] = startPos; //From degree to radiant currentAng_P[0] = startAngl * 2 * Math.PI / 360; //vel_P[0][0] = 2e-8; UpdateLevelSetFunction(); #endregion }
public void AddParticleShape(ParticleShape pS) { ParticleShapes.Add(pS); pS.Initialize(this); }
public static Particle CreateParticle(ParticleBehaviour Behaviour, ParticleShape Shape, Rectangle Clip, Vector2 PositionModifier, Random RandomFeed, Int32 Opacity, Int32 Lifespan, Single SizeRatio, Vector2 VelocityModifier) { Particle p = new Particle(); p.Shape = Shape; switch (Behaviour) { case ParticleBehaviour.Explode: { p.Opacity = Opacity; p.BackColor = Color.FromNonPremultiplied(RandomFeed.Next(255), 0, 0, 255); p.Position = new Vector2((Single)Clip.Width / 2f + PositionModifier.X, (Single)Clip.Height / 2f + PositionModifier.Y); p.Lifespan = Lifespan; p.SizeRatioOverTime = SizeRatio; p.VelocityX = ((Single)RandomFeed.NextDouble() - 0.5f) * ((Single)RandomFeed.NextDouble() * VelocityModifier.X); p.VelocityY = ((Single)RandomFeed.NextDouble() - 0.5f) * ((Single)RandomFeed.NextDouble() * VelocityModifier.Y); p.FadeOut = true; p.FadeOutStartAt = 40; p.FadeIn = false; p.FadeInFrameCount = 0; p.CurrentSize = RandomFeed.Next(5) + 5; p.PMathX = new PixelMath("x * 2"); p.PMathY = new PixelMath("x * 2"); } break; case ParticleBehaviour.Focus: { p.Opacity = Opacity; p.BackColor = Color.FromNonPremultiplied(RandomFeed.Next(255), 0, 0, 255); p.Position = new Vector2(RandomFeed.Next(Clip.Width), RandomFeed.Next(Clip.Height)); p.Lifespan = Lifespan; p.SizeRatioOverTime = SizeRatio; p.VelocityX = (Single)RandomFeed.NextDouble(); p.VelocityY = (Single)RandomFeed.NextDouble(); p.FadeOut = true; p.FadeOutStartAt = 40; p.FadeIn = true; p.FadeInFrameCount = 20; p.CurrentSize = RandomFeed.Next(5) + 5; Single xVariation = ((Single)Clip.Width / 2f - p.Position.X) / (Single)p.Lifespan; Single yVariation = ((Single)Clip.Height / 2f - p.Position.Y) / (Single)p.Lifespan; p.PMathX = new PixelMath(xVariation.ToString()); p.PMathY = new PixelMath(yVariation.ToString()); } break; case ParticleBehaviour.Trail: { p.Opacity = Opacity; p.BackColor = Color.FromNonPremultiplied(RandomFeed.Next(255), 0, 0, 255); p.Position = new Vector2((Single)Clip.Width / 2f + PositionModifier.X, (Single)Clip.Height / 2f + PositionModifier.Y); p.Lifespan = Lifespan; p.SizeRatioOverTime = SizeRatio; p.VelocityX = ((Single)RandomFeed.NextDouble() - 0.5f) * ((Single)RandomFeed.NextDouble() * VelocityModifier.X); p.VelocityY = ((Single)RandomFeed.NextDouble() - 0.5f) * ((Single)RandomFeed.NextDouble() * VelocityModifier.Y); p.FadeOut = true; p.FadeOutStartAt = 40; p.FadeIn = false; p.FadeInFrameCount = 0; p.CurrentSize = RandomFeed.Next(5) + 2; p.PMathX = new PixelMath("x"); p.PMathY = new PixelMath("x"); } break; } return p; }
public void AddParticules(Int32 Number, ParticleBehaviour Behaviour, ParticleShape Shape, Vector2 PositionModifier) { Number.TimesDo(() => Particles.Add(Particle.CreateParticle(Behaviour, Shape, ClipTarget, PositionModifier, RandomFeed))); }
public static Particle CreateParticle(ParticleBehaviour Behaviour, ParticleShape Shape, Rectangle Clip, Vector2 PositionModifier, Random RandomFeed) { return Particle.CreateParticle(Behaviour, Shape, Clip, PositionModifier, RandomFeed, 255, 60, 0.99f, new Vector2(3f, 3f)); }