Ejemplo 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;
            }
        }
Ejemplo n.º 3
0
        public virtual string GetHtmlTable(CoreGrid grid, List <Hashtable> data)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(
                "<html><head><style> table, td {border:1px solid black} table { border-collapse:collapse; background:transparent} .text{ mso-number-format:\"\\@\";/*force text*/ }</style></head> ");
            stringBuilder.Append("<table>");
            stringBuilder.Append("<tr>");
            foreach (CoreColumn column in grid.Columns)
            {
                if (column.Visible)
                {
                    string arg           = string.IsNullOrEmpty(column.HeaderText) ? column.DataField : column.HeaderText;
                    var    styleSettings = _exportExcelSettings.FirstOrDefault(t => t.Key.Name == column.DataField);
                    if (styleSettings.Value != null)
                    {
                        stringBuilder.AppendFormat("<td class=\"text\" style=\"{0}\"\">{1}</td>", BuildColumnStyle(styleSettings.Value, RenderExcelElementType.Header), arg);
                    }
                    else
                    {
                        stringBuilder.AppendFormat("<td class=\"text\">{0}</td>", arg);
                    }
                }
            }
            stringBuilder.Append("</tr>");
            for (int i = 0; i < data.Count; i++)
            {
                stringBuilder.Append("<tr>");
                for (int j = 0; j < grid.Columns.Count; j++)
                {
                    CoreColumn coreColumn = grid.Columns[j];
                    if (coreColumn.Visible)
                    {
                        string arg2 =
                            (!string.IsNullOrEmpty(coreColumn.DataField) &&
                             !string.IsNullOrEmpty(coreColumn.DataFormatString))
                                ? coreColumn.FormatDataValue(data[i][coreColumn.DataField], coreColumn.HtmlEncode)
                                : (data[i][coreColumn.DataField]?.ToString());
                        var styleSettings = _exportExcelSettings.FirstOrDefault(t => t.Key.Name == coreColumn.DataField);

                        if (styleSettings.Value != null)
                        {
                            stringBuilder.AppendFormat("<td class=\"text\" style=\"{0}\"\">{1}</td>", BuildColumnStyle(styleSettings.Value, RenderExcelElementType.Row), arg2);
                        }
                        else
                        {
                            //http://cosicimiento.blogspot.com/2008/11/styling-excel-cells-with-mso-number.html
                            stringBuilder.AppendFormat("<td class=\"text\">{0}</td>", arg2);
                        }
                    }
                }

                stringBuilder.Append("</tr>");
            }
            stringBuilder.Append("</table>");
            return(stringBuilder.ToString());
        }
 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
             });
         }
     }
 }
        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
                    });
                }
            }
        }
Ejemplo n.º 6
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
                        });
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public void GenerateParticles(CoreGrid grid, int particlesPerSection)
 {
     GenerateRandomParticles(grid, particlesPerSection);
 }
Ejemplo n.º 8
0
 public void GenerateParticles(CoreGrid grid, int particlesPerSection)
 {
     throw new NotImplementedException();
 }