Beispiel #1
0
 public void CreateOrbit()
 {
     if (orbitData.randomized || WarpDrivers.WarpDrive.seedString == AstroUtils.KERBIN_SYSTEM_COORDS)
     {
         // Already randomized data
         return;
     }
     orbitData            = new OrbitData();
     orbitData.randomized = true;
     if (IsSun())
     {
         // Special case
         orbitData.referenceBody = solarSystem.sun;
         orbitData.semiMajorAxis = 0;
         return;
     }
     #region Reference Body
     CreateReferenceBody();
     #endregion
     #region Gravity
     CreateGravity();
     #endregion
     #region Sphere of Influence
     CreateSphereOfInfluence();
     #endregion
     #region Semi-Major Axis
     double semiMajorAxis = AstroUtils.MAX_SEMI_MAJOR_AXIS;
     if (referenceBodyData.IsSun())
     {
         semiMajorAxis = CreatePlanet();
     }
     else
     {
         // Planet is moon
         semiMajorAxis = CreateMoon();
     }
     // Remove eccentricity from the semi-major axis
     if (orbitData.eccentricity != 1.0f)
     {
         semiMajorAxis /= (1.0 - orbitData.eccentricity);
     }
     orbitData.semiMajorAxis = semiMajorAxis;
     #endregion
     #region Inclination
     // New way uses normal distribution
     double normalRNG = WarpRNG.GenerateNormalRandom();
     double normalInc = normalRNG * 5.0;
     orbitData.inclination = normalInc;
     #endregion
     #region Eccentricity
     // Eccentricity must be a value between 0 and 0.99
     // We prefer low values
     normalRNG = WarpRNG.GenerateNormalRandom();
     // We want to try to clamp the range somewhere between 0 and 0.1, since that produces results most similar to KSP
     double eccentRNG = normalRNG * 0.01666667;
     eccentRNG += 0.05;
     if (eccentRNG < 0)
     {
         eccentRNG *= -1.0;
     }
     double eccentricity = eccentRNG;
     orbitData.eccentricity = eccentricity;
     #endregion
     #region Longitude Ascending Node
     int lan = WarpRNG.GenerateInt(0, 360);
     orbitData.longitudeAscendingNode = lan;
     #endregion
     #region Argument Of Periapsis
     int argumentOfPeriapsis = WarpRNG.GenerateInt(0, 360);
     orbitData.argumentOfPeriapsis = argumentOfPeriapsis;
     #endregion
     #region Mean Anomaly at Epoch
     float meanAnomalyAtEpoch = WarpRNG.GenerateFloat(0.0f, Mathf.PI * 2.0f);
     if (orbitData.semiMajorAxis < 0)
     {
         meanAnomalyAtEpoch /= Mathf.PI;
         meanAnomalyAtEpoch -= 1.0f;
         meanAnomalyAtEpoch *= 5.0f;
     }
     orbitData.meanAnomalyAtEpoch = meanAnomalyAtEpoch;
     #endregion
     #region Period
     double referenceMass = AstroUtils.MassInSolarMasses(referenceBody.Mass);
     double usMass        = AstroUtils.MassInSolarMasses(planet.Mass);
     orbitData.period = AstroUtils.CalculatePeriodFromSemiMajorAxis(semiMajorAxis, referenceMass, usMass);
     #endregion
 }