/// <summary> /// Callback to compute the launch transfer times and display them in the scene. /// </summary> public void Compute() { int itemNo = destDropdown.value; NBody toNbody = destinations[itemNo].GetComponent <NBody>(); OrbitData fromOrbit = new OrbitData(); fromOrbit.SetOrbit(fromNbody, centerNbody); OrbitData toOrbit = new OrbitData(); toOrbit.SetOrbit(toNbody, centerNbody); HohmannXfer hohmannXfer = new HohmannXfer(fromOrbit, toOrbit, true); // Find launch windows double[] times = hohmannXfer.LaunchTimes(numWindows); List <Dropdown.OptionData> items = new List <Dropdown.OptionData>(); foreach (double t in times) { Dropdown.OptionData item = new Dropdown.OptionData(); item.text = GravityScaler.GetWorldTimeFormatted(t, GravityScaler.Units.SOLAR); items.Add(item); } launchTimes.ClearOptions(); launchTimes.AddOptions(items); }
// Update is called once per frame void Update() { if (!frame1Hack) { frame1Hack = true; AddGhostBodies(); ComputeBaseTransferTime(); // need GE to process these updates Debug.LogFormat("Moon period={0:0.0}", ghostMoonOrbit[MOON_SOI_ENTER].GetPeriod()); } if (!running) { // Getting user input for FR AdjustTimeOfFlight(); UpdateManeuverSymbols(); HandleMouseSOIInput(); ComputeTransfer(); if (freeReturnInfo != null) { freeReturnInfo.text = string.Format("Perilune = {0:0.0}\nReturn Perigee={1:0.0}\nTime to SOI = {2:0.0}\n{3}", ghostShipOrbit[SOI_HYPER].GetPerigee(), ghostShipOrbit[EXIT_SOI].GetPerigee(), timeHohmann * tflightFactor, GravityScaler.GetWorldTimeFormatted(timeHohmann * tflightFactor, ge.units)); } } else { // RUNNING if (Input.GetKeyUp(KeyCode.C)) { // Circularize (if in the vicinity of the moon) CircularizeAroundMoon(); } else if (Input.GetKeyUp(KeyCode.R)) { // Raise circular orbit but Hohmann Xfer NewCircularOrbit(1.3f); } return; } if (Input.GetKeyUp(KeyCode.X)) { // execute the transfer ExecuteTransfer(); if (instructions != null) { instructions.gameObject.SetActive(false); } running = true; } else if (Input.GetKeyUp(KeyCode.Space)) { ge.SetEvolve(!ge.GetEvolve()); } }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.A)) { fromPhase += PHASE_PER_KEY; } else if (Input.GetKey(KeyCode.S)) { fromPhase -= PHASE_PER_KEY; } else if (Input.GetKey(KeyCode.Q)) { toPhase += PHASE_PER_KEY; } else if (Input.GetKey(KeyCode.W)) { toPhase -= PHASE_PER_KEY; } fromPhase = NUtils.DegreesMod360(fromPhase); toPhase = NUtils.DegreesMod360(toPhase); SetMarkers(); shipOrbitData.SetOrbitForVelocity(spaceshipNBody, shipOrbit.centerNbody); // Determine TOF Vector3d from = new Vector3d(shipOrbitData.GetPhysicsPositionforEllipse(fromPhase)); Vector3d to = new Vector3d(shipOrbitData.GetPhysicsPositionforEllipse(toPhase)); Vector3d shipPos = GravityEngine.instance.GetPositionDoubleV3(spaceshipNBody); double tPeri = shipOrbit.TimeOfFlight(shipPos, new Vector3d(shipOrbitData.GetPhysicsPositionforEllipse(0f))); double tApo = shipOrbit.TimeOfFlight(shipPos, new Vector3d(shipOrbitData.GetPhysicsPositionforEllipse(180f))); double tof = shipOrbit.TimeOfFlight(from, to); // Scale to game time //tApo = GravityScaler.ScaleToGameSeconds((float) tApo); //tPeri = GravityScaler.ScaleToGameSeconds((float)tPeri); //tof = GravityScaler.ScaleToGameSeconds((float)tof); //tofText.text = string.Format("Time of Flight = {0:#.#}\nTime to Apoapsis = {1:#.#}\nTime to Periapsis = {2:#.#}\ntau = {3}", // tof, tApo, tPeri, shipOrbitData.tau); GravityScaler.Units units = GravityEngine.instance.units; tofText.text = string.Format("Time of Flight = {0}\nTime to Apoapsis = {1}\nTime to Periapsis = {2}\ntau = {3}", GravityScaler.GetWorldTimeFormatted(tof, units), GravityScaler.GetWorldTimeFormatted(tApo, units), GravityScaler.GetWorldTimeFormatted(tPeri, units), GravityScaler.GetWorldTimeFormatted(shipOrbitData.tau, units)); }