Esempio n. 1
0
 /// <summary>
 /// Helper function for filling a particlespraytype structure.
 /// </summary>
 /// <param name="target">Target spray to be filled</param>
 /// <param name="firstBlock">First texture block which can be used by this spray</param>
 /// <param name="blockCount">How many blocks can be used by this spray after the first one</param>
 /// <param name="gravity">Y Gravity affecting this type of particles</param>
 /// <param name="fraction">Fraction (or air-resistance) for this type of particles</param>
 /// <param name="lifeTime">Static part of the lifetime for this type of particles. This is the minimum.</param>
 /// <param name="lifeTimeRandom">Random part of the lifetime. rand() * lifeTimeRandom will be added to each particle created with this spray.</param>
 /// <param name="size">Static part of a particle's size</param>
 /// <param name="sizeRandom">Random part of a particle's size</param>
 /// <param name="sizeInc">Static part of particle's sizeinc. How much the particle is groving or shrinking through time.</param>
 /// <param name="sizeIncRandom">Random part for the sizeinc.</param>
 /// <param name="angle">Static angle for the particle</param>
 /// <param name="angleRandom">Random maximum angle to be added to static angle.</param>
 /// <param name="angleInc">Static part of how much particle's created with this spray are rotating.</param>
 /// <param name="angleIncRandom">Random part for angleInc.</param>
 /// <param name="type">Currently unused. Qt version used this for indicating should the particle be rendered with alpha- or additive blending.</param>
 public void CreateSprayType(ParticleSprayType target,
                             int firstBlock,
                             int blockCount,
                             float gravity,
                             float fraction,
                             float lifeTime,
                             float lifeTimeRandom,
                             float size,
                             float sizeRandom,
                             float sizeInc,
                             float sizeIncRandom,
                             float angle,
                             float angleRandom,
                             float angleInc,
                             float angleIncRandom,
                             int type)
 {
     target.RenderType     = type;
     target.Gravity        = gravity;
     target.FirstBlock     = firstBlock;
     target.BlockCount     = blockCount;
     target.Fraction       = fraction;
     target.LifeTime       = lifeTime;
     target.LifeTimeRandom = lifeTimeRandom;
     target.Size           = size;
     target.FirstBlock     = firstBlock;
     target.BlockCount     = blockCount;
     target.SizeRandom     = sizeRandom;
     target.SizeInc        = sizeInc;
     target.SizeIncRandom  = sizeIncRandom;
     target.Angle          = angle;
     target.AngleRandom    = angleRandom;
     target.AngleInc       = angleInc;
     target.AngleIncRandom = angleIncRandom;
 }
Esempio n. 2
0
        /// <summary>
        /// Spray some particles
        /// </summary>
        /// <param name="count">How many particles</param>
        /// <param name="x">X position of an emit</param>
        /// <param name="y">Y position of an emit.</param>
        /// <param name="posrandom">Random R for modifying the position</param>
        /// <param name="dx">X direction of an emit</param>
        /// <param name="dy">Y direction of an emit</param>
        /// <param name="dirrandom">Random R for modifying the direction</param>
        /// <param name="userData">User data, just passed to the particle for later use.</param>
        /// <param name="spray">Which spray is used for emitting.</param>
        public void Spray(int count,
                          float x, float y, float posrandom,
                          float dx, float dy, float dirrandom,
                          int userData,
                          ParticleSprayType spray)
        {
            double l, nx, ny;

            System.Random r = rand;

            while (count > 0)
            {
                Particle p = m_particles[m_cp];
                m_cp++;

                if (m_cp >= MAX_PARTICLES)
                {
                    m_cp = 0;
                }

                p.Spray = spray;

                nx = (r.NextDouble() - 0.5) * 2.0;
                ny = (r.NextDouble() - 0.5) * 2.0;

                l = System.Math.Sqrt(nx * nx + ny * ny);
                if (l == 0)
                {
                    l = 1;
                }

                // random vactor
                double v = r.NextDouble();
                nx = nx * v / l;
                ny = ny * v / l;

                p.UserData = userData;

                p.X  = ((float)nx * posrandom) + x;
                p.Y  = ((float)ny * posrandom) + y;
                p.Dx = ((float)nx * dirrandom) + dx;
                p.Dy = ((float)ny * dirrandom) + dy;

                p.LifeTime  = spray.LifeTime + ((float)r.NextDouble() * spray.LifeTimeRandom);
                p.TileIndex = spray.FirstBlock + r.Next(spray.BlockCount);

                p.Size    = spray.Size + (float)r.NextDouble() * spray.SizeRandom;
                p.Sizeinc = spray.SizeInc + (float)r.NextDouble() * spray.SizeIncRandom;

                p.Angle    = spray.Angle + (float)r.NextDouble() * spray.AngleRandom;
                p.Angleinc = spray.AngleInc + (float)r.NextDouble() * spray.AngleIncRandom;

                count--;
            }
        }