Beispiel #1
0
        // at the two highest timewarp speed, the number of sun visibility samples drop to the point that
        // the quantization error first became noticeable, and then exceed 100%
        // to solve this, we switch to an analytical estimation of the portion of orbit that was in sunlight
        // - we check against timewarp rate, instead of index, to avoid issues during timewarp blending
        public void highspeedWarp(Vessel v)
        {
            // don't re-calculate this on every tick. So, if sunlight is not 1.0 or 0.0, do nothing here
            if (sunlight > 0.0001 && sunlight < 0.9999)
            {
                return;
            }

            sunlight   = 1.0 - Sim.ShadowPeriod(v) / Sim.OrbitalPeriod(v);
            solar_flux = Sim.SolarFlux(Sim.SunDistance(Lib.VesselPosition(v))) * atmo_factor;
        }
Beispiel #2
0
        /// <summary>Estimated solar flux from the first parent sun of the given body, including other neighbouring stars/suns (binary systems handling)</summary>
        /// <param name="body"></param>
        /// <param name="worstCase">if true, we use the largest distance between the body and the sun</param>
        /// <param name="mainSun"></param>
        /// <param name="mainSunDirection"></param>
        /// <param name="mainSunDistance"></param>
        /// <returns></returns>
        public static double SolarFluxAtBody(CelestialBody body, bool worstCase, out CelestialBody mainSun, out Vector3d mainSunDirection, out double mainSunDistance)
        {
            // get first parent sun
            mainSun = Lib.GetParentSun(body);

            // get direction and distance
            mainSunDirection = (mainSun.position - body.position).normalized;
            if (worstCase)
            {
                mainSunDistance = Sim.Apoapsis(Lib.GetParentPlanet(body)) - mainSun.Radius - body.Radius;
            }
            else
            {
                mainSunDistance = Sim.SunDistance(body.position, mainSun);
            }

            // get solar flux
            int mainSunIndex = mainSun.flightGlobalsIndex;

            Sim.SunData mainSunData = Sim.suns.Find(pr => pr.bodyIndex == mainSunIndex);
            double      solarFlux   = mainSunData.SolarFlux(mainSunDistance);

            // multiple suns handling (binary systems...)
            foreach (Sim.SunData otherSun in Sim.suns)
            {
                if (otherSun.body == mainSun)
                {
                    continue;
                }
                Vector3d otherSunDir = (otherSun.body.position - body.position).normalized;
                double   otherSunDist;
                if (worstCase)
                {
                    otherSunDist = Sim.Apoapsis(Lib.GetParentPlanet(body)) - otherSun.body.Radius;
                }
                else
                {
                    otherSunDist = Sim.SunDistance(body.position, otherSun.body);
                }
                // account only for other suns that have approximatively the same direction (+/- 30°), discard the others
                if (Vector3d.Angle(otherSunDir, mainSunDirection) > 30.0)
                {
                    continue;
                }
                solarFlux += otherSun.SolarFlux(otherSunDist);
            }
            return(solarFlux);
        }