public void AddParticle(Vector3 position, Vector3 velocity)
{
// Figure out where in the circular queue to allocate the new particle.
int nextFreeParticle = firstFreeParticle + 1;
if (nextFreeParticle >= particles.Length)
nextFreeParticle = 0;
// If there are no free particles, we just have to give up.
if (nextFreeParticle == firstRetiredParticle)
return;
// Adjust the input velocity based on how much
// this particle system wants to be affected by it.
velocity *= settings.EmitterVelocitySensitivity;
// Add in some random amount of horizontal velocity.
float horizontalVelocity = MathHelper.Lerp(settings.MinHorizontalVelocity,
settings.MaxHorizontalVelocity,
(float)random.NextDouble());
double horizontalAngle = random.NextDouble() * MathHelper.TwoPi;
velocity.X += horizontalVelocity * (float)Math.Cos(horizontalAngle);
velocity.Z += horizontalVelocity * (float)Math.Sin(horizontalAngle);
// Add in some random amount of vertical velocity.
velocity.Y += MathHelper.Lerp(settings.MinVerticalVelocity,
settings.MaxVerticalVelocity,
(float)random.NextDouble());
// Choose four random control values. These will be used by the vertex
// shader to give each particle a different size, rotation, and color.
Color randomValues = new Color((byte)random.Next(255),
(byte)random.Next(255),
(byte)random.Next(255),
(byte)random.Next(255));
// Fill in the particle vertex structure.
particles[firstFreeParticle].Position = position;
particles[firstFreeParticle].Velocity = velocity;
particles[firstFreeParticle].Random = randomValues;
particles[firstFreeParticle].Time = currentTime;
firstFreeParticle = nextFreeParticle;
}