public override void Generate(int numParticles, NewParticleDelegate newPartDel)
 {
     int numTries = 0;
     for (int i = 0; i < numParticles; ++i) {
         bool accepted = false;
         while (!accepted) {
             if (numTries >= numParticles * c_maxTriesFactor) {
                 // This is somewhat of a hack to add a failsafe for the random strategy of
                 // fitting things in. Currently we just give up if we tried too many time with
                 // no luck. This can happen when trying to fit too much into a small space.
                 // In the future a smarter packing strategy may be employed before giving up.
                 // TODO: print something
                 System.Console.WriteLine (
                     "Too many rejections when generating a field. " +
                     "Giving up after " + numTries + " fitting attempts.");
                 return;
             }
             ++numTries;
             float x = (float)(m_dimmensions.X * (m_rand.NextDouble() - 0.5));
             float y = (float)(m_dimmensions.Y * (m_rand.NextDouble() - 0.5));
             float z = (float)(m_dimmensions.Z * (m_rand.NextDouble() - 0.5));
             accepted = newPartDel(i, m_center + new Vector3(x, y, z));
         }
     }
 }
Пример #2
0
        public override void Generate(int numParticles, NewParticleDelegate newPartDel)
        {
            int numTries = 0;

            for (int i = 0; i < numParticles; ++i)
            {
                bool accepted = false;
                while (!accepted)
                {
                    if (numTries >= numParticles * c_maxTriesFactor)
                    {
                        // This is somewhat of a hack to add a failsafe for the random strategy of
                        // fitting things in. Currently we just give up if we tried too many time with
                        // no luck. This can happen when trying to fit too much into a small space.
                        // In the future a smarter packing strategy may be employed before giving up.
                        // TODO: print something
                        System.Console.WriteLine(
                            "Too many rejections when generating a field. " +
                            "Giving up after " + numTries + " fitting attempts.");
                        return;
                    }
                    ++numTries;
                    float x = (float)(m_dimmensions.X * (m_rand.NextDouble() - 0.5));
                    float y = (float)(m_dimmensions.Y * (m_rand.NextDouble() - 0.5));
                    float z = (float)(m_dimmensions.Z * (m_rand.NextDouble() - 0.5));
                    accepted = newPartDel(i, m_center + new Vector3(x, y, z));
                }
            }
        }
Пример #3
0
        public override void Generate(int numParticles, NewParticleDelegate newPartDeleg)
        {
            int numTries = 0;

            for (int i = 0; i < numParticles; ++i)
            {
                bool accepted = false;
                while (!accepted)
                {
                    if (numTries >= numParticles * c_maxTriesFactor)
                    {
                        // This is somewhat of a hack to add a failsafe for the random strategy of
                        // fitting things in. Currently we just give up if we tried too many time with
                        // no luck. This can happen when trying to fit too much into a small space.
                        // In the future a smarter packing strategy may be employed before giving up.
                        // TODO: print something
                        System.Console.WriteLine(
                            "Too many rejections when generating a field. " +
                            "Giving up after " + numTries + " fitting attempts.");
                        return;
                    }
                    ++numTries;
                    m_ringTheta = m_sectionStart + (float)m_rand.NextDouble() * (m_sectionEnd - m_sectionStart);
                    m_planeGenerator.Generate(1, onNewPlaneParticle);
                    accepted = newPartDeleg(i, m_newPos);
                }
            }
        }
 public override void Generate(int numParticles, NewParticleDelegate newPartDel)
 {
     for (int i = 0; i < numParticles; ++i) {
         bool accepted = false;
         while (!accepted) {
             float r = (float)m_rand.NextDouble();
             float theta = (float)(m_rand.NextDouble() * 2.0 * Math.PI);
             float x = r * (float)Math.Cos(theta) * m_horizontalMax;
             float y = r * (float)Math.Sin(theta) * m_verticalMax;
             accepted = newPartDel(i, new Vector2(x, y));
         }
     }
 }
Пример #5
0
 public override void Generate(int numParticles, NewParticleDelegate newPartDel)
 {
     for (int i = 0; i < numParticles; ++i)
     {
         bool accepted = false;
         while (!accepted)
         {
             float r     = (float)m_rand.NextDouble();
             float theta = (float)(m_rand.NextDouble() * 2.0 * Math.PI);
             float x     = r * (float)Math.Cos(theta) * m_horizontalMax;
             float y     = r * (float)Math.Sin(theta) * m_verticalMax;
             accepted = newPartDel(i, new Vector2(x, y));
         }
     }
 }
Пример #6
0
 abstract public void Generate(int numParticles,
                               NewParticleDelegate newPartDel); // density is in particles per cubic unit
Пример #7
0
 abstract public void Generate(int numParticles, NewParticleDelegate newPartDel);
 public abstract void Generate(int numParticles,
                               NewParticleDelegate newPartDel);
 public override void Generate(int numParticles, NewParticleDelegate newPartDeleg)
 {
     int numTries = 0;
     for (int i = 0; i < numParticles; ++i) {
         bool accepted = false;
         while (!accepted) {
             if (numTries >= numParticles * c_maxTriesFactor) {
                 // This is somewhat of a hack to add a failsafe for the random strategy of
                 // fitting things in. Currently we just give up if we tried too many time with
                 // no luck. This can happen when trying to fit too much into a small space.
                 // In the future a smarter packing strategy may be employed before giving up.
                 // TODO: print something
                 System.Console.WriteLine (
                     "Too many rejections when generating a field. " +
                     "Giving up after " + numTries + " fitting attempts.");
                 return;
             }
             ++numTries;
             m_ringTheta = m_sectionStart + (float)m_rand.NextDouble() * (m_sectionEnd - m_sectionStart);
             m_planeGenerator.Generate(1, onNewPlaneParticle);
             accepted = newPartDeleg(i, m_newPos);
         }
     }
 }