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(); }
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(); }
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); }