コード例 #1
0
ファイル: Orbit.cs プロジェクト: TruthfulGnome/SFSModLoader
 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);
 }