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; } }
private void SwitchFollowingBody(CelestialBodyData newFollow) { Double3 a = Double3.zero; if (newFollow.parentBody == this.following) { a = -newFollow.GetPosOut(Ref.controller.globalTime); } if (this.following.parentBody == newFollow) { a = this.following.GetPosOut(Ref.controller.globalTime); } this.mapPosition += a / 10000.0; this.following = newFollow; }
private void SwitchFollowingBody(CelestialBodyData newFollow) { Double3 @double = Double3.zero; if (newFollow.parentBody == this.following.targetPlanet) { @double = -newFollow.GetPosOut(Ref.controller.globalTime); } if (this.following.targetPlanet.parentBody == newFollow) { @double = this.following.targetPlanet.GetPosOut(Ref.controller.globalTime); } MonoBehaviour.print(@double); this.mapPosition += @double / 10000.0; this.following = new OrbitLines.Target(newFollow); }
private void Update() { this.CheckLoadDistance(); Double3 @double = this.GetGlobalPosition; if (this.state == Vessel.State.RealTime) { @double = Ref.positionOffset + this.partsManager.rb2d.worldCenterOfMass; if (Time.time > this.archivmentCheckTime) { this.archivmentCheckTime = Time.time + 1f; this.CheckForArchivments(); this.CheckOrbitArchivments(new Orbit(@double, this.GetGlobalVelocity, Ref.controller.loadedPlanet)); } if (@double.sqrMagnitude2d > Ref.controller.loadedPlanet.orbitData.SOI * Ref.controller.loadedPlanet.orbitData.SOI) { this.AddArchivment("Escaped " + Ref.controller.loadedPlanet.bodyName + " sphere of influence"); CelestialBodyData parentBody = Ref.controller.loadedPlanet.parentBody; this.mapIcon.parent = parentBody.mapRefs.holder; if (Ref.mainVessel == this) { Ref.controller.EnterTimeWarpMode(); this.EnterNextOrbit(); Ref.controller.ExitTimeWarpMode(); @double = this.GetGlobalPosition; } else { this.partsManager.ReCenter(); Double3 posIn = Ref.controller.loadedPlanet.GetPosOut(Ref.controller.globalTime) + @double; Double3 velIn = Ref.controller.loadedPlanet.GetVelOut(Ref.controller.globalTime) + this.GetGlobalVelocity; this.partsManager.rb2d.bodyType = RigidbodyType2D.Static; this.partsManager.rb2d.gameObject.SetActive(false); this.orbits = Orbit.CalculateOrbits(posIn, velIn, parentBody); this.state = Vessel.State.OnRailsUnloaded; } } CelestialBodyData[] satellites = Ref.controller.loadedPlanet.satellites; for (int i = 0; i < satellites.Length; i++) { CelestialBodyData celestialBodyData = satellites[i]; Double3 double2 = @double - celestialBodyData.GetPosOut(Ref.controller.globalTime); if (double2.sqrMagnitude2d < celestialBodyData.orbitData.SOI * celestialBodyData.orbitData.SOI) { this.AddArchivment("Entered " + celestialBodyData.bodyName + " sphere of influence"); this.mapIcon.parent = celestialBodyData.mapRefs.holder; Double3 posIn2 = double2; Double3 velIn2 = this.GetGlobalVelocity - celestialBodyData.GetVelOut(Ref.controller.globalTime); if (Ref.mainVessel == this) { Ref.controller.EnterTimeWarpMode(); this.EnterNextOrbit(); Ref.controller.ExitTimeWarpMode(); @double = this.GetGlobalPosition; } else { this.partsManager.ReCenter(); this.partsManager.rb2d.bodyType = RigidbodyType2D.Static; this.partsManager.rb2d.gameObject.SetActive(false); this.orbits = Orbit.CalculateOrbits(posIn2, velIn2, celestialBodyData); this.state = Vessel.State.OnRailsUnloaded; } } } if (Ref.mapView) { this.mapIcon.localPosition = (@double / 10000.0).toVector3; this.mapIcon.localRotation = this.partsManager.parts[0].transform.rotation; } } else if (this.state == Vessel.State.OnRails || this.state == Vessel.State.OnRailsUnloaded) { if (this.orbits[0].orbitEndTime < Ref.controller.globalTime) { this.EnterNextOrbit(); @double = this.GetGlobalPosition; } if (this.orbits[0].calculatePassesTime != double.PositiveInfinity && Ref.controller.globalTime > this.orbits[0].calculatePassesTime - this.orbits[0]._period * 0.9 && this.orbits[0].UpdatePass()) { this.orbits = Orbit.CalculateOrbits(this.orbits); if (Ref.selectedVessel == this) { Ref.map.UpdateVesselOrbitLines(this.orbits, true); } } if (Ref.mapView) { this.mapIcon.localPosition = (@double / 10000.0).toVector3; } else if (this.state == Vessel.State.OnRails) { base.transform.position = (@double - Ref.positionOffset).toVector3; } if (Ref.mainVessel != this && @double.magnitude2d - this.orbits[0].planet.radius < this.orbits[0].planet.GetTerrainSampleAtAngle(Math.Atan2(@double.y, @double.x) * 57.2958)) { this.DestroyVessel(); } } }
private void TryFollowSattelites() { CelestialBodyData[] satellites = this.following.satellites; for (int i = 0; i < satellites.Length; i++) { CelestialBodyData celestialBodyData = satellites[i]; if (celestialBodyData.orbitData.SOI * 10.0 / 10000.0 > -this.mapPosition.z && (celestialBodyData.GetPosOut(Ref.controller.globalTime) / 10000.0 - this.mapPosition).magnitude2d < celestialBodyData.orbitData.SOI * 3.0 / 10000.0) { this.SwitchFollowingBody(celestialBodyData); } } }
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); }
private void LateUpdate() { if (Ref.mapView) { Double3 b = Double3.zero; if (this.following.type == CelestialBodyData.Type.Star) { b = this.mapPosition.roundTo1000; b.z = this.mapPosition.z; Ref.cam.transform.position = (this.mapPosition - b).toVector3; } else { Ref.cam.transform.position = this.mapPosition.toVector3; if (this.following.type == CelestialBodyData.Type.Planet) { b = this.following.GetPosOut(Ref.controller.globalTime) / 10000.0; } else { b = (this.following.GetPosOut(Ref.controller.globalTime) + this.following.parentBody.GetPosOut(Ref.controller.globalTime)) / 10000.0; } } Ref.solarSystemRoot.mapRefs.holder.position = -b.toVector3; CelestialBodyData[] satellites = Ref.solarSystemRoot.satellites; for (int i = 0; i < satellites.Length; i++) { CelestialBodyData celestialBodyData = satellites[i]; celestialBodyData.mapRefs.holder.position = (celestialBodyData.GetPosOut(Ref.controller.globalTime) / 10000.0 - b).toVector3; celestialBodyData.mapRefs.orbitLine.transform.localEulerAngles = new Vector3(0f, 0f, (float)(Ref.controller.globalTime * celestialBodyData.orbitData._meanMotion) * 57.29578f); CelestialBodyData[] satellites2 = celestialBodyData.satellites; for (int j = 0; j < satellites2.Length; j++) { CelestialBodyData celestialBodyData2 = satellites2[j]; celestialBodyData2.mapRefs.holder.localPosition = (celestialBodyData2.GetPosOut(Ref.controller.globalTime) / 10000.0).toVector3; celestialBodyData2.mapRefs.orbitLine.transform.localEulerAngles = new Vector3(0f, 0f, (float)(Ref.controller.globalTime * celestialBodyData2.orbitData._meanMotion) * 57.29578f); } } bool flag = false; bool flag2 = false; bool flag3 = false; bool flag4 = false; if (Ref.selectedVessel != null) { List <Orbit> list = new List <Orbit>(); if (Ref.selectedVessel.state == Vessel.State.RealTime) { list = this.UpdateRealtimeVesselOrbitLines(Ref.selectedVessel); } else { list = Ref.selectedVessel.orbits; if (list.Count > 0 && list[0].orbitType == Orbit.Type.Encounter) { this.orbitLines[0].SetPositions(list[0].GenerateOrbitLinePoints(list[0].GetTrueAnomalyOut(Ref.controller.globalTime), list[0].endTrueAnomaly + (double)(12.566371f * (float)Math.Sign(list[0].meanMotion)), 200)); } } flag4 = (list.Count > 0); flag = (this.transferWindow.target != null && this.GetClosestApproach(list, this.transferWindow.target)); if (this.transferWindow.transferType != Map.TransferType.None) { if (this.transferWindow.transferType == Map.TransferType.ToNeighbour) { double num = this.transferWindow.phaseAngle + Ref.controller.globalTime * this.transferWindow.secondNeighbour.orbitData._meanMotion; this.transferWindow.markerMesh.transform.localEulerAngles = new Vector3(0f, 0f, (float)num * 57.29578f); flag2 = true; } flag3 = (list.Count > 0 && list[0].orbitType != Orbit.Type.Encounter); if (flag3) { flag3 = this.UpdateLocalTransferWindowMarker(Math.Min(list[0].periapsis * 1.2, list[0].apoapsis), list[0]); if (flag3) { this.UpdateTranserWindowMarkerAlpha(this.localTransferWindowMaterial, list[0].periapsis); } } } } if (this.transferWindow.closestApproachMarker.gameObject.activeSelf != flag) { this.transferWindow.closestApproachMarker.gameObject.SetActive(flag); } if (this.transferWindow.markerMesh.gameObject.activeSelf != flag2) { this.transferWindow.markerMesh.gameObject.SetActive(flag2); } if (this.transferWindow.localMarkerMesh.gameObject.activeSelf != flag3) { this.transferWindow.localMarkerMesh.gameObject.SetActive(flag3); } if (!flag4 && this.orbitLines[0].gameObject.activeSelf) { LineRenderer[] array = this.orbitLines; for (int k = 0; k < array.Length; k++) { LineRenderer lineRenderer = array[k]; lineRenderer.gameObject.SetActive(false); } } } }