#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 Microsoft.Xna.Framework;
namespace Nuclex.Graphics.SpecialEffects.Particles {
/// Moves particles by their current velocity
/// Data type of the particles
public class MovementAffector : IParticleAffector {
/// Initializes a new particle movement affector
/// Used to modify the particles
public MovementAffector(IParticleModifier modifier) {
this.modifier = modifier;
}
///
/// Whether the affector can do multiple updates in a single step without
/// changing the outcome of the simulation
///
public bool IsCoalescable { get { return false; } }
/// Applies the affector's effect to a series of particles
/// Particles the affector will be applied to
/// Index of the first particle that will be affected
/// Number of particles that will be affected
/// Number of updates to perform in the affector
///
/// Contrary to general-purpose particle systems like we might find in expensive
/// animation packages, we don't update particles based on time but instead
/// use the simplified approach of updating particles in simulation steps.
/// This simplifies the implementation and matches a game's architecture where
/// the simulation is updated in steps as well to have a predictable outcome.
///
public void Affect(ParticleType[] particles, int start, int count, int updates) {
if(this.modifier.HasVelocity) {
if(updates == 1) {
this.modifier.AddVelocityToPosition(particles, start, count);
} else {
this.modifier.AddScaledVelocityToPosition(
particles, start, count, (float)updates
);
}
}
}
/// Particle modifier used to apply gravity to the particles
private IParticleModifier modifier;
}
} // namespace Nuclex.Graphics.SpecialEffects.Particles