/// <summary>
        /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
        /// it is updated. Only valid if <see cref="ParticleModifier.ProcessOnUpdate"/> is set.
        /// </summary>
        /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
        /// came from.</param>
        /// <param name="particle">The <see cref="Particle"/> to process.</param>
        /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
        /// was last updated.</param>
        protected override void HandleProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime)
        {
            Vector2 deltaGrav;

            Vector2.Multiply(ref _gravity, elapsedTime * 0.001f, out deltaGrav);

            particle.ApplyForce(ref deltaGrav);
        }
Exemple #2
0
        /// <summary>
        /// When overridden in the derived class, generates the offset and normalized force vectors to
        /// release the <see cref="Particle"/> at.
        /// </summary>
        /// <param name="particle">The <see cref="Particle"/> that the values are being generated for.</param>
        /// <param name="offset">The offset vector.</param>
        /// <param name="force">The normalized force vector.</param>
        protected override void GenerateParticleOffsetAndForce(Particle particle, out Vector2 offset, out Vector2 force)
        {
            offset = Vector2.Zero;

            var f = ConeAngle * 0.5f;
            var radians = RandomHelper.NextFloat(Direction - f, Direction + f);

            GetForce(radians, out force);
        }
 /// <summary>
 /// Process a <see cref="Particle"/> that was released.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> the <paramref name="particle"/> came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 internal void ProcessReleased(ParticleEmitter emitter, Particle particle)
 {
     Debug.Assert(ProcessOnRelease, "This method should NOT be called when ProcessOnRelease is not set!");
     HandleProcessReleased(emitter, particle);
 }
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is updated. Only valid if <see cref="ParticleModifier.ProcessOnUpdate"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
 /// was last updated.</param>
 protected abstract void HandleProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime);
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is released. Only valid if <see cref="ParticleModifier.ProcessOnRelease"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 protected abstract void HandleProcessReleased(ParticleEmitter emitter, Particle particle);
Exemple #6
0
 /// <summary>
 /// When overridden in the derived class, generates the offset and normalized force vectors to
 /// release the <see cref="Particle"/> at.
 /// </summary>
 /// <param name="particle">The <see cref="Particle"/> that the values are being generated for.</param>
 /// <param name="offset">The offset vector.</param>
 /// <param name="force">The normalized force vector.</param>
 protected override void GenerateParticleOffsetAndForce(Particle particle, out Vector2 offset, out Vector2 force)
 {
     offset = Vector2.Zero;
     GetForce(RandomHelper.NextFloat(MathHelper.TwoPi), out force);
 }
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is updated. Only valid if <see cref="ParticleModifier.ProcessOnUpdate"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
 /// was last updated.</param>
 protected override void HandleProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime)
 {
     particle.Rotation += _rate * elapsedTime;
 }
Exemple #8
0
        /// <summary>
        /// When overridden in the derived class, generates the offset and normalized force vectors to
        /// release the <see cref="Particle"/> at.
        /// </summary>
        /// <param name="particle">The <see cref="Particle"/> that the values are being generated for.</param>
        /// <param name="offset">The offset vector.</param>
        /// <param name="force">The normalized force vector.</param>
        protected override void GenerateParticleOffsetAndForce(Particle particle, out Vector2 offset, out Vector2 force)
        {
            var halfLength = Length * 0.5f;

            offset = new Vector2(RandomHelper.NextFloat(-halfLength, halfLength), 0);

            Vector2.Transform(ref offset, ref _rotationMatrix, out offset);

            if (Rectilinear)
            {
                force = new Vector2(_rotationMatrix.Up.X, _rotationMatrix.Up.Y);

                if (EmitBothWays)
                {
                    if (_flip)
                        Vector2.Multiply(ref force, -1.0f, out force);

                    _flip = !_flip;
                }
            }
            else
                GetForce(RandomHelper.NextFloat(MathHelper.TwoPi), out force);
        }
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is released. Only valid if <see cref="ParticleModifier.ProcessOnRelease"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 protected override void HandleProcessReleased(ParticleEmitter emitter, Particle particle)
 {
 }
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is updated. Only valid if <see cref="ParticleModifier.ProcessOnUpdate"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
 /// was last updated.</param>
 protected override void HandleProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime)
 {
     particle.Scale = MathHelper.Lerp(InitialScale, UltimateScale, particle.GetAgePercent(CurrentTime));
 }
Exemple #11
0
        /// <summary>
        /// When overridden in the derived class, generates the offset and normalized force vectors to
        /// release the <see cref="Particle"/> at.
        /// </summary>
        /// <param name="particle">The <see cref="Particle"/> that the values are being generated for.</param>
        /// <param name="offset">The offset vector.</param>
        /// <param name="force">The normalized force vector.</param>
        protected override void GenerateParticleOffsetAndForce(Particle particle, out Vector2 offset, out Vector2 force)
        {
            if (Points.Count == 0)
                offset = Vector2.Zero;
            else if (Points.Count == 1)
                offset = Points[0];
            else if (Points.Count == 2)
                offset = Vector2.Lerp(Points[0], Points[1], RandomHelper.NextFloat());
            else
            {
                var i = Closed ? RandomHelper.NextInt(0, Points.Count) : RandomHelper.NextInt(0, Points.Count - 1);

                offset = Vector2.Lerp(Points[i], Points[(i + 1) % Points.Count], RandomHelper.NextFloat());
            }

            // Apply any necessary transformation to the resultant offset vector...
            Matrix transform;

            Matrix.Multiply(ref Points.TranslationMatrix, ref _rotationMatrix, out transform);

            Matrix.Multiply(ref _scaleMatrix, ref transform, out transform);

            Vector2.Transform(ref offset, ref transform, out offset);

            // Get the force
            GetForce(RandomHelper.NextFloat(MathHelper.TwoPi), out force);
        }
 /// <summary>
 /// When overridden in the derived class, generates the offset and normalized force vectors to
 /// release the <see cref="Particle"/> at.
 /// </summary>
 /// <param name="particle">The <see cref="Particle"/> that the values are being generated for.</param>
 /// <param name="offset">The offset vector.</param>
 /// <param name="force">The normalized force vector.</param>
 protected abstract void GenerateParticleOffsetAndForce(Particle particle, out Vector2 offset, out Vector2 force);
Exemple #13
0
        /// <summary>
        /// When overridden in the derived class, generates the offset and normalized force vectors to
        /// release the <see cref="Particle"/> at.
        /// </summary>
        /// <param name="particle">The <see cref="Particle"/> that the values are being generated for.</param>
        /// <param name="offset">The offset vector.</param>
        /// <param name="force">The normalized force vector.</param>
        protected override void GenerateParticleOffsetAndForce(Particle particle, out Vector2 offset, out Vector2 force)
        {
            var rads = RandomHelper.NextFloat(MathHelper.TwoPi);
            var radius = Radius.GetNext();

            var cosRads = (float)Math.Cos(rads);
            var sinRads = (float)Math.Sin(rads);
            offset = new Vector2(cosRads * radius, sinRads * radius);

            if (!Perimeter)
                Vector2.Multiply(ref offset, RandomHelper.NextFloat(), out offset);

            if (Radiate)
                force = new Vector2(cosRads, sinRads);
            else
                GetForce(RandomHelper.NextFloat(MathHelper.TwoPi), out force);
        }
 /// <summary>
 /// Process a <see cref="Particle"/> that was updated.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> the <paramref name="particle"/> came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
 /// was last updated.</param>
 internal void ProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime)
 {
     Debug.Assert(ProcessOnUpdate, "This method should NOT be called when ProcessOnUpdate is not set!");
     HandleProcessUpdated(emitter, particle, elapsedTime);
 }
Exemple #15
0
        /// <summary>
        /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
        /// it is released. Only valid if <see cref="ParticleModifier.ProcessOnRelease"/> is set.
        /// </summary>
        /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
        /// came from.</param>
        /// <param name="particle">The <see cref="Particle"/> to process.</param>
        protected override void HandleProcessReleased(ParticleEmitter emitter, Particle particle)
        {
            if (AllBitsSet())
                particle.Color = ReleaseColor;
            else
            {
                byte r, g, b, a;

                if (ModifyRed)
                    r = ReleaseColor.R;
                else
                    r = particle.Color.R;

                if (ModifyGreen)
                    g = ReleaseColor.G;
                else
                    g = particle.Color.G;

                if (ModifyBlue)
                    b = ReleaseColor.B;
                else
                    b = particle.Color.B;

                if (ModifyAlpha)
                    a = ReleaseColor.A;
                else
                    a = particle.Color.A;

                particle.Color = new Color(r, g, b, a);
            }
        }
Exemple #16
0
        /// <summary>
        /// When overridden in the derived class, generates the offset and normalized force vectors to
        /// release the <see cref="Particle"/> at.
        /// </summary>
        /// <param name="particle">The <see cref="Particle"/> that the values are being generated for.</param>
        /// <param name="offset">The offset vector.</param>
        /// <param name="force">The normalized force vector.</param>
        protected override void GenerateParticleOffsetAndForce(Particle particle, out Vector2 offset, out Vector2 force)
        {
            var hw = Width * 0.5f;
            var hh = Height * 0.5f;

            // Get the offset
            if (Perimeter)
            {
                if (RandomHelper.NextBool())
                    offset = new Vector2(RandomHelper.Choose(-hw, hw), RandomHelper.NextFloat(-hh, hh));
                else
                    offset = new Vector2(RandomHelper.NextFloat(-hw, hw), RandomHelper.Choose(-hh, hh));
            }
            else
                offset = new Vector2(RandomHelper.NextFloat(-hw, hw), RandomHelper.NextFloat(-hh, hh));

            // Get the force
            var radians = RandomHelper.NextFloat(MathHelper.TwoPi);
            force = new Vector2((float)Math.Sin(radians), (float)Math.Cos(radians));
        }
Exemple #17
0
        /// <summary>
        /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
        /// it is updated. Only valid if <see cref="ParticleModifier.ProcessOnUpdate"/> is set.
        /// </summary>
        /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
        /// came from.</param>
        /// <param name="particle">The <see cref="Particle"/> to process.</param>
        /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
        /// was last updated.</param>
        protected override void HandleProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime)
        {
            var agePercent = particle.GetAgePercent(CurrentTime);

            if (AllBitsSet())
                particle.Color = ReleaseColor.Lerp(UltimateColor, agePercent);
            else
            {
                byte r, g, b, a;

                if (ModifyRed)
                    r = (byte)MathHelper.Lerp(ReleaseColor.R, UltimateColor.R, agePercent);
                else
                    r = particle.Color.R;

                if (ModifyGreen)
                    g = (byte)MathHelper.Lerp(ReleaseColor.G, UltimateColor.G, agePercent);
                else
                    g = particle.Color.G;

                if (ModifyBlue)
                    b = (byte)MathHelper.Lerp(ReleaseColor.B, UltimateColor.B, agePercent);
                else
                    b = particle.Color.B;

                if (ModifyAlpha)
                    a = (byte)MathHelper.Lerp(ReleaseColor.A, UltimateColor.A, agePercent);
                else
                    a = particle.Color.A;

                particle.Color = new Color(r, g, b, a);
            }
        }
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is updated. Only valid if <see cref="ParticleModifier.ProcessOnUpdate"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 /// <param name="elapsedTime">The amount of time that has elapsed since the <paramref name="emitter"/>
 /// was last updated.</param>
 protected override void HandleProcessUpdated(ParticleEmitter emitter, Particle particle, int elapsedTime)
 {
 }
Exemple #19
0
 /// <summary>
 /// When overridden in the derived class, handles processing the <paramref name="particle"/> when
 /// it is released. Only valid if <see cref="ParticleModifier.ProcessOnRelease"/> is set.
 /// </summary>
 /// <param name="emitter">The <see cref="ParticleEmitter"/> that the <paramref name="particle"/>
 /// came from.</param>
 /// <param name="particle">The <see cref="Particle"/> to process.</param>
 protected override void HandleProcessReleased(ParticleEmitter emitter, Particle particle)
 {
 }