private void RemoveGhostBodies()
 {
     foreach (NBody nbody in ghostShip)
     {
         ge.RemoveBody(nbody.gameObject);
         Destroy(nbody.gameObject);
     }
     foreach (NBody nbody in ghostMoon)
     {
         ge.RemoveBody(nbody.gameObject);
         Destroy(nbody.gameObject);
     }
 }
    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;
    }
Esempio n. 3
0
    private void Deactivate()
    {
        // Get CM object pos & vel from GE
        GravityEngine ge    = GravityEngine.Instance();
        Vector3d      cmPos = ge.GetPositionDoubleV3(cmNbody);
        Vector3d      cmVel = ge.GetVelocityDoubleV3(cmNbody);

        int i = 0;

        foreach (NBody nbody in nbodies)
        {
            Rigidbody rb = nbody.GetComponentInChildren <Rigidbody>();
            if (rb == null)
            {
                Debug.LogWarning("could not find rigidbody for  " + nbody.gameObject.name);
                continue;
            }
            // rb.isKinematic = true;
            // set position and velocity
            Vector3d nbodyVel = new Vector3d(GravityScaler.ScaleVelSceneToPhys(rb.velocity));
            ge.SetVelocityDoubleV3(nbody, cmVel + nbodyVel);
            Vector3d nbodyPos = new Vector3d(GravityScaler.ScalePositionSceneToPhys(nbody.transform.localPosition));
            ge.SetPositionDoubleV3(nbody, cmPos + nbodyPos);
            ge.ActivateBody(nbody.gameObject);
            // restore parent
            nbody.transform.parent = priorParents[i];
            i++;
        }
        ge.RemoveBody(cmObject);
        Destroy(cmObject);
        // de-activate any RCS elements
        foreach (ReactionControlSystem r in rcs)
        {
            if (r != null)
            {
                r.SetRigidBodyEnabled(false);
            }
        }
    }