#region CPL License /* Nuclex Framework Copyright (C) 2002-2009 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #endregion using System; using System.Collections.Generic; using System.Runtime.InteropServices; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Nuclex.Graphics; namespace Nuclex.Graphics.SpecialEffects.Particles { /// Modifies fields in the simple particle structure public class SimpleParticleModifier : IParticleModifier { /// The default instance of this modifier public static readonly SimpleParticleModifier Default = new SimpleParticleModifier(); /// Adds each particle's velocity to its current position /// Particles that will be modified /// Index of the first particle that will be modified /// Number of particles that will be modified public void AddVelocityToPosition(SimpleParticle[] particles, int start, int count) { for(int end = start + count; start < end; ++start) { particles[start].Position.X += particles[start].Velocity.X; particles[start].Position.Y += particles[start].Velocity.Y; particles[start].Position.Z += particles[start].Velocity.Z; } } /// Adds each particle's velocity to its current position scaled /// Particles that will be modified /// Index of the first particle that will be modified /// Number of particles that will be modified /// Scale by which to multiply the particle velocity public void AddScaledVelocityToPosition( SimpleParticle[] particles, int start, int count, float scale ) { for(int end = start + count; start < end; ++start) { particles[start].Position.X += particles[start].Velocity.X * scale; particles[start].Position.Y += particles[start].Velocity.Y * scale; particles[start].Position.Z += particles[start].Velocity.Z * scale; } } /// Adds a fixed amount to each particle's velocity /// Particles that will be modified /// Index of the first particle that will be modified /// Number of particles that will be modified /// /// Velocity adjustment that will be added to each particle's velocity /// public void AddToVelocity( SimpleParticle[] particles, int start, int count, ref Vector3 velocityAdjustment ) { for(int end = start + count; start < end; ++start) { particles[start].Velocity.X += velocityAdjustment.X; particles[start].Velocity.Y += velocityAdjustment.Y; particles[start].Velocity.Z += velocityAdjustment.Z; } } /// Obtains the position of an individual particle /// Particle whose position will be returned /// /// Output parameter that will receive the particle's position /// public void GetPosition(ref SimpleParticle particle, out Vector3 position) { position = particle.Position; } /// Changes the position of an individual particle /// Particle whose position will be changed /// Position the particle will be moved to public void SetPosition(ref SimpleParticle particle, ref Vector3 position) { particle.Position = position; } /// Whether the particle type has a velocity public bool HasVelocity { get { return true; } } /// Obtains the velocity of an individual particle /// Particle whose velocity will be returned /// /// Output parameter that will receive the particle's velocity /// /// /// If the particle doesn't have a velocity, it's safe to set the velocity /// to Vector3.Zero. /// public void GetVelocity(ref SimpleParticle particle, out Vector3 velocity) { velocity = particle.Velocity; } /// Changes the velocity of an individual particle /// Particle whose velocity will be changed /// Velocity that will be assigned to the particle /// /// If particles don't have a velocity, it's safe to do nothing in this method. /// public void SetVelocity(ref SimpleParticle particle, ref Vector3 velocity) { particle.Velocity = velocity; } /// Whether the particle type has a weight public bool HasWeight { get { return false; } } /// Obtains the weight of a particle /// Particle whose weight will be returned /// The weight of the provided particle public float GetWeight(ref SimpleParticle particle) { return 0.0f; } /// Changes the weight of a particle /// Particle whose weight will be set /// Weight that will be assigned to the particle public void SetWeight(ref SimpleParticle particle, float weight) { } } } // namespace Nuclex.Graphics.SpecialEffects.Particles