Exemplo n.º 1
0
        public void GenerateParticles(CoreGrid grid, int particlesPerSection)
        {
            var sections                 = grid.GetCores().SelectMany(core => core.Sections);
            var sectionPositions         = sections.Select(section => (section.UpperBound + section.LowerBound) / 2);
            var centerVector             = new Vector3(sectionPositions.Average(section => section.X), sectionPositions.Average(section => section.Y), sectionPositions.Average(section => section.Z));
            var minVector                = new Vector3(sectionPositions.Min(s => s.X), sectionPositions.Min(s => s.Y), sectionPositions.Min(s => s.Z));
            var maxVector                = new Vector3(sectionPositions.Max(s => s.X), sectionPositions.Max(s => s.Y), sectionPositions.Max(s => s.Z));
            var minDistFromCenterSquared = sectionPositions.Select(position => (position - centerVector).LengthSquared()).Min();
            var centerSection            = sections.First(s => (((s.UpperBound + s.LowerBound) / 2 - centerVector).LengthSquared().Equals(minDistFromCenterSquared)));

            foreach (var section in sections)
            {
                for (var i = 0; i < particlesPerSection; i++)
                {
                    var delta = new Vector3(
                        ((float)((maxVector.X - minVector.X) * (random.NextDouble() - 0.5f))),
                        ((float)((maxVector.Y - minVector.Y) * (random.NextDouble() - 0.5f))),
                        ((float)((maxVector.Z - minVector.Z) * (random.NextDouble() - 0.5f))));
                    centerSection.AddParticle(new Particle()
                    {
                        Position = centerVector + delta / 10, Velocity = delta
                    });
                }
            }
        }
        private void GenerateLocalParticles(CoreGrid cGrid, int particlesPerSection)
        {
            bool didCore = false;

            foreach (var core in cGrid.GetCores())
            {
                if (didCore)
                {
                    continue;
                }
                foreach (var section in core.Sections)
                {
                    for (var i = 0; i < particlesPerSection; i++)
                    {
                        var position = section.LowerBound +
                                       new Vector3(
                            (section.UpperBound.X - section.LowerBound.X) *
                            (float)Math.Abs(random.NextDouble()),
                            (section.UpperBound.Y - section.LowerBound.Y) *
                            (float)Math.Abs(random.NextDouble()),
                            (section.UpperBound.Z - section.LowerBound.Z) *
                            (float)Math.Abs(random.NextDouble()));
                        var velocity = new Vector3(1f - 2 * (float)random.NextDouble(),
                                                   1f - 2 * (float)random.NextDouble(),
                                                   1f - 2 * (float)random.NextDouble());

                        section.AddParticle(new Particle {
                            Position = position, Velocity = velocity
                        });
                    }
                }
                didCore = true;
            }
        }
        public void GenerateParticles(CoreGrid grid, int particlesPerSection)
        {
            var sectionPositions = grid.GetCores().SelectMany(core => core.Sections).Select(section => (section.UpperBound + section.LowerBound) / 2);
            var centerVector     = new Vector3(sectionPositions.Average(section => section.X), sectionPositions.Average(section => section.Y), sectionPositions.Average(section => section.Z));
            var minVector        = new Vector3(sectionPositions.Min(s => s.X), sectionPositions.Min(s => s.Y), sectionPositions.Min(s => s.Z));
            var maxVector        = new Vector3(sectionPositions.Max(s => s.X), sectionPositions.Max(s => s.Y), sectionPositions.Max(s => s.Z));

            foreach (var section in grid.GetCores().SelectMany(c => c.Sections))
            {
                for (var i = 0; i < particlesPerSection; i++)
                {
                    var delta = new Vector3(
                        ((float)((maxVector.X - minVector.X) * (random.NextDouble() - 0.5f))),
                        ((float)((maxVector.Y - minVector.Y) * (random.NextDouble() - 0.5f))),
                        ((float)((maxVector.Z - minVector.Z) * (random.NextDouble() - 0.5f))));
                    section.AddParticle(new Particle()
                    {
                        Position = centerVector + delta / 10, Velocity = delta
                    });
                }
            }
        }
 public void GenerateParticles(CoreGrid grid, int particlesPerSection)
 {
     foreach (var particleSection in grid.GetCores().SelectMany(core => core.Sections))
     {
         for (var i = 0; i < particlesPerSection; i++)
         {
             var randomPositionWithinSphere = GetRandomPositionWithinSphere(ballCenter, ballRadius);
             var velocity = randomPositionWithinSphere - ballCenter;
             if (velocity.LengthSquared() != 0)
             {
                 velocity.Normalize();
                 velocity *= maxSpeed * ((float)random.NextDouble());
             }
             particleSection.AddParticle(new Particle()
             {
                 Position = randomPositionWithinSphere, Velocity = velocity
             });
         }
     }
 }
Exemplo n.º 5
0
        private void GenerateRandomParticles(CoreGrid cGrid, int particlesPerCore)
        {
            foreach (var core in cGrid.GetCores())
            {
                foreach (var section in core.Sections)
                {
                    for (var i = 0; i < particlesPerCore; i++)
                    {
                        var position = new Vector3((float)random.NextDouble(), (float)random.NextDouble(),
                                                   (float)random.NextDouble());

                        var velocity = new Vector3(1f - 2 * (float)random.NextDouble(),
                                                   1f - 2 * (float)random.NextDouble(),
                                                   1f - 2 * (float)random.NextDouble());

                        section.AddParticle(new Particle()
                        {
                            Position = position, Velocity = velocity
                        });
                    }
                }
            }
        }