Exemplo n.º 1
0
        // OPT: This could prolly be more efficient.
        // But a core i5 handles 50k particles without much sweat, so, no sweat.
        public void Update(double dt, ParticleGroup group)
        {
            var fdt       = (float)dt;
            var particles = group.Particles;

            // We iterate downwards through the list so if we remove a particle we don't
            // reorder anything we haven't already updated.
            for (int i = particles.Count - 1; i > -1; i--)
            {
                var p = particles[i];

                if (scaleWithTime)
                {
                    p.Scale += (deltaScale * fdt);
                    p.Scale  = (float)SMath.Clamp(p.Scale, 0.1, 5);
                }
                if (changeColorWithTime)
                {
                    doColorFade(ref p, group.colorFader, fdt);
                    //group.colorFader.setColor(ref p);
                }

                doMovement(ref p, dt);
                particles[i] = p;
                if (p.Life < 0)
                {
                    group.Remove(i);
                }
            }
        }
Exemplo n.º 2
0
        public override void Update(double dt, ParticleGroup particle_group)
        {
            Vector2d position = Vector2d.Zero, angleVec = Vector2d.Zero;
            float    rand_radius = radius * (float)rand.NextDouble();

            //current_angle = start_angle * Math.PI / 180;

            lastTime += dt;
            //for (int i = 0; i <= 360 && lastTime >= nextTime; i += 10, current_angle++) {			//while (lastTime >= nextTime)

            current_angle++;
            if (current_angle > end_angle - 1)
            {
                current_angle = start_angle;
                nextTime     += emitDelay;
                //break;
            }

            //angle = random.Next(start_angle, end_angle);
            position = new Vector2d(rand_radius * Math.Cos(current_angle * Math.PI / 180), rand_radius * Math.Sin(current_angle * Math.PI / 180));
            Vector2d.Normalize(ref position, out angleVec);
            //Log.Message(String.Format("Particle Angle {0} , {1} , {2}", current_angle, position.X, position.Y));
            particle_group.AddParticle(position, velocityMagnitude * angleVec, Color, maxLifeTime);
            //}
        }
Exemplo n.º 3
0
 public ParticleRenderState(Texture tex, ParticleGroup group, Vector2?scale = null, float rotation = 0.0f)
     : base("ParticleRenderer")
 {
     texture = tex;
     Log.Assert(texture != null);
     ParticleGroup = group;
     Rotation      = rotation;
     Scale         = scale ?? Vector2.One;
 }
Exemplo n.º 4
0
        public ParticleComponent(double _velocityMagnitude, int MaxParticles = 1024, float _gravity = 1f, float _deltaScale = 0f)
            : base()
        {
            HandledEvents = EventType.OnUpdate;
            //Setting these for Serialization purposes
            //this.velocityMagnitude = _velocityMagnitude;
            this.MaxParticles = MaxParticles;
            //Particle Controller Properties
            controller    = new ParticleController(Vector2d.One, _velocityMagnitude, _gravity, _deltaScale);
            particleGroup = new ParticleGroup(MaxParticles);

            Texture texture = Resources.TheResources.GetTexture("dot");

            RenderState = new ParticleRenderState(texture, particleGroup);
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dt"></param>
        public override void Update(double dt, ParticleGroup particle_group)
        {
            Vector2d position = Vector2d.Zero, angleVec = Vector2d.Zero;

            //current_angle = start_angle * Math.PI / 180;

            lastTime += dt;
            //for (int i = 0; i <= 360 && lastTime >= nextTime; i += 10, current_angle++)
            while (lastTime >= nextTime)
            {
                nextTime += emitDelay;
                position  = new Vector2d(Math.Cos(angle * Math.PI / 180), Math.Sin(angle * Math.PI / 180));
                Vector2d.Normalize(ref position, out angleVec);
                //Log.Message(String.Format("Particle Angle {0} , {1} , {2}", current_angle, position.X, position.Y));
                particle_group.AddParticle(position, velocityMagnitude * angleVec, Color, maxLifeTime);
            }
        }
Exemplo n.º 6
0
        public override void Update(double dt, ParticleGroup particle_group)
        {
            double xV = rand.NextDouble() * range.X * direction;

            direction *= -1;
            //double yV = rand.NextDouble() * velocity.Y;

            //Will Add Code Soon
            Vector2d position = Vector2d.Zero, angleVec = new Vector2d(xV, range.Y);

            //current_angle = start_angle * Math.PI / 180;

            lastTime += dt;
            //for (int i = 0; i <= 360 && lastTime >= nextTime; i += 10, current_angle++)
            while (lastTime >= nextTime)
            {
                nextTime += emitDelay;
                //position = new Vector2d(Math.Cos(angle * Math.PI / 180), Math.Sin(angle * Math.PI / 180));
                Vector2d.Normalize(ref angleVec, out angleVec);
                particle_group.AddParticle(position, velocityMagnitude * angleVec, Color, maxLifeTime);
            }
        }
Exemplo n.º 7
0
 public abstract void Update(double dt, ParticleGroup particle_group);