Exemple #1
0
    public void GetOrbitType(double timeIn, CelestialBodyData lastPlanet)
    {
        this.orbitType           = Orbit.Type.Eternal;
        this.orbitEndTime        = double.PositiveInfinity;
        this.calculatePassesTime = double.PositiveInfinity;
        if (this.apoapsis > this.planet.orbitData.SOI || this.eccentricity > 1.0)
        {
            this.orbitEndTime = this.periapsisPassageTime + this.GetPassAnomaly(this.planet.orbitData.SOI);
            if (!double.IsNaN(this.meanMotion))
            {
                this.endTrueAnomaly = Kepler.GetTrueAnomalyAtRadius(this.planet.orbitData.SOI, this.semiLatusRectum, this.eccentricity) * (double)Math.Sign(this.meanMotion);
            }
            this.orbitType  = Orbit.Type.Escape;
            this.nextPlanet = this.planet.parentBody;
        }
        double            cutEndTime = (this.orbitType != Orbit.Type.Escape) ? (timeIn + this._period * 0.995) : double.PositiveInfinity;
        List <Orbit.Pass> list       = new List <Orbit.Pass>();

        CelestialBodyData[] satellites = this.planet.satellites;
        for (int i = 0; i < satellites.Length; i++)
        {
            CelestialBodyData celestialBodyData = satellites[i];
            if (this.CanPasSOI(celestialBodyData.orbitData.orbitHeightM, celestialBodyData.orbitData.SOI))
            {
                double cutStartTime = timeIn + ((!(celestialBodyData != lastPlanet)) ? ((this.orbitType != Orbit.Type.Escape) ? (this._period * 0.05) : double.PositiveInfinity) : 0.0);
                list.AddRange(this.CreatePasses(this.orbitType == Orbit.Type.Escape, cutStartTime, cutEndTime, celestialBodyData));
                if (this.orbitType == Orbit.Type.Eternal)
                {
                    this.calculatePassesTime = cutEndTime;
                }
            }
        }
        this.ProcessPasses(this.SortPasses(list));
    }
Exemple #2
0
 public CANProtocol(Kepler KeplerInterface) : base(KeplerInterface)
 {
     //Enter CAN Mode
     KeplerInterface.KeplerSerialCommunication.SendMessage(new KeplerCommand {
         Message = new byte[] { 0x02, 0x00, 0x03, 0xA0, 0x02, 0x02 }
     });
 }
Exemple #3
0
    public double GetPassAnomaly(double height)
    {
        double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(height, this.semiLatusRectum, this.eccentricity);
        double meanAnomaly         = Kepler.GetMeanAnomaly(this.eccentricity, trueAnomalyAtRadius);

        return(Math.Abs(meanAnomaly / this.meanMotion));
    }
Exemple #4
0
    public double GetStopTimeWarpTime()
    {
        double num = this.planet.radius + this.planet.minTimewarpHeightKm * 1000.0;

        if (this.periapsis + 10.0 < num)
        {
            double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(num, this.semiLatusRectum, this.eccentricity);
            double num2 = this.GetNextTrueAnomalyPassageTime(this.timeIn, trueAnomalyAtRadius);
            double num3 = this.GetNextTrueAnomalyPassageTime(this.timeIn, -trueAnomalyAtRadius);
            if (num2 < this.timeIn)
            {
                num2 += this._period;
            }
            if (num3 < this.timeIn)
            {
                num3 += this._period;
            }
            if (num2 < this.timeIn)
            {
                num2 = double.PositiveInfinity;
            }
            if (num3 < this.timeIn)
            {
                num3 = double.PositiveInfinity;
            }
            return(Math.Min(num2, num3));
        }
        return(double.PositiveInfinity);
    }
Exemple #5
0
    public Orbit(Double3 posIn, Double3 velIn, double timeIn, CelestialBodyData planet, CelestialBodyData lastPlanet)
    {
        this.planet = planet;
        this.timeIn = timeIn;
        double  mass    = planet.mass;
        Double3 b       = Double3.Cross2d(posIn, velIn);
        Double3 @double = Double3.Cross(velIn, b) / mass - posIn.normalized2d;

        this.eccentricity        = @double.magnitude2d;
        this.argumentOfPeriapsis = Math.Atan2(@double.y, @double.x);
        this.semiMajorAxis       = -mass / (2.0 * (Math.Pow(velIn.magnitude2d, 2.0) / 2.0 - mass / posIn.magnitude2d));
        this.periapsis           = this.semiMajorAxis * (1.0 - this.eccentricity);
        this.apoapsis            = ((this.eccentricity >= 1.0) ? double.PositiveInfinity : (this.semiMajorAxis * (1.0 + this.eccentricity)));
        this.semiLatusRectum     = Kepler.GetSemiLatusRectum(this.periapsis, this.eccentricity);
        this._period             = Kepler.GetPeriod(this.eccentricity, this.semiMajorAxis, mass);
        this.meanMotion          = Kepler.GetMeanMotion(this._period, this.eccentricity, mass, this.semiMajorAxis) * (double)Math.Sign(b.z);
        double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(posIn.magnitude2d, this.semiLatusRectum, this.eccentricity);
        double num = Kepler.GetMeanAnomaly(this.eccentricity, trueAnomalyAtRadius, posIn, this.argumentOfPeriapsis) / this.meanMotion;

        if (this.apoapsis > planet.orbitData.SOI || this.eccentricity >= 1.0)
        {
            this._period = 0.0;
        }
        this.periapsisPassageTime = timeIn + num - this._period * 10.0;
        this.GetOrbitType(timeIn, lastPlanet);
        this.stopTimeWarpTime = this.GetStopTimeWarpTime();
    }
Exemple #6
0
    private static double GetDistanceSqrtAtHeight(Orbit orbitA, Orbit orbitB, double time, double globalTrueAnomaly)
    {
        double  nextTrueAnomalyPassageTime = orbitA.GetNextTrueAnomalyPassageTime(time, globalTrueAnomaly - orbitA.argumentOfPeriapsis);
        Double3 position = Kepler.GetPosition(Kepler.GetRadius(orbitA.semiLatusRectum, orbitA.eccentricity, globalTrueAnomaly - orbitA.argumentOfPeriapsis), globalTrueAnomaly, 0.0);
        Double3 posOut   = orbitB.GetPosOut(nextTrueAnomalyPassageTime);

        Debug.DrawLine((position / 10000.0).toVector3, (posOut / 10000.0).toVector3, Color.green);
        return((position - posOut).sqrMagnitude2d);
    }
 private void OnValidate()
 {
     base.transform.name      = this.bodyName;
     this.radius              = this.diameterKm * 500.0;
     this.mass                = Math.Pow(this.radius, 2.0) * this.surfaceGravity;
     this.cameraSwitchHeightM = this.cameraSwitchHeightKm * 1000.0;
     if (this.atmosphereData.shadowIntensity == 0f)
     {
         this.atmosphereData.shadowIntensity = 1.65f;
     }
     this.atmosphereData.atmosphereHeightM = this.atmosphereData.atmosphereHeightKm * 1000.0;
     if (this.terrainData.terrainMaterial != null)
     {
         this.terrainData.terrainMaterial.color = this.terrainData.terrainColor;
     }
     this.terrainData.maxTerrainHeight = this.GetMaxTerrainHeight();
     this.terrainData.unitToAngle      = 360.0 / ((this.radius + this.terrainData.maxTerrainHeight) * 2.0 * 3.1415926535897931);
     for (int i = 0; i < this.terrainData.detailLevels.Length; i++)
     {
         this.terrainData.detailLevels[i].chunckSize  = (double)this.terrainData.baseChunckSize / Math.Pow(2.0, (double)i);
         this.terrainData.detailLevels[i].angularSize = (float)this.terrainData.detailLevels[i].chunckSize / (float)this.terrainData.heightMaps[0].heightMap.HeightDataArray.Length * 360f;
     }
     this.terrainData.detailLevels[0].loadDistance = double.PositiveInfinity;
     if (this.type == CelestialBodyData.Type.Star)
     {
         this.parentBody = null;
         this.orbitData.SOIMultiplier = double.PositiveInfinity;
     }
     if (this.parentBody != null && (this.type == this.parentBody.type || (this.type == CelestialBodyData.Type.Planet && this.parentBody.type == CelestialBodyData.Type.Moon)))
     {
         this.parentBody = null;
     }
     if (this.parentBody != null)
     {
         this.orbitData._period         = Kepler.GetPeriod(0.0, this.orbitData.orbitHeightM, this.parentBody.mass);
         this.orbitData.periodString    = Ref.GetTimeString(this.orbitData._period);
         this.orbitData._meanMotion     = -6.2831853071795862 / this.orbitData._period;
         this.orbitData.orbitalVelocity = this.orbitData.orbitHeightM * this.orbitData._meanMotion;
         this.orbitData.SOI             = this.orbitData.orbitHeightM * Math.Pow(this.mass / this.parentBody.mass, 0.4) * this.orbitData.SOIMultiplier;
         if (!this.ParentHasThisBodyAsSatellite())
         {
             List <CelestialBodyData> list = new List <CelestialBodyData>(this.parentBody.satellites);
             list.Add(this);
             this.parentBody.satellites = list.ToArray();
             this.parentBody.ValidateSatellites();
         }
     }
     else
     {
         this.orbitData._period         = double.NaN;
         this.orbitData.periodString    = "NaN";
         this.orbitData._meanMotion     = double.NaN;
         this.orbitData.orbitalVelocity = double.NaN;
         this.orbitData.SOI             = ((this.type != CelestialBodyData.Type.Star) ? double.NaN : double.PositiveInfinity);
     }
     this.ValidateSatellites();
 }
Exemple #8
0
    public double GetLastTrueAnomalyPassageTime(double referenceTime, double trueAnomaly)
    {
        double num = this.periapsisPassageTime + Kepler.GetMeanAnomaly(this.eccentricity, trueAnomaly) / this.meanMotion;

        if (this.orbitType != Orbit.Type.Escape)
        {
            return(num + (double)((int)((referenceTime - num) / this._period)) * this._period);
        }
        return(num);
    }
Exemple #9
0
    public Vector3[] GenerateOrbitLinePoints(double fromTrueAnomaly, double toTrueAnomaly, int resolution)
    {
        Vector3[] array = new Vector3[resolution + 1];
        double    num   = (toTrueAnomaly - fromTrueAnomaly) % 6.2831853071795862 / (double)resolution;

        for (int i = 0; i < resolution + 1; i++)
        {
            double v      = fromTrueAnomaly + num * (double)i;
            double radius = Kepler.GetRadius(this.semiLatusRectum, this.eccentricity, v);
            array[i] = Kepler.GetPosition(radius, v, this.argumentOfPeriapsis).toVector3;
        }
        return(array);
    }
Exemple #10
0
    private static void CalculateClosestApproach(LineRenderer closestApproachLine, Orbit orbit, CelestialBodyData targetPlanet, ref bool drawn)
    {
        List <double> list = new List <double>();

        if (orbit.periapsis < targetPlanet.orbitData.orbitHeightM && orbit.apoapsis > targetPlanet.orbitData.orbitHeightM)
        {
            double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(targetPlanet.orbitData.orbitHeightM, orbit.semiLatusRectum, orbit.eccentricity);
            list.Add(trueAnomalyAtRadius);
            list.Add(-trueAnomalyAtRadius);
        }
        else
        {
            if (!orbit.CanPasSOI(targetPlanet.orbitData.orbitHeightM, targetPlanet.mapData.showClosestApproachDistance))
            {
                return;
            }
            if (orbit.apoapsis < targetPlanet.orbitData.orbitHeightM)
            {
                list.Add(3.1415927410125732);
            }
            else
            {
                list.Add(0.0);
            }
        }
        double  num  = double.PositiveInfinity;
        Double3 posA = Double3.zero;
        Double3 posB = Double3.zero;

        for (int i = 0; i < list.Count; i++)
        {
            double nextTrueAnomalyPassageTime = orbit.GetNextTrueAnomalyPassageTime(Ref.controller.globalTime, list[i]);
            if (nextTrueAnomalyPassageTime >= Ref.controller.globalTime)
            {
                Double3 position       = Kepler.GetPosition(Kepler.GetRadius(orbit.semiLatusRectum, orbit.eccentricity, list[i]), list[i], orbit.argumentOfPeriapsis);
                Double3 posOut         = targetPlanet.GetPosOut(nextTrueAnomalyPassageTime);
                double  sqrMagnitude2d = (position - posOut).sqrMagnitude2d;
                if (sqrMagnitude2d <= num)
                {
                    num  = sqrMagnitude2d;
                    posA = position;
                    posB = posOut;
                }
            }
        }
        if (list.Count > 0)
        {
            ClosestApproach.SetLine(closestApproachLine, posA, posB, Ref.map.mapRefs[targetPlanet.parentBody].holder);
            drawn = true;
        }
    }
    public void viewGhosts(float time)
    {
        for (int i = 0; i < planets.Length; i++)
        {
            spheres[i].SetActive(true);
            Body   b     = planets[i].GetComponent <Body>();
            Kepler orbit = b.orbit;
            spheres[i].transform.localScale    = new Vector3(units.coordinateScale * b.radius / 60, units.coordinateScale * b.radius / 60, 1);
            spheres[i].transform.localPosition = orbit.r(time) / units.AU * units.coordinateScale;
            //Gizmos.color = new Color(0,255,0);
            //Gizmos.DrawSphere(orbit.r(time), units.coordinateScale*b.radius/60);

            //Gizmos.Draw
        }
    }
Exemple #12
0
 public static double GetEccentricAnomaly(double M, double e)
 {
     if (e < 1.0)
     {
         return(Kepler.NewtonElliptical(M, e, 1));
     }
     if (e > 1.0)
     {
         return(Kepler.NewtonHyperbolic(M, e));
     }
     if (e == 1.0)
     {
         return(Kepler.NewtonParabolic(M, e, 1));
     }
     return(M);
 }
Exemple #13
0
 private void UpdateDynamicVariables(double newTime)
 {
     if (this.lastCalculationTime != newTime)
     {
         this.lastCalculationTime = newTime;
         double eccentricAnomaly = Kepler.GetEccentricAnomaly((newTime - this.periapsisPassageTime) * this.meanMotion, this.eccentricity);
         if (double.IsNaN(eccentricAnomaly))
         {
             return;
         }
         this.eccentricAnomnalyOut = eccentricAnomaly;
         this.trueAnomalyOut       = Kepler.GetTrueAnomaly(this.eccentricAnomnalyOut, this.eccentricity);
         double radius = Kepler.GetRadius(this.semiLatusRectum, this.eccentricity, this.trueAnomalyOut);
         this.posOut = Kepler.GetPosition(radius, this.trueAnomalyOut, this.argumentOfPeriapsis);
         this.velOut = Kepler.GetVelocity(this.semiMajorAxis, radius, this.meanMotion, this.eccentricAnomnalyOut, this.trueAnomalyOut, this.eccentricity, this.argumentOfPeriapsis);
     }
 }
Exemple #14
0
 public static List <Orbit> CalculateOrbits(List <Orbit> orbitsIn)
 {
     while (orbitsIn.Count < 3)
     {
         Orbit orbit = orbitsIn[orbitsIn.Count - 1];
         if (orbit.orbitType == Orbit.Type.Escape)
         {
             if (orbitsIn.Count >= 2 && orbitsIn[orbitsIn.Count - 2].orbitType == Orbit.Type.Encounter)
             {
                 return(orbitsIn);
             }
             Double3 position = Kepler.GetPosition(orbit.planet.orbitData.SOI, orbit.endTrueAnomaly, orbit.argumentOfPeriapsis);
             Double3 velocity = Kepler.GetVelocity(orbit.semiMajorAxis, orbit.planet.orbitData.SOI, orbit.meanMotion, Kepler.GetEccentricAnomalyFromTrueAnomaly(orbit.endTrueAnomaly, orbit.eccentricity), orbit.endTrueAnomaly, orbit.eccentricity, orbit.argumentOfPeriapsis);
             Double3 posIn    = position + orbit.planet.GetPosOut(orbit.orbitEndTime);
             Double3 velIn    = velocity + orbit.planet.GetVelOut(orbit.orbitEndTime);
             if (double.IsNaN(posIn.x * velIn.y - posIn.y * velIn.x))
             {
                 return(orbitsIn);
             }
             orbitsIn.Add(new Orbit(posIn, velIn, orbit.orbitEndTime, orbit.nextPlanet, orbit.planet));
         }
         else
         {
             if (orbit.orbitType != Orbit.Type.Encounter)
             {
                 return(orbitsIn);
             }
             if (orbitsIn.Count >= 2 && orbitsIn[orbitsIn.Count - 2].planet == orbit.nextPlanet)
             {
                 return(orbitsIn);
             }
             double  eccentricAnomalyFromTrueAnomaly = Kepler.GetEccentricAnomalyFromTrueAnomaly(orbit.endTrueAnomaly, orbit.eccentricity);
             double  radius    = Kepler.GetRadius(orbit.semiLatusRectum, orbit.eccentricity, orbit.endTrueAnomaly);
             Double3 position2 = Kepler.GetPosition(radius, orbit.endTrueAnomaly, orbit.argumentOfPeriapsis);
             Double3 velocity2 = Kepler.GetVelocity(orbit.semiMajorAxis, radius, orbit.meanMotion, eccentricAnomalyFromTrueAnomaly, orbit.endTrueAnomaly, orbit.eccentricity, orbit.argumentOfPeriapsis);
             Double3 posIn2    = position2 - orbit.nextPlanet.GetPosOut(orbit.orbitEndTime);
             Double3 velIn2    = velocity2 - orbit.nextPlanet.GetVelOut(orbit.orbitEndTime);
             if (double.IsNaN(posIn2.x * velIn2.y - posIn2.y * velIn2.x))
             {
                 return(orbitsIn);
             }
             orbitsIn.Add(new Orbit(posIn2, velIn2, orbit.orbitEndTime, orbit.nextPlanet, null));
         }
     }
     return(orbitsIn);
 }
Exemple #15
0
    private static void CalculateClosestApproach(LineRenderer closestApproachLine, Orbit orbitA, Orbit orbitB, double time, ref bool drawn)
    {
        if (orbitA.orbitType != Orbit.Type.Eternal || orbitB.orbitType != Orbit.Type.Eternal)
        {
            return;
        }
        List <double> list = new List <double>();

        if (orbitA._period > orbitB._period)
        {
            list.Add(ClosestApproach.GetIntersectTrueAnomalyGlobal(orbitA, orbitB, time, 15) - orbitA.argumentOfPeriapsis);
        }
        else
        {
            list.Add(ClosestApproach.GetIntersectTrueAnomalyGlobal(orbitB, orbitA, time, 15) - orbitA.argumentOfPeriapsis);
        }
        double  num  = double.PositiveInfinity;
        Double3 posA = Double3.zero;
        Double3 posB = Double3.zero;

        for (int i = 0; i < list.Count; i++)
        {
            double nextTrueAnomalyPassageTime = orbitA.GetNextTrueAnomalyPassageTime(Ref.controller.globalTime, list[i]);
            if (nextTrueAnomalyPassageTime >= Ref.controller.globalTime)
            {
                Double3 position       = Kepler.GetPosition(Kepler.GetRadius(orbitA.semiLatusRectum, orbitA.eccentricity, list[i]), list[i], orbitA.argumentOfPeriapsis);
                Double3 posOut         = orbitB.GetPosOut(nextTrueAnomalyPassageTime);
                double  sqrMagnitude2d = (position - posOut).sqrMagnitude2d;
                if (sqrMagnitude2d <= num)
                {
                    num  = sqrMagnitude2d;
                    posA = position;
                    posB = posOut;
                }
            }
        }
        if (list.Count > 0)
        {
            ClosestApproach.SetLine(closestApproachLine, posA, posB, Ref.map.mapRefs[orbitA.planet].holder);
            drawn = true;
        }
    }
Exemple #16
0
    private static double NewtonElliptical(double M, double e, int count)
    {
        double num  = M;
        double num2 = 0.0;

        for (int i = 0; i < Kepler.maxIterations * count; i++)
        {
            num2 = num - (num - e * Math.Sin(num2) - M) / (1.0 - e * Math.Cos(num2));
            if (Math.Abs(num2 - e * Math.Sin(num2) - M) < Kepler.tolerance)
            {
                return(num2);
            }
            num = num2;
        }
        if (count <= 3)
        {
            return(Kepler.NewtonElliptical(M + 1E-05, e, count + 1));
        }
        return(num2);
    }
Exemple #17
0
 private static void GenerateMeshOrbitTW(ref MeshFilter meshFilterOrbit, ref bool show, float ejectionAngle, Orbit orbit)
 {
     for (int i = 0; i < 2; i++)
     {
         double num = Math.Abs(Kepler.GetRadius(Kepler.GetSemiLatusRectum(orbit.periapsis, orbit.eccentricity), orbit.eccentricity, (double)(ejectionAngle + (float)i * 0.2f * (float)Math.Sign(orbit.meanMotion)) - orbit.argumentOfPeriapsis));
         if (num > orbit.planet.orbitData.SOI || num > orbit.periapsis * 1.35)
         {
             return;
         }
     }
     Vector3[] array = new Vector3[42];
     for (int j = 0; j < 21; j++)
     {
         float num2 = ejectionAngle + (float)j * 0.01f * (float)Math.Sign(orbit.meanMotion);
         array[j * 2]     = new Vector3(Mathf.Cos(num2), Mathf.Sin(num2), 0f) * (float)(Kepler.GetRadius(Kepler.GetSemiLatusRectum(orbit.periapsis, orbit.eccentricity), orbit.eccentricity, (double)num2 - orbit.argumentOfPeriapsis) / 10000.0);
         array[j * 2 + 1] = array[j * 2] * 0.915f;
     }
     meshFilterOrbit.mesh.vertices = array;
     meshFilterOrbit.mesh.RecalculateNormals();
     meshFilterOrbit.mesh.RecalculateBounds();
     show = true;
 }
    public void generate()
    {
        generateGhosts();
        Kepler test = new Kepler();

        test.fromEvA(units.AU, new Vector2(0, 0.0001f), units.G * (units.ME + units.ME * 333333));
        Debug.Log(test.r(0).x / units.AU);
        //Generate the mainstar

        mainStar = new GameObject();
        mainStar.AddComponent <Body>();
        mainStar.GetComponent <Body>().generateStar();
        //Generate planets
        planets = new GameObject[planetNum];
        for (int i = 0; i < planetNum; i++)
        {
            planets[i] = new GameObject();
            planets[i].AddComponent <Body>();
            planets[i].transform.SetParent(mainStar.transform);
            Body component = planets[i].GetComponent <Body>();
            component.generate();
            component.parent = mainStar.GetComponent <Body>();
            component.generateOrbit(systemSizelow, systemSizehigh);
        }
        //Generate Signals (events)
        signals = new Signal[signalNum];
        for (int i = 0; i < signalNum; i++)
        {
            signals[i].generate();
        }

        //Generate NPCs (enemies, shops, stations, one warp gate)
        //shop = new GameObject();
        //shop.AddComponent<Shop>();
        //Shop shopcomponent = shop.GetComponent<Shop>();
        //shop.transform.localPosition = new Vector2(Random.Range(2f, 4f), Random.Range(-2f, -4f));
        //ShopTextController stc = GameObject.Find("ShopPrices").GetComponent<ShopTextController>();
        //stc.initThis();
    }
Exemple #19
0
 private bool GenerateLocalTransferWindowMarker(float ejectionAngle, Orbit orbit)
 {
     for (int i = 0; i < 2; i++)
     {
         double num = Math.Abs(Kepler.GetRadius(Kepler.GetSemiLatusRectum(orbit.periapsis, orbit.eccentricity), orbit.eccentricity, (double)(ejectionAngle + (float)i * 0.2f * (float)Math.Sign(orbit.meanMotion)) - orbit.argumentOfPeriapsis));
         if (num > orbit.planet.orbitData.SOI || num > orbit.periapsis * 1.2)
         {
             return(false);
         }
     }
     Vector3[] array = new Vector3[42];
     for (int j = 0; j < 21; j++)
     {
         float num2 = ejectionAngle + (float)j * 0.01f * (float)Math.Sign(orbit.meanMotion);
         array[j * 2]     = new Vector3(Mathf.Cos(num2), Mathf.Sin(num2), 0f) * (float)(Kepler.GetRadius(Kepler.GetSemiLatusRectum(orbit.periapsis, orbit.eccentricity), orbit.eccentricity, (double)num2 - orbit.argumentOfPeriapsis) / 10000.0);
         array[j * 2 + 1] = array[j * 2] * 0.915f;
     }
     this.transferWindow.localMarkerMesh.mesh.vertices = array;
     this.transferWindow.localMarkerMesh.mesh.RecalculateNormals();
     this.transferWindow.localMarkerMesh.mesh.RecalculateBounds();
     return(true);
 }
Exemple #20
0
 public static void DrawClosestApproachPlanet(LineRenderer closestApproachLine, List <Orbit> orbits, CelestialBodyData targetPlanet, ref bool drawn)
 {
     for (int i = 0; i < orbits.Count; i++)
     {
         if (orbits[i].orbitType != Orbit.Type.Encounter)
         {
             if (orbits[i].planet == targetPlanet)
             {
                 ClosestApproach.SetLine(closestApproachLine, Kepler.GetPosition(orbits[i].periapsis, 0.0, orbits[i].argumentOfPeriapsis), Double3.zero, Ref.map.mapRefs[targetPlanet].holder);
                 drawn = true;
                 return;
             }
             if (orbits[i].planet == targetPlanet.parentBody)
             {
                 ClosestApproach.CalculateClosestApproach(closestApproachLine, orbits[i], targetPlanet, ref drawn);
                 if (drawn)
                 {
                     return;
                 }
             }
         }
     }
 }
Exemple #21
0
    private static void UpdateLocalTransferWindowMarker(ref bool show, ref MeshFilter meshFilterOrbit, double ejectionOrbitHeight, Orbit orbit, TransferWindow.Data transferWindow)
    {
        if (transferWindow.departure.type == CelestialBodyData.Type.Star || (transferWindow.transferType == TransferWindow.TransferType.ToNeighbour && transferWindow.departure != transferWindow.firstNeighbour))
        {
            return;
        }
        if (transferWindow.transferType == TransferWindow.TransferType.ToNeighbour || transferWindow.transferType == TransferWindow.TransferType.ToParent)
        {
            CelestialBodyData celestialBodyData = (transferWindow.transferType != TransferWindow.TransferType.ToNeighbour) ? transferWindow.departure : transferWindow.firstNeighbour;
            double            orbitHeightM      = celestialBodyData.orbitData.orbitHeightM;
            double            num        = (transferWindow.transferType != TransferWindow.TransferType.ToNeighbour) ? (transferWindow.target.radius + transferWindow.target.atmosphereData.atmosphereHeightM) : transferWindow.secondNeighbour.orbitData.orbitHeightM;
            double            num2       = Math.Min(num, orbitHeightM);
            double            num3       = (orbitHeightM + num) * 0.5;
            double            e          = 1.0 - num2 / num3;
            double            mass       = celestialBodyData.parentBody.mass;
            double            meanMotion = Kepler.GetMeanMotion(Kepler.GetPeriod(e, num3, mass), e, mass, num3);
            bool   flag           = num > orbitHeightM;
            double magnitude2d    = Kepler.GetVelocity(num3, orbitHeightM, meanMotion, (!flag) ? 3.1415926535897931 : 0.0, (!flag) ? 3.1415926535897931 : 0.0, e, 0.0).magnitude2d;
            double escapeVelocity = magnitude2d - -celestialBodyData.orbitData.orbitalVelocity;
            float  num4           = (float)(Kepler.GetEjectionAngle(escapeVelocity, ejectionOrbitHeight, celestialBodyData.mass, celestialBodyData.orbitData.SOI) * (double)Math.Sign(-orbit.meanMotion) + ((!flag) ? 3.1415926535897931 : 0.0));
            float  ejectionAngle  = num4 + (float)(Ref.controller.globalTime * celestialBodyData.orbitData._meanMotion) - 1.57079637f;
            TransferWindow.GenerateMeshOrbitTW(ref meshFilterOrbit, ref show, ejectionAngle, orbit);
            return;
        }
        if (transferWindow.transferType != TransferWindow.TransferType.ToSatellite)
        {
            return;
        }
        if (ejectionOrbitHeight > transferWindow.target.orbitData.orbitHeightM * 0.75)
        {
            return;
        }
        float num5           = (float)Kepler.GetPhaseAngle(ejectionOrbitHeight, transferWindow.target.orbitData.orbitHeightM);
        float ejectionAngle2 = num5 + (float)(Ref.controller.globalTime * transferWindow.target.orbitData._meanMotion);

        TransferWindow.GenerateMeshOrbitTW(ref meshFilterOrbit, ref show, ejectionAngle2, orbit);
    }
Exemple #22
0
    private bool CalculateClosestApproach(Orbit orbit, CelestialBodyData targetingPlanet)
    {
        double  num     = double.PositiveInfinity;
        Double3 @double = Double3.zero;
        Double3 a       = Double3.zero;
        bool    flag    = false;

        if (orbit.planet != targetingPlanet)
        {
            List <double> list = new List <double>();
            if (orbit.periapsis < targetingPlanet.orbitData.orbitHeightM && orbit.apoapsis > targetingPlanet.orbitData.orbitHeightM)
            {
                double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(targetingPlanet.orbitData.orbitHeightM, orbit.semiLatusRectum, orbit.eccentricity);
                list.Add(trueAnomalyAtRadius);
                list.Add(-trueAnomalyAtRadius);
            }
            else
            {
                if (!orbit.CanPasSOI(targetingPlanet.orbitData.orbitHeightM, targetingPlanet.mapData.showClosestApproachDistance))
                {
                    return(false);
                }
                if (orbit.apoapsis < targetingPlanet.orbitData.orbitHeightM)
                {
                    list.Add(3.1415927410125732);
                }
                else
                {
                    list.Add(0.0);
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                double nextTrueAnomalyPassageTime = orbit.GetNextTrueAnomalyPassageTime(Ref.controller.globalTime, list[i]);
                if (nextTrueAnomalyPassageTime >= Ref.controller.globalTime)
                {
                    Double3 position       = Kepler.GetPosition(Kepler.GetRadius(orbit.semiLatusRectum, orbit.eccentricity, list[i]), list[i], orbit.argumentOfPeriapsis);
                    Double3 double2        = (!(orbit.planet != targetingPlanet)) ? Double3.zero : targetingPlanet.GetPosOut(nextTrueAnomalyPassageTime);
                    double  sqrMagnitude2d = (position - double2).sqrMagnitude2d;
                    if (sqrMagnitude2d < num)
                    {
                        num     = sqrMagnitude2d;
                        @double = position;
                        a       = double2;
                        flag    = true;
                    }
                }
            }
        }
        else
        {
            @double = Kepler.GetPosition(orbit.periapsis, 0.0, orbit.argumentOfPeriapsis);
            flag    = true;
        }
        if (!flag)
        {
            return(false);
        }
        Transform transform = (!(orbit.planet != targetingPlanet)) ? targetingPlanet.mapRefs.holder : targetingPlanet.parentBody.mapRefs.holder;

        if (this.transferWindow.closestApproachMarker.transform.parent != transform)
        {
            this.transferWindow.closestApproachMarker.transform.parent = transform;
        }
        this.transferWindow.closestApproachMarker.transform.localPosition = (@double / 10000.0).toVector3;
        Double3 double3 = (a - @double) / 10000.0;

        this.transferWindow.closestApproachMarker.SetPosition(1, double3.toVector3);
        this.transferWindow.closestApproachMarker.sharedMaterial.mainTextureScale = new Vector2(Mathf.Max(1.6f, (float)(double3.magnitude2d / -(float)this.mapPosition.z * 80.0) + 0.6f), 1f);
        return(true);
    }
Exemple #23
0
 private Data(TransferWindow.TransferType transferType, CelestialBodyData departure, CelestialBodyData target, CelestialBodyData firstNeighbour, CelestialBodyData secondNeighbour)
 {
     this.transferType    = transferType;
     this.departure       = departure;
     this.target          = target;
     this.firstNeighbour  = firstNeighbour;
     this.secondNeighbour = secondNeighbour;
     this.phaseAngle      = double.NaN;
     this.phaseAngle      = ((transferType != TransferWindow.TransferType.ToNeighbour) ? double.NaN : Kepler.GetPhaseAngle(firstNeighbour, secondNeighbour));
 }
Exemple #24
0
 public BaseProtocol(Kepler KeplerInterface)
 {
     this.keplerInterface = KeplerInterface;
     this.ReceiverQueue   = new ConcurrentQueue <KeplerCommand>();
     PeriodicHandler      = new PeriodicMessageHandler();
 }
Exemple #25
0
 public SystemProtocol(Kepler KeplerInterface) : base(KeplerInterface)
 {
 }
Exemple #26
0
 private void UpdatePhaseAngle()
 {
     this.transferWindow.phaseAngle = Kepler.GetPhaseAngle(this.transferWindow.firstNeighbour, this.transferWindow.secondNeighbour);
     this.GenerateTransferWindowMarker(this.transferWindow.markerMesh, 0.05f, -0.005f, (float)(this.transferWindow.firstNeighbour.orbitData.orbitHeightM / 10000.0), this.transferWindow.firstNeighbour.parentBody.mapRefs.holder);
     this.UpdateTranserWindowMarkerAlpha(this.transferWindowMaterial, this.transferWindow.firstNeighbour.orbitData.orbitHeightM * 0.5);
 }