Ejemplo n.º 1
0
        public static StellarSystem GenerateStellarSystem(string systemName, SystemGenerationOptions genOptions = null, StellarBody sun = null, IEnumerable <Seed> seedSystem = null)
        {
            genOptions ??= new SystemGenerationOptions();

            var phy = new BodyPhysics();

            sun ??= new Star()
            {
                Science = phy
            };
            var useRandomTilt = seedSystem == null;

            var accrete = new Accrete(Ratio.FromDecimalFractions(genOptions.CloudEccentricity),
                                      Ratio.FromDecimalFractions(genOptions.GasDensityRatio),
                                      Ratio.FromDecimalFractions(genOptions.DustDensityCoeff));
            double outer_planet_limit = GetOuterLimit(sun);
            double outer_dust_limit   = GetStellarDustLimit(sun.Mass.SolarMasses);

            seedSystem = seedSystem ?? accrete.CreateSeeds(sun.Mass,
                                                           sun.Luminosity, Length.FromAstronomicalUnits(0.0), Length.FromAstronomicalUnits(outer_dust_limit), Length.FromAstronomicalUnits(outer_planet_limit), Length.Zero);

            var planets = GeneratePlanets(sun, seedSystem, useRandomTilt, genOptions);

            return(new StellarSystem()
            {
                Options = genOptions,
                Planets = planets,
                Name = systemName,
                Star = sun
            });
        }
            public void TestSunIllumination()
            {
                var phy = new BodyPhysics();

                var expectedValue      = 1.0;
                var sunLuminosity      = Luminosity.FromSolarLuminosities(1.0);
                var earthSemiMajorAxis = Length.FromAstronomicalUnits(1.0);

                Assert.AreEqual(expectedValue, phy.GetMinimumIllumination(earthSemiMajorAxis, sunLuminosity).DecimalFractions);
            }
            public void TestSunEcosphere()
            {
                const double expectedValue = 1.0;
                const double sunLuminosity = 1.0;

                var phy = new BodyPhysics();

                Assert.AreEqual(expectedValue, phy.Astronomy.GetEcosphereRadius(Mass.FromSolarMasses(1.0),
                                                                                Luminosity.FromSolarLuminosities(sunLuminosity)).AstronomicalUnits, 0.0001);
            }
            public void TestSunJupiterRocheLimit()
            {
                var phy = new BodyPhysics();

                var sunJupiterKM = 894677;
                var sunJupiterAU = sunJupiterKM / GlobalConstants.KM_PER_AU;

                var dAU = phy.GetRocheLimit(SunRadius, SunDensity, JupiterDensity).AstronomicalUnits;

                Assert.AreEqual(sunJupiterAU, dAU, 0.99);

                var dKM = phy.GetRocheLimit(SunRadius, SunDensity, JupiterDensity).Kilometers;

                Assert.AreEqual(sunJupiterKM, dKM, 0.99);
            }
            public void TestEarthAverageCometRocheLimit()
            {
                var phy = new BodyPhysics();

                var earthAvgCometKM = 17887;
                var earthAvgCometAU = earthAvgCometKM / GlobalConstants.KM_PER_AU;

                var dAU = phy.GetRocheLimit(EarthRadius, EarthDensity, AvgCometDensity).AstronomicalUnits;

                Assert.AreEqual(earthAvgCometAU, dAU, 0.99);

                var dKM = phy.GetRocheLimit(EarthRadius, EarthDensity, AvgCometDensity).Kilometers;

                Assert.AreEqual(earthAvgCometKM, dKM, 0.99);
            }
            public void TestEarthMoonRocheLimit()
            {
                var phy = new BodyPhysics();

                var earthMoonKM = 9492;
                var earthMoonAU = earthMoonKM / GlobalConstants.KM_PER_AU;

                var dAU = phy.GetRocheLimit(EarthRadius, EarthDensity, MoonDensity).AstronomicalUnits;

                Assert.AreEqual(earthMoonAU, dAU, 0.99);

                var dKM = phy.GetRocheLimit(EarthRadius, EarthDensity, MoonDensity).Kilometers;

                Assert.AreEqual(earthMoonKM, dKM, 0.99);
            }
            public void TestSunJupiterHillSphere()
            {
                var phy = new BodyPhysics();

                var jupiterSphereKM = 53129256;
                var jupiterSphereAU = jupiterSphereKM / GlobalConstants.KM_PER_AU;

                var hAU = phy.GetHillSphere(SunMass, JupiterMass, JupiterSemiMajorAxis).AstronomicalUnits;

                Assert.AreEqual(jupiterSphereAU, hAU, 0.001);

                var hKM = phy.GetHillSphere(SunMass, JupiterMass, JupiterSemiMajorAxis).Kilometers;

                Assert.AreEqual(jupiterSphereKM, hKM, 0.99);
            }
            public void TestSunVenusHillSphere()
            {
                var phy = new BodyPhysics();

                var venusSphereKM = 1011028;
                var venusSphereAU = venusSphereKM / GlobalConstants.KM_PER_AU;

                var hAU = phy.GetHillSphere(SunMass, VenusMass, VenusSemiMajorAxis).AstronomicalUnits;

                Assert.AreEqual(venusSphereAU, hAU, 0.001);

                var hKM = phy.GetHillSphere(SunMass, VenusMass, VenusSemiMajorAxis).Kilometers;

                Assert.AreEqual(venusSphereKM, hKM, 0.99);
            }
            public void TestSunMercuryHillSphere()
            {
                var phy = new BodyPhysics();

                var mercurySphereKM = 220314;
                var mercurySphereAU = mercurySphereKM / GlobalConstants.KM_PER_AU;

                var hAU = phy.GetHillSphere(SunMass, MercuryMass, MercurySemiMajorAxis).AstronomicalUnits;

                Assert.AreEqual(mercurySphereAU, hAU, 0.001);

                var hKM = phy.GetHillSphere(SunMass, MercuryMass, MercurySemiMajorAxis).Kilometers;

                Assert.AreEqual(mercurySphereKM, hKM, 0.99);
            }
            public void TestSunEarthHillSphere()
            {
                var phy = new BodyPhysics();

                var earthSphereKM = 1496498;
                var earthSphereAU = earthSphereKM / GlobalConstants.KM_PER_AU;

                var hAU = phy.GetHillSphere(SunMass, EarthMass, EarthSemiMajorAxis).AstronomicalUnits;

                Assert.AreEqual(earthSphereAU, hAU, 0.001);

                var hKM = phy.GetHillSphere(SunMass, EarthMass, EarthSemiMajorAxis).Kilometers;

                Assert.AreEqual(earthSphereKM, hKM, 0.99);
            }
Ejemplo n.º 11
0
        public void Update(float deltaTime)
        {
            foreach (Entity entity in EntityWorld.Entities)
            {
                entity.Brain?.Update(entity, this, deltaTime);

                if (PhysicsWorld.TryGetBody(entity.BodyID, out Body? body))
                {
                    float speed = body.Velocity.Length();

                    if (speed >= entity.DangerSpeed && body.Contact.Y > 0f)
                    {
                        body.Friction = entity.DangerFriction;
                    }
                    else
                    {
                        body.Friction = body.Contact.Y > 0f ? entity.GroundFriction : entity.AirFriction;
                    }

                    if (entity.CanRotate)
                    {
                        entity.Rotation += body.Velocity.X * deltaTime;
                    }

                    if (body.Position.Y >= WaterTop)
                    {
                        entity.WaterTimer += deltaTime;

                        if (entity.WaterTimer >= 1f)
                        {
                            entity.IsPutOut = true;
                        }
                    }
                    else
                    {
                        entity.WaterTimer = 0f;
                    }

                    if (entity.IsBlowable)
                    {
                        for (int i = 0; i < WindChannels.Count; i++)
                        {
                            float channel = WindChannels[i];

                            if (body.Position.Y + body.Bounds.Center.Y >= channel - 4f && body.Position.Y + body.Bounds.Center.Y <= channel + 4f)
                            {
                                body.Force += new Vector2(i % 2 == 0 ? 1f : -1f, 0f) * 10f;
                            }
                        }
                    }
                }
            }

            foreach (Body body in PhysicsWorld.Bodies)
            {
                BodyPhysics.UpdateBody(body, deltaTime, TileMap);
            }

            if (SlowMoTimer > 0f)
            {
                SlowMoTimer -= deltaTime;
            }
        }