Beispiel #1
0
        /// <summary>
        /// Create particles evenly spaced on ground of the boundary.
        /// </summary>
        public static FluidParticles Create(int nParticles, float cellSpace, RectangleF domain, float particleMass)
        {
            FluidParticles particles = new FluidParticles(nParticles);

            // Init. Particle positions
            float x0 = domain.X + cellSpace;
            float x  = x0;
            float y  = domain.Y;

            for (int i = 0; i < nParticles; i++)
            {
                if (x == x0)
                {
                    y += cellSpace;
                }
                Vector2 pos = new Vector2(x, y);
                particles.Add(new FluidParticle
                {
                    Position    = pos,
                    PositionOld = pos,
                    Mass        = particleMass,
                });
                x = x + cellSpace < domain.Width ? x + cellSpace : x0;
            }

            return(particles);
        }
Beispiel #2
0
        /// <summary>
        /// Emits particles.
        /// </summary>
        /// <param name="dTime">The delta time.</param>
        /// <returns></returns>
        public FluidParticles Emit(double dTime)
        {
            FluidParticles particles = new FluidParticles();

            if (this.Enabled)
            {
                // Calc particle count based on frequency
                m_time += dTime;
                int nParts = (int)(this.Frequency * m_time);
                if (nParts > 0)
                {
                    // Create Particles
                    for (int i = 0; i < nParts; i++)
                    {
                        // Calc velocity based on the distribution along the normalized direction
                        float   dist   = (float)m_randGen.NextDouble() * this.Distribution - this.Distribution * 0.5f;
                        Vector2 normal = this.Direction.PerpendicularRight;
                        Vector2.Mult(ref normal, dist, out normal);
                        Vector2 vel = this.Direction + normal;
                        vel.Normalize();
                        float velLen = (float)m_randGen.NextDouble() * (this.VelocityMax - this.VelocityMin) + this.VelocityMin;
                        Vector2.Mult(ref vel, velLen, out vel);

                        // Calc Oldpos (for right velocity) using simple euler
                        // oldPos = this.Position - vel * m_time;
                        Vector2 oldPos = this.Position - vel * (float)m_time;

                        particles.Add(new FluidParticle
                        {
                            Position    = this.Position,
                            PositionOld = oldPos,
                            Velocity    = vel,
                            Mass        = this.ParticleMass
                        });
                    }
                    // Reset time
                    m_time = 0.0;
                }
            }
            return(particles);
        }