Example #1
0
 public override void Apply()
 {
     if (!IsSun())
     {
         Debugger.Log("Sphere of influence: " + sphereOfInfluence + " meters (" + (sphereOfInfluence / AstroUtils.KERBIN_SOI) + " times Kerbin SOI)");
         planet.sphereOfInfluence = sphereOfInfluence;
     }
     Debugger.Log("Gravity: " + (gravity / AstroUtils.KERBIN_GRAVITY) + " times Kerbin gravity.");
     planet.gravParameter = gravity;
     if (orbitDriver != null)
     {
         orbit             = CreateOrbit(orbitData, orbit);
         orbitDriver.orbit = orbit;
         orbitDriver.UpdateOrbit();
     }
 }
Example #2
0
        public void OnPSystemReady(CelestialBody Sun, CelestialBody star, Transform starTransform)
        {
            var LocalSunCB           = Sun;
            var LocalStarCB          = star;
            var StarRatio            = (float)defintion.Radius / 261600000f;
            var ScaledStar           = starTransform;
            var ScaledStarMeshFilter = (MeshFilter)ScaledStar.GetComponent(typeof(MeshFilter));

            //Set Star Variables
            LocalStarCB.Mass               = defintion.Mass;
            LocalStarCB.Radius             = defintion.Radius;
            LocalStarCB.GeeASL             = LocalStarCB.Mass * (6.674E-11 / 9.81) / Math.Pow(LocalStarCB.Radius, 2.0);
            LocalStarCB.gMagnitudeAtCenter = LocalStarCB.GeeASL * 9.81 * Math.Pow(LocalStarCB.Radius, 2.0);
            LocalStarCB.gravParameter      = LocalStarCB.gMagnitudeAtCenter;
            LocalStarCB.bodyDescription    = defintion.BodyDescription;

            //Set Science parameters
            LocalStarCB.scienceValues.InSpaceLowDataValue = LocalStarCB.scienceValues.InSpaceLowDataValue *
                                                            defintion.ScienceMultiplier;
            LocalStarCB.scienceValues.RecoveryValue = LocalStarCB.scienceValues.RecoveryValue *
                                                      defintion.ScienceMultiplier;

            //Create new Orbitdriver
            OrbitDriver NewOrbitDriver = LocalStarCB.gameObject.AddComponent <OrbitDriver>();

            //Add new OrbitDriver to Kerbol
            LocalStarCB.orbitDriver = NewOrbitDriver;

            //Set OrbitDriver parameters
            LocalStarCB.orbitDriver.name          = LocalStarCB.name;
            LocalStarCB.orbitDriver.celestialBody = LocalStarCB;
            LocalStarCB.orbitDriver.referenceBody = LocalSunCB;
            LocalStarCB.orbitDriver.updateMode    = OrbitDriver.UpdateMode.UPDATE;
            LocalStarCB.orbitDriver.QueuedUpdate  = true;

            //Create new orbit
            LocalStarCB.orbitDriver.orbit = defintion.orbit.getOrbit(LocalSunCB);

            //Calculate SOI
            LocalStarCB.sphereOfInfluence = (LocalStarCB.orbit.semiMajorAxis *
                                             Math.Pow(LocalStarCB.Mass / LocalStarCB.orbit.referenceBody.Mass, (2.0 / 5)));
            LocalStarCB.hillSphere = LocalStarCB.orbit.semiMajorAxis * (1.0 - LocalStarCB.orbit.eccentricity) *
                                     Math.Pow((LocalStarCB.Mass / (3.0 * LocalStarCB.orbit.referenceBody.Mass)), 1.0 / 3.0);

            //Update CelestialBody
            LocalStarCB.CBUpdate();

            //Update OrbitDriver
            NewOrbitDriver.UpdateOrbit();

            //Update Star Scale
            MeshScaler.ScaleMesh(ScaledStarMeshFilter.mesh, StarRatio);

            //Update Corona Ratio
            foreach (var StarCorona in ScaledStar.GetComponentsInChildren <SunCoronas>())
            {
                var StarCoronaMeshFilter = (MeshFilter)StarCorona.GetComponent(typeof(MeshFilter));
                MeshScaler.ScaleMesh(StarCoronaMeshFilter.mesh, StarRatio);
            }

            if (defintion.StarColor != null)
            {
                ScaledStar.renderer.material.SetColor("_EmitColor0", defintion.StarColor.emitColor0);
                ScaledStar.renderer.material.SetColor("_EmitColor1", defintion.StarColor.emitColor1);
                ScaledStar.renderer.material.SetColor("_SunspotColor", defintion.StarColor.sunSpotColor);
                ScaledStar.renderer.material.SetColor("_RimColor", defintion.StarColor.rimColor);

                foreach (var StarCorona in ScaledStar.GetComponentsInChildren <SunCoronas>())
                {
                    StarCorona.renderer.material.mainTexture = defintion.StarColor.coronaTexture;
                }
            }
            else
            {
                Debug.Log("StarColor for " + defintion.Name + " is null!");
            }
        }
Example #3
0
        public void OnPSystemReady(CelestialBody Sun, CelestialBody star, Transform starTransform)
        {
            var LocalSunCB           = Sun;
            var LocalStarCB          = star;
            var StarRatio            = (float)defintion.Radius / 261600000f;
            var ScaledStar           = starTransform;
            var ScaledStarMeshFilter = (MeshFilter)ScaledStar.GetComponent(typeof(MeshFilter));

            //Set Star Variables
            LocalStarCB.Mass               = defintion.Mass;
            LocalStarCB.Radius             = defintion.Radius;
            LocalStarCB.GeeASL             = LocalStarCB.Mass * (6.674E-11 / 9.81) / Math.Pow(LocalStarCB.Radius, 2.0);
            LocalStarCB.gMagnitudeAtCenter = LocalStarCB.GeeASL * 9.81 * Math.Pow(LocalStarCB.Radius, 2.0);
            LocalStarCB.gravParameter      = LocalStarCB.gMagnitudeAtCenter;
            LocalStarCB.bodyDescription    = defintion.BodyDescription;

            //Set Science parameters
            LocalStarCB.scienceValues.InSpaceLowDataValue = LocalStarCB.scienceValues.InSpaceLowDataValue *
                                                            defintion.ScienceMultiplier;
            LocalStarCB.scienceValues.RecoveryValue = LocalStarCB.scienceValues.RecoveryValue *
                                                      defintion.ScienceMultiplier;

            //Create new Orbitdriver
            OrbitDriver NewOrbitDriver = LocalStarCB.gameObject.AddComponent <OrbitDriver>();

            //Add new OrbitDriver to Kerbol
            LocalStarCB.orbitDriver = NewOrbitDriver;

            //Set OrbitDriver parameters
            LocalStarCB.orbitDriver.name          = LocalStarCB.name;
            LocalStarCB.orbitDriver.celestialBody = LocalStarCB;
            LocalStarCB.orbitDriver.referenceBody = LocalSunCB;
            LocalStarCB.orbitDriver.updateMode    = OrbitDriver.UpdateMode.UPDATE;
            LocalStarCB.orbitDriver.QueuedUpdate  = true;

            //Create new orbit
            LocalStarCB.orbitDriver.orbit = new Orbit(defintion.Inclination, defintion.Eccentricity, defintion.SemiMajorAxis,
                                                      defintion.LAN, defintion.ArgumentOfPeriapsis, defintion.MeanAnomalyAtEpoch, defintion.Epoch, LocalSunCB);

            //Calculate SOI
            LocalStarCB.sphereOfInfluence = (LocalStarCB.orbit.semiMajorAxis *
                                             Math.Pow(LocalStarCB.Mass / LocalStarCB.orbit.referenceBody.Mass, (2.0 / 5)));
            LocalStarCB.hillSphere = LocalStarCB.orbit.semiMajorAxis * (1.0 - LocalStarCB.orbit.eccentricity) *
                                     Math.Pow((LocalStarCB.Mass / (3.0 * LocalStarCB.orbit.referenceBody.Mass)), 1.0 / 3.0);

            //Update CelestialBody
            LocalStarCB.CBUpdate();

            //Update OrbitDriver
            NewOrbitDriver.UpdateOrbit();

            //Update Star Scale
            MeshScaler.ScaleMesh(ScaledStarMeshFilter.mesh, StarRatio);

            //Update Corona Ratio
            foreach (var StarCorona in ScaledStar.GetComponentsInChildren <SunCoronas>())
            {
                var StarCoronaMeshFilter = (MeshFilter)StarCorona.GetComponent(typeof(MeshFilter));
                MeshScaler.ScaleMesh(StarCoronaMeshFilter.mesh, StarRatio);
            }
            switch (defintion.StarColor)
            {
            case PlanetColor.Blue:
                //Change to Blue Star

                ScaledStar.renderer.material.SetColor("_EmitColor0", new Color(0.357f, 0.588f, 0.405f, 1));
                ScaledStar.renderer.material.SetColor("_EmitColor1", new Color(0.139f, 0.061f, 1.0f, 1));
                ScaledStar.renderer.material.SetColor("_SunspotColor", new Color(1.0f, 1.0f, 1.0f, 1));
                ScaledStar.renderer.material.SetColor("_RimColor", new Color(0.388f, 0.636f, 1.0f, 1.0f));

                foreach (var StarCorona in ScaledStar.GetComponentsInChildren <SunCoronas>())
                {
                    StarCorona.renderer.material.mainTexture =
                        GameDatabase.Instance.GetTexture("StarSystems/Resources/BlueStarCorona", false);
                }
                break;

            case PlanetColor.Red:
                //Change to Red Star

                ScaledStar.renderer.material.SetColor("_EmitColor0", new Color(0.861f, 0.704f, 0.194f, 1));
                ScaledStar.renderer.material.SetColor("_EmitColor1", new Color(0.398f, 0.071f, 1.0f, 1));
                ScaledStar.renderer.material.SetColor("_SunspotColor", new Color(0.01f, 0.003f, 0.007f, 1));
                ScaledStar.renderer.material.SetColor("_RimColor", new Color(0.626f, 0.231f, 0.170f, 1.0f));

                foreach (var StarCorona in ScaledStar.GetComponentsInChildren <SunCoronas>())
                {
                    StarCorona.renderer.material.mainTexture =
                        GameDatabase.Instance.GetTexture("StarSystems/Resources/RedStarCorona", false);
                }
                break;
            }
        }