// 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>
 /// Sets a series of maneuvers required to execute an orbital transfer.
 ///
 /// Maneuvers are passed on to the GravityEngine to be executed on the correct
 /// integrator timeslice.
 /// </summary>
 ///
 /// <param name="transfer">The transfer</param>
 public void SetTransfer(OrbitTransfer transfer)
 {
     foreach (Maneuver m in transfer.GetManeuvers())
     {
         m.onExecuted = ManeuverExecutedCallback;
         GravityEngine.Instance().AddManeuver(m);
         maneuverList.Add(m);
     }
 }
Beispiel #3
0
    /// <summary>
    /// Update the UI fields based on the transfer
    /// </summary>
    public void UpdateUI(OrbitTransfer transfer)
    {
        this.transfer = transfer;

        titleText.text   = transfer.ToString();
        summaryText.text = string.Format("dV={0:0.00} time={1:0.00}", transfer.GetDeltaV(), transfer.GetDeltaT());

        // maneuvers
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("Maneuvers:\n");
        foreach (Maneuver m in transfer.GetManeuvers())
        {
            sb.Append(string.Format("time={0:0.0}  dV={1:0.0}\n", m.worldTime, m.dV));
        }
        maneuverText.text = sb.ToString();
    }
Beispiel #4
0
    /// <summary>
    /// Factory method to instantiate and initialize a UI widget to present an orbit transfer. The
    /// specific transfer widget will present its input attributes and allow then to be changed.
    ///
    /// Select calls back into the controller.
    ///
    /// </summary>
    /// <param name="transfer"></param>
    /// <param name="controller"></param>
    /// <returns></returns>
    public GameObject GetUIWidget(OrbitTransfer transfer, OrbitMGController controller)
    {
        GameObject newWidget = null;

        if (transfer.GetType() == typeof(HohmannXfer))
        {
            newWidget = Instantiate(hohmannUIPrefab) as GameObject;
        }
        else if (transfer.GetType() == typeof(PatchedConicXfer))
        {
            newWidget = Instantiate(patchedConicUIPrefab) as GameObject;
        }
        else if (transfer.GetType() == typeof(BiellipticXfer))
        {
            newWidget = Instantiate(biellipticUIPrefab) as GameObject;
        }
        else
        {
            Debug.LogError("Unsupported transfer type: " + transfer.GetType());
        }

        if (newWidget != null)
        {
            OrbitXferUI orbitXferUI = newWidget.GetComponent <OrbitXferUI>();
            if (orbitXferUI != null)
            {
                orbitXferUI.SetController(controller);
                orbitXferUI.UpdateUI(transfer);
            }
            else
            {
                Debug.LogError("No OrbitXferUI component on " + newWidget.name);
            }
        }

        return(newWidget);
    }
    //-------------------------------------------------------------------------
    // Transfer/Maneuver calculations
    //-------------------------------------------------------------------------

    public void OrbitTransferSelected(OrbitTransfer transfer)
    {
        spaceshipCtrl.SetTransfer(transfer);
        ClearUIWidgets();
        SetState(State.MANEUVER);
    }