Example #1
0
        private void ApplyGlobalForces(CpuParticle particle, float elapsedTime)
        {
            particle.Velocity += (Preset.Gravity + Velocity) * elapsedTime;

            if (Preset.RandomAcceleration > 0)
            {
                float randomFactor = Preset.RandomAcceleration / 1.732f /* approx. sqrt(3) */;
                particle.Velocity += RandomUtils.GetRandomVector3(
                    new Vector3(-randomFactor, -randomFactor, -randomFactor),
                    new Vector3(randomFactor, randomFactor, randomFactor));
            }
        }
Example #2
0
        private void ApplyEmitterForces(CpuParticle particle, float elapsedTime)
        {
            Vector3 particlePosition  = particle.Position.ApplyOffset(PreTransformedPosition);
            float   particleDistance  = particlePosition.Length();
            Vector3 particleDirection = Vector3.Normalize(particlePosition);

            if (particleDistance < Preset.EmitterRepelRange)
            {
                float repelFactor = 1 - (particleDistance / Preset.EmitterRepelRange);
                particle.Velocity += particleDirection * repelFactor * Preset.EmitterRepelSpeed * elapsedTime;
            }

            if (particleDistance > Preset.EmitterSuctionRange)
            {
                float suctionFactor = (particleDistance / Preset.EmitterSuctionRange) - 1;
                particle.Velocity -= particleDirection * suctionFactor * Preset.EmitterSuctionSpeed * elapsedTime;
            }
        }
Example #3
0
 /// <summary>
 /// Adds a new particle
 /// </summary>
 /// <param name="position">The initial position of the particle</param>
 /// <param name="parameters1">The initial configuration of this particle</param>
 /// <param name="parameters2">The configuration this particle will take in its "second life"</param>
 private void AddParticle(DoubleVector3 position, CpuParticleParametersStruct parameters1, CpuParticleParametersStruct parameters2)
 {
     if (_deadParticles.Count > 0)
     {
         CpuParticle particle = _deadParticles.Pop();
         particle.Alive       = true;
         particle.Position    = position;
         particle.Velocity    = default(Vector3);
         particle.Parameters1 = parameters1;
         particle.Parameters2 = parameters2;
         particle.Color       = parameters1.Color;
         particle.SecondLife  = false;
         _firstLifeParticles.Add(particle);
     }
     else
     {
         _firstLifeParticles.Add(new CpuParticle(position, parameters1, parameters2));
     }
 }
Example #4
0
 /// <summary>
 /// Updates a specific particle
 /// </summary>
 /// <param name="particle">The particle to update</param>
 /// <param name="elapsedTime">How many seconds have passed since the update of this particle</param>
 private void UpdateParticle(CpuParticle particle, float elapsedTime)
 {
     ApplyGlobalForces(particle, elapsedTime);
     ApplyEmitterForces(particle, elapsedTime);
     particle.Update(elapsedTime);
 }