/// <summary> /// Raise a circular orbit by the specified percent /// - only on-rail is implemented /// </summary> /// <param name="percentRaise"></param> private void NewCircularOrbit(float percentRaise) { if (onRails) { KeplerSequence keplerSeq = spaceship.GetComponent <KeplerSequence>(); OrbitUniversal orbitU = keplerSeq.GetCurrentOrbit(); // check orbit is circular if (orbitU.eccentricity < 1E-2) { // circular, ok to proceed OrbitData fromOrbit = new OrbitData(orbitU); OrbitData toOrbit = new OrbitData(fromOrbit); toOrbit.a = percentRaise * fromOrbit.a; const bool rendezvous = false; OrbitTransfer hohmannXfer = new HohmannXfer(fromOrbit, toOrbit, rendezvous); keplerSeq.RemoveFutureSegments(); keplerSeq.AddManeuvers(hohmannXfer.GetManeuvers()); } } else { // assume we're in orbit around the moon OrbitData orbitData = new OrbitData(); orbitData.SetOrbitForVelocity(spaceship, moonBody); OrbitData toOrbit = new OrbitData(orbitData); toOrbit.a = percentRaise * orbitData.a; const bool rendezvous = false; OrbitTransfer hohmannXfer = new HohmannXfer(orbitData, toOrbit, rendezvous); ge.AddManeuvers(hohmannXfer.GetManeuvers()); } }
// Update is called once per frame void Update() { if (Input.GetKeyUp(KeyCode.H)) { OrbitData shipOrbit = new OrbitData(); shipOrbit.SetOrbitForVelocity(shipNbody, centerNbody); OrbitData targetOrbit = new OrbitData(); targetOrbit.SetOrbitForVelocity(targetNbody, centerNbody); // determine the transfer orbitTransfer = new HohmannXfer(shipOrbit, targetOrbit, rendezvous); // If this is a ship with a Kepler sequence take the maneuvers and add them as KeplerSequence elements // This allows the transfer to be time-reversible if the whole scene is on rails. if (keplerSeq != null) { keplerSeq.AddManeuvers(orbitTransfer.GetManeuvers()); } else { // Nbody evolution (or plain onRails w/o KeplerSequence) use maneuvers foreach (Maneuver m in orbitTransfer.GetManeuvers()) { GravityEngine.Instance().AddManeuver(m); } } // Maneuver markers if (markerPrefab != null) { foreach (Maneuver m in orbitTransfer.GetManeuvers()) { // set maneuver position marker GameObject marker = Instantiate(markerPrefab, centerNbody.gameObject.transform, true); marker.transform.position = m.physPosition.ToVector3(); markers.Add(marker); m.onExecuted = RemoveMarker; } } } if (Input.GetKeyUp(KeyCode.C)) { // clear maneuvers GravityEngine.Instance().ClearManeuvers(); // delete on rails maneuvers if (keplerSeq != null) { keplerSeq.RemoveManeuvers(orbitTransfer.GetManeuvers()); } foreach (GameObject marker in markers) { Destroy(marker); } markers.Clear(); } // optionally report time to next maneuver // for now just do first maneuver if ((timeToManeuverText != null) && (orbitTransfer != null)) { double time = orbitTransfer.GetManeuvers()[0].worldTime - GravityEngine.Instance().GetPhysicalTime(); timeToManeuverText.text = string.Format("Time to Next Maneuver = {0:0.00}", time); } }
/// <summary> /// Circularize around Moon /// - currently only onRails is implemented /// </summary> private void CircularizeAroundMoon() { // check ship is on segment where it near Moon if (onRails) { KeplerSequence keplerSeq = spaceship.GetComponent <KeplerSequence>(); OrbitUniversal orbitU = keplerSeq.GetCurrentOrbit(); if (orbitU.centerNbody == moonBody) { // in orbit around the moon - do circularization OrbitData orbitData = new OrbitData(orbitU); OrbitTransfer circularizeXfer = new CircularizeXfer(orbitData); keplerSeq.RemoveFutureSegments(); keplerSeq.AddManeuvers(circularizeXfer.GetManeuvers()); } } else { // assume we're in orbit around the moon OrbitData orbitData = new OrbitData(); orbitData.SetOrbitForVelocity(spaceship, moonBody); OrbitTransfer circularizeXfer = new CircularizeXfer(orbitData); ge.AddManeuvers(circularizeXfer.GetManeuvers()); } }
// Update is called once per frame void Update() { if (Input.GetKeyUp(KeyCode.C)) { OrbitData currentOrbit = new OrbitData(); currentOrbit.SetOrbitForVelocity(shipNbody, centerNbody); // circularize the orbit OrbitTransfer t = new CircularizeXfer(currentOrbit); // If this is a ship with a Kepler sequence take the maneuvers and add them as KeplerSequence elements // This allows the transfer to be time-reversible if the whole scene is on rails. if (keplerSeq != null) { keplerSeq.AddManeuvers(t.GetManeuvers()); } else { // Nbody evolution (or plain onRails w/o KeplerSequence) use maneuvers GravityEngine.Instance().AddManeuver(t.GetManeuvers()[0]); } } else if (Input.GetKeyDown(KeyCode.R)) { // return orbit to GravityEngine control (go Off-Rails) if (keplerSeq != null) { keplerSeq.AppendReturnToGE(GravityEngine.Instance().GetPhysicalTime(), shipNbody); } } else if (Input.GetKeyDown(KeyCode.W)) { // return orbit to GravityEngine control (go Off-Rails) GravityEngine.Instance().ApplyImpulse(shipNbody, Vector3.up); } }
/// <summary> /// Raise a circular orbit by the specified percent /// - only on-rail is implemented /// </summary> /// <param name="percentRaise"></param> private void NewCircularOrbit(float percentRaise) { KeplerSequence keplerSeq = spaceship.GetComponent <KeplerSequence>(); OrbitUniversal orbitU = keplerSeq.GetCurrentOrbit(); // check orbit is circular if (orbitU.eccentricity < 1E-2) { // circular, ok to proceed OrbitData fromOrbit = new OrbitData(orbitU); OrbitData toOrbit = new OrbitData(fromOrbit); toOrbit.a = percentRaise * fromOrbit.a; const bool rendezvous = false; OrbitTransfer hohmannXfer = new HohmannXfer(fromOrbit, toOrbit, rendezvous); keplerSeq.RemoveFutureSegments(); keplerSeq.AddManeuvers(hohmannXfer.GetManeuvers()); } }