Example #1
0
        public Galaxy(double width, double height, int systems, int minBodsPerSys, int maxBodsPerSys)
        {
            this.width  = width;
            this.height = height;
            root        = new Barnes_Hut.BHNode(width, height);
            Bodies      = new List <CelestialBody>(systems * maxBodsPerSys);
            Planets     = new List <Planet>();
            Stars       = new List <Star>();
            Count       = N;
            double totalMass = 0;

            for (int i = 0; i < systems; i++)
            {
                double posX, posY;
                double theta  = Rand.NextDouble() * (Math.PI * 2);//GET VALUE BETWEEN 0 AND 2PI
                double radius = Rand.NextDouble();
                if (width > height)
                {
                    radius *= height / 2;
                }
                else
                {
                    radius *= width / 2;
                }
                posX = radius * Math.Cos(theta);
                posY = radius * Math.Sin(theta);
                double randomValue = Rand.Next(0, 100000000);
                randomValue /= 100000000;
                Star star = Star.GenerateRandomStar(i, randomValue, posX, posY);
                Bodies.Add(star);
                Stars.Add(star);
                totalMass += star.mass;
                double bodies = Rand.Next(minBodsPerSys, maxBodsPerSys);
                for (int j = 0; j < bodies; j++)
                {
                    double randomValue2 = Rand.Next(0, 100000000);
                    randomValue2 /= 100000000;
                    double theta2 = Rand.NextDouble() * (Math.PI * 2);
                    double posX2, posY2;
                    double radius2 = Rand.Next((int)(star.size * Constants.MIN_DISTANCE_RATIO), (int)(star.size * Constants.MAX_DISTANCE_RATIO));
                    posX2  = radius2 * Math.Cos(theta2);
                    posY2  = radius2 * Math.Sin(theta2);
                    posX2 += posX;
                    posY2 += posY;
                    Planet planet = Planet.GeneratePlanet(systems + (i * j), randomValue2, posX2, posY2, star, theta2);
                    Planets.Add(planet);
                    star.OrbitingPlanets.Add(planet);
                    totalMass += planet.mass;
                }
            }
            //Spawn black hole in middle
            //double px = 0, py = 0;
            //double m = 10e15 * N;
            //Bodies.Insert(0, new CelestialBody(0, px, py, m, m / 200));
            //Galaxy.Instance = this;
            //for (int i = 1; i < N; i++) //Apply orbital velocity
            //{
            //    GenerateOrbitalAcceleration(Bodies[i], m);
            //    Bodies[i].Update();
            //}
            this.N = Bodies.Count;
        }
Example #2
0
        /// <summary>
        /// Generate a star
        /// </summary>
        /// <param name="randomValue">Value between 0 and 1</param>
        /// <param name="id">ID of celestial body</param>
        /// <param name="posX">X coordinate</param>
        /// <param name="posY">Y coordinate</param>
        /// <returns></returns>
        public static Star GenerateRandomStar(int id, double randomValue, double posX, double posY)
        {
            Class  starClass;
            double size = Constants.SUN_SIZE;
            double mass = Constants.SUN_MASS;

            randomValue *= 100;
            if (randomValue <= Constants.STAR_O_CLASS_CUTOFF) //CLASS O STAR, >= 16 M
            {
                double massscale = 6 + (randomValue / Constants.STAR_O_CLASS_CUTOFF) * 4;
                double sizescale = 3 + (randomValue / Constants.STAR_O_CLASS_CUTOFF) * 2;
                mass     *= massscale;
                size     *= sizescale;
                starClass = Class.O;
            }
            else if (randomValue <= Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF) //CLASS B STAR, 2.1 -> 16M
            {
                double massscale = 2.1 + (randomValue / (Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF)) * 13.9;
                double sizescale = 1.9 + (randomValue / (Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF)) * 1.1;
                mass     *= massscale;
                size     *= sizescale;
                starClass = Class.B;
            }
            else if (randomValue <= Constants.STAR_A_CLASS_CUTOFF + Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF)//CLASS A 1.4 -> 2.1M
            {
                double massscale = 1.4 + (randomValue / (Constants.STAR_A_CLASS_CUTOFF + Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF)) * 0.7;
                double sizescale = 1.4 + (randomValue / (Constants.STAR_A_CLASS_CUTOFF + Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF)) * 0.5;
                mass     *= massscale;
                size     *= sizescale;
                starClass = Class.A;
            }
            else if (randomValue <= Constants.STAR_F_CLASS_CUTOFF + Constants.STAR_A_CLASS_CUTOFF + Constants.STAR_B_CLASS_CUTOFF +
                     Constants.STAR_O_CLASS_CUTOFF) //CLASS F 1.04 -> 1.4M
            {
                double massscale = 1.04 + (randomValue / (Constants.STAR_F_CLASS_CUTOFF + Constants.STAR_A_CLASS_CUTOFF + Constants.STAR_B_CLASS_CUTOFF +
                                                          Constants.STAR_O_CLASS_CUTOFF)) * 0.3;
                double sizescale = 1.04 + (randomValue / (Constants.STAR_F_CLASS_CUTOFF + Constants.STAR_A_CLASS_CUTOFF + Constants.STAR_B_CLASS_CUTOFF +
                                                          Constants.STAR_O_CLASS_CUTOFF)) * 0.26;
                mass     *= massscale;
                size     *= sizescale;
                starClass = Class.F;
            }
            else if (randomValue <= Constants.STAR_G_CLASS_CUTOFF + Constants.STAR_F_CLASS_CUTOFF + Constants.STAR_A_CLASS_CUTOFF +
                     Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF) //CLASS G 0.8 -> 1.04M
            {
                double massscale = 0.8 + (randomValue / (Constants.STAR_G_CLASS_CUTOFF + Constants.STAR_F_CLASS_CUTOFF + Constants.STAR_A_CLASS_CUTOFF +
                                                         Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF)) * 0.24;
                double sizescale = 0.8 + (randomValue / (Constants.STAR_G_CLASS_CUTOFF + Constants.STAR_F_CLASS_CUTOFF + Constants.STAR_A_CLASS_CUTOFF +
                                                         Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF)) * 0.24;
                mass     *= massscale;
                size     *= sizescale;
                starClass = Class.G;
            }
            else if (randomValue <= Constants.STAR_K_CLASS_CUTOFF + Constants.STAR_G_CLASS_CUTOFF + Constants.STAR_F_CLASS_CUTOFF +
                     Constants.STAR_A_CLASS_CUTOFF + Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF)
            {
                double massscale = 0.45 + (randomValue / (Constants.STAR_K_CLASS_CUTOFF + Constants.STAR_G_CLASS_CUTOFF + Constants.STAR_F_CLASS_CUTOFF +
                                                          Constants.STAR_A_CLASS_CUTOFF + Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF)) * 0.35;
                double sizescale = 0.45 + (randomValue / (Constants.STAR_K_CLASS_CUTOFF + Constants.STAR_G_CLASS_CUTOFF + Constants.STAR_F_CLASS_CUTOFF +
                                                          Constants.STAR_A_CLASS_CUTOFF + Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF)) * 0.35;
                mass     *= massscale;
                size     *= sizescale;
                starClass = Class.K;
            }
            else
            {
                double massscale = 0.08 + (randomValue / (Constants.STAR_M_CLASS_CUTOFF + Constants.STAR_K_CLASS_CUTOFF + Constants.STAR_G_CLASS_CUTOFF + Constants.STAR_F_CLASS_CUTOFF +
                                                          Constants.STAR_A_CLASS_CUTOFF + Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF)) * 0.37;
                double sizescale = 0.08 + (randomValue / (Constants.STAR_M_CLASS_CUTOFF + Constants.STAR_K_CLASS_CUTOFF + Constants.STAR_G_CLASS_CUTOFF + Constants.STAR_F_CLASS_CUTOFF +
                                                          Constants.STAR_A_CLASS_CUTOFF + Constants.STAR_B_CLASS_CUTOFF + Constants.STAR_O_CLASS_CUTOFF)) * 0.37;
                mass     *= massscale;
                size     *= sizescale;
                starClass = Class.M;
            }

            Star star = new Star(id, posX, posY, mass, size, starClass);

            return(star);
        }