// 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());
        }
    }
示例#2
0
 void FixedUpdate()
 {
     if (!running)
     {
         running = true;
         gravityEngine.SetEvolve(true);
     }
 }
    private void ExecuteTransfer()
    {
        // Need to account for phasing, rotate ship forward to correct launch point and
        // rotate TLI vector. (This assumes circular orbit in the XY plane with the planet at the origin!)
        // Should set as a maneuver, but just jump there for demonstration code
        double transferTime = tflightFactor * lambertU.GetTMin();

        float moonOmega    = (float)System.Math.Sqrt(ge.GetMass(planet)) / Mathf.Sqrt(moonRadius * moonRadius * moonRadius);
        float shipThetaDeg = (float)(transferTime * moonOmega) * Mathf.Rad2Deg;

        Debug.LogFormat("t={0} theta={1} deg. omega={2} rad", transferTime, shipThetaDeg, moonOmega);
        // Inclination support. Recompute the transfer using inclination
        // @TODO: HACK XY only
        Vector3 shipPos       = ge.GetPhysicsPosition(spaceship);
        Vector3 shipPosPhased = Quaternion.AngleAxis(shipThetaDeg, Vector3.forward) * shipPos;
        Vector3 shipVelPhased = Quaternion.AngleAxis(shipThetaDeg, Vector3.forward) * lambertU.GetTransferVelocity();

        if (onRails)
        {
            TransferOnRails(transferTime, shipPosPhased, shipVelPhased, moonOmega);
        }
        else
        {
            Debug.LogFormat("tli NBody mode r={0} v={1}", shipPosPhased, shipVelPhased);
            ge.UpdatePositionAndVelocity(spaceship, shipPosPhased, shipVelPhased);
        }

        // remove placeholder ships/orbit visualizers
        ge.RemoveBody(shipExitSOI.gameObject);
        shipExitSOI.gameObject.SetActive(false);
        ge.RemoveBody(shipEnterSOI.gameObject);
        shipEnterSOI.gameObject.SetActive(false);
        SetOrbitDisplays(false);

        ge.SetEvolve(true);
        running = true;
    }